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

Enum is Comparable but EnumSet is not a SortedSet and EnumMap is not a SortedMap

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      While you can construct

          NavigableSet<EnumType> set = new TreeSet<EnumType>();
          NavigableMap<EnumType, Object> map = new TreeMap<EnumType, Object>();

      you can't construct

          NavigableSet<EnumType> set = new EnumSet<EnumType>();
          NavigableMap<EnumType, Object> map = new EnumMap<EnumType, Object>();


      JUSTIFICATION :
      As Enum is Comparable, this implies it has a natural order which you can use in generic sorted collection but not those collection specific to Enums which appears to be inconsistent.

      Insert, update and delete on a Tree is O(log n) whereas for an Enum collection its O(1)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      EnumSet supports the functionality which a TreeSet of enum supports
      EnumMap supports the functionality which a TreeMap of enum supports.
      ACTUAL -
      Enum collections are not aware that enum is Comparable.

      CUSTOMER SUBMITTED WORKAROUND :
      Use a TreeMap and an EnumMap to get O(1) access and a sorted collection.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: