Jacson

de.spieleck.app.ngramj
Class NGramImpl

java.lang.Object
  extended by de.spieleck.app.ngramj.NGramImpl
All Implemented Interfaces:
NGram

public class NGramImpl
extends java.lang.Object
implements NGram

Class to modell a concrete and simple NGram.

To make it slightly more interestion (and efficient), those NGrams follow a Flyweight pattern! I.e. of each different NGram there will only be one instance in the System. This is a bit technical, but one can safely ignore this and just deliberately call newNGram().

Version:
$Revision: 2 $ $Date: 2006-03-27 23:00:21 +0200 (Mo, 27 Mrz 2006) $ $Author: nestefan $
Author:
Christiaan Fluit, Frank S. Nestel, $Author: nestefan $

Field Summary
protected  byte[] bytes
           
protected static NGramImpl[] known
           
protected static int knownCount
           
protected static int knownStep
           
protected  int size
           
 
Constructor Summary
protected NGramImpl()
           
 
Method Summary
static int appendCode(int h, byte b)
          scrambler for hashcodes...
static int code(byte[] bytes, int start, int length)
          Encode a byte sequence.
 boolean equals(byte[] bytes, int start, int length)
          Compare a ngram to a bunch of bytes
 int getByte(int pos)
          Return a single byte of the NGram.
static int getKnownCount()
           
 NGramImpl getNGramImpl()
          Hand out a special representation of yourself
static int getNGramImplCount()
           
 int getSize()
          Return the size of the ngram.
 int hashCode()
          Override the hashCode by s.th. that allows to hash NGrams against tiny byte sequences.
static NGram newNGram(byte[] bytes, int start)
          QuasiConstructor.
static NGram newNGram(byte[] bytes, int start, int length)
          QuasiConstructor.
static NGram newNGram(byte[] bytes, int start, int length, boolean cacheObject)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

bytes

protected byte[] bytes

size

protected int size

known

protected static NGramImpl[] known

knownCount

protected static int knownCount

knownStep

protected static int knownStep
Constructor Detail

NGramImpl

protected NGramImpl()
Method Detail

newNGram

public static NGram newNGram(byte[] bytes,
                             int start)
QuasiConstructor. FlyWeight means that we first have to look if we allready know the current beasty.


newNGram

public static NGram newNGram(byte[] bytes,
                             int start,
                             int length)
QuasiConstructor. FlyWeight means that we first have to look if we allready know the current beasty.


newNGram

public static NGram newNGram(byte[] bytes,
                             int start,
                             int length,
                             boolean cacheObject)

getSize

public int getSize()
Return the size of the ngram.

Specified by:
getSize in interface NGram

getByte

public int getByte(int pos)
Return a single byte of the NGram.

Specified by:
getByte in interface NGram
Throws:
ArrayIndexOutOfBoundException - ...

getKnownCount

public static int getKnownCount()

equals

public boolean equals(byte[] bytes,
                      int start,
                      int length)
Description copied from interface: NGram
Compare a ngram to a bunch of bytes

Specified by:
equals in interface NGram

hashCode

public int hashCode()
Override the hashCode by s.th. that allows to hash NGrams against tiny byte sequences.

Overrides:
hashCode in class java.lang.Object

code

public static int code(byte[] bytes,
                       int start,
                       int length)
Encode a byte sequence.


appendCode

public static final int appendCode(int h,
                                   byte b)
scrambler for hashcodes...


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getNGramImpl

public NGramImpl getNGramImpl()
Description copied from interface: NGram
Hand out a special representation of yourself

Specified by:
getNGramImpl in interface NGram

getNGramImplCount

public static int getNGramImplCount()

spieleck.de