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

SortedSet should implement Comparable

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8
    • core-libs
    • None

      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.

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

              Created:
              Updated: