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

SortedSet should implement Comparable

    XMLWordPrintable

    Details

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

      Description

      A DESCRIPTION OF THE REQUEST :
      It would be easy to implement the Comparable interface in SortedSets such as TreeSet by comparing each element in the sets.

      JUSTIFICATION :
      If TreeSet was comparable, you could create treesets containing treesets.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      @Override
      public int compareTo(SortedSet<T> arg0) {
      Iterator<T> i = this.iterator();
      Iterator<T> j = arg0.iterator();

      while(i.hasNext() && j.hasNext())
      {
      int c = i.next().compareTo(j.next());
      if(c!=0){return c;}
      }

      if(!i.hasNext() && j.hasNext()){return -1;}
      if(!j.hasNext() && i.hasNext()){return 1;}

      return 0;
      }
      ACTUAL -
      SortedSets are not comparable.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: