All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.commons.equivalence.IdentityEquivalence Maven / Gradle / Ivy

There is a newer version: 9.1.7.Final
Show newest version
package org.infinispan.commons.equivalence;

/**
 * {@link org.infinispan.commons.equivalence.Equivalence} implementation that uses the {@link
 * java.lang.System#identityHashCode(Object)} as hash code function.
 *
 * @author Pedro Ruivo
 * @since 7.1
 */
public class IdentityEquivalence implements Equivalence {

   @Override
   public int hashCode(Object obj) {
      return System.identityHashCode(obj);
   }

   @Override
   public boolean equals(T obj, Object otherObj) {
      return obj != null ? obj.equals(otherObj) : otherObj == null;
   }

   @Override
   public String toString(Object obj) {
      return String.valueOf(obj);
   }

   @Override
   public boolean isComparable(Object obj) {
      return obj instanceof Comparable;
   }

   @Override
   public int compare(T obj, T otherObj) {
      //noinspection unchecked
      return ((Comparable) obj).compareTo(otherObj);
   }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy