From ff4244b2b2591fa62638a109aa10c80f4919c7bd Mon Sep 17 00:00:00 2001 From: Alexander Date: Fri, 7 May 2021 09:05:01 +0100 Subject: [PATCH] Add MoreObjectUtils --- .../mc/civmodcore/util/MoreObjectUtils.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/util/MoreObjectUtils.java diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/util/MoreObjectUtils.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/util/MoreObjectUtils.java new file mode 100644 index 000000000..e1a2fb686 --- /dev/null +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/util/MoreObjectUtils.java @@ -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 The left hand object type. + * @param 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 boolean hashEquals(final L lhs, final R rhs) { + return lhs == rhs || (!(lhs == null || rhs == null) && lhs.hashCode() == rhs.hashCode()); + } + +}