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 boolean values. */
008 public class InputSequenceBoolean implements InputSequence<Boolean> {
009 boolean[] data;
010
011 /** default constructor */
012 public InputSequenceBoolean() { }
013
014 /** creates an input sequence using data from this boolean array
015 * @param a a boolean array containing the input sequence */
016 public InputSequenceBoolean(boolean[] a) {
017 data = a;
018 }
019
020 /** gets the boolean array containing the data for this sequence.
021 * @return the boolean array containing the data for this sequence
022 */
023 public boolean[] getData() {
024 return data;
025 }
026
027 public Boolean 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<Boolean> subSequence(int start, int end) {
044 Assert.a(start >= 1);
045 Assert.a(end <= this.length());
046 Assert.a(start <= end);
047 boolean[] newdata = new boolean[end-start+1];
048 for (int j=0; j<(end-start+1); j++) {
049 newdata[j] = data[j+start-1];
050 }
051 InputSequenceBoolean B = new InputSequenceBoolean(newdata);
052 return B;
053 }
054 }