TopoWeb Commons API

org.topoweb.util
Class StringRange

java.lang.Object
  |
  +--org.topoweb.util.Range
        |
        +--org.topoweb.util.StringRange

public class StringRange
extends Range

A Range based on the lexicographical order of the string representation of Objects. This class just encapsulates a StringComparator instance as the Comparator used by its superclass.

Note: the ordering of the range is generally not consistent with equals. If, however, the user can guarantee that for any two objects a and b the expression a.equals(b) implies a.toString().compareTo( b.toString() ), then the ordering is consistent with equals.

Author:
Babak Farhang

Field Summary
static StringRange ALL
          The lexical range containing all strings.
static StringRange Z
          The lexical range containing only the empty string.
 
Constructor Summary
StringRange(java.lang.Object lo, java.lang.Object hi)
          Creates a new instance with the specified bounds.
 
Method Summary
 boolean equals(java.lang.Object other)
          Tests this instance for equality against the other object.
 boolean equals(StringRange other)
          Tests this instance for equality against the other instance.
 java.lang.String getHiString()
          Returns the upper bound as a string.
 java.lang.String getLoString()
          Returns the lower bound as a string.
 int hashCode()
          Returns the hash code.
 
Methods inherited from class org.topoweb.util.Range
contains, getComparator, getHi, getLo, outcode
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Z

public static final StringRange Z
The lexical range containing only the empty string.
= new StringRange("", new String(new char[] { 0 }) )


ALL

public static final StringRange ALL
The lexical range containing all strings.
= new StringRange("", null)

Constructor Detail

StringRange

public StringRange(java.lang.Object lo,
                   java.lang.Object hi)
            throws java.lang.IllegalArgumentException
Creates a new instance with the specified bounds.

Parameters:
lo - the inclusive lower bound for this range
hi - the exclusive upper bound for this range, or null to indicate the highest possible upper bound
See Also:
Range.Range(Object,Object,Comparator)
Method Detail

getLoString

public final java.lang.String getLoString()
Returns the lower bound as a string.

Returns:
the lower bound

getHiString

public final java.lang.String getHiString()
Returns the upper bound as a string. The value null represents the largest string.

Returns:
the upper bound

hashCode

public final int hashCode()
Returns the hash code. The hash code is consistent with equals as per the contract in java.lang.Object.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code

equals

public final boolean equals(java.lang.Object other)
Tests this instance for equality against the other object.

Overrides:
equals in class java.lang.Object
Parameters:
other - the other object
Returns:
true, iff other is an instance of this class and equals(StringRange) returns true
See Also:
equals(StringRange)

equals

public final boolean equals(StringRange other)
Tests this instance for equality against the other instance.

Parameters:
other - the other instance
Returns:
true, iff the string representation of the hi and lo of this range and other are the same

TopoWeb Commons API

Copyright (C) 2002 Babak Farhang

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.