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 integer values. */
008 public class InputSequenceInt implements InputSequence<Integer> {
009 int[] data;
010
011 /** default constructor */
012 public InputSequenceInt() { }
013
014 /** creates an input sequence using data from this int array
015 * @param a an int array containing the input sequence */
016 public InputSequenceInt(int[] a) {
017 data = a;
018 }
019
020 /** gets the int array containing the data for this sequence.
021 * @return the int array containing the data for this sequence
022 */
023 public int[] getData() {
024 return data;
025 }
026
027 public Integer getX(int ix) {
028 return data[ix];
029 }
030
031 public int length() {
032 return data == null ? 0 : data.length;
033 }
034
035 public InputSequence<?> getComponent(String name) {
036 throw new UnsupportedOperationException();
037 }
038
039 public Collection<String> listComponents() {
040 throw new UnsupportedOperationException();
041 }
042
043 public InputSequence<Integer> subSequence(int start, int end) {
044 Assert.a(start >= 1);
045 Assert.a(end <= this.length());
046 Assert.a(start <= end);
047 int[] newdata = new int[end-start+1];
048 for (int j=0; j<(end-start+1); j++) {
049 newdata[j] = data[j+start-1];
050 }
051 InputSequenceInt B = new InputSequenceInt(newdata);
052 return B;
053 }
054 }