Class ProductData

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class 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.Long
      The Long class is a ProductData specialisation for signed 64-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.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected ProductData​(int type)
      Constructs a new value of the given type.
    • Field Detail

      • TYPE_UNDEFINED

        public static final int TYPE_UNDEFINED
        The ID for an undefined data type.
        See Also:
        Constant Field Values
      • TYPE_INT8

        public static final int TYPE_INT8
        The ID for a signed 8-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_INT16

        public static final int TYPE_INT16
        The ID for a signed 16-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_INT32

        public static final int TYPE_INT32
        The ID for a signed 32-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_INT64

        public static final int TYPE_INT64
        The ID for a signed 64-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_UINT8

        public static final int TYPE_UINT8
        The ID for an unsigned 8-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_UINT16

        public static final int TYPE_UINT16
        The ID for an unsigned 16-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_UINT32

        public static final int TYPE_UINT32
        The ID for an unsigned 32-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_UINT64

        public static final int TYPE_UINT64
        The ID for an unsigned 64-bit integer data type.
        See Also:
        Constant Field Values
      • TYPE_FLOAT32

        public static final int TYPE_FLOAT32
        The ID for a signed 32-bit floating point data type.
        See Also:
        Constant Field Values
      • TYPE_FLOAT64

        public static final int TYPE_FLOAT64
        The ID for a signed 64-bit floating point data type.
        See Also:
        Constant Field Values
      • TYPE_ASCII

        public static final int TYPE_ASCII
        The ID for a ASCII string represented by an array of bytes (byte[]).
        See Also:
        Constant Field Values
      • TYPE_UTC

        public static final 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).
        See Also:
        Constant Field Values
      • TYPESTRING_INT16

        public static final String TYPESTRING_INT16
        The string representation of TYPE_INT16
        See Also:
        Constant Field Values
      • TYPESTRING_INT32

        public static final String TYPESTRING_INT32
        The string representation of TYPE_INT32
        See Also:
        Constant Field Values
      • TYPESTRING_INT64

        public static final String TYPESTRING_INT64
        The string representation of TYPE_INT64
        See Also:
        Constant Field Values
      • TYPESTRING_UINT8

        public static final String TYPESTRING_UINT8
        The string representation of TYPE_UINT8
        See Also:
        Constant Field Values
      • TYPESTRING_UINT16

        public static final String TYPESTRING_UINT16
        The string representation of TYPE_UINT16
        See Also:
        Constant Field Values
      • TYPESTRING_UINT32

        public static final String TYPESTRING_UINT32
        The string representation of TYPE_UINT32
        See Also:
        Constant Field Values
      • TYPESTRING_UINT64

        public static final String TYPESTRING_UINT64
        The string representation of TYPE_UINT64
        See Also:
        Constant Field Values
      • TYPESTRING_FLOAT32

        public static final String TYPESTRING_FLOAT32
        The string representation of TYPE_FLOAT32
        See Also:
        Constant Field Values
      • TYPESTRING_FLOAT64

        public static final String TYPESTRING_FLOAT64
        The string representation of TYPE_FLOAT64
        See Also:
        Constant Field Values
      • TYPESTRING_ASCII

        public static final String TYPESTRING_ASCII
        The string representation of TYPE_ASCII
        See Also:
        Constant Field Values
    • Constructor Detail

      • ProductData

        protected ProductData​(int type)
        Constructs a new value of the given type.
        Parameters:
        type - the value's type
    • Method Detail

      • createInstance

        public static ProductData createInstance​(int type)
        Factory method which creates a value instance of the given type and with exactly one element.
        Parameters:
        type - the value's type
        Returns:
        a new value instance, null if the given type is not known
      • createInstance

        public 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.
        Parameters:
        type - the value's type
        numElems - the number of elements, must be greater than zero if type is not TYPE_UTC
        Returns:
        a new value instance
        Throws:
        IllegalArgumentException - if one of the arguments is invalid
      • createInstance

        public 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.
        Parameters:
        type - the value's type
        data - if type is TYPE_ASCII the String, otherwise the primitive array type corresponding to type
        Returns:
        a new value instance, null if the given type is not known
        Throws:
        IllegalArgumentException - if one of the arguments is invalid
      • createInstance

        public static ProductData createInstance​(byte[] elems)
      • createUnsignedInstance

        public static ProductData createUnsignedInstance​(byte[] elems)
      • createInstance

        public static ProductData createInstance​(short[] elems)
      • createUnsignedInstance

        public static ProductData createUnsignedInstance​(short[] elems)
      • createInstance

        public static ProductData createInstance​(int[] elems)
      • createUnsignedInstance

        public static ProductData createUnsignedInstance​(int[] elems)
      • createInstance

        public static ProductData createInstance​(long[] elems)
      • createInstance

        public static ProductData createInstance​(float[] elems)
      • createInstance

        public static ProductData createInstance​(double[] elems)
      • getType

        public int getType()
        Returns this value's type ID.
      • getElemSize

        public static int getElemSize​(int type)
        Gets the element size of an element of the given type in bytes.
        Parameters:
        type - the element type
        Returns:
        the size of a single element in bytes.
        Throws:
        IllegalArgumentException - if the type is not supported.
      • getElemSize

        public int getElemSize()
        Gets the element size of an element of this product data in bytes.
        Returns:
        the size of a single element in bytes
      • getTypeString

        public static String getTypeString​(int type)
        Returns a textual representation of the given data type.
        Returns:
        a data type string, null if the type is unknown
      • getType

        public static int getType​(String type)
        Returns a integer representation of the given data type string.
        Returns:
        a data type integer, null if the type is unknown
      • getTypeString

        public String getTypeString()
        Returns this value's data type String.
      • isInt

        public boolean isInt()
        Tests whether this value has an integer.
        Returns:
        true, if so
      • isIntType

        public static boolean isIntType​(int type)
        Tests whether the given value type is a signed or unsigned integer type.
        Returns:
        true, if so
      • isSigned

        public boolean isSigned()
        Tests whether the actual instance is an signed data type.
        Returns:
        true, if so
      • isUnsigned

        public boolean isUnsigned()
        Tests whether the actual instance is an unsigned data type.
        Returns:
        true, if so
      • isUIntType

        public static boolean isUIntType​(int type)
        Tests whether the given value type is an unsigned integer type.
        Returns:
        true, if so
      • isFloatingPointType

        public static boolean isFloatingPointType​(int type)
        Tests whether the given value type is a floating point type.
        Returns:
        true, if so
      • isScalar

        public boolean isScalar()
        Tests if this value is a scalar.
        Returns:
        true, if so
      • getNumElems

        public abstract int getNumElems()
        Returns the number of data elements this value has.
      • getElemInt

        public int getElemInt()
        Returns the value as an int.

        The method assumes that this value is a scalar and therefore simply returns getElemIntAt(0).

        See Also:
        getElemIntAt(int index)
      • getElemUInt

        public long getElemUInt()
        Returns the value as an unsigned int given as a long.

        The method assumes that this value is a scalar and therefore simply returns getElemUIntAt(0).

        See Also:
        getElemUIntAt(int index)
      • getElemLong

        public long getElemLong()
        Returns the value as a long.

        The method assumes that this value is a scalar and therefore simply returns getElemLongAt(0).

        See Also:
        getElemLongAt(int index)
      • getElemFloat

        public float getElemFloat()
        Returns the value as an float.

        The method assumes that this value is a scalar and therefore simply returns getElemFloatAt(0).

        See Also:
        getElemFloatAt(int index)
      • getElemDouble

        public double getElemDouble()
        Returns the value as an double.

        The method assumes that this value is a scalar and therefore simply returns getElemDoubleAt(0).

        See Also:
        getElemDoubleAt(int index)
      • getElemString

        public String getElemString()
        Returns the value as a String. The text returned is the comma-separated list of elements contained in this value.
        Returns:
        a text representing this fields value, never null
      • getElemBoolean

        public boolean getElemBoolean()
        Returns the value as an boolean.

        The method assumes that this value is a scalar and therefore simply returns getElemBooleanAt(0).

        See Also:
        getElemBooleanAt(int index)
      • getElemIntAt

        public abstract int getElemIntAt​(int index)
        Gets the value element with the given index as an int.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemUIntAt

        public abstract long getElemUIntAt​(int index)
        Gets the value element with the given index as a long.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemLongAt

        public abstract long getElemLongAt​(int index)
        Gets the value element with the given index as an long.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemFloatAt

        public abstract float getElemFloatAt​(int index)
        Gets the value element with the given index as a float.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemDoubleAt

        public abstract double getElemDoubleAt​(int index)
        Gets the value element with the given index as a double.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemStringAt

        public abstract String getElemStringAt​(int index)
        Gets the value element with the given index as a String.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElemBooleanAt

        public boolean getElemBooleanAt​(int index)
        Gets the value element with the given index as a boolean.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemInt

        public void setElemInt​(int value)
        Sets the value as an int.

        The method assumes that this value is a scalar and therefore simply calls setElemIntAt(0, value).

        Parameters:
        value - the value to be set
        See Also:
        setElemIntAt(int index, int value)
      • setElemUInt

        public void setElemUInt​(long value)
        Sets the value as an unsigned int given as a long.

        The method assumes that this value is a scalar and therefore simply calls setElemUIntAt(0, value).

        Parameters:
        value - the value to be set
        See Also:
        setElemUIntAt(int index, long value)
      • setElemLong

        public void setElemLong​(long value)
        Sets the value as a long.

        The method assumes that this value is a scalar and therefore simply calls setElemLongInt(0, value).

        Parameters:
        value - the value to be set
        See Also:
        setElemLongAt(int index, long value)
      • setElemFloat

        public void setElemFloat​(float value)
        Sets the value as a float.

        The method assumes that this value is a scalar and therefore simply calls setElemFloatAt(0, value).

        Parameters:
        value - the value to be set
        See Also:
        setElemFloatAt(int index, float value)
      • setElemDouble

        public void setElemDouble​(double value)
        Sets the value as a double.

        The method assumes that this value is a scalar and therefore simply calls setElemDoubleAt(0).

        Parameters:
        value - the value to be set
        See Also:
        setElemDoubleAt(int index, double value)
      • setElemString

        public void setElemString​(String value)
        Sets the value as a String.

        The method assumes that this value is a scalar and therefore simply calls setElemStringAt(0).

        Parameters:
        value - the value to be set
        See Also:
        setElemStringAt(int, java.lang.String)
      • setElemBoolean

        public void setElemBoolean​(boolean value)
        Sets the value as a boolean.

        The method assumes that this value is a scalar and therefore simply calls setElemDoubleAt(0).

        Parameters:
        value - the value to be set
        See Also:
        setElemBooleanAt(int index, boolean value)
      • setElemIntAt

        public abstract void setElemIntAt​(int index,
                                          int value)
        Sets the value at the specified index as an int.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemUIntAt

        public abstract void setElemUIntAt​(int index,
                                           long value)
        Sets the value at the specified index as an unsigned int given as a long.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemLongAt

        public abstract void setElemLongAt​(int index,
                                           long value)
        Sets the value at the specified index as a long.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemFloatAt

        public abstract void setElemFloatAt​(int index,
                                            float value)
        Sets the value at the specified index as a float.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemDoubleAt

        public abstract void setElemDoubleAt​(int index,
                                             double value)
        Sets the value at the specified index as a double.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemStringAt

        public void setElemStringAt​(int index,
                                    String value)
        Sets the value at the specified index as a String.

        THE METHOD IS CURRENTLY NOT IMPLEMENTED.

        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • setElemBooleanAt

        public void setElemBooleanAt​(int index,
                                     boolean value)
        Sets the value at the specified index as a boolean.
        Parameters:
        index - the value index, must be >=0 and <getNumDataElems()
        value - the value to be set
        Throws:
        IndexOutOfBoundsException - if the index is out of bounds
      • getElems

        public abstract Object getElems()
        Returns the internal value. The actual type of the returned object should only be one of
        1. byte[] - for signed/unsigned 8-bit integer fields
        2. short[] - for signed/unsigned 16-bit integer fields
        3. int[] - for signed/unsigned 32-bit integer fields
        4. long[] - for signed/unsigned 64-bit integer fields
        5. float[] - for signed 32-bit floating point fields
        6. double[] - for signed 64-bit floating point fields
        Returns:
        an array of one of the described types
      • setElems

        public abstract void setElems​(Object data)
        Sets the internal value. The actual type of the given data object should only be one of
        1. byte[] - for signed/unsigned 8-bit integer fields
        2. short[] - for signed/unsigned 16-bit integer fields
        3. int[] - for signed/unsigned 32-bit integer fields
        4. long[] - for signed/unsigned 64-bit integer fields
        5. float[] - for signed 32-bit floating point fields
        6. double[] - for signed 64-bit floating point fields
        7. String[] - for all field types
        Parameters:
        data - an array of one of the described types
      • readFrom

        public void readFrom​(ImageInputStream input)
                      throws IOException
        Reads all elements of this 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.

        Parameters:
        input - a seekable data input stream
        Throws:
        IOException - if an I/O error occurs
      • readFrom

        public void readFrom​(int pos,
                             ImageInputStream input)
                      throws IOException
        Reads a single element of this 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.

        Parameters:
        pos - the destination position (zero-based)
        input - a seekable data input stream
        Throws:
        IOException - if an I/O error occurs
      • readFrom

        public abstract void readFrom​(int startPos,
                                      int numElems,
                                      ImageInputStream input)
                               throws IOException
        Reads elements of this 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.

        Parameters:
        startPos - the destination start position (zero-based)
        numElems - the number of elements to read
        input - a seekable data input stream
        Throws:
        IOException - if an I/O error occurs
      • readFrom

        public void readFrom​(int startPos,
                             int numElems,
                             ImageInputStream input,
                             long inputPos)
                      throws IOException
        Reads elements into this 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.

        Parameters:
        startPos - the destination start position (zero-based)
        numElems - the number of elements to read
        input - a seekable data input stream
        inputPos - the (zero-based) position in the data output stream where reading starts
        Throws:
        IOException - if an I/O error occurs
      • writeTo

        public void writeTo​(ImageOutputStream output)
                     throws IOException
        Writes all elements of this 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.

        Parameters:
        output - a seekable data output stream
        Throws:
        IOException - if an I/O error occurs
      • writeTo

        public void writeTo​(int pos,
                            ImageOutputStream output)
                     throws IOException
        Writes a single element of this 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.

        Parameters:
        pos - the source position (zero-based)
        output - a seekable data output stream
        Throws:
        IOException - if an I/O error occurs
      • writeTo

        public abstract void writeTo​(int startPos,
                                     int numElems,
                                     ImageOutputStream output)
                              throws IOException
        Writes elements of this 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.

        Parameters:
        startPos - the source start position (zero-based)
        numElems - the number of elements to be written
        output - a seekable data output stream
        Throws:
        IOException - if an I/O error occurs
      • writeTo

        public void writeTo​(int startPos,
                            int numElems,
                            ImageOutputStream output,
                            long outputPos)
                     throws IOException
        Writes elements of this 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.

        Parameters:
        startPos - the source start position (zero-based)
        numElems - the number of elements to be written
        output - a seekable data output stream
        outputPos - the position in the data output stream where writing starts
        Throws:
        IOException - if an I/O error occurs
      • toString

        public String toString()
        Returns a string representation of this value which can be used for debugging purposes.
        Overrides:
        toString in class Object
      • equalElems

        public boolean equalElems​(ProductData other)
        Tests whether this ProductData is equal to another one. Performs an element-wise comparision if the other object is a ProductData instance of the same data type. Otherwise the method behaves like Object.equals(Object).
        Parameters:
        other - the other one
      • createDeepClone

        protected abstract ProductData createDeepClone()
        Retuns a "deep" copy of this product data.
        Returns:
        a copy of this product data
      • dispose

        public abstract void dispose()
        Releases all of the resources used by this object instance and all of its owned children. Its primary use is to allow the garbage collector to perform a vanilla job.

        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.