Class SimpleSymbolList

  • All Implemented Interfaces:
    java.io.Serializable, java.util.EventListener, SymbolList, Changeable, ChangeListener

    public class SimpleSymbolList
    extends AbstractSymbolList
    implements ChangeListener, java.io.Serializable
    Basic implementation of SymbolList. This is currently backed by a normal Java array.

    SimpleSymbolList is now editable. edit() has been implemented in a way that edits are relatively inefficient, but symbolAt() is very efficient.

    A new constructor SimpleSymbolList(SymbolParser,String) has been added so you can now simply turn a String into a SymbolList. This is mostly to provide a simple way to create a SymbolList for people just trying to get their feet wet. So here is an example.

    String seqString = "gaattc"; FiniteAlphabet dna = (FiniteAlphabet) AlphabetManager.alphabetForName("DNA"); SymbolParser parser = dna.getTokenization("token"); SymbolList mySl = new SimpleSymbolList (parser,seqString); System.out.println("Look at my sequence " + mySl.seqString());

    with the right parser you should be able to make a protein sequence from the String "AspAlaValIleAsp"

    subList() is implemented such that subLists are views of the original until such time as the underlying SymbolList is edited in a way that would modify the subList, at which point the subList gets its own array of Symbols and does not reflect the edit to the original. When subList() is called on another subList (which is a veiw SimpleSymbolList) the new SimpleSymbolList is a view of the original, not the subList.

    Author:
    Thomas Down, David Waring, David Huen (another constructor), George Waldon
    See Also:
    Serialized Form
    • Constructor Detail

      • SimpleSymbolList

        public SimpleSymbolList​(Alphabet alpha)
        Construct an empty SimpleSymbolList.
        Parameters:
        alpha - The alphabet of legal symbols in this list.
      • SimpleSymbolList

        public SimpleSymbolList​(Alphabet alpha,
                                java.util.List rList)
                         throws IllegalSymbolException
        Construct a SymbolList containing the symbols in the specified list.
        Parameters:
        alpha - The alphabet of legal symbols for this list.
        rList - A Java List of symbols.
        Throws:
        IllegalSymbolException - if a Symbol is not in the specified alphabet.
        java.lang.ClassCastException - if rList contains objects which do not implement Symbol.
      • SimpleSymbolList

        public SimpleSymbolList​(SymbolList sl)
        Construct a copy of an existing SymbolList.
        Parameters:
        sl - the list to copy.
      • SimpleSymbolList

        public SimpleSymbolList​(Symbol[] symbols,
                                int length,
                                Alphabet alphabet)
        Construct a SimpleSymbolList given the Symbol array that backs it. Used primarily with the chunked SymbolList builder but could be used elsewhere too.
    • Method Detail

      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • length

        public int length()
        Get the length of this SymbolList.
        Specified by:
        length in interface SymbolList
        Returns:
        the length
      • symbolAt

        public Symbol symbolAt​(int pos)
        Find a symbol at a specified offset in the SymbolList.
        Specified by:
        symbolAt in interface SymbolList
        Parameters:
        pos - Position in biological coordinates (1..length)
        Returns:
        the Symbol at that index
      • subList

        public SymbolList subList​(int start,
                                  int end)
        create a subList of the original, this will be a view until either the original symbolList or the sublist is edited
        Specified by:
        subList in interface SymbolList
        Overrides:
        subList in class AbstractSymbolList
        Parameters:
        start - the first symbol of the new SymbolList
        end - the last symbol (inclusive) of the new SymbolList
      • edit

        public void edit​(Edit edit)
                  throws java.lang.IndexOutOfBoundsException,
                         IllegalAlphabetException,
                         ChangeVetoException
        Apply and edit to the SymbolList as specified by Edit.

        edit() is now supported using the ChangeEvent system. SubLists do NOT reflect edits.

        Specified by:
        edit in interface SymbolList
        Overrides:
        edit in class AbstractSymbolList
        Parameters:
        edit - the Edit to perform
        Throws:
        java.lang.IndexOutOfBoundsException - if the edit does not lie within the SymbolList
        IllegalAlphabetException - if the SymbolList to insert has an incompatible alphabet
        ChangeVetoException - if either the SymboList does not support the edit, or if the change was vetoed
      • postChange

        public void postChange​(ChangeEvent cev)
        Description copied from interface: ChangeListener

        Called when a change has just taken place.

        This method is the place to perform any behavior in response to the change event.

        Specified by:
        postChange in interface ChangeListener
        Parameters:
        cev - An event encapsulating the change which has occured.
      • getSymbolArray

        public Symbol[] getSymbolArray()
        Return the Java Symbol[] array that backs this object. primarily used to accelerate reconstruction of symbol lists in the packed chunked symbol list implementation.