jbil.sequence
Class SymbolArraySequence

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

public class SymbolArraySequence
extends Sequence

Basic high-level implementation of Sequence using an array of symbols. Each position in the array is a reference to the corresponding symbol object in the base alphabet. This implementation is time-efficient but not so much space-efficient.

Author:
Paulo G. S. da Fonseca

Constructor Summary
SymbolArraySequence(Alphabet alphabet)
          Creates an empty sequence over a given alphabet.
SymbolArraySequence(Alphabet alphabet, int initialCapacity)
          Creates an empty sequence with a given initial capacity over a given alphabet.
 
Method Summary
 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.
 Alphabet getAlphabet()
           
 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, indexAt, occursAt, setName, startsWith, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SymbolArraySequence

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

Parameters:
alphabet - The base alphabet.

SymbolArraySequence

public SymbolArraySequence(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.

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.

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.

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.

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.