Skip to content

Instantly share code, notes, and snippets.

@jotak
Last active October 29, 2015 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jotak/de86105d72d3e7d7c2b2 to your computer and use it in GitHub Desktop.
Save jotak/de86105d72d3e7d7c2b2 to your computer and use it in GitHub Desktop.
Uniqueness
// Check out Uniqueness API: https://github.com/jotak/jmisc/tree/master/jotak-misc/src/main/java/com/jotak/misc/collection
// Build a collection with removed duplicates on a custom criteria, regardless the "equals" and "hashCode" of the data object
// Here we build a "unique key" based on Something::getField1
final List<Something> allFields = Uniqueness.from(inputList)
.constraintOn(ImmutableList.of(Something::getField1))
.asList();
private static final class Something {
private final int field1;
private final int field2;
private Something(final int field1, final int field2) {
this.field1 = field1;
this.field2 = field2;
}
public int getField1() {
return field1;
}
public int getField2() {
return field2;
}
}
@jotak
Copy link
Author

jotak commented Oct 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment