-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Open
Labels
Description
Guava Version
33.5.0-jre
Description
I noticed a minor issue with some of the entry set spliterators not consistently reporting DISTINCT (ImmutableMap, ImmutableBiMap, etc). This is because they are backed by an ImmutableList, but we could easily override the characteristics of the Spliterator since it is known to be distinct.
Example
ImmutableBiMap.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
ImmutableBiMap.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableBiMap.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableMap.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
ImmutableMap.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT)) // false
ImmutableMap.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // false
Contrast that with the JDK:
Map.of().entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b", "c", "d").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // true
Map.of("a", "b", "c", "d", "e", "f").entrySet().spliterator().hasCharacteristics(Spliterator.DISTINCT); // trueExpected Behavior
I would expect the spliterator characteristics to match the JDK and report DISTINCT for an entry set.
Actual Behavior
Entry set spliterators don't consistently report DISTINCT.
Packages
com.google.common.collect
Platforms
No response
Checklist
-
I agree to follow the code of conduct.
-
I can reproduce the bug with the latest version of Guava available.