javatools.datatypes
Class CompressedString

java.lang.Object
  extended by javatools.datatypes.CompressedString
All Implemented Interfaces:
java.lang.CharSequence, java.lang.Comparable<CompressedString>

public class CompressedString
extends java.lang.Object
implements java.lang.CharSequence, java.lang.Comparable<CompressedString>

This class is part of the Java Tools (see http://mpii.de/yago-naga/javatools). It is licensed under the Creative Commons Attribution License (see http://creativecommons.org/licenses/by/3.0) by the YAGO-NAGA team (see http://mpii.de/yago-naga). This class represents an equivalence class of Strings. The equivalence class stores one prototype String, but compresses the String with 7, 6 or less bits per character (the String-class uses 16). This makes the CompressedString less memory consuming than a normal String, but possibly the original String cannot be reconstructed. The less bits you use, the less space you will consume, the less likely it will be that you can reconstruct the original String and the larger the equivalence class will be. Example:

    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


Constructor Summary
CompressedString(java.lang.CharSequence s1)
          Compresses a CharSequence with 6 bits
CompressedString(java.lang.CharSequence s1, int bits)
          Compresses a CharSequence
 
Method Summary
 int bits()
          Returns the bits per character
 char charAt(int index)
          Returns the character at position index
 int compareTo(java.lang.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(java.lang.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(java.lang.String[] args)
          Test routine
 java.lang.CharSequence normalize(java.lang.CharSequence s)
          Normalizes (see Char.java) and upcases a CharSequence if necessary
 int size()
          Returns the bytes used by this CompressedString
 java.lang.CharSequence subSequence(int start, int end)
          Returns a subsequence of this CompressedString (without duplicating the data)
 java.lang.String toString()
          Tries to reconstruct the original String
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompressedString

public CompressedString(java.lang.CharSequence s1,
                        int bits)
Compresses a CharSequence


CompressedString

public CompressedString(java.lang.CharSequence s1)
Compresses a CharSequence with 6 bits

Method Detail

hashCode

public int hashCode()
Returns a hash-code

Overrides:
hashCode in class java.lang.Object

length

public int length()
Returns the number of characters in this CompressedString

Specified by:
length in interface java.lang.CharSequence

size

public int size()
Returns the bytes used by this CompressedString


bits

public int bits()
Returns the bits per character


charAt

public char charAt(int index)
Returns the character at position index

Specified by:
charAt in interface java.lang.CharSequence

equals

public boolean equals(java.lang.Object o)
Tells whether the argument (any CharSequence) is in the equivalence class of this CompressedString

Overrides:
equals in class java.lang.Object

normalize

public java.lang.CharSequence normalize(java.lang.CharSequence s)
Normalizes (see Char.java) and upcases a CharSequence if necessary


compareTo

public int compareTo(java.lang.CharSequence s0)
1 if this CompressedString is lexically larger than the CompressedString of the argument, else -1 or 0


compareTo

public int compareTo(CompressedString s)
1 if this CompressedString is lexically larger than the the argument, else -1 or 0

Specified by:
compareTo in interface java.lang.Comparable<CompressedString>

subSequence

public java.lang.CharSequence subSequence(int start,
                                          int end)
Returns a subsequence of this CompressedString (without duplicating the data)

Specified by:
subSequence in interface java.lang.CharSequence

toString

public java.lang.String toString()
Tries to reconstruct the original String

Specified by:
toString in interface java.lang.CharSequence
Overrides:
toString in class java.lang.Object

main

public static void main(java.lang.String[] args)
Test routine