jbil.sequence
Class Alphabet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractList<Symbol>
          extended by jbil.sequence.Alphabet
All Implemented Interfaces:
java.lang.Iterable<Symbol>, java.util.Collection<Symbol>, java.util.List<Symbol>
Direct Known Subclasses:
DNAAlphabet, ExtendedDNAAlphabet

public class Alphabet
extends java.util.AbstractList<Symbol>

Class representing an alphabet of symbols.

Author:
Paulo G. S. da Fonseca

Constructor Summary
Alphabet()
          Creates an empty alphabet.
Alphabet(int initialCapacity)
          Creates an empty alphabet with a given initial capacity.
Alphabet(java.util.List<? extends Symbol> symbols)
          Creates an alphabet from a list of symbols.
 
Method Summary
 void add(int index, Symbol symbol)
          Adds a symbol to the alphabet at a given position.
 boolean contains(java.lang.Object o)
           
 Symbol get(int index)
          Return a symbol at a given position in the alphabet.
 int indexOf(java.lang.Object o)
          Gets the position of a given symbol object in the alphabet.
 Alphabet intersection(Alphabet other)
          Computes the intersection between this alphabet and a given alphabet.
 boolean isLocked()
           
 void lock()
          Lock the alphabet, i.e., forbid any further modification.
 Symbol remove(int index)
          Removes the symbol at a given position.
 Symbol set(int index, Symbol symbol)
          Replaces the symbol at a given position.
 int size()
           
 
Methods inherited from class java.util.AbstractList
add, addAll, clear, equals, hashCode, iterator, lastIndexOf, listIterator, listIterator, subList
 
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.List
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray
 

Constructor Detail

Alphabet

public Alphabet()
Creates an empty alphabet.


Alphabet

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

Parameters:
initialCapacity -

Alphabet

public Alphabet(java.util.List<? extends Symbol> symbols)
Creates an alphabet from a list of symbols.

Parameters:
symbols - The source list of symbols.
Method Detail

contains

public boolean contains(java.lang.Object o)
Specified by:
contains in interface java.util.Collection<Symbol>
Specified by:
contains in interface java.util.List<Symbol>
Overrides:
contains in class java.util.AbstractCollection<Symbol>
Returns:
True if the alphabet contains the given symbol object, or false otherwise.

get

public Symbol get(int index)
Return a symbol at a given position in the alphabet.

Specified by:
get in interface java.util.List<Symbol>
Specified by:
get in class java.util.AbstractList<Symbol>
Parameters:
index - The position of the symbol.

indexOf

public int indexOf(java.lang.Object o)
Gets the position of a given symbol object in the alphabet.

Specified by:
indexOf in interface java.util.List<Symbol>
Overrides:
indexOf in class java.util.AbstractList<Symbol>
Parameters:
o - The symbol object.
Returns:
The position of the object o in the alphabet.

size

public int size()
Specified by:
size in interface java.util.Collection<Symbol>
Specified by:
size in interface java.util.List<Symbol>
Specified by:
size in class java.util.AbstractCollection<Symbol>
Returns:
The size of the alphabet.

add

public void add(int index,
                Symbol symbol)
Adds a symbol to the alphabet at a given position.

Specified by:
add in interface java.util.List<Symbol>
Overrides:
add in class java.util.AbstractList<Symbol>
Parameters:
index - The position at which the symbol should be added.
symbol - The symbol to be added.

set

public Symbol set(int index,
                  Symbol symbol)
Replaces the symbol at a given position.

Specified by:
set in interface java.util.List<Symbol>
Overrides:
set in class java.util.AbstractList<Symbol>
Parameters:
index - The position to be replaced.
symbol - The new symbol.

remove

public Symbol remove(int index)
Removes the symbol at a given position.

Specified by:
remove in interface java.util.List<Symbol>
Overrides:
remove in class java.util.AbstractList<Symbol>
Parameters:
index - The position to be removed.

intersection

public Alphabet intersection(Alphabet other)
Computes the intersection between this alphabet and a given alphabet. The order of the symbols in the intersection will follow the order of the symbols in this alphabet.

Parameters:
other - The other alphabet.
Returns:
The intersection between this and the other alphabet.

lock

public void lock()
Lock the alphabet, i.e., forbid any further modification. Alphabets are normally supposed to be constant. Hence this operation should be invoked as soon as the construction of the alphabet is finished. Once locked, the alphabet cannot be unlocked.


isLocked

public boolean isLocked()
Returns:
True if the alphabet is locked, or false, otherwise.