Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.kubernetes.client.custom.Quantity doesn't implement hashCode #3490

Open
nulls opened this issue Jun 17, 2024 · 0 comments
Open

io.kubernetes.client.custom.Quantity doesn't implement hashCode #3490

nulls opened this issue Jun 17, 2024 · 0 comments

Comments

@nulls
Copy link
Contributor

nulls commented Jun 17, 2024

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

nulls pushed a commit to nulls/java that referenced this issue Jun 19, 2024
### What's done:
- overrode `hashCode` in `Quantity`
- added test which compares two sets of equal elements

It closes kubernetes-client#3490
nulls pushed a commit to nulls/java that referenced this issue Jun 19, 2024
### What's done:
- overrode `hashCode` in `Quantity`
- added test which compares two sets of equal elements

It closes kubernetes-client#3490
nulls added a commit to nulls/java that referenced this issue Jun 19, 2024
### What's done:
- overrode `hashCode` in `Quantity`
- added test which compares two sets of equal elements

It closes kubernetes-client#3490
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant