United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5036680 ObjectName should implement Comparable<ObjectName>
JDK-5036680 : ObjectName should implement Comparable

Details
Type:
Enhancement
Submit Date:
2004-04-23
Status:
Resolved
Updated Date:
2005-04-01
Project Name:
JDK
Resolved Date:
2005-04-01
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
javax.management.ObjectName should implement Comparable<ObjectName>.  Even though it is not very meaningful to say that one ObjectName is "less than" another, by implementing Comparable we would allow a SortedSet<ObjectName> to show its contents in a reasonable order without having to define a custom Comparator.  In particular, ObjectNames with the same domain should be grouped together.

The proposed semantics would be that name1.compareTo(name2) would be the same as name1.getCanonicalName().compareTo(name2.getCanonicalName()).

                                    

Comments
SUGGESTED FIX

public class ObjectName implements Comparable<ObjectName> {
    public int compareTo(ObjectName n) {
        return getCanonicalName().compareTo(n.getCanonicalName());
    }
}

This could be optimized, but it's probably not worth it.
###@###.### 2004-04-23
                                     
2004-04-23
PUBLIC COMMENTS

javax.management.ObjectName should implement Comparable<ObjectName>.  The proposed semantics would be that name1.compareTo(name2) would be the same as name1.getCanonicalName().compareTo(name2.getCanonicalName()).
                                     
2004-09-01
WORK AROUND

Supply an explicit Comparator wherever necessary:

public final class ObjectNameComparator implements Comparator<ObjectName> {
    public int compare(ObjectName o1, ObjectName o2) {
        return o1.getCanonicalName().compareTo(o2.getCanonicalName());
    }
    public boolean equals(Object o) {
        return (o instanceof ObjectNameComparator);
    }
}
                                     
2004-09-01
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
mustang


                                     
2004-09-01
EVALUATION

Straightforward and obvious change.  Implies API change, so cannot be done before Mustang.
###@###.### 2004-04-23

Rather than comparing the canonical names, it might be better to compare the keys in a "smart" order.  In particular, it makes sense to compare the "type" key first since it is conventionally present in all ObjectNames.  Doing so would allow us to group together MBeans of the same type that are in the same domain.  Probably it is enough to leave the key order unspecified but to say that any given implementation will apply a consistent ordering to all keys of all ObjectNames.  The purpose, after all, is simply to sort ObjectNames into an order that is convenient for humans.
###@###.### 2005-2-18 16:16:00 GMT
                                     
2005-02-18



Hardware and Software, Engineered to Work Together