Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8170945

Collectors$Partition should override more Map methods

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 21
    • 9
    • core-libs
    • None

      Collectors$Partition is an internal class that implements the collector returned by Collectors.partitioningBy. It's a subclass of AbstractMap<Boolean, ?> that contains fields for the false and true entries. Its implementation is currently overrides only entrySet(), which is the minimum requirement for implementing an AbstractMap. It would also benefit from overriding more methods, so that AbstractMap doesn't have to create an entrySet and an Iterator in every case.

      Candidates for overriding:

      boolean containsKey(Boolean b) {
          return b != null;
      }

      V get(Boolean b) {
          return b == null ? null : b.booleanValue() ? forTrue : forFalse;
      }

      int size() { return 2; }

      boolean isEmpty() { return false; }

      These are probably the most common methods used when reading results out of the Map. It's probably not worth it to override any of the mutator methods, since they all bottom out by throwing UnsupportedOperationException.

            vklang Viktor Klang
            smarks Stuart Marks
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: