org.biojava.bio.symbol
Class AbstractSymbolList

java.lang.Object
  |
  +--org.biojava.bio.symbol.AbstractSymbolList
Direct Known Subclasses:
GappedSymbolList, OrderNSymbolList, ReverseSymbolList, SimpleAlignment, SimpleSymbolList, TranslatedSymbolList, WindowedSymbolList

public abstract class AbstractSymbolList
extends java.lang.Object
implements SymbolList

Abstract helper implementation of the SymbolList core interface. To produce a concrete SymbolList implementation, you need only implement the getAlphabet, length and symbolAt methods. Iterators and sublists are handled for you automatically.

This class makes many custom SymbolList implementations very quick to implement. See org.biojava.bio.seq.tools.ComplementSymbolList for an example of this.

Author:
Thomas Down, Matthew Pocock

Inner classes inherited from class org.biojava.bio.symbol.SymbolList
SymbolList.EmptySymbolList
 
Fields inherited from interface org.biojava.bio.symbol.SymbolList
EMPTY_LIST
 
Constructor Summary
protected AbstractSymbolList()
           
 
Method Summary
abstract  Alphabet getAlphabet()
          The alphabet that this SymbolList is over.
 java.util.Iterator iterator()
          An Iterator over all Symbols in this SymbolList.
abstract  int length()
          The number of symbols in this SymbolList.
 java.lang.String seqString()
          Stringify this symbol list.
 SymbolList subList(int start, int end)
          Return a new SymbolList for the symbols start to end inclusive.
 java.lang.String subStr(int start, int end)
          Return a region of this symbol list as a String.
abstract  Symbol symbolAt(int index)
          Return the symbol at index, counting from 1.
 java.util.List toList()
          Returns a List of symbols.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSymbolList

protected AbstractSymbolList()
Method Detail

getAlphabet

public abstract Alphabet getAlphabet()
Description copied from interface: SymbolList
The alphabet that this SymbolList is over.

Every symbol within this SymbolList is a member of this alphabet. alphabet.contains(symbol) == true for each symbol that is within this sequence.

Specified by:
getAlphabet in interface SymbolList
Tags copied from interface: SymbolList
Returns:
the alphabet

iterator

public java.util.Iterator iterator()
Description copied from interface: SymbolList
An Iterator over all Symbols in this SymbolList.

This is an ordered iterator over the Symbols. It cannot be used to edit the underlying symbols.

Specified by:
iterator in interface SymbolList
Tags copied from interface: SymbolList
Returns:
an iterator

length

public abstract int length()
Description copied from interface: SymbolList
The number of symbols in this SymbolList.
Specified by:
length in interface SymbolList
Tags copied from interface: SymbolList
Returns:
the length

symbolAt

public abstract Symbol symbolAt(int index)
Description copied from interface: SymbolList
Return the symbol at index, counting from 1.
Specified by:
symbolAt in interface SymbolList
Tags copied from interface: SymbolList
Parameters:
index - the ofset into this SymbolList
Returns:
the Symbol at that index
Throws:
java.lang.IndexOutOfBoundsException - if index is less than 1, or greater than the length of the symbol list

subList

public SymbolList subList(int start,
                          int end)
Description copied from interface: SymbolList
Return a new SymbolList for the symbols start to end inclusive.

The resulting SymbolList will count from 1 to (end-start + 1) inclusive, and refer to the symbols start to end of the original sequence.

Specified by:
subList in interface SymbolList
Tags copied from interface: SymbolList
Parameters:
start - the first symbol of the new SymbolList
end - the last symbol (inclusive) of the new SymbolList

toList

public java.util.List toList()
Description copied from interface: SymbolList
Returns a List of symbols.

This is an immutable list of symbols. Do not edit it.

Specified by:
toList in interface SymbolList
Tags copied from interface: SymbolList
Returns:
a List of Symbols

seqString

public java.lang.String seqString()
Description copied from interface: SymbolList
Stringify this symbol list.

It is expected that this will use the symbol's token to render each symbol. It should be parsable back into a SymbolList using the default token parser for this alphabet.

Specified by:
seqString in interface SymbolList
Tags copied from interface: SymbolList
Returns:
a string representation of the symbol list

subStr

public java.lang.String subStr(int start,
                               int end)
Description copied from interface: SymbolList
Return a region of this symbol list as a String.

This should use the same rules as seqString.

Specified by:
subStr in interface SymbolList
Tags copied from interface: SymbolList
Parameters:
start - the first symbol to include
end - the last symbol to include
Returns:
the string representation
Throws:
java.lang.IndexOutOfBoundsException - if either start or end are not within the sequence