core: add shortcut via hash in EqualsUtil

Return false as soon as the hashed value does not match. This is
sound, since every class that implements equals(Object) should also
implement hashCode().
This commit is contained in:
Florian Schmaus 2020-04-13 20:01:20 +02:00
parent 4f609b855c
commit c49999b933
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,6 @@
/**
*
* Copyright 2019 Florian Schmaus.
* Copyright 2019-2020 Florian Schmaus.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -34,6 +34,12 @@ public final class EqualsUtil {
return false;
}
int thisHashCode = thisObject.hashCode();
int otherHashCode = other.hashCode();
if (thisHashCode != otherHashCode) {
return false;
}
EqualsUtil.Builder equalsBuilder = new EqualsUtil.Builder();
equalsComperator.compare(equalsBuilder, thisObjectClass.cast(other));