org.biojava.bio.symbol
Class SimpleAlphabet

java.lang.Object
  |
  +--org.biojava.bio.symbol.AbstractAlphabet
        |
        +--org.biojava.bio.symbol.SimpleAlphabet

public class SimpleAlphabet
extends AbstractAlphabet
implements java.io.Serializable

A simple no-frills implementation of the FiniteAlphabet interface.

Author:
Matthew Pocock
See Also:
Serialized Form

Constructor Summary
SimpleAlphabet()
           
SimpleAlphabet(java.util.Set symbols)
           
 
Method Summary
 void addAmbiguity(Symbol aSym)
          Add a commonly recognized ambiguiy symbol to this alphabet.
 void addSymbol(Symbol s)
          Adds a symbol to this alphabet.
 java.util.Iterator ambiguities()
           
 boolean contains(Symbol r)
          Returns whether or not this Alphabet contains the symbol.
 Annotation getAnnotation()
          Should return the associated annotation object.
 java.lang.String getName()
          Get the name of the alphabet.
 java.util.Iterator iterator()
          Retrieve an Iterator over the Symbols in this FiniteAlphabet.
 void removeSymbol(Symbol s)
          Remove a symbol from this alphabet.
 void setName(java.lang.String name)
          Assign a name to the alphabet
 int size()
          The number of symbols in the alphabet.
 SymbolList symbols()
          A list of symbols that make up this alphabet.
 void validate(Symbol s)
          Throws a precanned IllegalSymbolException if the symbol is not contained within this Alphabet.
 
Methods inherited from class org.biojava.bio.symbol.AbstractAlphabet
getParser, putParser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleAlphabet

public SimpleAlphabet()

SimpleAlphabet

public SimpleAlphabet(java.util.Set symbols)
Method Detail

iterator

public java.util.Iterator iterator()
Description copied from interface: FiniteAlphabet
Retrieve an Iterator over the Symbols in this FiniteAlphabet.

Each AtomicSymbol as for which this.contains(as) is true will be returned exactly once by this iterator in no specified order.

Tags copied from interface: FiniteAlphabet
Returns:
an Iterator over the contained AtomicSymbol objects

ambiguities

public java.util.Iterator ambiguities()

getName

public java.lang.String getName()
Description copied from interface: Alphabet
Get the name of the alphabet.
Tags copied from interface: Alphabet
Returns:
the name as a string.

setName

public void setName(java.lang.String name)
Assign a name to the alphabet
Parameters:
name - the name you wish to give this alphabet

getAnnotation

public Annotation getAnnotation()
Description copied from interface: Annotatable
Should return the associated annotation object.
Tags copied from interface: Annotatable
Returns:
an Annotation object, never null

size

public int size()
Description copied from interface: FiniteAlphabet
The number of symbols in the alphabet.
Tags copied from interface: FiniteAlphabet
Returns:
the size of the alphabet

symbols

public SymbolList symbols()
Description copied from interface: FiniteAlphabet
A list of symbols that make up this alphabet.

Subsequent calls to this method are not required to return either the same symbol list, or even a symbol list with the symbols in the same order.

Tags copied from interface: FiniteAlphabet
Returns:
a SymbolList containing one AtomicSymbol for each AtomicSymbol in this alphabet

contains

public boolean contains(Symbol r)
Description copied from interface: Alphabet
Returns whether or not this Alphabet contains the symbol.

An alphabet contains an ambiguity symbol iff the ambiguity symbol's getMemberAlphabet() returns an alphabe that is a propper sub-set of this alphabet. That means that every one of the symbols that could mach the ambiguity symbol is also a member of this alphabet.

Tags copied from interface: Alphabet
Parameters:
r - the Symbol to check
Returns:
boolean true if the Alphabet contains the symbol and false otherwise

addSymbol

public void addSymbol(Symbol s)
               throws IllegalSymbolException
Adds a symbol to this alphabet.

If the symbol matches more than one AtomicSymbol, then each symbol matching it will be added.

Parameters:
s - the Symbol to add
Throws:
IllegalSymbolException - if the symbol is null, or if for any reason it can't be added

addAmbiguity

public void addAmbiguity(Symbol aSym)
                  throws IllegalSymbolException
Add a commonly recognized ambiguiy symbol to this alphabet.

This effectively forges an alias between aSym and the symbols in its 'matches' alphabet for all derived parsers.

Parameters:
as - the ambiguity symbol to add
Throws:
IllegalSymbolException - if aSym contains an AtomicSymbol not found within this alpahbet

removeSymbol

public void removeSymbol(Symbol s)
                  throws IllegalSymbolException
Remove a symbol from this alphabet.

If the symbol matches multiple AtomicSymbols, then each matching symbol it will be removed.

Parameters:
s - the Symbol to remove
Throws:
IllegalSymbolException - if the symbol is null, or if for any reason it can't be removed

validate

public void validate(Symbol s)
              throws IllegalSymbolException
Description copied from interface: Alphabet
Throws a precanned IllegalSymbolException if the symbol is not contained within this Alphabet.

This function is used all over the code to validate symbols as they enter a method. Also, the code is littered with catches for IllegalSymbolException. There is a preferred style of handling this, which should be covererd in the package documentation.

Tags copied from interface: Alphabet
Parameters:
r - the Symbol to validate
Throws:
IllegalSymbolException - if r is not contained in this alphabet