Set Relations

The operations containsNone, overlaps; and the relation xorAll don't exist in Java (and the last two don't exist in UnicodeSet). They can be implemented in terms of other operations, but not efficiently. It would be better if they were natively supported, which is a rather small amount of code.

The last two columns describe operations in terms of what you would have to do to change A to match the results of the first three columns. For actions that replace an object by an equal object, it is useful to have 3 choices:

  • Retain the old one (A)

  • Replace the old by new (B)

  • Throw an exception - this is useful when you don't expect to get a new, different object or mapping, such as when building a map from data that is supposed to have unique keys.

Java appears to always have A win, for operations that leave the intersection. To favor the other, you have to use workarounds in the last column.

setTo is a convenience, not for efficiency.

A.setTo(B) := A.clear(); A.addAll(B);

Similar operations can be performed on two Maps. In that case, the choice of whether to have A or B win goes the other way in Java; B normally wins over A, when the keys are equals, as you'd expect from a "put" operation.