public class CompressedString extends Object implements CharSequence, Comparable<CompressedString>
System.out.println(new CompressedString("How are you?",7));
System.out.println(new CompressedString("How are you?",6));
System.out.println(new CompressedString("How are you?",5));
System.out.println(new CompressedString("How are you?",4));
System.out.println(new CompressedString("How are you?",3));
-->
How are you?
HOW ARE YOU?
HOW ARE YOU?
HOW@ARE@YOU
HOG@ABE@IOEO
@GG@ABE@AGEG
CompressedStrings are useful for large Collections of Strings where only membership
checks are made. If the Strings are sufficiently different, then a TreeSet can
contain CompressedStrings with a low bit number and membership checks will be handled
correctly.
A CompressedString is equal to all the (uncompressed) Strings in its equivalence
class (violating the transitivity of equals on calls with non-CompressedStrings).| Modifier and Type | Field and Description |
|---|---|
protected byte |
BITSPERCHAR
Number of bits per character
|
protected byte[] |
data
The string
|
protected int |
length
Number of characters in this CompressedString
|
protected int |
startBit
StartBit (for subsequence)
|
| Modifier | Constructor and Description |
|---|---|
protected |
CompressedString(byte[] data,
int startBit,
int length)
Duplicates a CompressedString (for subSequence)
|
|
CompressedString(CharSequence s1)
Compresses a CharSequence with 6 bits
|
|
CompressedString(CharSequence s1,
int bits)
Compresses a CharSequence
|
| Modifier and Type | Method and Description |
|---|---|
int |
bits()
Returns the bits per character
|
char |
charAt(int index)
Returns the character at position index
|
int |
compareTo(CharSequence s0)
1 if this CompressedString is lexically larger than the
CompressedString of the argument, else -1 or 0
|
int |
compareTo(CompressedString s)
1 if this CompressedString is lexically larger than the
the argument, else -1 or 0
|
boolean |
equals(Object o)
Tells whether the argument (any CharSequence)
is in the equivalence class of this CompressedString
|
int |
hashCode()
Returns a hash-code
|
int |
length()
Returns the number of characters in this CompressedString
|
static void |
main(String[] args)
Test routine
|
CharSequence |
normalize(CharSequence s)
Normalizes (see Char.java) and upcases a CharSequence if necessary
|
int |
size()
Returns the bytes used by this CompressedString
|
CharSequence |
subSequence(int start,
int end)
Returns a subsequence of this CompressedString (without duplicating the data)
|
String |
toString()
Tries to reconstruct the original String
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitchars, codePointsprotected byte BITSPERCHAR
protected byte[] data
protected int startBit
protected int length
protected CompressedString(byte[] data,
int startBit,
int length)
public CompressedString(CharSequence s1, int bits)
public CompressedString(CharSequence s1)
public int length()
length in interface CharSequencepublic int size()
public int bits()
public char charAt(int index)
charAt in interface CharSequencepublic boolean equals(Object o)
public CharSequence normalize(CharSequence s)
public int compareTo(CharSequence s0)
public int compareTo(CompressedString s)
compareTo in interface Comparable<CompressedString>public CharSequence subSequence(int start, int end)
subSequence in interface CharSequencepublic String toString()
toString in interface CharSequencetoString in class Objectpublic static void main(String[] args)
Copyright © 2018. All rights reserved.