public abstract class ProductData extends Object implements Cloneable
ProductData
class represents a generic data buffer used to hold the actual data values
stored in remote sensing data products.
A single ProductData
instance can have one or more elements of a primitive type. The primitive types
are:
signed 8-bit integer
unsigned 16-bit integer
signed 32-bit integer
unsigned 16-bit integer
signed 32-bit integer
unsigned 32-bit integer
32-bit floating point
64-bit floating point
a character string (8-bit ASCII encoding)
a MJD-2000 encoded data/time value
The number of elements is an inmutable property of a ProductData
instance.
In order to access the data in a ProductData
instance, multiple setters and getters are provided
which use generic transfer data types in order to make the data transfer in and out of a
ProductData
instance easy for programmers.
For scalar (one-element) values the prototypes are
void setElemType(Type elem); Type getElemType();For vector (multiple-element) values the prototypes are
void setElemTypeAt(int index, Type elem); Type getElemTypeAt(int index);Where the transfer data type
Type
is one of int
, long
,
float
, double
and String
.Modifier and Type | Class and Description |
---|---|
static class |
ProductData.ASCII
The
ProductData.ASCII class is a ProductData.Byte specialisation representing textual
values. |
static class |
ProductData.Byte
The
Byte class is a ProductData specialisation for signed 8-bit integer fields. |
static class |
ProductData.Double
The
ProductData.Float class is a ProductData specialisation for 64-bit floating point
fields. |
static class |
ProductData.Float
The
ProductData.Float class is a ProductData specialisation for 32-bit floating point
fields. |
static class |
ProductData.Int
The
Int class is a ProductData specialisation for signed 32-bit integer fields. |
static class |
ProductData.Short
The
Short class is a ProductData specialisation for signed 16-bit integer fields. |
static class |
ProductData.UByte
The
UByte class is a ProductData specialisation for unsigned 8-bit integer fields. |
static class |
ProductData.UInt
The
UInt class is a ProductData specialisation for unsigned 32-bit integer fields. |
static class |
ProductData.UShort
The
UShort class is a ProductData specialisation for unsigned 16-bit integer fields. |
static class |
ProductData.UTC
The
ProductData.UTC class is a ProductData.UInt specialisation for UTC date/time
values. |
Modifier and Type | Field and Description |
---|---|
static int |
TYPE_ASCII
The ID for a ASCII string represented by an array of bytes (
byte[] ). |
static int |
TYPE_FLOAT32
The ID for a signed 32-bit floating point data type.
|
static int |
TYPE_FLOAT64
The ID for a signed 64-bit floating point data type.
|
static int |
TYPE_INT16
The ID for a signed 16-bit integer data type.
|
static int |
TYPE_INT32
The ID for a signed 32-bit integer data type.
|
static int |
TYPE_INT8
The ID for a signed 8-bit integer data type.
|
static int |
TYPE_UINT16
The ID for an unsigned 16-bit integer data type.
|
static int |
TYPE_UINT32
The ID for an unsigned 32-bit integer data type.
|
static int |
TYPE_UINT8
The ID for an unsigned 8-bit integer data type.
|
static int |
TYPE_UNDEFINED
The ID for an undefined data type.
|
static int |
TYPE_UTC
The ID for a UTC date/time value represented as Modified Julian Day (MJD) (an
int[3] : int[0] = days,
int[1] = seconds, int[2] = micro-seconds). |
static String |
TYPESTRING_ASCII
The string representation of
TYPE_ASCII |
static String |
TYPESTRING_FLOAT32
The string representation of
TYPE_FLOAT32 |
static String |
TYPESTRING_FLOAT64
The string representation of
TYPE_FLOAT64 |
static String |
TYPESTRING_INT16
The string representation of
TYPE_INT16 |
static String |
TYPESTRING_INT32
The string representation of
TYPE_INT32 |
static String |
TYPESTRING_INT8
The string representation of
TYPE_INT8 |
static String |
TYPESTRING_UINT16
The string representation of
TYPE_UINT16 |
static String |
TYPESTRING_UINT32
The string representation of
TYPE_UINT32 |
static String |
TYPESTRING_UINT8
The string representation of
TYPE_UINT8 |
static String |
TYPESTRING_UTC
The string representation of
TYPE_UTC |
Modifier | Constructor and Description |
---|---|
protected |
ProductData(int type)
Constructs a new value of the given type.
|
Modifier and Type | Method and Description |
---|---|
protected abstract ProductData |
createDeepClone()
Retuns a "deep" copy of this product data.
|
static ProductData |
createInstance(byte[] elems) |
static ProductData |
createInstance(double[] elems) |
static ProductData |
createInstance(float[] elems) |
static ProductData |
createInstance(int type)
Factory method which creates a value instance of the given type and with exactly one element.
|
static ProductData |
createInstance(int[] elems) |
static ProductData |
createInstance(int type,
int numElems)
Factory method which creates a value instance of the given type and with the specified number of elements.
|
static ProductData |
createInstance(int type,
Object data)
Factory method which creates a value instance of the given type and with the specified number of elements.
|
static ProductData |
createInstance(long[] elems)
Deprecated.
|
static ProductData |
createInstance(short[] elems) |
static ProductData |
createInstance(String strData) |
static ProductData |
createUnsignedInstance(byte[] elems) |
static ProductData |
createUnsignedInstance(int[] elems) |
static ProductData |
createUnsignedInstance(short[] elems) |
abstract void |
dispose()
Releases all of the resources used by this object instance and all of its owned children.
|
boolean |
equalElems(ProductData other)
Tests whether this ProductData is equal to another one.
|
boolean |
equals(Object other)
Returns
Object.equals(Object) . |
boolean |
getElemBoolean()
Returns the value as an
boolean . |
boolean |
getElemBooleanAt(int index)
Gets the value element with the given index as a
boolean . |
double |
getElemDouble()
Returns the value as an
double . |
abstract double |
getElemDoubleAt(int index)
Gets the value element with the given index as a
double . |
float |
getElemFloat()
Returns the value as an
float . |
abstract float |
getElemFloatAt(int index)
Gets the value element with the given index as a
float . |
int |
getElemInt()
Returns the value as an
int . |
abstract int |
getElemIntAt(int index)
Gets the value element with the given index as an
int . |
abstract Object |
getElems()
Returns the internal value.
|
int |
getElemSize()
Gets the element size of an element of this product data in bytes.
|
static int |
getElemSize(int type)
Gets the element size of an element of the given type in bytes.
|
String |
getElemString()
Returns the value as a
String . |
abstract String |
getElemStringAt(int index)
Gets the value element with the given index as a
String . |
long |
getElemUInt()
Returns the value as an unsigned
int given as a long . |
abstract long |
getElemUIntAt(int index)
Gets the value element with the given index as a
long . |
abstract int |
getNumElems()
Returns the number of data elements this value has.
|
int |
getType()
Returns this value's type ID.
|
static int |
getType(String type)
Returns a integer representation of the given data type string.
|
String |
getTypeString()
Returns this value's data type String.
|
static String |
getTypeString(int type)
Returns a textual representation of the given data type.
|
int |
hashCode()
Returns
Object.hashCode() . |
static boolean |
isFloatingPointType(int type)
Tests whether the given value type is a floating point type.
|
boolean |
isInt()
Tests whether this value has an integer.
|
static boolean |
isIntType(int type)
Tests whether the given value type is a signed or unsigned integer type.
|
boolean |
isScalar()
Tests if this value is a scalar.
|
boolean |
isSigned()
Tests whether the actual instance is an signed data type.
|
static boolean |
isUIntType(int type)
Tests whether the given value type is an unsigned integer type.
|
boolean |
isUnsigned()
Tests whether the actual instance is an unsigned data type.
|
void |
readFrom(ImageInputStream input)
Reads all elements of this
ProductData instance from to the given input stream. |
void |
readFrom(int pos,
ImageInputStream input)
Reads a single element of this
ProductData instance from to the given output stream. |
abstract void |
readFrom(int startPos,
int numElems,
ImageInputStream input)
Reads elements of this
ProductData instance from the given output stream. |
void |
readFrom(int startPos,
int numElems,
ImageInputStream input,
long inputPos)
Reads elements into this
ProductData instance from the given input stream. |
void |
setElemBoolean(boolean value)
Sets the value as a
boolean . |
void |
setElemBooleanAt(int index,
boolean value)
Sets the value at the specified index as a
boolean . |
void |
setElemDouble(double value)
Sets the value as a
double . |
abstract void |
setElemDoubleAt(int index,
double value)
Sets the value at the specified index as a
double . |
void |
setElemFloat(float value)
Sets the value as a
float . |
abstract void |
setElemFloatAt(int index,
float value)
Sets the value at the specified index as a
float . |
void |
setElemInt(int value)
Sets the value as an
int . |
abstract void |
setElemIntAt(int index,
int value)
Sets the value at the specified index as an
int . |
abstract void |
setElems(Object data)
Sets the internal value.
|
void |
setElemString(String value)
Sets the value as a
String . |
void |
setElemStringAt(int index,
String value)
Sets the value at the specified index as a
String . |
void |
setElemUInt(long value)
Sets the value as an unsigned
int given as a long . |
abstract void |
setElemUIntAt(int index,
long value)
Sets the value at the specified index as an unsigned
int given as a long . |
String |
toString()
Returns a string representation of this value which can be used for debugging purposes.
|
void |
writeTo(ImageOutputStream output)
Writes all elements of this
ProductData instance to to the given output stream. |
void |
writeTo(int pos,
ImageOutputStream output)
Writes a single element of this
ProductData instance to to the given output stream. |
abstract void |
writeTo(int startPos,
int numElems,
ImageOutputStream output)
Writes elements of this
ProductData instance to to the given output stream. |
void |
writeTo(int startPos,
int numElems,
ImageOutputStream output,
long outputPos)
Writes elements of this
ProductData instance to to the given output stream. |
public static final int TYPE_UNDEFINED
public static final int TYPE_INT8
public static final int TYPE_INT16
public static final int TYPE_INT32
public static final int TYPE_UINT8
public static final int TYPE_UINT16
public static final int TYPE_UINT32
public static final int TYPE_FLOAT32
public static final int TYPE_FLOAT64
public static final int TYPE_ASCII
byte[]
).public static final int TYPE_UTC
int[3]
: int[0] = days,
int[1] = seconds, int[2] = micro-seconds).public static final String TYPESTRING_INT8
TYPE_INT8
public static final String TYPESTRING_INT16
TYPE_INT16
public static final String TYPESTRING_INT32
TYPE_INT32
public static final String TYPESTRING_UINT8
TYPE_UINT8
public static final String TYPESTRING_UINT16
TYPE_UINT16
public static final String TYPESTRING_UINT32
TYPE_UINT32
public static final String TYPESTRING_FLOAT32
TYPE_FLOAT32
public static final String TYPESTRING_FLOAT64
TYPE_FLOAT64
public static final String TYPESTRING_ASCII
TYPE_ASCII
public static final String TYPESTRING_UTC
TYPE_UTC
protected ProductData(int type)
type
- the value's typepublic static ProductData createInstance(int type)
type
- the value's typenull
if the given type is not knownpublic static ProductData createInstance(int type, int numElems)
type
- the value's typenumElems
- the number of elements, must be greater than zero if type is not TYPE_UTC
null
if the given type is not knownIllegalArgumentException
- if one of the arguments is invalidpublic static ProductData createInstance(int type, Object data)
type
- the value's typedata
- if type
is TYPE_ASCII
the String
, otherwise the primitive array type corresponding to type
null
if the given type is not knownIllegalArgumentException
- if one of the arguments is invalidpublic static ProductData createInstance(byte[] elems)
public static ProductData createUnsignedInstance(byte[] elems)
public static ProductData createInstance(short[] elems)
public static ProductData createUnsignedInstance(short[] elems)
public static ProductData createInstance(int[] elems)
public static ProductData createUnsignedInstance(int[] elems)
@Deprecated public static ProductData createInstance(long[] elems)
public static ProductData createInstance(String strData)
public static ProductData createInstance(float[] elems)
public static ProductData createInstance(double[] elems)
public int getType()
public static int getElemSize(int type)
type
- the element typeIllegalArgumentException
- if the type is not supported.public int getElemSize()
public static String getTypeString(int type)
null
if the type is unknownpublic static int getType(String type)
null
if the type is unknownpublic String getTypeString()
public boolean isInt()
public static boolean isIntType(int type)
public boolean isSigned()
public boolean isUnsigned()
public static boolean isUIntType(int type)
public static boolean isFloatingPointType(int type)
public boolean isScalar()
public abstract int getNumElems()
public int getElemInt()
int
. The method assumes that this value is a scalar and therefore simply
returns getElemIntAt(0)
.
getElemIntAt(int index)
public long getElemUInt()
int
given as a long
. The method assumes that this
value is a scalar and therefore simply returns getElemUIntAt(0)
.
getElemUIntAt(int index)
public float getElemFloat()
float
. The method assumes that this value is a scalar and therefore
simply returns getElemFloatAt(0)
.
getElemFloatAt(int index)
public double getElemDouble()
double
. The method assumes that this value is a scalar and therefore
simply returns getElemDoubleAt(0)
.
getElemDoubleAt(int index)
public String getElemString()
String
. The text returned is the comma-separated list of elements contained
in this value.null
public boolean getElemBoolean()
boolean
. The method assumes that this value is a scalar and therefore
simply returns getElemBooleanAt(0)
.
getElemBooleanAt(int index)
public abstract int getElemIntAt(int index)
int
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic abstract long getElemUIntAt(int index)
long
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic abstract float getElemFloatAt(int index)
float
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic abstract double getElemDoubleAt(int index)
double
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic abstract String getElemStringAt(int index)
String
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic boolean getElemBooleanAt(int index)
boolean
.index
- the value index, must be >=0
and <getNumDataElems()
IndexOutOfBoundsException
- if the index is out of boundspublic void setElemInt(int value)
int
. The method assumes that this value is a scalar and therefore simply
calls setElemInt(0, value)
.
value
- the value to be setsetElemIntAt(int index, int value)
public void setElemUInt(long value)
int
given as a long
. The method assumes that this
value is a scalar and therefore simply calls setElemUInt(0, value)
.
value
- the value to be setsetElemUIntAt(int index, long value)
public void setElemFloat(float value)
float
. The method assumes that this value is a scalar and therefore simply
calls setElemFloatAt(0, value)
.
value
- the value to be setsetElemFloatAt(int index, float value)
public void setElemDouble(double value)
double
. The method assumes that this value is a scalar and therefore simply
calls setElemDoubleAt(0)
.
value
- the value to be setsetElemDoubleAt(int index, double value)
public void setElemString(String value)
String
. The method assumes that this value is a scalar and therefore simply
calls setElemStringAt(0)
.
value
- the value to be setsetElemStringAt(int, java.lang.String)
public void setElemBoolean(boolean value)
boolean
. The method assumes that this value is a scalar and therefore simply
calls setElemDoubleAt(0)
.
value
- the value to be setsetElemBooleanAt(int index, boolean value)
public abstract void setElemIntAt(int index, int value)
int
.index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic abstract void setElemUIntAt(int index, long value)
int
given as a long
.index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic abstract void setElemFloatAt(int index, float value)
float
.index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic abstract void setElemDoubleAt(int index, double value)
double
.index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic void setElemStringAt(int index, String value)
String
.
THE METHOD IS CURRENTLY NOT IMPLEMENTED.
index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic void setElemBooleanAt(int index, boolean value)
boolean
.index
- the value index, must be >=0
and <getNumDataElems()
value
- the value to be setIndexOutOfBoundsException
- if the index is out of boundspublic abstract Object getElems()
byte[]
- for signed/unsigned 8-bit integer fieldsshort[]
- for
signed/unsigned 16-bit integer fieldsint[]
- for signed/unsigned 32-bit integer
fieldsfloat[]
- for signed 32-bit floating point fieldsdouble[]
-
for signed 64-bit floating point fieldspublic abstract void setElems(Object data)
byte[]
- for signed/unsigned 8-bit integer fieldsshort[]
- for
signed/unsigned 16-bit integer fieldsint[]
- for signed/unsigned 32-bit integer
fieldsfloat[]
- for signed 32-bit floating point fieldsdouble[]
-
for signed 64-bit floating point fieldsString[]
- for all field typesdata
- an array of one of the described typespublic void readFrom(ImageInputStream input) throws IOException
ProductData
instance from to the given input stream.
The method subsequentially reads the elements at 0
to getNumElems()-1
of this
ProductData
instance from the given input stream.
Reading starts at the current seek position
within the input stream.
input
- a seekable data input streamIOException
- if an I/O error occurspublic void readFrom(int pos, ImageInputStream input) throws IOException
ProductData
instance from to the given output stream.
The method reads the element at pos
of this ProductData
instance from the given
output stream.
Reading starts at the current seek position within the output stream.
pos
- the destination position (zero-based)input
- a seekable data input streamIOException
- if an I/O error occurspublic abstract void readFrom(int startPos, int numElems, ImageInputStream input) throws IOException
ProductData
instance from the given output stream.
The method subsequentially reads the elements at startPos
to startPos+numElems-1
of
this ProductData
instance from the given input stream.
Reading starts at the current seek
position of the input stream.
startPos
- the destination start position (zero-based)numElems
- the number of elements to readinput
- a seekable data input streamIOException
- if an I/O error occurspublic void readFrom(int startPos, int numElems, ImageInputStream input, long inputPos) throws IOException
ProductData
instance from the given input stream.
The method subsequentially reads the elements at startPos
to startPos+numElems-1
of
this ProductData
instance from the given input stream.
Reading starts at inputPos
within the output stream. The method multiplies this position with the value returned by
getElemSize()
in order to find the correct stream offset in bytes.
startPos
- the destination start position (zero-based)numElems
- the number of elements to readinput
- a seekable data input streaminputPos
- the (zero-based) position in the data output stream where reading startsIOException
- if an I/O error occurspublic void writeTo(ImageOutputStream output) throws IOException
ProductData
instance to to the given output stream.
The method subsequentially writes the elements at 0
to getNumElems()-1
of this
ProductData
instance to the given output stream.
Writing starts at the current seek position
within the output stream.
output
- a seekable data output streamIOException
- if an I/O error occurspublic void writeTo(int pos, ImageOutputStream output) throws IOException
ProductData
instance to to the given output stream.
The method writes the element at pos
of this ProductData
instance to the given
output stream.
Writing starts at the current seek position within the output stream.
pos
- the source position (zero-based)output
- a seekable data output streamIOException
- if an I/O error occurspublic abstract void writeTo(int startPos, int numElems, ImageOutputStream output) throws IOException
ProductData
instance to to the given output stream.
The method subsequentially writes the elements at startPos
to startPos+numElems-1
of this ProductData
instance to the given output stream.
Writing starts at the current seek
position within the output stream.
startPos
- the source start position (zero-based)numElems
- the number of elements to be writtenoutput
- a seekable data output streamIOException
- if an I/O error occurspublic void writeTo(int startPos, int numElems, ImageOutputStream output, long outputPos) throws IOException
ProductData
instance to to the given output stream.
The method subsequentially writes the elements at startPos
to startPos+numElems-1
of this ProductData
instance to the given output stream.
Writing starts at
outputPos
within the output stream. The method multiplies this position with the value returned by
getElemSize()
in order to find the correct stream offset in bytes.
startPos
- the source start position (zero-based)numElems
- the number of elements to be writtenoutput
- a seekable data output streamoutputPos
- the position in the data output stream where writing startsIOException
- if an I/O error occurspublic String toString()
public final int hashCode()
Object.hashCode()
.public final boolean equals(Object other)
Object.equals(Object)
.
Use equalElems(org.esa.snap.core.datamodel.ProductData)
in order to perform an element-wise comparision.public boolean equalElems(ProductData other)
ProductData
instance of the same data type.
Otherwise the method behaves like Object.equals(Object)
.other
- the other oneprotected abstract ProductData createDeepClone()
public abstract void dispose()
This method should be called only if it is for sure that this object instance will never be used again. The
results of referencing an instance of this class after a call to dispose()
are undefined.
Copyright © 2014–2015 European Space Agency (ESA). All rights reserved.