Package org.zkoss.lang
Class Objects
java.lang.Object
org.zkoss.lang.Objects
Utilities related to the Object class.
- Author:
- tomyeh
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CharacterThe null character.static final ObjectDenotes unknown.static final BigDecimalRepresents 0 in big decimal.static final BigIntegerRepresents 0 in big integer.static final ByteThe zero integer.static final DoubleThe zero double.static final FloatThe zero float.static final IntegerThe zero integer.static final LongThe zero long.static final ShortThe zero short. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final ObjectClones the specified object.static final booleanTests whether two objects are equals.static final inthashCode(boolean[] v) Generates hash codes for an array of boolean.static final inthashCode(byte[] v) Generates hash codes for an array of bytes.static final inthashCode(byte[] v, int len) Generates hash codes for an array of bytes up to the specified length.static final inthashCode(char[] v) Generates hash codes for an array.static final inthashCode(int[] v) Generates hash codes for an array.static final inthashCode(long[] v) Generates hash codes for an array.static final inthashCode(short[] v) Generates hash codes for an array.static final intReturns the object's hash code, or zero if null.static final intnextHashCode(int prevHashVal, int newVal) Returns the next hash value by giving the previous one and a new one.static final byte[]toByteArray(byte v) Converts a byte to a big-endian byte array.static final byte[]toByteArray(int v) Converts an integer to a big-endian byte array.static final byte[]toByteArray(long v) Converts a long to a big-endian byte array.static final byte[]toByteArray(short v) Converts a short to a big-endian byte array.static final char[]Converts any object to a character array.static final StringConverts any object to a string.
-
Field Details
-
UNKNOWN
Denotes unknown. It is useful if both null and unknown is required. -
ZERO_LONG
The zero long. -
ZERO_INTEGER
The zero integer. -
ZERO_SHORT
The zero short. -
ZERO_BYTE
The zero integer. -
ZERO_FLOAT
The zero float. -
ZERO_DOUBLE
The zero double. -
ZERO_BIG_DECIMAL
Represents 0 in big decimal. The same asBigDecimals.ZERO.- See Also:
-
ZERO_BIG_INTEGER
Represents 0 in big integer. Same asBigIntegers.ZERO. -
NULL_CHARACTER
The null character.
-
-
Constructor Details
-
Objects
public Objects()
-
-
Method Details
-
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
Returns the object's hash code, or zero if null. -
equals
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
Converts any object to a character array.- Parameters:
o- the object to convert- Returns:
- the char array or null if o is null
-
toString
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
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
-