1 package prefuse.data.column; 2 3 import java.util.Arrays ; 4 5 import prefuse.data.DataReadOnlyException; 6 import prefuse.data.DataTypeException; 7 8 13 public class LongColumn extends AbstractColumn { 14 15 private long[] m_values; 16 private int m_size; 17 18 21 public LongColumn() { 22 this(0, 10, 0L); 23 } 24 25 29 public LongColumn(int nrows) { 30 this(nrows, nrows, 0L); 31 } 32 33 39 public LongColumn(int nrows, int capacity, long defaultValue) { 40 super(long.class, new Long (defaultValue)); 41 if ( capacity < nrows ) { 42 throw new IllegalArgumentException ( 43 "Capacity value can not be less than the row count."); 44 } 45 m_values = new long[capacity]; 46 Arrays.fill(m_values, defaultValue); 47 m_size = nrows; 48 } 49 50 53 56 public int getRowCount() { 57 return m_size; 58 } 59 60 63 public void setMaximumRow(int nrows) { 64 if ( nrows > m_values.length ) { 65 int capacity = Math.max((3*m_values.length)/2 + 1, nrows); 66 long[] values = new long[capacity]; 67 System.arraycopy(m_values, 0, values, 0, m_size); 68 Arrays.fill(values, m_size, capacity, 69 ((Long )m_defaultValue).longValue()); 70 m_values = values; 71 } 72 m_size = nrows; 73 } 74 75 78 81 public Object get(int row) { 82 return new Long (getLong(row)); 83 } 84 85 88 public void set(Object val, int row) throws DataTypeException { 89 if ( m_readOnly ) { 90 throw new DataReadOnlyException(); 91 } else if ( val != null ) { 92 if ( val instanceof Number ) { 93 setLong(((Number )val).longValue(), row); 94 } else if ( val instanceof String ) { 95 setString((String )val, row); 96 } else { 97 throw new DataTypeException(val.getClass()); 98 } 99 } else { 100 throw new DataTypeException("Column does not accept null values"); 101 } 102 } 103 104 107 110 public long getLong(int row) throws DataTypeException { 111 if ( row < 0 || row > m_size ) { 112 throw new IllegalArgumentException ("Row index out of bounds: "+row); 113 } 114 return m_values[row]; 115 } 116 117 120 public void setLong(long val, int row) throws DataTypeException { 121 if ( m_readOnly ) { 122 throw new DataReadOnlyException(); 123 } else if ( row < 0 || row >= m_size ) { 124 throw new IllegalArgumentException ("Row index out of bounds: "+row); 125 } 126 long prev = m_values[row]; 128 129 if ( prev == val ) return; 131 132 m_values[row] = val; 134 135 fireColumnEvent(row, prev); 137 } 138 139 153 155 158 public int getInt(int row) throws DataTypeException { 159 return (int)getLong(row); 160 } 161 162 165 public float getFloat(int row) throws DataTypeException { 166 return getLong(row); 167 } 168 169 172 public double getDouble(int row) throws DataTypeException { 173 return getLong(row); 174 } 175 176 } | Popular Tags |