// A class for structuring associations that may be compared. // (c) 1996 duane a. bailey package structure; public class ComparableAssociation extends Association implements Comparable { public ComparableAssociation(Comparable key) // pre: key is non-null // post: constructs comparable association with null value { this(key,null); } public ComparableAssociation(Comparable key, Object value) // pre: key is non-null // post: constructs association comparable key and a value { super(key,value); } public boolean lessThan(Comparable other) // pre: other is non-null ComparableAssociation // post: returns true iff this key is less than other key { Assert.pre(other instanceof ComparableAssociation, "lessThan expects a ComparableAssociation"); ComparableAssociation that = (ComparableAssociation)other; Comparable thisKey = (Comparable)this.key(); Comparable thatKey = (Comparable)that.key(); return thisKey.lessThan(thatKey); } public String toString() // post: returns string representation { StringBuffer s = new StringBuffer(); s.append(""); return s.toString(); } }