-
Enhancement
-
Resolution: Unresolved
-
P4
-
8
-
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.
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.
- relates to
-
JDK-8184694 add lexicographic comparator methods for collections
-
- Open
-