Last active
October 29, 2015 07:31
-
-
Save jotak/de86105d72d3e7d7c2b2 to your computer and use it in GitHub Desktop.
Uniqueness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check out Uniqueness API: https://github.com/jotak/jmisc/tree/master/jotak-misc/src/main/java/com/jotak/misc/collection