Class StringKeyAnalyzer
- java.lang.Object
-
- org.apache.commons.collections4.trie.KeyAnalyzer<java.lang.String>
-
- org.apache.commons.collections4.trie.analyzer.StringKeyAnalyzer
-
- All Implemented Interfaces:
java.io.Serializable
,java.util.Comparator<java.lang.String>
public class StringKeyAnalyzer extends KeyAnalyzer<java.lang.String>
AnKeyAnalyzer
forString
s.- Since:
- 4.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static StringKeyAnalyzer
INSTANCE
A singleton instance ofStringKeyAnalyzer
.static int
LENGTH
The number of bits perCharacter
.-
Fields inherited from class org.apache.commons.collections4.trie.KeyAnalyzer
EQUAL_BIT_KEY, NULL_BIT_KEY, OUT_OF_BOUNDS_BIT_KEY
-
-
Constructor Summary
Constructors Constructor Description StringKeyAnalyzer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
bitIndex(java.lang.String key, int offsetInBits, int lengthInBits, java.lang.String other, int otherOffsetInBits, int otherLengthInBits)
Returns the n-th different bit between key and other.int
bitsPerElement()
Returns the number of bits per element in the key.boolean
isBitSet(java.lang.String key, int bitIndex, int lengthInBits)
Returns whether or not a bit is set.boolean
isPrefix(java.lang.String prefix, int offsetInBits, int lengthInBits, java.lang.String key)
Determines whether or not the given prefix (from offset to length) is a prefix of the given key.int
lengthInBits(java.lang.String key)
Returns the length of the Key in bits.-
Methods inherited from class org.apache.commons.collections4.trie.KeyAnalyzer
compare
-
-
-
-
Field Detail
-
INSTANCE
public static final StringKeyAnalyzer INSTANCE
A singleton instance ofStringKeyAnalyzer
.
-
LENGTH
public static final int LENGTH
The number of bits perCharacter
.- See Also:
- Constant Field Values
-
-
Method Detail
-
bitsPerElement
public int bitsPerElement()
Description copied from class:KeyAnalyzer
Returns the number of bits per element in the key. This is only useful for variable-length keys, such as Strings.- Specified by:
bitsPerElement
in classKeyAnalyzer<java.lang.String>
- Returns:
- the number of bits per element
-
lengthInBits
public int lengthInBits(java.lang.String key)
Description copied from class:KeyAnalyzer
Returns the length of the Key in bits.- Specified by:
lengthInBits
in classKeyAnalyzer<java.lang.String>
- Parameters:
key
- the key- Returns:
- the bit length of the key
-
bitIndex
public int bitIndex(java.lang.String key, int offsetInBits, int lengthInBits, java.lang.String other, int otherOffsetInBits, int otherLengthInBits)
Description copied from class:KeyAnalyzer
Returns the n-th different bit between key and other. This starts the comparison in key at 'offsetInBits' and goes for 'lengthInBits' bits, and compares to the other key starting at 'otherOffsetInBits' and going for 'otherLengthInBits' bits.- Specified by:
bitIndex
in classKeyAnalyzer<java.lang.String>
- Parameters:
key
- the key to useoffsetInBits
- the bit offset in the keylengthInBits
- the maximum key length in bits to useother
- the other key to useotherOffsetInBits
- the bit offset in the other keyotherLengthInBits
- the maximum key length in bits for the other key- Returns:
- the bit index where the key and other first differ
-
isBitSet
public boolean isBitSet(java.lang.String key, int bitIndex, int lengthInBits)
Description copied from class:KeyAnalyzer
Returns whether or not a bit is set.- Specified by:
isBitSet
in classKeyAnalyzer<java.lang.String>
- Parameters:
key
- the key to check, may not be nullbitIndex
- the bit index to checklengthInBits
- the maximum key length in bits to check- Returns:
true
if the bit is set in the given key andbitIndex
<lengthInBits
,false
otherwise.
-
isPrefix
public boolean isPrefix(java.lang.String prefix, int offsetInBits, int lengthInBits, java.lang.String key)
Description copied from class:KeyAnalyzer
Determines whether or not the given prefix (from offset to length) is a prefix of the given key.- Specified by:
isPrefix
in classKeyAnalyzer<java.lang.String>
- Parameters:
prefix
- the prefix to checkoffsetInBits
- the bit offset in the keylengthInBits
- the maximum key length in bits to usekey
- the key to check- Returns:
true
if this is a valid prefix for the given key
-
-