001 package calhoun.analysis.crf.io;
002
003 import java.util.Collection;
004
005 import calhoun.util.Assert;
006
007 /** an input sequence where the elements of the sequence are objects. */
008 public class InputSequenceObject<T> implements InputSequence<T> {
009 T[] t;
010
011 /** default constructor */
012 public InputSequenceObject() {
013 }
014
015 /** creates an input sequence using data from this Object array
016 * @param t a an object array containing the input sequence */
017 public InputSequenceObject(T[] t) {
018 this.t = t;
019 }
020
021 public T getX(int ix) {
022 return t[ix];
023 }
024
025 public int length() {
026 return t.length;
027 }
028
029 public InputSequence<?> getComponent(String name) {
030 throw new UnsupportedOperationException();
031 }
032
033 public Collection<String> listComponents() {
034 throw new UnsupportedOperationException();
035 }
036
037 public InputSequence<T> subSequence(int start, int end) {
038 Assert.a(start >= 1);
039 Assert.a(end <= this.length());
040 Assert.a(start <= end);
041
042 int length = end - start + 1;
043 T[] ret = (T[]) new Object[length];
044 for(int i= 0; i<length; ++i) {
045 ret[i] = t[i+start-1];
046 }
047 return new InputSequenceObject<T>(ret);
048 }
049 }