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.


Constructor Index

 o ComparableString(String)
Constructs a comparable string from a String.

Method Index

 o equals(Object)
Test for equality between this and other string.
 o hashCode()
Compute the hashcode for a comparable string.
 o lessThan(Comparable)
The lessThan method, required by the Comparable interface.
 o toString()
Return string representation of value (itself).
 o value()
Fetch value of underlying string.

Constructors

 o 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.

Methods

 o 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.
 o 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
 o 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
 o value
 public String value()
Fetch value of underlying string.

Postcondition:
returns the underlying value of the string.

Returns:
The string contained within the wrapper.
 o 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