On Mon, 29 Jun 2026 18:23:05 GMT, Andy Goryachev <[email protected]> wrote:

> re: disjoint(): sorry, I don't want to deal with peculiarities of it (empty 
> set etc.).

What peculiarities? We are talking about sets of `String`s. How are empty sets 
a problem? If a set has no elements then it is disjoint; the docs are clear 
"Returns `true` if the two specified collections have no elements in common.", 
so any empty set returns `true.

It's a suggestions to make the code clearer, ignore it if you want. As it is, 
it takes quite some effort to understand what the constructor does and it's 
mostly complexity for irrelevant optimizations (the registry will not be larger 
than a few dozen entries, and this is a stretch probably). I'd value 
readability here over saving a microsecond and write:

        public DataFormat(String... ids) {
                if (ids == null || ids.length == 0) {
                        identifier = Set.of();
                        return;
                }

                identifier = Set.of(ids);

                if (registry.containsValue(this)) {
                        // all ids exist in an existing data format - no need 
to change registry
                        return;
                }
                if (!Collections.disjoint(identifier, registry.keySet())) {
                        // existing ids can't be overridden - throw
                        throw new IllegalArgumentException("An id already 
exists");
                }
                // no existing ids - add
                identifier.forEach(id -> registry.put(id, this));
        }


I also find the name `identifier` confusing, I would use `identifiers` since 
it's a collection.

-------------

PR Comment: https://git.openjdk.org/jfx/pull/2197#issuecomment-4839356409

Reply via email to