001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021
022package org.biojava.bio.seq.impl;
023
024import java.util.Iterator;
025import java.util.List;
026
027import org.biojava.bio.Annotation;
028import org.biojava.bio.BioException;
029import org.biojava.bio.seq.Feature;
030import org.biojava.bio.seq.FeatureFilter;
031import org.biojava.bio.seq.FeatureHolder;
032import org.biojava.bio.seq.Sequence;
033import org.biojava.bio.symbol.Alphabet;
034import org.biojava.bio.symbol.Edit;
035import org.biojava.bio.symbol.IllegalAlphabetException;
036import org.biojava.bio.symbol.Symbol;
037import org.biojava.bio.symbol.SymbolList;
038import org.biojava.utils.AbstractChangeable;
039import org.biojava.utils.ChangeListener;
040import org.biojava.utils.ChangeVetoException;
041
042/**
043 * A Sequence implementation that has a name and URI but no features,
044 * and a zero length symbol list.
045 *
046 * You will probably want to use
047 * {@link org.biojava.bio.seq.SequenceTools#createDummy(String uri, String name)} instead of using this
048 * class directly
049 *
050 * A better alternative may be a {@link org.biojavax.bio.seq.RichSequence RichSequence}
051 * with an {@link org.biojavax.bio.seq.InfinitelyAmbiguousSymbolList InfinitelyAmbiguousSymbolList}
052 *
053 * @author Thomas Down
054 * @author David Allen
055 * @author Matthew Pocock
056 */
057public final class DummySequence
058        extends AbstractChangeable
059        implements Sequence
060{
061    private String urn;
062    private String name;
063
064    private FeatureHolder features;
065    private SymbolList    symbols;
066    private Annotation    annotation;
067
068    public DummySequence(String urn, String name)
069    {
070        this.urn  = urn;
071        this.name = name;
072
073        features   = FeatureHolder.EMPTY_FEATURE_HOLDER;
074        symbols    = SymbolList.EMPTY_LIST;
075        annotation = Annotation.EMPTY_ANNOTATION;
076
077        // Lock all delegates to prevent changes
078        features.addChangeListener(ChangeListener.ALWAYS_VETO);
079        symbols.addChangeListener(ChangeListener.ALWAYS_VETO);
080        annotation.addChangeListener(ChangeListener.ALWAYS_VETO);
081    }
082
083    public Annotation getAnnotation()
084    {
085        return annotation;
086    }
087
088    public int length()
089    {
090        return symbols.length();
091    }
092
093    public Iterator iterator()
094    {
095        return symbols.iterator();
096    }
097
098    public SymbolList subList(int start, int end)
099        throws IndexOutOfBoundsException
100    {
101        return symbols.subList(start, end);
102    }
103
104    public Alphabet getAlphabet()
105    {
106        return symbols.getAlphabet();
107    }
108
109    public Symbol symbolAt(int index) throws IndexOutOfBoundsException
110    {
111        return symbols.symbolAt(index);
112    }
113
114    public List toList()
115    {
116        return symbols.toList();
117    }
118
119    public String seqString()
120    {
121        return symbols.seqString();
122    }
123
124    public String subStr(int start, int end)
125        throws IndexOutOfBoundsException
126    {
127        return symbols.subStr(start, end);
128    }
129
130    public void edit(Edit edit)
131        throws IndexOutOfBoundsException, IllegalAlphabetException,
132            ChangeVetoException
133    {
134        symbols.edit(edit);
135    }
136
137    public String getName()
138    {
139        return name;
140    }
141
142    public String getURN()
143    {
144        return urn;
145    }
146
147    public int countFeatures()
148    {
149        return features.countFeatures();
150    }
151
152    public Iterator features()
153    {
154        return features.features();
155    }
156
157    public FeatureHolder filter(FeatureFilter ff, boolean recurse)
158    {
159        return features.filter(ff, recurse);
160    }
161
162    public FeatureHolder filter(FeatureFilter ff) {
163        return features.filter(ff);
164    }
165    
166    public Feature createFeature(Feature.Template template)
167        throws BioException, ChangeVetoException
168    {
169        return features.createFeature(template);
170    }
171
172    public void removeFeature(Feature feature)
173            throws ChangeVetoException, BioException
174    {
175        features.removeFeature(feature);
176    }
177
178    public boolean containsFeature(Feature feature)
179    {
180        return features.containsFeature(feature);
181    }
182    
183    public FeatureFilter getSchema() {
184        return features.getSchema();
185    }
186}