1 package prefuse.data.column; 2 3 import java.util.Date ; 4 5 import prefuse.data.DataTypeException; 6 import prefuse.data.Table; 7 import prefuse.data.expression.Expression; 8 9 15 public class ColumnFactory { 16 17 22 public static final Column getColumn(Class type) { 23 return getColumn(type, 0, 0, null); 24 } 25 26 32 public static final Column getColumn(Class type, int nrows) { 33 return getColumn(type, nrows, nrows, null); 34 } 35 36 43 public static final Column getColumn(Class type, int nrows, 44 Object defaultValue) 45 { 46 return getColumn(type, nrows, nrows, defaultValue); 47 } 48 49 58 public static final Column getColumn(Class type, int nrows, int nnz, 59 Object defaultValue) 60 { 61 if ( type == byte.class ) 62 { 63 if ( defaultValue == null ) { 64 return new ByteColumn(nrows); 65 } else { 66 byte def = ((Number )defaultValue).byteValue(); 67 return new ByteColumn(nrows, nrows, def); 68 } 69 } 70 if ( type == int.class ) 71 { 72 if ( defaultValue == null ) { 73 return new IntColumn(nrows); 74 } else { 75 int def = ((Number )defaultValue).intValue(); 76 return new IntColumn(nrows, nrows, def); 77 } 78 } 79 else if ( type == long.class ) 80 { 81 if ( defaultValue == null ) { 82 return new LongColumn(nrows); 83 } else { 84 long def = ((Number )defaultValue).longValue(); 85 return new LongColumn(nrows, nrows, def); 86 } 87 } 88 else if ( type == float.class ) 89 { 90 if ( defaultValue == null ) { 91 return new FloatColumn(nrows); 92 } else { 93 float def = ((Number )defaultValue).floatValue(); 94 return new FloatColumn(nrows, nrows, def); 95 } 96 } 97 else if ( type == double.class ) 98 { 99 if ( defaultValue == null ) { 100 return new DoubleColumn(nrows); 101 } else { 102 double def = ((Number )defaultValue).doubleValue(); 103 return new DoubleColumn(nrows, nrows, def); 104 } 105 } 106 else if ( type == boolean.class ) 107 { 108 if ( defaultValue == null ) { 109 return new BooleanColumn(nrows); 110 } else { 111 boolean def = ((Boolean )defaultValue).booleanValue(); 112 return new BooleanColumn(nrows, nrows, def); 113 } 114 } 115 else if ( Date .class.isAssignableFrom(type) ) 116 { 117 if ( defaultValue == null ) { 118 return new DateColumn(type, nrows); 119 } else { 120 Date d = ((Date )defaultValue); 121 return new DateColumn(type, nrows, nrows, d.getTime()); 122 } 123 } 124 else if ( type == byte.class 125 || type == short.class 126 || type == char.class 127 || type == void.class ) 128 { 129 throw new DataTypeException(type); 130 } 131 else 132 { 133 return new ObjectColumn(type, nrows, nrows, defaultValue); 134 } 135 } 136 137 143 public static final Column getColumn(Table t, Expression expr) { 144 return new ExpressionColumn(t, expr); 145 } 146 147 153 public static final Column getConstantColumn(Class type, Object dflt) { 154 return new ConstantColumn(type, dflt); 155 } 156 157 } | Popular Tags |