1 package prefuse.data.column; 2 3 import java.util.BitSet ; 4 5 import prefuse.data.DataReadOnlyException; 6 import prefuse.data.DataTypeException; 7 8 14 public class BooleanColumn extends AbstractColumn { 15 16 private BitSet m_bits; 17 private int m_size; 18 19 22 public BooleanColumn() { 23 this(0, 10, false); 24 } 25 26 30 public BooleanColumn(int nrows) { 31 this(nrows, nrows, false); 32 } 33 34 40 public BooleanColumn(int nrows, int capacity, boolean defaultValue) { 41 super(boolean.class, new Boolean (defaultValue)); 42 if ( capacity < nrows ) { 43 throw new IllegalArgumentException ( 44 "Capacity value can not be less than the row count."); 45 } 46 m_bits = new BitSet (capacity); 47 m_bits.set(0, capacity, defaultValue); 48 m_size = nrows; 49 } 50 51 54 57 public int getRowCount() { 58 return m_size; 59 } 60 61 64 public void setMaximumRow(int nrows) { 65 if ( nrows > m_size ) { 66 m_bits.set(m_size, nrows, 67 ((Boolean )m_defaultValue).booleanValue()); 68 } 69 m_size = nrows; 70 } 71 72 75 78 public Object get(int row) { 79 return new Boolean (getBoolean(row)); 80 } 81 82 85 public void set(Object val, int row) throws DataTypeException { 86 if ( m_readOnly ) { 87 throw new DataReadOnlyException(); 88 } else if ( val != null ) { 89 if ( val instanceof Boolean ) { 90 setBoolean(((Boolean )val).booleanValue(), row); 91 } else if ( val instanceof String ) { 92 setString((String )val, row); 93 } else { 94 throw new DataTypeException(val.getClass()); 95 } 96 } else { 97 throw new DataTypeException("Column does not accept null values"); 98 } 99 } 100 101 104 107 public boolean getBoolean(int row) throws DataTypeException { 108 if ( row < 0 || row > m_size ) { 109 throw new IllegalArgumentException ("Row index out of bounds: "+row); 110 } 111 return m_bits.get(row); 112 } 113 114 117 public void setBoolean(boolean val, int row) throws DataTypeException { 118 if ( m_readOnly ) { 119 throw new DataReadOnlyException(); 120 } else if ( row < 0 || row >= m_size ) { 121 throw new IllegalArgumentException ("Row index out of bounds: "+row); 122 } 123 boolean prev = m_bits.get(row); 125 126 if ( prev == val ) return; 128 129 m_bits.set(row, val); 131 132 fireColumnEvent(row, prev); 134 } 135 136 159 } | Popular Tags |