All Packages Class Hierarchy This Package Previous Next Index
Class structure.ComparableString
java.lang.Object
|
+----structure.ComparableString
- public class ComparableString
- extends Object
- implements Comparable
A comparable wrapper class for strings. This class holds a string
and implements a lessThan method. This class is used to support
the insertion of strings into Ordered structures.
If Strings were not final in Java, it would be more reasonable to
make this class a direct extension of the String class, implementing
comparable.
-
ComparableString(String)
- Constructs a comparable string from a String.
-
equals(Object)
- Test for equality between this and other string.
-
hashCode()
- Compute the hashcode for a comparable string.
-
lessThan(Comparable)
- The lessThan method, required by the Comparable interface.
-
toString()
- Return string representation of value (itself).
-
value()
- Fetch value of underlying string.
ComparableString
public ComparableString(String s)
- Constructs a comparable string from a String.
- Precondition:
- s is non-null
- Postcondition:
- construct a ComparableString whose initial value is s.
- Parameters:
- s - The non-null string to be used as the value.
lessThan
public boolean lessThan(Comparable other)
- The lessThan method, required by the Comparable interface.
- Precondition:
- other is non-null
- Postcondition:
- returns true if this string is less than the other
string, lexically
- Parameters:
- other - The other comparable string.
- Returns:
- True if this string is lexically less than the other.
equals
public boolean equals(Object other)
- Test for equality between this and other string.
Two comparable strings are "equals" if their component strings are.
- Precondition:
- other is non-null
- Postcondition:
- returns true if this string is same as other
string, lexically
- Parameters:
- other - The other comparable string.
- Returns:
- True iff the underlying strings are equals.
- Overrides:
- equals in class Object
hashCode
public int hashCode()
- Compute the hashcode for a comparable string.
- Precondition:
- returns hash code associated with string.
- Returns:
- An integer hashcode for underlying string.
- Overrides:
- hashCode in class Object
- See Also:
- Hashtable
value
public String value()
- Fetch value of underlying string.
- Postcondition:
- returns the underlying value of the string.
- Returns:
- The string contained within the wrapper.
toString
public String toString()
- Return string representation of value (itself).
- Postcondition:
- returns string representation
- Returns:
- Underlying string.
- Overrides:
- toString in class Object
All Packages Class Hierarchy This Package Previous Next Index