.
*/
/** ***********************************************************
*
*
* PURPOSE:
* This class represents a MArray with base type Integer.
* @version $Revision: 1.11 $
* for ODMG type UShort(2 bytes, due to ODMG standard) you can use RasMArrayInteger,
* but only values up to 2^16 (performance loss because of convertion 4 bytes-> 2 bytes!);
* method intersectionWith(RasMInterval) uses byte array and is not optimized for special data arrays
*
*
* COMMENTS:
*
*
*********************************************************** */
public class RasMArrayInteger extends RasGMArray
{
/** default constructor */
public RasMArrayInteger()
{
super();
typeLength = SIZE_OF_INTEGER;
}
/**
* constructor for uninitialized MDD objects
* @param initDomain The initial Domain of the MArray
* */
public RasMArrayInteger(final RasMInterval initDomain)
{
super(initDomain, SIZE_OF_INTEGER);
objectData = new int[(int)(dataSize/SIZE_OF_INTEGER)];
data = null;
}
/**
* Constructor for uninitialized MDD objects with Storage Layout
* @param initDomain The initial Domain of the MArray
* @param RasStorageLayout The storage layout to be used
*/
public RasMArrayInteger(final RasMInterval initDomain, RasStorageLayout stl)
{
super(initDomain, SIZE_OF_INTEGER, stl);
objectData = new int[(int)(dataSize/SIZE_OF_INTEGER)];
data = null;
}
/**
* copy constructor
* @param obj a copy of this object will be created
*/
public RasMArrayInteger(final RasMArrayInteger obj)
{
super(obj);
if(obj.objectData!=null)
{
objectData = new int[(int)(obj.dataSize/SIZE_OF_INTEGER)];
System.arraycopy(obj.getIntArray(), 0, objectData, 0, (int)(obj.dataSize/SIZE_OF_INTEGER));
data = null;
}
}
/**
* subscript operator for read access of a cell. The cell value is returned
* as a byte[SIZE_OF_INTEGER] array. This kind of access to a cell is significantly slower
* than getInt(), because each cell value has to be converted from int to a
* byte[SIZE_OF_INTEGER] array.
* The user has to take care that each Cell value is stored, before getting the next Cell.
*/
public byte[] getCell(RasPoint point)
throws RasDimensionMismatchException, RasIndexOutOfBoundsException
{
int cellValue;
int tmp;
//first test dimensionality
if(point.dimension() != domain.dimension())
throw new RasDimensionMismatchException(point.dimension(), domain.dimension());
cellValue = ((int[])objectData)[(int)domain.cellOffset(point)];
for(int i=0; i>>= (((SIZE_OF_INTEGER -1)-i)*8);
currentCell[i] = (byte)tmp;
}
return currentCell;
}
/** subscript operator for read access of a cell. The cell value is returned as
* an Integer. This access method is faster then getCell(), because no conversion
* from int to Byte[SIZE_OF_INTEGER] has to be done.
*/
public int getInt( final RasPoint point)
throws RasDimensionMismatchException, RasIndexOutOfBoundsException
{
// first test dimensionality
if(point.dimension() != domain.dimension())
throw new RasDimensionMismatchException(point.dimension(), domain.dimension());
return ((int[])objectData)[(int)domain.cellOffset(point)];
}
/**
* get the internal representation of the array
*/
public int[] getIntArray()
{
if(objectData==null)
{
ByteArrayInputStream bis = new ByteArrayInputStream(data);
DataInputStream dis = new DataInputStream(bis);
objectData = new int[data.length/SIZE_OF_INTEGER];
try
{
for(int j=0; j