Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.infinispan.commons.equivalence;

A compare function for objects.

Author(s):
Galder ZamarreƱo
Since:
5.3
 
 public final class AnyEquivalence<T> implements Equivalence<T> {
   private static AnyEquivalence<ObjectOBJECT = new AnyEquivalence<Object>();
   public static AnyEquivalence<StringSTRING = getInstance(String.class);
   public static AnyEquivalence<ByteBYTE = getInstance(Byte.class);
   public static AnyEquivalence<ShortSHORT = getInstance(Short.class);
   public static AnyEquivalence<IntegerINT = getInstance(Integer.class);
   public static AnyEquivalence<LongLONG = getInstance(Long.class);
   public static AnyEquivalence<DoubleDOUBLE  = getInstance(Double.class);
   public static AnyEquivalence<FloatFLOAT = getInstance(Float.class);
   public static AnyEquivalence<BooleanBOOLEAN = getInstance(Boolean.class);
   // To avoid instantiation
   private AnyEquivalence() {
   }
   @Override
   public int hashCode(Object obj) {
      return obj.hashCode();
   }
   @Override
   public boolean equals(T objObject otherObj) {
      return obj != null && obj.equals(otherObj);
   }
   @Override
   public String toString(Object obj) {
      return obj.toString();
   }
   @Override
   public boolean isComparable(Object obj) {
      return obj instanceof Comparable;
   }
   @Override
   @SuppressWarnings("unchecked")
   public int compare(T obj, T otherObj) {
      return ((Comparable<T>) obj).compareTo(otherObj);
   }
   @SuppressWarnings("unchecked")
   public static <T> AnyEquivalence<T> getInstance() {
      return (AnyEquivalence<T>) ;
   }
   @SuppressWarnings("unchecked")
   public static <T> AnyEquivalence<T> getInstance(Class<T> classType) {
      return (AnyEquivalence<T>) ;
   }
New to GrepCode? Check out our FAQ X