`io.kubernetes.client.custom.Quantity` doesn't implement `hashCode`
nulls opened this issue · 1 comments
nulls commented
Describe the bug
io.kubernetes.client.custom.Quantity
has overridden equals
, but a default one for hashCode
. It leads to problem with comparing set of io.kubernetes.client.custom.Quantity
Client Version
20.0.1
To Reproduce
import io.kubernetes.client.custom.Quantity;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
class Scratch {
public static void main(String[] args) {
final List<Quantity> quantityList1 = Stream.of(
Quantity.fromString("200Mi"), Quantity.fromString("300Mi")
).toList();
final List<Quantity> quantityList2 = Stream.of(
Quantity.fromString("200Mi"), Quantity.fromString("300Mi")
).toList();
System.out.println("Comparing as lists: " + Objects.equals(quantityList1, quantityList2)); // true here
final Set<Quantity> quantitySet1 = Stream.of(
Quantity.fromString("200Mi"), Quantity.fromString("300Mi")
).collect(Collectors.toSet());
final Set<Quantity> quantitySet2 = Stream.of(
Quantity.fromString("200Mi"), Quantity.fromString("300Mi")
).collect(Collectors.toSet());
System.out.println("Comparing as sets: " + Objects.equals(quantitySet1, quantitySet2)); // false here
}
}
Expected behavior
Equals with set of Quantity
passes