1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.jbeans.j3d.data;
24
25 /* ------------------ Import classes (packages) ------------------- *//package-summary/html">class="comment"> ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment">/* ------------------ Import classes (packages) ------------------- *//package-summary.html">class="comment"> ------------------ Import classes (packages) ------------------- */
26 import net.jbeans.lang.*;
27 import net.jbeans.util.debug.*;
28
29
30
31
32 /***
33 * AttributeArray is an abstract class that defines various methods
34 * to handle n-dimensional attribute data such as scalars, vectors, tensors,
35 * etc.
36 *
37 * @version $Revision: 1.3 $
38 * @author Masahiro Takatsuka (masa@jbeans.net)
39 */
40
41 public abstract class AttributeArray {
42 private static final boolean DEBUG = Debug.getDebugFlag(AttributeArray.class);
43
44 /***
45 * serialVersionUID
46 * Masahiro Takatsuka/2000-Oct-10
47 */
48 private static final long serialVersionUID = 8817898063130280170L;
49
50 protected DataArray data;
51
52 /***
53 * Construct object with an initial data array of type dataType.
54 * The default dataType is DataType.FLOAT.
55 */
56 public AttributeArray(int dataType) {
57 this.setDataType(dataType);
58 }
59
60 public AttributeArray() {
61 this(DataType.FLOAT);
62 }
63
64 public AttributeArray(AttributeArray aa) {
65 this(aa.getDataType());
66 copy(aa);
67 }
68
69 public void copy(AttributeArray aa) {
70 this.data.copy(aa.getData());
71 }
72
73 /***
74 * Virtual constructor creates object of same type as this object.
75 */
76 public abstract AttributeArray makeObject();
77
78 /***
79 * Allocates the specified number (numOfAtt) of attributes.
80 */
81 public boolean allocate(int numOfAtt) {
82 int dim = this.data.getDimension();
83 return this.data.allocate(numOfAtt * dim);
84 }
85
86 public void initialize() {
87 this.data.initialize();
88 }
89
90 public int getDimension() {
91 return this.data.getDimension();
92 }
93
94 public int getDataType() {
95 return this.data.getDataType();
96 }
97
98 /***
99 * Specify the underlying data type of the object.
100 */
101 public void setDataType(int dataType) {
102 if (this.data != null && dataType == this.data.getDataType()) {
103 return;
104 }
105 switch (dataType) {
106 case DataType.BIT:
107 this.data = new BitArray();
108 break;
109 case DataType.CHAR:
110 this.data = new CharArray();
111 break;
112 case DataType.SHORT:
113 this.data = new ShortArray();
114 break;
115 case DataType.INT:
116 this.data = new IntArray();
117 break;
118 case DataType.LONG:
119 this.data = new LongArray();
120 break;
121 case DataType.FLOAT:
122 this.data = new FloatArray();
123 break;
124 case DataType.DOUBLE:
125 default:
126 this.data = new DoubleArray();
127 break;
128 case DataType.STRING:
129 this.data = new StringArray();
130 break;
131 }
132 }
133
134 /***
135 * Set the data for this object. The tuple dimension must be consistent
136 * with the object.
137 */
138 public void setData(DataArray data) {
139 if ((data != this.data) && (data != null)) {
140 if (data.getDimension() != this.data.getDimension()) {
141 if (DEBUG) {
142 System.out.println("Number of components is different...can't set data");
143 }
144 return;
145 }
146 this.data = data;
147 }
148 }
149
150 public DataArray getData() {
151 return this.data;
152 }
153
154 public void setDataTypeToBit() {
155 setDataType(DataType.BIT);
156 }
157
158 public void setDataTypeToChar() {
159 setDataType(DataType.CHAR);
160 }
161
162 public void setDataTypeToShort() {
163 setDataType(DataType.SHORT);
164 }
165
166 public void setDataTypeToInt() {
167 setDataType(DataType.INT);
168 }
169
170 public void setDataTypeToLong() {
171 setDataType(DataType.LONG);
172 }
173
174 public void setDataTypeToFloat() {
175 setDataType(DataType.FLOAT);
176 }
177
178 public void setDataTypeToDouble() {
179 setDataType(DataType.DOUBLE);
180 }
181
182 public void setDataTypeToString() {
183 setDataType(DataType.STRING);
184 }
185
186 /***
187 * Compact the data array. (Reclaim any extra memory.)
188 */
189 public void squeeze() {
190 this.data.squeeze();
191 }
192
193 /***
194 * Make object look empty but do not delete memory.
195 */
196 public void reset() {
197 this.data.reset();
198 }
199 }