edu.rice.cs.plt.object
Class ObjectUtil

java.lang.Object
  extended by edu.rice.cs.plt.object.ObjectUtil

public final class ObjectUtil
extends Object

Utility methods that may be useful in implementing an object of any type.


Method Summary
static
<T1,T2> int
compare(Comparator<? super T1> comp1, T1 x1, T1 y1, Comparator<? super T2> comp2, T2 x2, T2 y2)
           
static
<T1,T2,T3> int
compare(Comparator<? super T1> comp1, T1 x1, T1 y1, Comparator<? super T2> comp2, T2 x2, T2 y2, Comparator<? super T3> comp3, T3 x3, T3 y3)
           
static
<T1,T2,T3,T4>
int
compare(Comparator<? super T1> comp1, T1 x1, T1 y1, Comparator<? super T2> comp2, T2 x2, T2 y2, Comparator<? super T3> comp3, T3 x3, T3 y3, Comparator<? super T4> comp4, T4 x4, T4 y4)
           
static
<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>>
int
compare(T1 x1, T1 y1, T2 x2, T2 y2)
           
static
<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>,T3 extends Comparable<? super T3>>
int
compare(T1 x1, T1 y1, T2 x2, T2 y2, T3 x3, T3 y3)
           
static
<T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>,T3 extends Comparable<? super T3>,T4 extends Comparable<? super T4>>
int
compare(T1 x1, T1 y1, T2 x2, T2 y2, T3 x3, T3 y3, T4 x4, T4 y4)
           
static int compositeHeight(Iterable<?> objs)
          Get the maximum composite height of a set of objects.
static int compositeHeight(Object... objs)
          Get the maximum composite height of a set of objects.
static int compositeHeight(Object obj)
          Get the height of the object when treated as a composite.
static int compositeSize(Iterable<?> objs)
          Get the total composite size of a set of objects.
static int compositeSize(Object... objs)
          Get the total composite size of a set of objects.
static int compositeSize(Object obj)
          Get the composite size of the object.
static boolean equal(Object o1, Object o2)
           
static int hash()
          Optimized implementation of hash(int[]) with 0 args.
static int hash(int... keys)
          Produce a hash value based on the given keys according to an algorithm attributed to Knuth (The Art of Programming, Vol.
static int hash(int a)
          Optimized implementation of hash(int[]) with 1 arg.
static int hash(int a, int b)
          Optimized implementation of hash(int[])) with 2 args.
static int hash(int a, int b, int c)
          Optimized implementation of hash(int[]) with 3 args.
static int hash(int a, int b, int c, int d)
          Optimized implementation of hash(int[]) with 4 args.
static int hash(Iterable<?> iter)
          Produce a hash code for an object in which equals() depends on the given values.
static int hash(Object... objs)
          Produce a hash code for an object in which #equals() depends on the given values.
static int hash(Object a)
          Optimized implementation of hash(Object[]) with 1 arg.
static int hash(Object a, Object b)
          Optimized implementation of hash(Object[])) with 2 args.
static int hash(Object a, Object b, Object c)
          Optimized implementation of hash(Object[]) with 3 args.
static int hash(Object a, Object b, Object c, Object d)
          Optimized implementation of hash(Object[]) with 4 args.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equal

public static boolean equal(Object o1,
                            Object o2)

hash

public static int hash()
Optimized implementation of hash(int[]) with 0 args.


hash

public static int hash(int a)
Optimized implementation of hash(int[]) with 1 arg.


hash

public static int hash(int a,
                       int b)
Optimized implementation of hash(int[])) with 2 args.


hash

public static int hash(int a,
                       int b,
                       int c)
Optimized implementation of hash(int[]) with 3 args.


hash

public static int hash(int a,
                       int b,
                       int c,
                       int d)
Optimized implementation of hash(int[]) with 4 args.


hash

public static int hash(int... keys)
Produce a hash value based on the given keys according to an algorithm attributed to Knuth (The Art of Programming, Vol. 3, Sorting and Searching) (TODO: verify this source). The key idea is to combine 32-bit hash keys (where a typical class has multiple hash keys) using exclusive OR after multiplying the existing accumulated result by a large prime number.


hash

public static int hash(Object a)
Optimized implementation of hash(Object[]) with 1 arg.


hash

public static int hash(Object a,
                       Object b)
Optimized implementation of hash(Object[])) with 2 args.


hash

public static int hash(Object a,
                       Object b,
                       Object c)
Optimized implementation of hash(Object[]) with 3 args.


hash

public static int hash(Object a,
                       Object b,
                       Object c,
                       Object d)
Optimized implementation of hash(Object[]) with 4 args.


hash

public static int hash(Object... objs)
Produce a hash code for an object in which #equals() depends on the given values.


hash

public static int hash(Iterable<?> iter)
Produce a hash code for an object in which equals() depends on the given values.


compare

public static <T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>> int compare(T1 x1,
                                                                                                T1 y1,
                                                                                                T2 x2,
                                                                                                T2 y2)

compare

public static <T1,T2> int compare(Comparator<? super T1> comp1,
                                  T1 x1,
                                  T1 y1,
                                  Comparator<? super T2> comp2,
                                  T2 x2,
                                  T2 y2)

compare

public static <T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>,T3 extends Comparable<? super T3>> int compare(T1 x1,
                                                                                                                                  T1 y1,
                                                                                                                                  T2 x2,
                                                                                                                                  T2 y2,
                                                                                                                                  T3 x3,
                                                                                                                                  T3 y3)

compare

public static <T1,T2,T3> int compare(Comparator<? super T1> comp1,
                                     T1 x1,
                                     T1 y1,
                                     Comparator<? super T2> comp2,
                                     T2 x2,
                                     T2 y2,
                                     Comparator<? super T3> comp3,
                                     T3 x3,
                                     T3 y3)

compare

public static <T1 extends Comparable<? super T1>,T2 extends Comparable<? super T2>,T3 extends Comparable<? super T3>,T4 extends Comparable<? super T4>> int compare(T1 x1,
                                                                                                                                                                    T1 y1,
                                                                                                                                                                    T2 x2,
                                                                                                                                                                    T2 y2,
                                                                                                                                                                    T3 x3,
                                                                                                                                                                    T3 y3,
                                                                                                                                                                    T4 x4,
                                                                                                                                                                    T4 y4)

compare

public static <T1,T2,T3,T4> int compare(Comparator<? super T1> comp1,
                                        T1 x1,
                                        T1 y1,
                                        Comparator<? super T2> comp2,
                                        T2 x2,
                                        T2 y2,
                                        Comparator<? super T3> comp3,
                                        T3 x3,
                                        T3 y3,
                                        Comparator<? super T4> comp4,
                                        T4 x4,
                                        T4 y4)

compositeHeight

public static int compositeHeight(Object obj)
Get the height of the object when treated as a composite. If obj implements Composite, invokes Composite.compositeHeight(); otherwise, returns 0.


compositeHeight

public static int compositeHeight(Object... objs)
Get the maximum composite height of a set of objects.


compositeHeight

public static int compositeHeight(Iterable<?> objs)
Get the maximum composite height of a set of objects.


compositeSize

public static int compositeSize(Object obj)
Get the composite size of the object. If obj implements Composite, invokes Composite.compositeSize(); otherwise, returns 1.


compositeSize

public static int compositeSize(Object... objs)
Get the total composite size of a set of objects.


compositeSize

public static int compositeSize(Iterable<?> objs)
Get the total composite size of a set of objects.