Class Objects

java.lang.Object
org.zkoss.lang.Objects

public class Objects extends Object
Utilities related to the Object class.
Author:
tomyeh
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Character
    The null character.
    static final Object
    Denotes unknown.
    static final BigDecimal
    Represents 0 in big decimal.
    static final BigInteger
    Represents 0 in big integer.
    static final Byte
    The zero integer.
    static final Double
    The zero double.
    static final Float
    The zero float.
    static final Integer
    The zero integer.
    static final Long
    The zero long.
    static final Short
    The zero short.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final Object
    Clones the specified object.
    static final boolean
    Tests whether two objects are equals.
    static final int
    hashCode(boolean[] v)
    Generates hash codes for an array of boolean.
    static final int
    hashCode(byte[] v)
    Generates hash codes for an array of bytes.
    static final int
    hashCode(byte[] v, int len)
    Generates hash codes for an array of bytes up to the specified length.
    static final int
    hashCode(char[] v)
    Generates hash codes for an array.
    static final int
    hashCode(int[] v)
    Generates hash codes for an array.
    static final int
    hashCode(long[] v)
    Generates hash codes for an array.
    static final int
    hashCode(short[] v)
    Generates hash codes for an array.
    static final int
    Returns the object's hash code, or zero if null.
    static final int
    nextHashCode(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 String
    Converts any object to a string.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNKNOWN

      public static final Object UNKNOWN
      Denotes unknown. It is useful if both null and unknown is required.
    • ZERO_LONG

      public static final Long ZERO_LONG
      The zero long.
    • ZERO_INTEGER

      public static final Integer ZERO_INTEGER
      The zero integer.
    • ZERO_SHORT

      public static final Short ZERO_SHORT
      The zero short.
    • ZERO_BYTE

      public static final Byte ZERO_BYTE
      The zero integer.
    • ZERO_FLOAT

      public static final Float ZERO_FLOAT
      The zero float.
    • ZERO_DOUBLE

      public static final Double ZERO_DOUBLE
      The zero double.
    • ZERO_BIG_DECIMAL

      public static final BigDecimal ZERO_BIG_DECIMAL
      Represents 0 in big decimal. The same as BigDecimals.ZERO.
      See Also:
    • ZERO_BIG_INTEGER

      public static final BigInteger ZERO_BIG_INTEGER
      Represents 0 in big integer. Same as BigIntegers.ZERO.
    • NULL_CHARACTER

      public static final Character 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 array
      len - 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(Object o)
      Returns the object's hash code, or zero if null.
    • equals

      public static final boolean equals(Object a, 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(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 String toString(Object o)
      Converts any object to a string. If o is an object array, it invokes ArraysX.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 Object clone(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