97 protected int banks; 98 99 /** Offset into default (first) bank from which to get the first element. */ 100 protected int offset; 101 102 /** Usable size of all banks. */ 103 protected int size; 104 105 /** Offsets into all banks. */ 106 protected int offsets[]; 107 108 /* The current StateTrackable state. */ 109 StateTrackableDelegate theTrackable; 110 111 /** Size of the data types indexed by DataType tags defined above. */ 112 private static final int dataTypeSize[] = {8,16,16,32,32,64}; 113 114 /** Returns the size (in bits) of the data type, given a datatype tag. 115 * @param type the value of one of the defined datatype tags 116 * @return the size of the data type 117 * @throws IllegalArgumentException if <code>type</code> is less than 118 * zero or greater than {@link #TYPE_DOUBLE} 119 */ 120 public static int getDataTypeSize(int type) { 121 if (type < TYPE_BYTE || type > TYPE_DOUBLE) { 122 throw new IllegalArgumentException("Unknown data type "+type); 123 } 124 return dataTypeSize[type]; 125 } 126 127 /** 128 * Constructs a DataBuffer containing one bank of the specified 129 * data type and size. 130 * 131 * @param dataType the data type of this <code>DataBuffer</code> 132 * @param size the size of the banks 133 */ 134 protected DataBuffer(int dataType, int size) { 135 this(UNTRACKABLE, dataType, size); 136 } 137 138 /** 139 * Constructs a DataBuffer containing one bank of the specified 140 * data type and size with the indicated initial {@link State State}. 141 * 142 * @param initialState the initial {@link State State} state of the data 143 * @param dataType the data type of this <code>DataBuffer</code> 144 * @param size the size of the banks 145 * @since 1.7 146 */ 147 DataBuffer(State initialState, 148 int dataType, int size) 149 { 150 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 151 this.dataType = dataType; 152 this.banks = 1; 153 this.size = size; 154 this.offset = 0; 155 this.offsets = new int[1]; // init to 0 by new 156 } 157 158 /** 159 * Constructs a DataBuffer containing the specified number of 160 * banks. Each bank has the specified size and an offset of 0. 161 * 162 * @param dataType the data type of this <code>DataBuffer</code> 163 * @param size the size of the banks 164 * @param numBanks the number of banks in this 165 * <code>DataBuffer</code> 166 */ 167 protected DataBuffer(int dataType, int size, int numBanks) { 168 this(UNTRACKABLE, dataType, size, numBanks); 169 } 170 171 /** 172 * Constructs a DataBuffer containing the specified number of 173 * banks with the indicated initial {@link State State}. 174 * Each bank has the specified size and an offset of 0. 175 * 176 * @param initialState the initial {@link State State} state of the data 177 * @param dataType the data type of this <code>DataBuffer</code> 178 * @param size the size of the banks 179 * @param numBanks the number of banks in this 180 * <code>DataBuffer</code> 181 * @since 1.7 182 */ 183 DataBuffer(State initialState, 184 int dataType, int size, int numBanks) 185 { 186 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 187 this.dataType = dataType; 188 this.banks = numBanks; 189 this.size = size; 190 this.offset = 0; 191 this.offsets = new int[banks]; // init to 0 by new 192 } 193 194 /** 195 * Constructs a DataBuffer that contains the specified number 196 * of banks. Each bank has the specified datatype, size and offset. 197 * 198 * @param dataType the data type of this <code>DataBuffer</code> 199 * @param size the size of the banks 200 * @param numBanks the number of banks in this 201 * <code>DataBuffer</code> 202 * @param offset the offset for each bank 203 */ 204 protected DataBuffer(int dataType, int size, int numBanks, int offset) { 205 this(UNTRACKABLE, dataType, size, numBanks, offset); 206 } 207 208 /** 209 * Constructs a DataBuffer that contains the specified number 210 * of banks with the indicated initial {@link State State}. 211 * Each bank has the specified datatype, size and offset. 212 * 213 * @param initialState the initial {@link State State} state of the data 214 * @param dataType the data type of this <code>DataBuffer</code> 215 * @param size the size of the banks 216 * @param numBanks the number of banks in this 217 * <code>DataBuffer</code> 218 * @param offset the offset for each bank 219 * @since 1.7 220 */ 221 DataBuffer(State initialState, 222 int dataType, int size, int numBanks, int offset) 223 { 224 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 225 this.dataType = dataType; 226 this.banks = numBanks; 227 this.size = size; 228 this.offset = offset; 229 this.offsets = new int[numBanks]; 230 for (int i = 0; i < numBanks; i++) { 231 this.offsets[i] = offset; 232 } 233 } 234 235 /** 236 * Constructs a DataBuffer which contains the specified number 237 * of banks. Each bank has the specified datatype and size. The 238 * offset for each bank is specified by its respective entry in 239 * the offsets array. 240 * 241 * @param dataType the data type of this <code>DataBuffer</code> 242 * @param size the size of the banks 243 * @param numBanks the number of banks in this 244 * <code>DataBuffer</code> 245 * @param offsets an array containing an offset for each bank. 246 * @throws ArrayIndexOutOfBoundsException if <code>numBanks</code> 247 * does not equal the length of <code>offsets</code> 248 */ 249 protected DataBuffer(int dataType, int size, int numBanks, int offsets[]) { 250 this(UNTRACKABLE, dataType, size, numBanks, offsets); 251 } 252 253 /** 254 * Constructs a DataBuffer which contains the specified number 255 * of banks with the indicated initial {@link State State}. 256 * Each bank has the specified datatype and size. The 257 * offset for each bank is specified by its respective entry in 258 * the offsets array. 259 * 260 * @param initialState the initial {@link State State} state of the data 261 * @param dataType the data type of this <code>DataBuffer</code> 262 * @param size the size of the banks 263 * @param numBanks the number of banks in this 264 * <code>DataBuffer</code> 265 * @param offsets an array containing an offset for each bank. 266 * @throws ArrayIndexOutOfBoundsException if <code>numBanks</code> 267 * does not equal the length of <code>offsets</code> 268 * @since 1.7 269 */ 270 DataBuffer(State initialState, 271 int dataType, int size, int numBanks, int offsets[]) 272 { 273 if (numBanks != offsets.length) { 274 throw new ArrayIndexOutOfBoundsException("Number of banks" + 275 " does not match number of bank offsets"); 276 } 277 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 278 this.dataType = dataType; 279 this.banks = numBanks; 280 this.size = size; 281 this.offset = offsets[0]; 282 this.offsets = offsets.clone(); 283 } 284 285 /** Returns the data type of this DataBuffer. 286 * @return the data type of this <code>DataBuffer</code>. 287 */ 288 public int getDataType() { 289 return dataType; 290 } 291 292 /** Returns the size (in array elements) of all banks. 293 * @return the size of all banks. 294 */ 295 public int getSize() { 296 return size; 297 } 298 299 /** Returns the offset of the default bank in array elements. 300 * @return the offset of the default bank. 301 */ 302 public int getOffset() { 303 return offset; 304 } 305 306 /** Returns the offsets (in array elements) of all the banks. | 97 protected int banks; 98 99 /** Offset into default (first) bank from which to get the first element. */ 100 protected int offset; 101 102 /** Usable size of all banks. */ 103 protected int size; 104 105 /** Offsets into all banks. */ 106 protected int offsets[]; 107 108 /* The current StateTrackable state. */ 109 StateTrackableDelegate theTrackable; 110 111 /** Size of the data types indexed by DataType tags defined above. */ 112 private static final int dataTypeSize[] = {8,16,16,32,32,64}; 113 114 /** Returns the size (in bits) of the data type, given a datatype tag. 115 * @param type the value of one of the defined datatype tags 116 * @return the size of the data type 117 * @throws IllegalArgumentException if {@code type} is less than 118 * zero or greater than {@link #TYPE_DOUBLE} 119 */ 120 public static int getDataTypeSize(int type) { 121 if (type < TYPE_BYTE || type > TYPE_DOUBLE) { 122 throw new IllegalArgumentException("Unknown data type "+type); 123 } 124 return dataTypeSize[type]; 125 } 126 127 /** 128 * Constructs a DataBuffer containing one bank of the specified 129 * data type and size. 130 * 131 * @param dataType the data type of this {@code DataBuffer} 132 * @param size the size of the banks 133 */ 134 protected DataBuffer(int dataType, int size) { 135 this(UNTRACKABLE, dataType, size); 136 } 137 138 /** 139 * Constructs a DataBuffer containing one bank of the specified 140 * data type and size with the indicated initial {@link State State}. 141 * 142 * @param initialState the initial {@link State State} state of the data 143 * @param dataType the data type of this {@code DataBuffer} 144 * @param size the size of the banks 145 * @since 1.7 146 */ 147 DataBuffer(State initialState, 148 int dataType, int size) 149 { 150 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 151 this.dataType = dataType; 152 this.banks = 1; 153 this.size = size; 154 this.offset = 0; 155 this.offsets = new int[1]; // init to 0 by new 156 } 157 158 /** 159 * Constructs a DataBuffer containing the specified number of 160 * banks. Each bank has the specified size and an offset of 0. 161 * 162 * @param dataType the data type of this {@code DataBuffer} 163 * @param size the size of the banks 164 * @param numBanks the number of banks in this 165 * {@code DataBuffer} 166 */ 167 protected DataBuffer(int dataType, int size, int numBanks) { 168 this(UNTRACKABLE, dataType, size, numBanks); 169 } 170 171 /** 172 * Constructs a DataBuffer containing the specified number of 173 * banks with the indicated initial {@link State State}. 174 * Each bank has the specified size and an offset of 0. 175 * 176 * @param initialState the initial {@link State State} state of the data 177 * @param dataType the data type of this {@code DataBuffer} 178 * @param size the size of the banks 179 * @param numBanks the number of banks in this 180 * {@code DataBuffer} 181 * @since 1.7 182 */ 183 DataBuffer(State initialState, 184 int dataType, int size, int numBanks) 185 { 186 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 187 this.dataType = dataType; 188 this.banks = numBanks; 189 this.size = size; 190 this.offset = 0; 191 this.offsets = new int[banks]; // init to 0 by new 192 } 193 194 /** 195 * Constructs a DataBuffer that contains the specified number 196 * of banks. Each bank has the specified datatype, size and offset. 197 * 198 * @param dataType the data type of this {@code DataBuffer} 199 * @param size the size of the banks 200 * @param numBanks the number of banks in this 201 * {@code DataBuffer} 202 * @param offset the offset for each bank 203 */ 204 protected DataBuffer(int dataType, int size, int numBanks, int offset) { 205 this(UNTRACKABLE, dataType, size, numBanks, offset); 206 } 207 208 /** 209 * Constructs a DataBuffer that contains the specified number 210 * of banks with the indicated initial {@link State State}. 211 * Each bank has the specified datatype, size and offset. 212 * 213 * @param initialState the initial {@link State State} state of the data 214 * @param dataType the data type of this {@code DataBuffer} 215 * @param size the size of the banks 216 * @param numBanks the number of banks in this 217 * {@code DataBuffer} 218 * @param offset the offset for each bank 219 * @since 1.7 220 */ 221 DataBuffer(State initialState, 222 int dataType, int size, int numBanks, int offset) 223 { 224 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 225 this.dataType = dataType; 226 this.banks = numBanks; 227 this.size = size; 228 this.offset = offset; 229 this.offsets = new int[numBanks]; 230 for (int i = 0; i < numBanks; i++) { 231 this.offsets[i] = offset; 232 } 233 } 234 235 /** 236 * Constructs a DataBuffer which contains the specified number 237 * of banks. Each bank has the specified datatype and size. The 238 * offset for each bank is specified by its respective entry in 239 * the offsets array. 240 * 241 * @param dataType the data type of this {@code DataBuffer} 242 * @param size the size of the banks 243 * @param numBanks the number of banks in this 244 * {@code DataBuffer} 245 * @param offsets an array containing an offset for each bank. 246 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} 247 * does not equal the length of {@code offsets} 248 */ 249 protected DataBuffer(int dataType, int size, int numBanks, int offsets[]) { 250 this(UNTRACKABLE, dataType, size, numBanks, offsets); 251 } 252 253 /** 254 * Constructs a DataBuffer which contains the specified number 255 * of banks with the indicated initial {@link State State}. 256 * Each bank has the specified datatype and size. The 257 * offset for each bank is specified by its respective entry in 258 * the offsets array. 259 * 260 * @param initialState the initial {@link State State} state of the data 261 * @param dataType the data type of this {@code DataBuffer} 262 * @param size the size of the banks 263 * @param numBanks the number of banks in this 264 * {@code DataBuffer} 265 * @param offsets an array containing an offset for each bank. 266 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} 267 * does not equal the length of {@code offsets} 268 * @since 1.7 269 */ 270 DataBuffer(State initialState, 271 int dataType, int size, int numBanks, int offsets[]) 272 { 273 if (numBanks != offsets.length) { 274 throw new ArrayIndexOutOfBoundsException("Number of banks" + 275 " does not match number of bank offsets"); 276 } 277 this.theTrackable = StateTrackableDelegate.createInstance(initialState); 278 this.dataType = dataType; 279 this.banks = numBanks; 280 this.size = size; 281 this.offset = offsets[0]; 282 this.offsets = offsets.clone(); 283 } 284 285 /** Returns the data type of this DataBuffer. 286 * @return the data type of this {@code DataBuffer}. 287 */ 288 public int getDataType() { 289 return dataType; 290 } 291 292 /** Returns the size (in array elements) of all banks. 293 * @return the size of all banks. 294 */ 295 public int getSize() { 296 return size; 297 } 298 299 /** Returns the offset of the default bank in array elements. 300 * @return the offset of the default bank. 301 */ 302 public int getOffset() { 303 return offset; 304 } 305 306 /** Returns the offsets (in array elements) of all the banks. |