This is my code:
private class UniqueClassByTwoIntProperties {
private final int propertyOne;
private final int propertyTwo;
UniqueCase(final int propertyOne, final int propertyTwo) {
this.propertyOne= propertyOne;
this.propertyTwo= propertyTwo;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (this == obj) {
return true;
}
if (!(obj instanceof UniqueCase)) {
return false;
}
UniqueClassByTwoIntProperties unique = (UniqueClassByTwoIntProperties) obj;
return unique.claimApplicationId == claimApplicationId && unique.claimCoverageId == claimCoverageId;
}
@Override
public int hashCode() {
return Objects.hash(propertyOne, propertyTwo);
}
}
I am looping through a list with objects, where I want to get the unique's in the following way:
myList.stream()
.map(row -> new UniqueClassByTwoIntProperties(row.getOne(), row.getTwo()))
.collect(Collectors.toSet());
I was wondering if there was a build-in class/method in Java. I have looked into dictionaries and MultiMapValues, but it was a bit hacky.