Class StringIndicators

  • All Implemented Interfaces:
    DataObject, FastSerializable, Serializable

    public final class StringIndicators
    extends AbstractLazyEncodedByteArray
    implements FastSerializable
    Class StringIndicators represents the encoded form of a String field.

    The API offered by this class is as if the type were specified in ASN.1 as follows.

     StringIndicators ::= SEQUENCE {
         odd           BOOLEAN OPTIONAL,
         numSemiOctets INTEGER OPTIONAL
     }
    The class takes care of encoding the field values into a byte-array and decoding field values from a byte-array, the encoded representation being as tabulated below.

    Data Encoding - made up by OpenCloud
    87654321
    Octet 1SpareOdd
    Octet 2NumSemiOctets
    See Also:
    Serialized Form
    • Constructor Detail

      • StringIndicators

        public StringIndicators()
        Constructs a new StringIndicators object with no fields set.
      • StringIndicators

        public StringIndicators​(byte[] data)
        Constructs a new StringIndicators object from network-encoded data. The data is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        Throws:
        NullPointerException - if data is null
      • StringIndicators

        public StringIndicators​(byte[] data,
                                int start,
                                int len)
        Constructs a new StringIndicators object from part of network-encoded data. The part starts at index start and is len bytes long. The data is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        start - starting offset of network-encoded data in byte array
        len - default length if not predictable
        Throws:
        NullPointerException - if data is null
        IllegalArgumentException - if len is negative
      • StringIndicators

        public StringIndicators​(DataInput in)
                         throws IOException
        Constructs a new StringIndicators object from data deserialized from a stream that was written by toStream(DataOutput).
        Parameters:
        in - the stream to read from
        Throws:
        EOFException - if reading is pre-empted by end-of-file
        IOException - if the data cannot be read
    • Method Detail

      • hasOdd

        public boolean hasOdd()
                       throws DecodeException
        Tests whether the field Odd has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • setOddPresent

        public StringIndicators setOddPresent​(boolean flag)
                                       throws IllegalStateException
        Sets the presence or absence of the field Odd.
        Parameters:
        flag - whether the field should be marked as present
        Returns:
        this
        Throws:
        IllegalStateException - if this instance has been marked as read-only
      • hasNumSemiOctets

        public boolean hasNumSemiOctets()
                                 throws DecodeException
        Tests whether the field NumSemiOctets has a value.
        Returns:
        whether the field has a value
        Throws:
        DecodeException - if encoded state cannot be decoded
      • setNumSemiOctetsPresent

        public StringIndicators setNumSemiOctetsPresent​(boolean flag)
                                                 throws IllegalStateException
        Sets the presence or absence of the field NumSemiOctets.
        Parameters:
        flag - whether the field should be marked as present
        Returns:
        this
        Throws:
        IllegalStateException - if this instance has been marked as read-only
      • getOdd

        public boolean getOdd()
                       throws DecodeException
        Gets the value of the odd indicator.
        Returns:
        boolean representation of the odd indicator
        Throws:
        DecodeException - if encoded state cannot be decoded
      • getNumSemiOctets

        public int getNumSemiOctets()
                             throws DecodeException
        Gets the value of the numSemiOctets indicator.
        Returns:
        int representation of the numSemiOctets indicator
        Throws:
        DecodeException - if encoded state cannot be decoded
      • copyOf

        public static StringIndicators copyOf​(StringIndicators from)
        Creates a new object of this type, initialising its field values from those of the given object.
        Parameters:
        from - the object from which to copy
        Returns:
        new StringIndicators
      • getFieldAccessors

        public static FieldAccessor[] getFieldAccessors()
        Gets a new array of the accessors for fields of this type.
        Returns:
        FieldAccessor[]
      • getFieldsMap

        public Map<String,​Object> getFieldsMap​(boolean withAbsents)
        Gets a Map from field-name to field-value. For a field of primitive type, the field-value is boxed. For a field of String type, the field-value is lax-decoded if a StringCodec is known, otherwise the encoded form is used. For an absent optional field, a mapping to AbstractFieldsObject.FIELD_ABSENT is included if requested. For an uninitialised mandatory field, a mapping to AbstractFieldsObject.FIELD_UNINITIALISED is included. If state cannot be decoded, returns a Map from "encodedValue" to byte[].
        Specified by:
        getFieldsMap in class AbstractFieldsObject
        Parameters:
        withAbsents - whether to put unknown fields into Map
        Returns:
        Map from field-name to field-value
      • encodedIsInvalid

        protected boolean encodedIsInvalid()
        Determines whether the encoded form is invalid.
        Returns:
        boolean
      • getEncodedForm

        public byte[] getEncodedForm()
                              throws EncodeException
        Gets the encoded form.
        Returns:
        encoded form
        Throws:
        EncodeException - if encoding fails
      • getContainedLength

        public static int getContainedLength​(byte[] data,
                                             int start,
                                             int len)
        Determines the length of the encoded value that commences at offset start in the given data. The value is not fully decoded and might not be decodable. Values of this type are of a fixed length, so that length is returned if the data is long enough, otherwise 0 is returned.
        Parameters:
        data - network-encoded data
        start - index into data where value commences
        len - length in data to be considered
        Returns:
        2, or 0 if encoded value is not long enough
      • encode

        protected void encode()
        Description copied from class: AbstractLazyEncodedDataObject
        Computes the encoded form of the state from the decoded form. Should check that individual field values are within appropriate ranges, and different fields have mutually consistent values, but needn't repeat the checks done by checkFieldsSet(). The computed encoded form should equal that from which the decoded form could have been calculated using decode(), i.e. encode o decode = id.
        Specified by:
        encode in class AbstractLazyEncodedDataObject<byte[]>
      • decode

        protected void decode()
        Description copied from class: AbstractLazyEncodedDataObject
        Computes the decoded form of the state from the encoded form. The computed decoded form should equal that from which the encoded form could have been calculated using encode(), i.e. decode o encode = id. If a field cannot be decoded without further information, such as a DigitCodec to be used for decoding a digit string, then the encoded form of that field should be copied and kept for decoding by that field's getter, which will be given the further information. The caller should set isDecoded to true.
        Specified by:
        decode in class AbstractLazyEncodedDataObject<byte[]>