Class AbstractLazyEncodedDataObject<T>

  • All Implemented Interfaces:
    DataObject, Serializable
    Direct Known Subclasses:
    AbstractLazyEncodedByteArray, AbstractLazyEncodedNamedInteger

    public abstract class AbstractLazyEncodedDataObject<T>
    extends AbstractEncodedDataObject<T>
    Class AbstractLazyEncodedDataObject represents a DataObject in which the state is represented in an encoded form or a decoded form, with conversions between the two forms done lazily (when needed). Having a decoded representation of the state is convenient if the positions of fields in the encoded representation can vary depending on the values of other fields that might not have been supplied yet. For example, the presence/absence of optional fields, and the lengths of variable-length fields, can both affect the positions of later fields. Once an object has been marked read-only, both encoded and decoded forms can co-exist.
    See Also:
    Serialized Form
    • Field Detail

      • isDecoded

        protected volatile boolean isDecoded
        Whether the state is in the decoded form. (The state is in the encoded form if encoded != null.)
    • Constructor Detail

      • AbstractLazyEncodedDataObject

        protected AbstractLazyEncodedDataObject()
        Constructs a new AbstractLazyEncodedDataObject. The state is in the decoded form, despite none of the fields having been set yet, as there is no encoded form.
      • AbstractLazyEncodedDataObject

        protected AbstractLazyEncodedDataObject​(byte[] data,
                                                int start,
                                                int len)
        Constructs a new AbstractLazyEncodedDataObject from part of given network-encoded data. The part starts at index start and is len bytes long. The state is in the encoded form: it is not decoded and might not be decodable.
        Parameters:
        data - network-encoded data
        start - starting offset of network-encoded data
        len - length of encoded data in bytes
        Throws:
        NullPointerException - if data is null
        IllegalArgumentException - if len is negative
        ArrayIndexOutOfBoundsException - if the part is not within the data
    • Method Detail

      • checkFieldsSet

        protected abstract void checkFieldsSet()
                                        throws EncodeException
        Checks that all mandatory fields are present. Should be called immediately before all calls to encode().
        Throws:
        EncodeException - if any mandatory field is not present
      • encode

        protected abstract void encode()
                                throws EncodeException
        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.
        Throws:
        EncodeException - if encoding fails
      • decode

        protected abstract void decode()
                                throws DecodeException
        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.
        Throws:
        DecodeException - if decoding fails
      • checkDecode

        protected void checkDecode()
                            throws DecodeException
        Ensures that the state is in the decoded form.
        Throws:
        DecodeException - if decoding fails
      • checkModifyAndDecode

        protected void checkModifyAndDecode()
                                     throws IllegalStateException,
                                            DecodeException
        For use before setting a field of the decoded representation: checks that the object has not been marked read-only, and ensures that the state is in the decoded form.
        Throws:
        IllegalStateException - if the object is readonly
        DecodeException - if decoding fails