Package org.zkoss.lang
Class Objects
- java.lang.Object
-
- org.zkoss.lang.Objects
-
public class Objects extends java.lang.ObjectUtilities related to the Object class.- Author:
- tomyeh
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.CharacterNULL_CHARACTERThe null character.static java.lang.ObjectUNKNOWNDenotes unknown.static java.math.BigDecimalZERO_BIG_DECIMALRepresents 0 in big decimal.static java.math.BigIntegerZERO_BIG_INTEGERRepresents 0 in big integer.static java.lang.ByteZERO_BYTEThe zero integer.static java.lang.DoubleZERO_DOUBLEThe zero double.static java.lang.FloatZERO_FLOATThe zero float.static java.lang.IntegerZERO_INTEGERThe zero integer.static java.lang.LongZERO_LONGThe zero long.static java.lang.ShortZERO_SHORTThe zero short.
-
Constructor Summary
Constructors Constructor Description Objects()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.Objectclone(java.lang.Object o)Clones the specified object.static booleanequals(java.lang.Object a, java.lang.Object b)Tests whether two objects are equals.static inthashCode(boolean[] v)Generates hash codes for an array of boolean.static inthashCode(byte[] v)Generates hash codes for an array of bytes.static inthashCode(byte[] v, int len)Generates hash codes for an array of bytes up to the specified length.static inthashCode(char[] v)Generates hash codes for an array.static inthashCode(int[] v)Generates hash codes for an array.static inthashCode(long[] v)Generates hash codes for an array.static inthashCode(short[] v)Generates hash codes for an array.static inthashCode(java.lang.Object o)Returns the object's hash code, or zero if null.static intnextHashCode(int prevHashVal, int newVal)Returns the next hash value by giving the previous one and a new one.static byte[]toByteArray(byte v)Converts a byte to a big-endian byte array.static byte[]toByteArray(int v)Converts an integer to a big-endian byte array.static byte[]toByteArray(long v)Converts a long to a big-endian byte array.static byte[]toByteArray(short v)Converts a short to a big-endian byte array.static char[]toCharArray(java.lang.Object o)Converts any object to a character array.static java.lang.StringtoString(java.lang.Object o)Converts any object to a string.
-
-
-
Field Detail
-
UNKNOWN
public static final java.lang.Object UNKNOWN
Denotes unknown. It is useful if both null and unknown is required.
-
ZERO_LONG
public static final java.lang.Long ZERO_LONG
The zero long.
-
ZERO_INTEGER
public static final java.lang.Integer ZERO_INTEGER
The zero integer.
-
ZERO_SHORT
public static final java.lang.Short ZERO_SHORT
The zero short.
-
ZERO_BYTE
public static final java.lang.Byte ZERO_BYTE
The zero integer.
-
ZERO_FLOAT
public static final java.lang.Float ZERO_FLOAT
The zero float.
-
ZERO_DOUBLE
public static final java.lang.Double ZERO_DOUBLE
The zero double.
-
ZERO_BIG_DECIMAL
public static final java.math.BigDecimal ZERO_BIG_DECIMAL
Represents 0 in big decimal. The same asBigDecimals.ZERO.- See Also:
BigDecimals.ONE
-
ZERO_BIG_INTEGER
public static final java.math.BigInteger ZERO_BIG_INTEGER
Represents 0 in big integer. Same asBigIntegers.ZERO.
-
NULL_CHARACTER
public static final java.lang.Character NULL_CHARACTER
The null character.
-
-
Method Detail
-
nextHashCode
public static final int nextHashCode(int prevHashVal, int newVal)Returns the next hash value by giving the previous one and a new one. The caller usually uses a loop to accumulate all related fields.- Parameters:
prevHashVal- the previous hash value returned by this method; 0 if it is the first call.newVal- the new value to put in- Returns:
- the new hash value
-
hashCode
public static final int hashCode(boolean[] v)
Generates hash codes for an array of boolean. It is suggested to cache the hash code.- Parameters:
v- the array- Returns:
- the hash code
-
hashCode
public static final int hashCode(byte[] v)
Generates hash codes for an array of bytes. It is suggested to cache the hash code.- Parameters:
v- the array- Returns:
- the hash code
-
hashCode
public static final int hashCode(byte[] v, int len)Generates hash codes for an array of bytes up to the specified length. It is suggested to cache the hash code.- Parameters:
v- the arraylen- the maximal length to generate hashCode- Returns:
- the hash code
-
hashCode
public static final int hashCode(char[] v)
Generates hash codes for an array. It is suggested to cache the hash code.- Parameters:
v- the array- Returns:
- the hash code
-
hashCode
public static final int hashCode(short[] v)
Generates hash codes for an array. It is suggested to cache the hash code.- Parameters:
v- the array- Returns:
- the hash code
-
hashCode
public static final int hashCode(int[] v)
Generates hash codes for an array. It is suggested to cache the hash code.- Parameters:
v- the byte array- Returns:
- the hash code
-
hashCode
public static final int hashCode(long[] v)
Generates hash codes for an array. It is suggested to cache the hash code.- Parameters:
v- the array- Returns:
- the hash code
-
hashCode
public static final int hashCode(java.lang.Object o)
Returns the object's hash code, or zero if null.
-
equals
public static final boolean equals(java.lang.Object a, java.lang.Object b)Tests whether two objects are equals.It takes care of the null case. Thus, it is helpful to implement Object.equals.
Notice: it uses compareTo if BigDecimal is found. So, in this case, a.equals(b) might not be the same as Objects.equals(a, b).
If both a and b are Object[], they are compared item-by-item.
-
toCharArray
public static final char[] toCharArray(java.lang.Object o)
Converts any object to a character array.- Parameters:
o- the object to convert- Returns:
- the char array or null if o is null
-
toString
public static final java.lang.String toString(java.lang.Object o)
Converts any object to a string. If o is an object array, it invokesArraysX.toString(java.lang.Object[])to make the string more readable.
-
toByteArray
public static final byte[] toByteArray(int v)
Converts an integer to a big-endian byte array.
-
toByteArray
public static final byte[] toByteArray(long v)
Converts a long to a big-endian byte array.
-
toByteArray
public static final byte[] toByteArray(short v)
Converts a short to a big-endian byte array.
-
toByteArray
public static final byte[] toByteArray(byte v)
Converts a byte to a big-endian byte array.
-
clone
public static final java.lang.Object clone(java.lang.Object o)
Clones the specified object. Use clone() if Cloneable. Otherwise, try to serialize/deserialize it by use of MarshalledObject.If o is null, null is returned.
- Throws:
SystemException- if failed to clone
-
-