Package ucar.ma2
Class ArrayStructureBB
- java.lang.Object
-
- ucar.ma2.Array
-
- ucar.ma2.ArrayStructure
-
- ucar.ma2.ArrayStructureBB
-
- All Implemented Interfaces:
Iterable<StructureData>
- Direct Known Subclasses:
ArrayStructureBBpos
,ArrayStructureBBsection
public class ArrayStructureBB extends ArrayStructure
Concrete implementation of ArrayStructure, data storage is in a ByteBuffer, which is converted to member data on the fly. In order to use this, the records must have the same size, and the member offset must be the same for each record. Use StructureMembers.setStructureSize() to set the record size. Use StructureMembers.Member.setDataParam() to set the offset of the member from the start of each record. The member data will then be located in the BB at offset = recnum * getStructureSize() + member.getDataParam(). This defers object creation for efficiency. Use getArray() and getScalar () data accessors if possible. Structure pdata = (Structure) ncfile.findVariable(name); StructureMembers members = pdata.makeStructureMembers(); members.findMember("value").setDataParam(0); // these are the offsets into the record members.findMember("x_start").setDataParam(2); members.findMember("y_start").setDataParam(4); members.findMember("direction").setDataParam(6); members.findMember("speed").setDataParam(8); int recsize = pos[1] - pos[0]; // each record must be all the same size members.setStructureSize(recsize); ArrayStructureBB asbb = new ArrayStructureBB(members, new int[] {size}, bos, pos[0]);
For String members, you must store the Strings in the stringHeap. An integer index into the heap is used in the ByteBuffer.- See Also:
Array
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ucar.ma2.ArrayStructure
ArrayStructure.ArrayStructureIterator
-
-
Constructor Summary
Constructors Constructor Description ArrayStructureBB(StructureMembers members, int[] shape)
Create a new Array of type StructureData and the given members and shape.ArrayStructureBB(StructureMembers members, int[] shape, ByteBuffer bbuffer, int offset)
Construct an ArrayStructureBB with the given ByteBuffer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addObjectToHeap(int recnum, StructureMembers.Member m, Object s)
int
addObjectToHeap(Object s)
protected int
calcOffsetSetOrder(int recnum, StructureMembers.Member m)
protected void
copyBytes(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyChars(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyDoubles(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyFloats(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyInts(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyLongs(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyObjects(int recnum, StructureMembers.Member m, IndexIterator result)
protected void
copyShorts(int recnum, StructureMembers.Member m, IndexIterator result)
Array
getArray(int recnum, StructureMembers.Member m)
Get member data of any type for a specific record as an Array.ArraySequence
getArraySequence(int recnum, StructureMembers.Member m)
Get member data of type ArraySequenceArrayStructure
getArrayStructure(int recnum, StructureMembers.Member m)
Get member data of type array of Structure.ByteBuffer
getByteBuffer()
Return backing storage as a ByteBufferList<Object>
getHeap()
DO NOT MODIFYbyte[]
getJavaArrayByte(int recnum, StructureMembers.Member m)
Get member data of type byte as a 1D array.char[]
getJavaArrayChar(int recnum, StructureMembers.Member m)
Get member data of type char as a 1D array.double[]
getJavaArrayDouble(int recnum, StructureMembers.Member m)
Get member data of type double as a 1D array.float[]
getJavaArrayFloat(int recnum, StructureMembers.Member m)
Get member data of type float as a 1D array.int[]
getJavaArrayInt(int recnum, StructureMembers.Member m)
Get member data of type int as a 1D array.long[]
getJavaArrayLong(int recnum, StructureMembers.Member m)
Get member data of type long as a 1D array.short[]
getJavaArrayShort(int recnum, StructureMembers.Member m)
Get member data of type short as a 1D array.String[]
getJavaArrayString(int recnum, StructureMembers.Member m)
Get member data of type String as a 1D array.byte
getScalarByte(int recnum, StructureMembers.Member m)
Get scalar member data of type byte.char
getScalarChar(int recnum, StructureMembers.Member m)
Get scalar member data of type char.double
getScalarDouble(int recnum, StructureMembers.Member m)
Get scalar member data of type double.float
getScalarFloat(int recnum, StructureMembers.Member m)
Get scalar member data of type float.int
getScalarInt(int recnum, StructureMembers.Member m)
Get scalar member data of type int.long
getScalarLong(int recnum, StructureMembers.Member m)
Get scalar member data of type long.short
getScalarShort(int recnum, StructureMembers.Member m)
Get scalar member data of type short.String
getScalarString(int recnum, StructureMembers.Member m)
Get member data of type String or char.StructureData
getScalarStructure(int recnum, StructureMembers.Member m)
Get member data of type Structure.protected StructureData
makeStructureData(ArrayStructure as, int index)
static int
setOffsets(StructureMembers members)
Set the offsets, based on m.getSizeBytes().void
showInternal(Formatter f, Indent indent)
static int
showOffsets(StructureMembers members, Indent indent, Formatter f)
-
Methods inherited from class ucar.ma2.ArrayStructure
convertScalarDouble, convertScalarFloat, convertScalarInt, convertScalarLong, copy, copyFrom1DJavaArray, copySequences, copyStructures, copyTo1DJavaArray, createView, extractMemberArray, findMember, getArrayObject, getBoolean, getBoolean, getByte, getByte, getChar, getChar, getDouble, getDouble, getElementType, getFloat, getFloat, getInt, getInt, getLong, getLong, getMembers, getObject, getObject, getScalarObject, getShort, getShort, getSizeBytes, getStorage, getStructureData, getStructureData, getStructureDataIterator, getStructureMemberNames, getStructureMembers, getStructureSize, iterator, sectionNoReduce, setBoolean, setBoolean, setByte, setByte, setChar, setChar, setDouble, setDouble, setFloat, setFloat, setInt, setInt, setLong, setLong, setMemberArray, setObject, setObject, setShort, setShort, showInternalMembers
-
Methods inherited from class ucar.ma2.Array
arraycopy, copyTo1DJavaArray, copyToNDJavaArray, factory, factory, factory, factory, factoryConstant, factoryCopy, flip, get1DJavaArray, get1DJavaArray, getDataAsByteBuffer, getDataAsByteBuffer, getDataAsByteBuffer, getDataType, getIndex, getIndexIterator, getRangeIterator, getRank, getShape, getSize, hasNext, isConstant, isUnsigned, isVlen, makeArray, makeArray, makeArray, makeArrayRankPlusOne, makeFromJavaArray, makeFromJavaArray, makeObjectArray, makeVlenArray, next, nextBoolean, nextByte, nextChar, nextDouble, nextFloat, nextInt, nextLong, nextShort, permute, reduce, reduce, resetLocalIterator, reshape, reshapeNoCopy, section, section, section, sectionNoReduce, shapeToString, slice, toString, transpose
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
bbuffer
protected ByteBuffer bbuffer
-
bb_offset
protected int bb_offset
-
-
Constructor Detail
-
ArrayStructureBB
public ArrayStructureBB(StructureMembers members, int[] shape)
Create a new Array of type StructureData and the given members and shape. Generally, you extract the byte array and fill it:byte[] result = (byte[]) structureArray.getStorage();
- Parameters:
members
- a description of the structure membersshape
- the shape of the Array.
-
ArrayStructureBB
public ArrayStructureBB(StructureMembers members, int[] shape, ByteBuffer bbuffer, int offset)
Construct an ArrayStructureBB with the given ByteBuffer.- Parameters:
members
- the list of structure members.shape
- the shape of the structure arraybbuffer
- the data is stored in this ByteBuffer. bbuffer.order must already be set.offset
- offset from the start of the ByteBufffer to the first record.
-
-
Method Detail
-
setOffsets
public static int setOffsets(StructureMembers members)
Set the offsets, based on m.getSizeBytes(). Also sets members.setStructureSize().- Parameters:
members
- set offsets for these members- Returns:
- the total size
-
showOffsets
public static int showOffsets(StructureMembers members, Indent indent, Formatter f)
-
makeStructureData
protected StructureData makeStructureData(ArrayStructure as, int index)
- Specified by:
makeStructureData
in classArrayStructure
-
getByteBuffer
public ByteBuffer getByteBuffer()
Return backing storage as a ByteBuffer- Returns:
- backing storage as a ByteBuffer
-
getScalarDouble
public double getScalarDouble(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type double.- Overrides:
getScalarDouble
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type double.- Returns:
- scalar double value
-
getJavaArrayDouble
public double[] getJavaArrayDouble(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type double as a 1D array. The member data may be any rank.- Overrides:
getJavaArrayDouble
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type double.- Returns:
- double[]
-
copyDoubles
protected void copyDoubles(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyDoubles
in classArrayStructure
-
getScalarFloat
public float getScalarFloat(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type float.- Overrides:
getScalarFloat
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- scalar double value
-
getArray
public Array getArray(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of any type for a specific record as an Array. This may avoid the overhead of creating the StructureData object, but is equivilent to getStructure(recno).getArray( Member m).- Overrides:
getArray
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member.- Returns:
- Array values.
-
getJavaArrayFloat
public float[] getJavaArrayFloat(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type float as a 1D array.- Overrides:
getJavaArrayFloat
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- float[]
-
copyFloats
protected void copyFloats(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyFloats
in classArrayStructure
-
getScalarByte
public byte getScalarByte(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type byte.- Overrides:
getScalarByte
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type byte.- Returns:
- scalar double value
-
getJavaArrayByte
public byte[] getJavaArrayByte(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type byte as a 1D array.- Overrides:
getJavaArrayByte
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type byte.- Returns:
- byte[]
-
copyBytes
protected void copyBytes(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyBytes
in classArrayStructure
-
getScalarShort
public short getScalarShort(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type short.- Overrides:
getScalarShort
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type short.- Returns:
- scalar double value
-
getJavaArrayShort
public short[] getJavaArrayShort(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type short as a 1D array.- Overrides:
getJavaArrayShort
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type float.- Returns:
- short[]
-
copyShorts
protected void copyShorts(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyShorts
in classArrayStructure
-
getScalarInt
public int getScalarInt(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type int.- Overrides:
getScalarInt
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type int.- Returns:
- scalar double value
-
getJavaArrayInt
public int[] getJavaArrayInt(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type int as a 1D array.- Overrides:
getJavaArrayInt
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type int.- Returns:
- int[]
-
copyInts
protected void copyInts(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyInts
in classArrayStructure
-
getScalarLong
public long getScalarLong(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type long.- Overrides:
getScalarLong
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type long.- Returns:
- scalar double value
-
getJavaArrayLong
public long[] getJavaArrayLong(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type long as a 1D array.- Overrides:
getJavaArrayLong
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type long.- Returns:
- long[]
-
copyLongs
protected void copyLongs(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyLongs
in classArrayStructure
-
getScalarChar
public char getScalarChar(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get scalar member data of type char.- Overrides:
getScalarChar
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type char.- Returns:
- scalar double value
-
getJavaArrayChar
public char[] getJavaArrayChar(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type char as a 1D array.- Overrides:
getJavaArrayChar
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type char.- Returns:
- char[]
-
copyChars
protected void copyChars(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyChars
in classArrayStructure
-
getScalarString
public String getScalarString(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type String or char.- Overrides:
getScalarString
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type String or char.- Returns:
- scalar String value
-
getJavaArrayString
public String[] getJavaArrayString(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type String as a 1D array.- Overrides:
getJavaArrayString
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type String.- Returns:
- String[]
-
copyObjects
protected void copyObjects(int recnum, StructureMembers.Member m, IndexIterator result)
- Overrides:
copyObjects
in classArrayStructure
-
getScalarStructure
public StructureData getScalarStructure(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type Structure.- Overrides:
getScalarStructure
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- scalar StructureData
-
getArrayStructure
public ArrayStructure getArrayStructure(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type array of Structure.- Overrides:
getArrayStructure
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- nested ArrayStructure.
-
getArraySequence
public ArraySequence getArraySequence(int recnum, StructureMembers.Member m)
Description copied from class:ArrayStructure
Get member data of type ArraySequence- Overrides:
getArraySequence
in classArrayStructure
- Parameters:
recnum
- get data from the recnum-th StructureData of the ArrayStructure. Must be less than getSize();m
- get data from this StructureMembers.Member. Must be of type Structure.- Returns:
- nested ArrayStructure.
-
calcOffsetSetOrder
protected int calcOffsetSetOrder(int recnum, StructureMembers.Member m)
-
addObjectToHeap
public int addObjectToHeap(Object s)
-
addObjectToHeap
public void addObjectToHeap(int recnum, StructureMembers.Member m, Object s)
-
showInternal
public void showInternal(Formatter f, Indent indent)
- Overrides:
showInternal
in classArrayStructure
-
-