Class ArrayType

  • All Implemented Interfaces:
    java.lang.Comparable<DataType>

    public final class ArrayType
    extends DataType
    Provides binary serialization/de-serialization of an object collection. The collection must contain EMessageObject objects of the same class type.

    Supports array sizes up to DataType.MAX_ARRAY_SIZE items.

    Author:
    Charles Rapp
    • Constructor Detail

      • ArrayType

        public ArrayType​(java.lang.Class<?> jClass,
                         DataType subtype)
        Creates an array type which encapsulates the specified data type. Arrays are homogeneous collections and considered a built-in type.
        Parameters:
        jClass - the Java array class.
        subtype - the array element type.
    • Method Detail

      • isInstance

        public boolean isInstance​(java.lang.Object o)
        Returns true if o is either null or a Collection instance; false otherwise.
        Overrides:
        isInstance in class DataType
        Parameters:
        o - Check this object's type.
        Returns:
        true if o is either null or a Collection instance; false otherwise.
      • deserialize

        public java.lang.Object deserialize​(MessageType.MessageField field,
                                            java.nio.ByteBuffer buffer)
        Returns the de-serialized collection as an Object. If the array size is zero, then returns an empty collection. The returned value may be safely typecast to java.util.Collection.
        Specified by:
        deserialize in class DataType
        Parameters:
        field - contains information needed to de-serialize this message field.
        buffer - de-serialize the list object from this ByteBuffer.
        Returns:
        the de-serialized Collection.
        Throws:
        DeserializeException - if encoded array size is either < zero or > maximum allowed size.
        java.nio.BufferUnderflowException - if buffer contains an incomplete serialized array.
        See Also:
        serialize(java.lang.Object, net.sf.eBus.messages.type.MessageType.MessageField, java.nio.ByteBuffer)
      • createSerializer

        protected void createSerializer​(MessageType.MessageField field,
                                        java.lang.String fieldName,
                                        java.lang.String indent,
                                        java.util.Formatter output)
        Generates the array serialization code.
        Specified by:
        createSerializer in class DataType
        Parameters:
        field - message field.
        fieldName - fully-qualified field name.
        indent - indent generated code by this spacing.
        output - place generated code into this formatter.
      • createDeserializer

        protected void createDeserializer​(MessageType.MessageField field,
                                          java.lang.String fieldName,
                                          java.lang.String indent,
                                          java.util.Formatter output,
                                          boolean useBuilder)
        Generates the Java code for de-serializing an array.
        Specified by:
        createDeserializer in class DataType
        Parameters:
        field - message field.
        fieldName - the array message field name.
        indent - indent the code by this amount.
        output - append the code to this formatter.
        useBuilder - if true then fieldName is a builder method name; otherwise a local variable.
      • toString

        public java.lang.String toString()
        Returns the subtype Java class name followed by "[]".
        Overrides:
        toString in class DataType
        Returns:
        the subtype Java class name followed by "[]".
      • dataClassName

        public java.lang.String dataClassName()
        Returns the Java class name with "[]" appended.
        Overrides:
        dataClassName in class DataType
        Returns:
        Java class name.
      • subtype

        public DataType subtype()
        Returns the array subtype. All array items are of this type.
        Returns:
        the array subtype.