mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-10-31 17:25:58 +01:00
EqualsUtil, HashCode: Add methods for lists
This commit is contained in:
parent
0a6c21982b
commit
d4e205beed
2 changed files with 28 additions and 0 deletions
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class EqualsUtil {
|
||||
|
||||
private EqualsUtil() {
|
||||
|
@ -244,6 +246,19 @@ public final class EqualsUtil {
|
|||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public <O> Builder append(List<O> left, List<O> right) {
|
||||
nullSafeCompare(left, right, () -> {
|
||||
if (left.size() != right.size()) {
|
||||
isEquals = false;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < left.size() && isEquals; i++) {
|
||||
append(left.get(i), right.get(i));
|
||||
}
|
||||
});
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.jivesoftware.smack.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HashCode {
|
||||
|
||||
private static final int MULTIPLIER_VALUE = 37;
|
||||
|
@ -203,6 +205,17 @@ public class HashCode {
|
|||
return this;
|
||||
}
|
||||
|
||||
public <O> Builder append(List<O> list) {
|
||||
if (list == null) {
|
||||
applyHash();
|
||||
return this;
|
||||
}
|
||||
for (O o : list) {
|
||||
append(o);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public int build() {
|
||||
return hashcode;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue