Interface Convert


  • public interface Convert
    Convert between numeric types,convert any field to a string, and convert from a string to a scalar field.
    Author:
    mrk

    Numeric conversions are between scalar numeric types or between arrays of numeric types. It is not possible to convert between a scalar and an array. Numeric conversions are between types: pvByte, pvShort, pvInt, pvLong, pvFloat, or pvDouble.

    getString converts any supported type to a String. Code that implements a PVField interface can implement method toString by calling this method.

    fromString converts a String to a scalar. fromStringArray converts an array of String to a pvArray, which must have a scaler element type. A scalar field is a numeric field or pvBoolean or pvString.

    All from methods put data into a PVField, e.g. from means where the PVField gets it's data.

    • Method Detail

      • getFullFieldName

        void getFullFieldName​(StringBuilder builder,
                              PVField pvField)
        Get the full fieldName for the PVField and add to a StringBuilder.
        Parameters:
        builder - the StringBuilder that will have the result
        pvField - the PVField.
      • getString

        void getString​(StringBuilder buf,
                       PVField pv,
                       int indentLevel)
        Convert a PVField to a String. If a PVField is a structure or array be prepared for a very long string.
        Parameters:
        buf - the buffer for the result
        pv - the PVField to convert to a string
        indentLevel - the indentation level
      • getString

        void getString​(StringBuilder buf,
                       PVField pv)
        Convert a PVField to a string. If the PVField is a structure or array be prepared for a very long string.
        Parameters:
        buf - the buffer for the result
        pv - the PVField to convert to a string
      • fromString

        void fromString​(PVScalar pv,
                        String from)
        Convert from a String to a PVScalar
        Parameters:
        pv - the PVScalar to convert to
        from - the String value to convert from
        Throws:
        NumberFormatException - if the String does not have a valid value
      • fromString

        int fromString​(PVScalarArray pv,
                       String from)
        Convert from a String to a PVScalarArray. The String must be a comma separated set of values optionally enclosed in [].
        Parameters:
        pv - the PVScalarArray to convert to
        from - the String value to convert from
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element Type is not a scalar
        NumberFormatException - if the String is not that of a valid set of array values
      • fromStringArray

        int fromStringArray​(PVScalarArray pv,
                            int offset,
                            int length,
                            String[] from,
                            int fromOffset)
        Convert from a String array and to a PVScalarArray array.
        Parameters:
        pv - the PVScalarArray to convert to
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the array of values to put into the PVScalarArray
        fromOffset - the starting element in the source array
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element Type is not a scalar
        NumberFormatException - if the String does not have a valid value
      • toStringArray

        int toStringArray​(PVScalarArray pv,
                          int offset,
                          int length,
                          String[] to,
                          int toOffset)
        Convert from a PVScalarArray to a String array.
        Parameters:
        pv - the PVScalarArray
        offset - the starting element in the PVScalarArray
        length - the number of elements to convert to
        to - the array to receive the converted PVScalarArray data
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        the number of elements converted
      • isCopyCompatible

        boolean isCopyCompatible​(Field from,
                                 Field to)
        Are from and to valid arguments to copy. This first checks of both arguments have the same Type. Then calls one of isCopyScalarCompatible, isCopyArrayCompatible, or isCopyStructureCompatible.
        Parameters:
        from - the source
        to - the destination
        Returns:
        (false,true) is the arguments (are not, are) compatible
      • copy

        void copy​(PVField from,
                  PVField to)
        Copy from a PVField to another PVField. This calls one of copyScalar, copyArray or copyStructure. The two arguments must be compatible.
        Parameters:
        from - the source
        to - the destination
        Throws:
        IllegalArgumentException - if the arguments are not compatible
      • isCopyScalarCompatible

        boolean isCopyScalarCompatible​(Scalar from,
                                       Scalar to)
        Are from and to the instrospection interfaces for valid arguments for copyScalar. false will be returned if either argument is not a scalar as defined by Type.isScalar(). If both are scalars the return value is true if any of the following are true:
        • Both arguments are numeric.
        • Both arguments have the same type.
        • Either argument is a string.
        Parameters:
        from - the introspection interface for the from data
        to - the introspection interface for the to data
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • copyScalar

        void copyScalar​(PVScalar from,
                        PVScalar to)
        Copy from a PVScalar to another PVScalar.
        Parameters:
        from - the source
        to - the destination
        Throws:
        IllegalArgumentException - if the arguments are not compatible
      • isCopyScalarArrayCompatible

        boolean isCopyScalarArrayCompatible​(ScalarArray from,
                                            ScalarArray to)
        Are from and to valid arguments to copyArray. The results are like isCopyScalarCompatible except that the tests are made on the elementType.
        Parameters:
        from - the introspection interface for a source array
        to - the introspection interface for a destination array
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • copyScalarArray

        int copyScalarArray​(PVScalarArray from,
                            int offset,
                            PVScalarArray to,
                            int toOffset,
                            int length)
        Copy from a source PVScalarArray to a destination PVScalarArray.
        Parameters:
        from - the source PVScalarArray
        offset - the starting element in the source
        to - the destination PVScalarArray
        toOffset - the element in the destination array at which to start putting the copied data
        length - the number of elements to copy
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the arguments are not compatible
      • isCopyStructureCompatible

        boolean isCopyStructureCompatible​(Structure from,
                                          Structure to)
        Are from and to the instrospection interfaces for valid arguments for copyStructure. They are only compatible if they have the same Structure description.
        Parameters:
        from - the introspection interface for a source structure
        to - the introspection interface for a destination structure
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • copyStructure

        void copyStructure​(PVStructure from,
                           PVStructure to)
        Copy from a PVStructure to another PVStructure. NOTE: Only compatible nodes are copied. This means:
        • For scalar nodes this means that isCopyScalarCompatible is true.
        • For array nodes this means that isCopyArrayCompatible is true.
        • For structure nodes this means that isCopyStructureCompatible is true.
        • Link nodes are not copied.
        Parameters:
        from - the source
        to - the destination
        Throws:
        IllegalArgumentException - if the arguments are not compatible
      • isCopyUnionCompatible

        boolean isCopyUnionCompatible​(Union from,
                                      Union to)
        Are from and to the instrospection interfaces for valid arguments for copyUnion. They are only compatible if they have the same Union description.
        Parameters:
        from - the introspection interface for the source union
        to - the introspection interface for the destination union
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • copyUnion

        void copyUnion​(PVUnion from,
                       PVUnion to)
        Copy from a PVUnion to another PVUnion.
        Parameters:
        from - the source
        to - the destination
        Throws:
        IllegalArgumentException - if the arguments are not compatible
      • isCopyStructureArrayCompatible

        boolean isCopyStructureArrayCompatible​(StructureArray from,
                                               StructureArray to)
        Are from and to the instrospection interfaces for valid arguments for copyStructureArray.
        Parameters:
        from - the introspection interface for a source array
        to - the introspection interface for a destination array
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • isCopyUnionArrayCompatible

        boolean isCopyUnionArrayCompatible​(UnionArray from,
                                           UnionArray to)
        Are from and to the instrospection interfaces for valid arguments for copyUnionArray.
        Parameters:
        from - the from UnionArray
        to - the to UnionArray
        Returns:
        (false,true) if the arguments (are not, are) compatible
      • copyStructureArray

        void copyStructureArray​(PVStructureArray from,
                                PVStructureArray to)
        Copy from a PVStructureArray array to another PVStructureArray array.
        Parameters:
        from - the source array
        to - the destination array
      • copyStructureArray

        int copyStructureArray​(PVStructureArray from,
                               int offset,
                               PVStructureArray to,
                               int toOffset,
                               int length)
        Copy from a subset of a PVStructureArray to another PVStructureArray.
        Parameters:
        from - the source array
        offset - the element in the source array to start copying at
        to - the destination array
        toOffset - the element in the destination array at which to start putting the copied data
        length - the number of elements to copy
        Returns:
        the number of elements copied
      • copyUnionArray

        void copyUnionArray​(PVUnionArray from,
                            PVUnionArray to)
        Copy from a PVUnionArray to another PVUnionArray.
        Parameters:
        from - the source array
        to - the destination array
      • copyUnionArray

        int copyUnionArray​(PVUnionArray from,
                           int offset,
                           PVUnionArray to,
                           int toOffset,
                           int length)
        Copy from a subset of a PVUnionArray to another PVUnionArray.
        Parameters:
        from - the source array
        offset - the element in the source array to start copying at
        to - the destination array
        toOffset - the element in the destination array at which to start putting the copied data
        length - the number of elements to copy
        Returns:
        the number of elements copied
      • toByte

        byte toByte​(PVScalar pv)
        Convert a PVScalar to a byte.
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toShort

        short toShort​(PVScalar pv)
        Convert a PVScalar to a short.
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toInt

        int toInt​(PVScalar pv)
        Convert a PVScalar to an int
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toLong

        long toLong​(PVScalar pv)
        Convert a PVScalar to a long
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toFloat

        float toFloat​(PVScalar pv)
        Convert a PVScalar to a float
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toDouble

        double toDouble​(PVScalar pv)
        Convert a PVScalar to a double
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toString

        String toString​(PVScalar pv)
        Convert a PVScalar to a String
        Parameters:
        pv - the PVScalar to convert
        Returns:
        converted value
      • fromByte

        void fromByte​(PVScalar pv,
                      byte from)
        Convert a PVScalar from a byte
        Parameters:
        pv - a PVScalar
        from - value to put into PVScalar
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromShort

        void fromShort​(PVScalar pv,
                       short from)
        Convert a PVScalar from a short
        Parameters:
        pv - a PVScalar
        from - value to put into PVScalar
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromInt

        void fromInt​(PVScalar pv,
                     int from)
        Convert a PVScalar from an int
        Parameters:
        pv - a PVScalar
        from - the value to put into the PVScalar
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromLong

        void fromLong​(PVScalar pv,
                      long from)
        Convert a PVScalar from a long
        Parameters:
        pv - a PVScalar
        from - the value to put into the PVScalar
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromUByte

        void fromUByte​(PVScalar pv,
                       byte from)
        Convert a PV from a byte interpreted as unsigned
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromUShort

        void fromUShort​(PVScalar pv,
                        short from)
        Convert a PV from a short interpreted as unsigned
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromUInt

        void fromUInt​(PVScalar pv,
                      int from)
        Convert a PV from an int interpreted as unsigned
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromULong

        void fromULong​(PVScalar pv,
                       long from)
        Convert a PV from a long interpreted as unsigned
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromFloat

        void fromFloat​(PVScalar pv,
                       float from)
        Convert a PV from a float.
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • fromDouble

        void fromDouble​(PVScalar pv,
                        double from)
        Convert a PV from a double.
        Parameters:
        pv - a PV
        from - the value to put into the PV
        Throws:
        IllegalArgumentException - if the ScalarType of pv is not a numeric scalar
      • toByteArray

        int toByteArray​(PVScalarArray pv,
                        int offset,
                        int length,
                        byte[] to,
                        int toOffset)
        Convert a PVScalarArray to a byte array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • toShortArray

        int toShortArray​(PVScalarArray pv,
                         int offset,
                         int length,
                         short[] to,
                         int toOffset)
        Convert a PVScalarArray to a short array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • toIntArray

        int toIntArray​(PVScalarArray pv,
                       int offset,
                       int length,
                       int[] to,
                       int toOffset)
        Convert a PVScalarArray array to an int array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • toLongArray

        int toLongArray​(PVScalarArray pv,
                        int offset,
                        int length,
                        long[] to,
                        int toOffset)
        Convert a PVScalarArray to a long array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • toFloatArray

        int toFloatArray​(PVScalarArray pv,
                         int offset,
                         int length,
                         float[] to,
                         int toOffset)
        Convert a PVScalarArray to a float array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • toDoubleArray

        int toDoubleArray​(PVScalarArray pv,
                          int offset,
                          int length,
                          double[] to,
                          int toOffset)
        Convert a PVScalarArray to a double array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray to start converting at
        length - the number of elements to convert
        to - the array to put the converted PVScalarArray data into
        toOffset - the element in the destination array at which to start putting the converted data
        Returns:
        number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromByteArray

        int fromByteArray​(PVScalarArray pv,
                          int offset,
                          int length,
                          byte[] from,
                          int fromOffset)
        Convert to a PVScalarArray from a byte array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromShortArray

        int fromShortArray​(PVScalarArray pv,
                           int offset,
                           int length,
                           short[] from,
                           int fromOffset)
        Convert to a PVScalarArray from a short array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromIntArray

        int fromIntArray​(PVScalarArray pv,
                         int offset,
                         int length,
                         int[] from,
                         int fromOffset)
        Convert to a PVScalarArray from an int array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromLongArray

        int fromLongArray​(PVScalarArray pv,
                          int offset,
                          int length,
                          long[] from,
                          int fromOffset)
        Convert to a PVScalarArray from a long array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromUByteArray

        int fromUByteArray​(PVScalarArray pv,
                           int offset,
                           int length,
                           byte[] from,
                           int fromOffset)
        Convert to a PVScalarArray from a byte array interpreted as unsigned.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromUShortArray

        int fromUShortArray​(PVScalarArray pv,
                            int offset,
                            int length,
                            short[] from,
                            int fromOffset)
        Convert to a PVScalarArray from a short array interpreted as unsigned.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromUIntArray

        int fromUIntArray​(PVScalarArray pv,
                          int offset,
                          int length,
                          int[] from,
                          int fromOffset)
        Convert to a PVScalarArray from an int array interpreted as unsigned.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromULongArray

        int fromULongArray​(PVScalarArray pv,
                           int offset,
                           int length,
                           long[] from,
                           int fromOffset)
        Convert to a PVScalarArray from a long array interpreted as unsigned.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromFloatArray

        int fromFloatArray​(PVScalarArray pv,
                           int offset,
                           int length,
                           float[] from,
                           int fromOffset)
        Convert to a PVScalarArray from a float array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • fromDoubleArray

        int fromDoubleArray​(PVScalarArray pv,
                            int offset,
                            int length,
                            double[] from,
                            int fromOffset)
        Convert to a PVScalarArray from a double array.
        Parameters:
        pv - a PVScalarArray
        offset - the element in the PVScalarArray at which to start putting the converted data
        length - the number of elements to convert
        from - the source array to put into the PVScalarArray
        fromOffset - the element in the source array to start converting at
        Returns:
        the number of elements converted
        Throws:
        IllegalArgumentException - if the element type of pv is not numeric
      • newLine

        void newLine​(StringBuilder builder,
                     int indentLevel)
        Convenience method for implementing toString. It generates a newline and inserts blanks at the beginning of the newline.
        Parameters:
        builder - the StringBuilder being constructed
        indentLevel - indentation level. Each level is four spaces.