com.softicar.platform.common.core.utils.equals.IEqualsComparer Maven / Gradle / Ivy
Show all versions of platform-common Show documentation
package com.softicar.platform.common.core.utils.equals;
import java.util.function.Function;
/**
* Interface to compare two objects for equality.
*
* @author Oliver Richers
*/
public interface IEqualsComparer {
/**
* Compares the two objects for equality.
*
* If both objects are the same or if both objects are null,
* true will be returned without any further evaluation.
*
* @param first
* the first object (may be null)
* @param second
* the second object (may be null)
* @return true if both object are equal or both arguments are null;
* false otherwise
*/
boolean compare(T first, T second);
/**
* Compares the two objects for equality.
*
* If both objects are the same or if both objects are null,
* true will be returned without any further evaluation.
*
* This method is helpful when implementing {@link Object#equals(Object)}
* methods. The second object can be of arbitrary type. To be considered
* equal to the first object, the second object must implement the same
* class.
*
* @param thisObject
* the first object (may be null)
* @param otherObject
* the second object (may be null)
* @return true if both object are equal or both arguments are null;
* false otherwise
*/
boolean compareToObject(T thisObject, Object otherObject);
/**
* Extends this {@link IEqualsComparer} with the comparison of the values
* returned by the given key extractor.
*
* The given key extractor need not be null-safe, that is, it can assume
* that its parameter will never be null.
*
* @param keyExtractor
* the key extractor (never null)
* @return the extended {@link IEqualsComparer} (never null)
*/
IEqualsComparer comparing(Function keyExtractor);
/**
* Extends this {@link IEqualsComparer} with the given
* {@link IEqualsComparer}.
*
* This and the given {@link IEqualsComparer} are combined using the logical
* and operation.
*
* @param otherComparer
* the other comparer (never null)
* @return the extended comparer (never null)
*/
IEqualsComparer comparing(IEqualsComparer otherComparer);
}