org.biojava.bio.symbol
Class DoubleAlphabet

java.lang.Object
  |
  +--org.biojava.bio.symbol.DoubleAlphabet

public class DoubleAlphabet
extends java.lang.Object
implements Alphabet, java.io.Serializable

An efficient implementation of an Alphabet over the infinite set of double values.

This class can be used to represent lists of floating-point numbers as a SymbolList with the alphabet DoubleAlphabet. These lists can then be annotated with features, or fed into dynamic-programming algorithms, or processed as per any other SymbolList object.

Object identity can not be used to decide if two DoubleResidue objects are the same. You must use the equals method, or compare doubleValue manualy.

Author:
Matthew Pocock
See Also:
Serialized Form

Inner Class Summary
static class DoubleAlphabet.DoubleSymbol
          A single double value.
 
Inner classes inherited from class org.biojava.bio.symbol.Alphabet
Alphabet.EmptyAlphabet
 
Fields inherited from interface org.biojava.bio.symbol.Alphabet
EMPTY_ALPHABET
 
Constructor Summary
DoubleAlphabet()
           
 
Method Summary
 boolean contains(Symbol r)
          Returns whether or not this Alphabet contains the symbol.
static SymbolList fromArray(double[] dArray)
          Retrieve a SymbolList view of an array of doubles.
 Annotation getAnnotation()
          Should return the associated annotation object.
static DoubleAlphabet getInstance()
          Retrieve the single DoubleAlphabet instance.
 java.lang.String getName()
          Get the name of the alphabet.
 SymbolParser getParser(java.lang.String name)
          Get a parser by name.
 DoubleAlphabet.DoubleSymbol getSymbol(double val)
          Retrieve the Symbol for a double.
 void validate(Symbol r)
          Throws a precanned IllegalSymbolException if the symbol is not contained within this Alphabet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleAlphabet

public DoubleAlphabet()
Method Detail

fromArray

public static SymbolList fromArray(double[] dArray)
Retrieve a SymbolList view of an array of doubles.

The returned object is a view onto the underlying array, and does not copy it. Changes made to the original array will alter the resulting SymbolList.

Parameters:
dArray - the array of doubles to view
Returns:
a SymbolList over the DoubleAlphabet that represent the values in dArray

getInstance

public static DoubleAlphabet getInstance()
Retrieve the single DoubleAlphabet instance.
Returns:
the singleton DoubleAlphabet instance

getSymbol

public DoubleAlphabet.DoubleSymbol getSymbol(double val)
Retrieve the Symbol for a double.
Parameters:
val - the double to view
Returns:
a DoubleSymbol embodying val

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

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.

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

validate

public void validate(Symbol r)
              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.

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

getName

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

getParser

public SymbolParser getParser(java.lang.String name)
Description copied from interface: Alphabet
Get a parser by name.

The parser returned is guaranteed to return Symbols and SymbolLists that conform to this alphabet.

Every alphabet should have a SymbolParser under the name 'token' that uses the symbol token characters to translate a string into a SymbolList. Likewise, there should be a SymbolParser under the name 'name' that uses symbol names to identify symbols. Any other names may also be defined, but the behaviour of that parser is not defined here.

Specified by:
getParser in interface Alphabet
Tags copied from interface: Alphabet
Parameters:
name - the name of the parser
Returns:
a parser for that name
Throws:
java.util.NoSuchElementException - if the name is unknown
BioException - if for any reason the parser could not be built