    001    package calhoun.analysis.crf.io;
    002
    003    import java.util.Collection;
    004
    005    import calhoun.util.Assert;
    006
    007    /** input sequence that captures the 'name' of a sequence.  This is useful for display or for tracking outputs,
    008     * but usually won't be used by the engine.  The full sequence name is returned as the data element for every position.
    009     * In this respect it is not really a sequence.<p>
    010     * This feature has some special properties that allow sequences to be tracked as they are subsetted.
    011     * When subsetting a <code>NameInputSequence</code>, a string is append to the name showing the start and stop (one-based
    012     * inclusive) of the subsetting.  For example, if the sequence with name "CND1" is subsetting to based 201 to 1000, then
    013     * the new name will be "CND1:201-1000".  To avoid repetitive subsetting, the NameInput does not allow subsetting on names
    014     * containing a '-'.
    015     */
    016    public class NameInputSequence implements InputSequence<String>  {
    017            String str;
    018
    019            /** default constructor */
    020            public NameInputSequence() { }
    021
    022            /** constructors an input sequence using this name */
    023            public NameInputSequence(String a) {
    024                    str = a;
    025            }
    026
    027            public String getName() {
    028                    return str;
    029            }
    030
    031            public String getX(int ix) {
    032                    return str;
    033            }
    034
    035            public int length() {
    036                    return -1;
    037            }
    038
    039            public InputSequence<?> getComponent(String name) {
    040                    throw new UnsupportedOperationException();
    041            }
    042
    043            public Collection<String> listComponents() {
    044                    throw new UnsupportedOperationException();
    045            }
    046
    047            public InputSequence<String> subSequence(int start, int end)  {
    048                    Assert.a(!str.contains("-"));
    049                    NameInputSequence n = new NameInputSequence(str + ":" + start + "-" + end);
    050                    return n;
    051            }
    052    }