jbil.sequence
Class ByteArraySequence

java.lang.Object
  extended by jbil.sequence.Sequence
      extended by jbil.sequence.ByteArraySequence

public class ByteArraySequence
extends Sequence

Implementation of Sequence in which the sequence of symbols is translated into an array of bytes s.t. each position represents the position of the corresponding symbol in the underlying alphabet. It assumes therefore that the alphabet is constant and that it contains no more than 127 symbols. This implementation offers a reasonable compromise between time and space efficiency for most real-world alphabets.

Author:
Paulo G. S. da Fonseca

Constructor Summary
ByteArraySequence(Alphabet alphabet)
          Creates an empty sequence over a given alphabet.
ByteArraySequence(Alphabet alphabet, int initialCapacity)
          Creates an empty sequence with a given initial capacity over a given alphabet.
 
Method Summary
 void append(ByteArraySequence sequence)
          Optmised append operation for the case in which the operand is known to be of the same type.
 void append(Sequence sequence)
          Appends a sequence to this sequence.
 void append(Symbol s)
          Appends a symbol to this sequence.
 Sequence clone()
           
 void delete(int beginIndex, int endIndex)
          Deletes a subsequence of this sequence.
 boolean equals(java.lang.Object other)
           
 Alphabet getAlphabet()
           
 int hashCode()
           
 int indexAt(int index)
          Gets the position in the base alphabet of the symbol at a given position in the sequence.
 void insert(int index, Sequence sequence)
          Inserts a sequence at a given position in this sequence.
 void insert(int index, Symbol s)
          Inserts a new symbol at a given position in this sequence.
 int length()
           
 void prepend(Sequence sequence)
          Prepends a sequence to this sequence.
 void prepend(Symbol s)
          Prepends a symbol to this sequence.
 void setSymbolAt(int index, Symbol s)
          Sets the symbol at a given position in this sequence.
 Sequence subSequence(int beginIndex)
          Gets a new sequence that is a suffix of this sequence.
 Sequence subSequence(int beginIndex, int endIndex)
          Gets a new sequence that is a subsequence of this sequence.
 Symbol symbolAt(int index)
          Gets the symbol at a given position in the sequence.
 java.lang.String toString(int beginIndex, int endIndex)
          Returns the srting representation of a subsequence of this sequence.
 
Methods inherited from class jbil.sequence.Sequence
endsWith, getName, occursAt, setName, startsWith, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteArraySequence

public ByteArraySequence(Alphabet alphabet)
Creates an empty sequence over a given alphabet.

Parameters:
alphabet - The base alphabet.

ByteArraySequence

public ByteArraySequence(Alphabet alphabet,
                         int initialCapacity)
Creates an empty sequence with a given initial capacity over a given alphabet.

Parameters:
alphabet - The base alphabet.
initialCapacity - The initial capacity.
Method Detail

append

public void append(Symbol s)
Description copied from class: Sequence
Appends a symbol to this sequence.

Specified by:
append in class Sequence
Parameters:
s - The symbol to be appended.

append

public void append(Sequence sequence)
Description copied from class: Sequence
Appends a sequence to this sequence.

Specified by:
append in class Sequence
Parameters:
sequence - The sequence to be appended.

append

public void append(ByteArraySequence sequence)
Optmised append operation for the case in which the operand is known to be of the same type.


clone

public Sequence clone()
Specified by:
clone in class Sequence
Returns:
A clone of this sequence.

insert

public void insert(int index,
                   Symbol s)
Description copied from class: Sequence
Inserts a new symbol at a given position in this sequence.

Specified by:
insert in class Sequence
Parameters:
index - The position at which the symbol is inserted.
s - The symbol to be inserted.

insert

public void insert(int index,
                   Sequence sequence)
Description copied from class: Sequence
Inserts a sequence at a given position in this sequence.

Specified by:
insert in class Sequence
Parameters:
index - The position at which the sequence is inserted.
sequence - The sequence to be inserted.

length

public int length()
Specified by:
length in class Sequence
Returns:
The length of this sequence.

prepend

public void prepend(Symbol s)
Description copied from class: Sequence
Prepends a symbol to this sequence.

Specified by:
prepend in class Sequence
Parameters:
s - The symbol to be prepended.

prepend

public void prepend(Sequence sequence)
Description copied from class: Sequence
Prepends a sequence to this sequence.

Specified by:
prepend in class Sequence
Parameters:
sequence - The sequence to be prepended.

setSymbolAt

public void setSymbolAt(int index,
                        Symbol s)
Description copied from class: Sequence
Sets the symbol at a given position in this sequence.

Specified by:
setSymbolAt in class Sequence
Parameters:
index - The position to be set.
s - The new symbol.

subSequence

public Sequence subSequence(int beginIndex)
Description copied from class: Sequence
Gets a new sequence that is a suffix of this sequence.

Specified by:
subSequence in class Sequence
Parameters:
beginIndex - The start position of the suffix.
Returns:
The suffix starting at the given position.

subSequence

public Sequence subSequence(int beginIndex,
                            int endIndex)
Description copied from class: Sequence
Gets a new sequence that is a subsequence of this sequence.

Specified by:
subSequence in class Sequence
Parameters:
beginIndex - The start position of the subsequence.
endIndex - The end position of the subsequence.
Returns:
The subsequence starting at beginIndex and ending at endIndex-1.

delete

public void delete(int beginIndex,
                   int endIndex)
Description copied from class: Sequence
Deletes a subsequence of this sequence.

Specified by:
delete in class Sequence
Parameters:
beginIndex - The start position of the subsequence to be deleted.
endIndex - The end position (not inclusive) of the subsequence to be deleted.

symbolAt

public Symbol symbolAt(int index)
Description copied from class: Sequence
Gets the symbol at a given position in the sequence.

Specified by:
symbolAt in class Sequence
Parameters:
index - A position in the sequence.
Returns:
The symbol at the given position.

indexAt

public int indexAt(int index)
Description copied from class: Sequence
Gets the position in the base alphabet of the symbol at a given position in the sequence.

Overrides:
indexAt in class Sequence
Parameters:
index - A position in the sequence.
Returns:
The position in the base alphabet of the symbol at the given position.

toString

public java.lang.String toString(int beginIndex,
                                 int endIndex)
Description copied from class: Sequence
Returns the srting representation of a subsequence of this sequence.

Specified by:
toString in class Sequence
Parameters:
beginIndex - The start position of the subsequence.
endIndex - The end position of the subsequence.
Returns:
The string representation of the subsequence starting at beginIndex and ending at endIndex-1.

getAlphabet

public Alphabet getAlphabet()
Specified by:
getAlphabet in class Sequence
Returns:
The base alphabet.

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object