Merge pull request #95 from Protonull/more-object-utils

Add MoreObjectUtils
This commit is contained in:
wingzero54
2021-05-24 20:49:36 -05:00
committed by GitHub

View File

@@ -0,0 +1,26 @@
package vg.civcraft.mc.civmodcore.util;
import org.apache.commons.lang3.ObjectUtils;
/**
* Utility class that fills in the gaps of {@link ObjectUtils}.
*
* @author Protonull
*/
public final class MoreObjectUtils {
/**
* Determines whether two things are equal based on their respective hash codes. This is obviously less accurate
* than {@link Object#equals(Object)}, however this can be used to, for example, test if an object has been changed.
*
* @param <L> The left hand object type.
* @param <R> The right hand object type.
* @param lhs The left hand object.
* @param rhs THe right hand object.
* @return Returns whether the left hand and right hand objects have matching hashes.
*/
public static <L, R> boolean hashEquals(final L lhs, final R rhs) {
return lhs == rhs || (!(lhs == null || rhs == null) && lhs.hashCode() == rhs.hashCode());
}
}