Package db

Class Field

  • All Implemented Interfaces:
    java.lang.Comparable<Field>
    Direct Known Subclasses:
    BinaryField, BooleanField, ByteField, IntField, LongField, ShortField, StringField

    public abstract class Field
    extends java.lang.Object
    implements java.lang.Comparable<Field>

    Field is an abstract data wrapper for use with Records. Note that when comparing two Field instances both must be of the same class.

    Fields may take on a null state. In the case of FixedField and PrimitiveField this state is distinct from value and only applies when used for a sparse column within a SparseRecord. In this sparse column situation the SparseRecord.setField(int, Field) method may be passed a null Field argument. Sparse columns with a null value/state will not be indexed within a Table.

    Stored Schema Field Type Encoding:

    8-bit Legacy Field Type Encoding (I....FFF)

    Supported encodings: 0x00..0x06 and 0x80..0x86, where:
         FFF  - indexed field type (0..6)
         I    - index field indicator (only long primary keys were supported)
     

    8-bit Field Type Encoding (PPPPFFFF)

    (Reserved for future field extensions: 0x88 and 0xf0..0xff)
         0xff - see Schema.FIELD_EXTENSION_INDICATOR
     
    where:
         FFFF - normal/indexed field type
         PPPP - indexed table primary key type (1000b: LegacyIndexField)  
     
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Field[] EMPTY_ARRAY  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canIndex​(Field field)
      Determine if a specified field instance may be indexed
      abstract int compareTo​(Field otherField)
      Compares this Field with another Field for order.
      abstract Field copyField()
      Create new instance of this field with the same value.
      abstract boolean equals​(java.lang.Object obj)
      Determine if the specified Object is another Field which has the same type and value as this Field.
      abstract byte[] getBinaryData()
      Get data as a byte array.
      boolean getBooleanValue()
      Get field as a boolean value.
      byte getByteValue()
      Get field as a byte value.
      int getIntValue()
      Get field as an integer value.
      long getLongValue()
      Get field as a long value.
      short getShortValue()
      Get field as a short value.
      java.lang.String getString()
      Get field as a String value.
      abstract java.lang.String getValueAsString()
      Get field value as a formatted string
      abstract int hashCode()  
      abstract boolean isNull()
      Determine if the field has been set to a null-state or value.
      boolean isSameType​(Field field)
      Determine if specified field is same type as this field
      boolean isVariableLength()  
      abstract Field newField()
      Create new instance of this field type.
      abstract void setBinaryData​(byte[] bytes)
      Set data from binary byte array.
      void setBooleanValue​(boolean value)
      Set field's boolean value.
      void setByteValue​(byte value)
      Set field's byte value.
      void setIntValue​(int value)
      Set field's integer value.
      void setLongValue​(long value)
      Set field's long value.
      void setShortValue​(short value)
      Set field's short value.
      void setString​(java.lang.String str)
      Set field's String value.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_ARRAY

        public static final Field[] EMPTY_ARRAY
    • Method Detail

      • getLongValue

        public long getLongValue()
        Get field as a long value. All fixed-length field objects must implement this method
        Returns:
        long value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setLongValue

        public void setLongValue​(long value)
        Set field's long value. All fixed-length field objects must implement this method
        Parameters:
        value - long value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • getIntValue

        public int getIntValue()
        Get field as an integer value.
        Returns:
        integer value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setIntValue

        public void setIntValue​(int value)
        Set field's integer value.
        Parameters:
        value - integer value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • getShortValue

        public short getShortValue()
        Get field as a short value.
        Returns:
        short value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setShortValue

        public void setShortValue​(short value)
        Set field's short value.
        Parameters:
        value - short value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • getByteValue

        public byte getByteValue()
        Get field as a byte value.
        Returns:
        byte value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setByteValue

        public void setByteValue​(byte value)
        Set field's byte value.
        Parameters:
        value - byte value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • getBooleanValue

        public boolean getBooleanValue()
        Get field as a boolean value.
        Returns:
        boolean value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setBooleanValue

        public void setBooleanValue​(boolean value)
        Set field's boolean value.
        Parameters:
        value - boolean value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • getBinaryData

        public abstract byte[] getBinaryData()
        Get data as a byte array.
        Returns:
        byte[]
      • setBinaryData

        public abstract void setBinaryData​(byte[] bytes)
        Set data from binary byte array. All variable-length fields must implement this method.
        Parameters:
        bytes - field data
        Throws:
        IllegalFieldAccessException - if error occurs while reading bytes into field which will generally be caused by the incorrect number of bytes provided to a fixed-length field.
      • getString

        public java.lang.String getString()
        Get field as a String value.
        Returns:
        String value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • setString

        public void setString​(java.lang.String str)
        Set field's String value.
        Parameters:
        str - String value
        Throws:
        IllegalFieldAccessException - thrown if method is not supported by specific Field instance.
      • isVariableLength

        public boolean isVariableLength()
        Returns:
        true if a Field instance is variable length, else false.
      • isSameType

        public boolean isSameType​(Field field)
        Determine if specified field is same type as this field
        Parameters:
        field - a Field instance
        Returns:
        true if field is same type as this field
      • copyField

        public abstract Field copyField()
        Create new instance of this field with the same value.
        Returns:
        new field instance with same value
      • newField

        public abstract Field newField()
        Create new instance of this field type.
        Returns:
        new field instance with undefined initial value
      • equals

        public abstract boolean equals​(java.lang.Object obj)
        Determine if the specified Object is another Field which has the same type and value as this Field. When comparing a PrimitiveField, with a null state, a value of zero (0) is used.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - another object
        Returns:
        true if this field equals obj
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • getValueAsString

        public abstract java.lang.String getValueAsString()
        Get field value as a formatted string
        Returns:
        field value string
      • isNull

        public abstract boolean isNull()
        Determine if the field has been set to a null-state or value.
        Returns:
        true if field has been set to a null state or value, else false
      • compareTo

        public abstract int compareTo​(Field otherField)
        Compares this Field with another Field for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified Field.
        NOTE: Field objects do not fully comply with the Comparable interface. Only the same Field implementations may be compared. In addition, the null state is not considered when comparing PrimitiveFields which have a zero (0) value.
        Specified by:
        compareTo in interface java.lang.Comparable<Field>
        Parameters:
        otherField - another Field which is the same type as this Field
        Returns:
        field comparison result (see Comparable.compareTo(Object)).
        Throws:
        java.lang.ClassCastException - if an attempt to compare dissimilar Fields (e.g., an IntField may not be compared with a ShortField).
      • canIndex

        public static boolean canIndex​(Field field)
        Determine if a specified field instance may be indexed
        Parameters:
        field - field to be checked
        Returns:
        true if field can be indexed