dev.marksman.collectionviews.SetHelpers Maven / Gradle / Ivy
Show all versions of collection-views Show documentation
package dev.marksman.collectionviews;
/**
* Helper methods for implementers of custom {@link Set}s.
*
* If you are implementing a custom {@link Set}, your {@code equals} and {@code hashCode}
* methods SHOULD delegate to {@code setEquals} and {@code setHashCode}, respectively. This will
* ensure that equality works correctly with the built-in {@link Set} types.
*
* Your {@code toString} method MAY delegate to {@code setToString}.
*/
@SuppressWarnings("WeakerAccess")
public final class SetHelpers {
private SetHelpers() {
}
@SuppressWarnings("unchecked")
public static boolean setEquals(Set> set, Set> other) {
if (set == null || other == null) {
return false;
}
if (other == set) {
return true;
}
if (other.size() != set.size()) {
return false;
}
return containsAllElements((Set