net.innig.collect
Class StringRadix

java.lang.Object
  extended by net.innig.collect.StringRadix
All Implemented Interfaces:
java.io.Serializable, java.util.Comparator, Radix

public class StringRadix
extends java.lang.Object
implements Radix, java.io.Serializable

A radix which supports String.

Maturity: All the radix utilities in innig-util are completely experimental. They mostly work, but perform poorly. They may stay; they may improve; they may go away.
Plans: Experiment.

See Also:
Radix, Serialized Form

Field Summary
static StringRadix DEFAULT
           
 
Constructor Summary
StringRadix(int digitBits)
           
StringRadix(int digitBits, boolean force8bit)
           
 
Method Summary
 int compare(java.lang.Object aObj, java.lang.Object bObj)
          Compares two strings in a manner consistent with this radix.
 int digit(java.lang.Object o, int pos)
          Returns the digits of the radix representation of the given String.
 boolean equals(java.lang.Object that)
          Returns true if the given Object is a Radix identical to this one.
 int getBase()
          Returns the base (the number of digit values) in this radix.
 int getMaxPosition(java.lang.Object o)
          Returns zero.
 int getMaxPositionForAll(java.util.Collection values)
          Returns the lowest position of any of the least significant digits of the given strings.
 int getMinPosition(java.lang.Object o)
          Returns the position of the least significant digit.
 int getMinPositionForAll(java.util.Collection values)
          Returns the lowest position of any of the least significant digits of the given strings.
 java.lang.Object objectFromDigits(int[] digits)
          Constructs a String from the given digits.
 java.lang.Object objectFromDigits(int[] digits, int offset, int len)
          Constructs a String from the given digits.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT

public static final StringRadix DEFAULT
Constructor Detail

StringRadix

public StringRadix(int digitBits)

StringRadix

public StringRadix(int digitBits,
                   boolean force8bit)
Method Detail

getBase

public int getBase()
Returns the base (the number of digit values) in this radix.

Specified by:
getBase in interface Radix

digit

public int digit(java.lang.Object o,
                 int pos)
Returns the digits of the radix representation of the given String. Lower positions are less significant digits.

Specified by:
digit in interface Radix
Parameters:
o - a String.
pos - a digit position within o.
Returns:
a digit d, with -1 <= x < getBase(). The digit -1 signifies that the position is beyond the end of the String.
Throws:
java.lang.ClassCastException - if o is not a String.

getMaxPosition

public int getMaxPosition(java.lang.Object o)
Returns zero.

Specified by:
getMaxPosition in interface Radix

getMinPosition

public int getMinPosition(java.lang.Object o)
Returns the position of the least significant digit.

Specified by:
getMinPosition in interface Radix
Parameters:
o - a String

getMaxPositionForAll

public int getMaxPositionForAll(java.util.Collection values)
Returns the lowest position of any of the least significant digits of the given strings.

Specified by:
getMaxPositionForAll in interface Radix
Throws:
java.lang.ClassCastException - if an of the values is not a String.

getMinPositionForAll

public int getMinPositionForAll(java.util.Collection values)
Returns the lowest position of any of the least significant digits of the given strings.

Specified by:
getMinPositionForAll in interface Radix
Throws:
java.lang.ClassCastException - if an of the values is not a String.

objectFromDigits

public java.lang.Object objectFromDigits(int[] digits)
Constructs a String from the given digits.

Specified by:
objectFromDigits in interface Radix
Throws:
java.lang.IllegalArgumentException - if the digits don't represent a valid string.

objectFromDigits

public java.lang.Object objectFromDigits(int[] digits,
                                         int offset,
                                         int len)
Constructs a String from the given digits.

Specified by:
objectFromDigits in interface Radix
Throws:
java.lang.IllegalArgumentException - if the digits don't represent a valid string.

compare

public int compare(java.lang.Object aObj,
                   java.lang.Object bObj)
Compares two strings in a manner consistent with this radix. Without the force8bit option, this is identical to the natural ordering of the strings.

Specified by:
compare in interface java.util.Comparator

equals

public boolean equals(java.lang.Object that)
Returns true if the given Object is a Radix identical to this one.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class java.lang.Object