2
TreeSet<Pair<String, String>> istovjetna = new TreeSet<Pair<String, String>>();
    for (Pair<String, String> par : parovi) {
        if (!distinguishable.contains(par)) {
            istovjetna.add(par);
            System.out.println(par.toString());
        }
    }

So this is a small part of the code I've been writing to minimize a DKA, more precisely, to find the equivalent states.

The problem that I'm encountering is that the Pair class isn't comparable so functions such as "contains" won't work and I'll have to make a big overhaul.

In the example above, it will call an error on the if clause. Is there a quick workaround for this exact problem?

  • 1
    You could make a wrapper using a Pair delegate that implements Comparable, but that's the easiest thing I can think of – user Apr 19 '20 at 19:26
  • 1
    Is it your own `Pair` class, or one that's provided to you? If it's your own, you can just make it `implement Comparable`. – dimo414 Apr 19 '20 at 19:27
  • 2
    The answer in the future will be: Use a record: `record MyStringPair implements Comparable(String a, String b) {public int compareTo(MyStringPair other) {...}}` – Johannes Kuhn Apr 19 '20 at 19:31
  • I have just created my own Pair class which implements Comparable and now it works. – Ante Grgurević Apr 19 '20 at 19:38

0 Answers0