Class Field

java.lang.Object
uk.co.sculptor.kflibjava.Field
All Implemented Interfaces:
AutoCloseable

public abstract class Field extends Object implements AutoCloseable

Represents one field inside a FileIndex (main or secondary). Can only be created from any of the KeyedFile constructor and accessed via the KeyedFile.getIndex(java.lang.String)

Note: This class implements the AutoCloseable interface, meaning that an object may hold resources (such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically when exiting a try-with-resources block for which the object has been declared in the resource specification header. This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.
Author:
Marcos Gutierrez Batz
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Field Arithmetic data type (KF_TEXT, KF_LONG, KF_DOUBLE, KF_BINARY) enumerator.
    static enum 
    Field Sculptor field type (SCFT_*) enumerator.
    static enum 
    Field flag enumeration.
    static enum 
    Field Sculptor Logical Data type (SCLT_*) enumerator.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected abstract byte[]
    _getBinary(byte[] buffer, int offset, int index)
    Get the field value as binary.
    protected abstract double
    _getDouble(byte[] buffer, int offset, int index)
    Get the field value as double.
    protected abstract long
    _getLong(byte[] buffer, int offset, int index, boolean round)
    Get the field value as long.
    protected abstract String
    _getString(byte[] buffer, int offset, int index, boolean removeTs)
    Get the field value as String.
    protected abstract void
    _setBinary(byte[] value, byte[] buffer, int offset, int index)
    Set the binary on the field.
    protected abstract void
    _setDouble(double value, byte[] buffer, int offset, int index)
    Set the double on the field.
    protected abstract void
    _setLong(long value, byte[] buffer, int offset, int index)
    Set the long on the field.
    protected abstract void
    _setString(String value, byte[] buffer, int offset, int index)
    Set the String on the field.
    void
    Close the field and remove the field from the parent FileIndex.
    protected abstract void
    copyKeyToRecord(byte[] keyBuffer, int keyOffset, byte[] recordBuffer, int recordOffset)
    Fill the information on the KeyedFile.m_recordBuffer from the m_keyBuffer.
    protected abstract void
    copyRecordToKey(byte[] recordBuffer, int recordOffset, byte[] keyBuffer, int keyOffset)
    Fill the information on the m_keyBuffer from the KeyedFile.m_recordBuffer.
    static Field
    create(FileIndex fileIndex, String fieldName, String format, EnumSet<Field.Flag> flags, int dim, int offset, int element, byte len, Field.ArithmeticDataType adt, Field.FieldType scft, Field.LogicalDataType sclt, boolean isRealKey)
    Creates the correct Field type (depending on adt field).
    static Field
    create(FileIndex fileIndex, Field field)
    Creates the correct Field type (depending on m_adt field).
    protected final String
    daynoToText(long dayno)
    Get the Day number long value as a formated String.
    Return the Field adt
    final byte[]
    Get the binary byte array of values as stored by Sculptor.
    final byte[]
    getBinary(int index)
    Get the binary byte array of values as stored by Sculptor.
    protected final byte[]
    Get buffer.
    int
    Return the Field dim
    final double
    Get the field value as double.
    final double
    getDouble(int index)
    Get the field value as double.
    int
    Return the Field element
    Return the Field fieldName
    Return the Field flags
    Return the Field format
    int
    Return the Field len
    final long
    Get the field value as long.
    final long
    getLong(int index)
    Get the field value as long.
    final long
    Get the field value as rounded long.
    final long
    getLongRounded(int index)
    Get the field value as rounded long.
    int
    Return the Field offset
    protected final int
    getOffset(int recordOffset, int index)
    Get the offset to the field data inside the record buffer
    Return the Field scft
    Return the Field sclt
    byte
    Convert the new Sculptor Field Type and Sculptor Logical Type values to the old Sculptor Data Type
    final String
    Get the field value as String removing trailing spaces.
    final String
    getString(int index)
    Get the field value as String removing trailing spaces.
    final String
    Get the field value as String without removing trailing spaces.
    final String
    getStringTS(int index)
    Get the field value as String without removing trailing spaces.
    protected boolean
    That function is used on secondary indexes to know if the field is part of the secondary key (true) or a copy from the main index (false).
    protected final String
    moneyToText(double money)
    Get the money String formated from the double value.
    final void
    setBinary(byte[] value)
    Set the byte array value to the field directly.
    final void
    setBinary(byte[] value, int index)
    Set the byte array value to the field directly.
    final void
    setDouble(double value)
    Set the double value to the field and convert it if necessary.
    final void
    setDouble(double value, int index)
    Set the double value to the field and convert it if necessary.
    final void
    setLong(long value)
    Set the long value to the field and convert it if necessary.
    final void
    setLong(long value, int index)
    Set the long value to the field and convert it if necessary.
    final void
    Set the String value to the field and convert it if necessary.
    final void
    setString(String value, int index)
    Set the String value to the field and convert it if necessary.
    protected final long
    Get the dayno long value from the formated Date text.
    protected final double
    Get the double value from the formated text.
    protected final long
    Get the long value from the formated text.
    protected final double
    Get the money double value from the formated money text.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • create

      public static Field create(FileIndex fileIndex, Field field)
      Creates the correct Field type (depending on m_adt field). Can only be created from a KeyedFile constructor.
      Parameters:
      fileIndex - the Field index object.
      field - to where copy the structure.
      Returns:
      the created Field
    • create

      public static Field create(FileIndex fileIndex, String fieldName, String format, EnumSet<Field.Flag> flags, int dim, int offset, int element, byte len, Field.ArithmeticDataType adt, Field.FieldType scft, Field.LogicalDataType sclt, boolean isRealKey)
      Creates the correct Field type (depending on adt field). Can only be created from a KeyedFile constructor.
      Parameters:
      fileIndex - the Field index object.
      fieldName - Name
      format - Format
      flags - Attribute flags
      dim - Dimension
      offset - Offset in record buffer
      element - For indexing main key field or cursor field
      len - Length in bytes
      adt - Arithmetic data type (KF_TEXT, KF_LONG, KF_DOUBLE, KF_BINARY)
      scft - Sculptor field type (SCFT_)
      sclt - Sculptor logical type (SCLT_)
      isRealKey - true when the field represents a real key field on the index.
      Returns:
      the created Field
    • _getBinary

      protected abstract byte[] _getBinary(byte[] buffer, int offset, int index) throws KfException
      Get the field value as binary. Converting where necessary.
      Parameters:
      buffer - Key or record buffer containing the field value we want.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field
      Returns:
      the field converted to double
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _getDouble

      protected abstract double _getDouble(byte[] buffer, int offset, int index) throws KfException
      Get the field value as double. Converting where necessary.
      Parameters:
      buffer - Key or record buffer containing the field value we want.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field
      Returns:
      the field converted to double
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _getLong

      protected abstract long _getLong(byte[] buffer, int offset, int index, boolean round) throws KfException
      Get the field value as long. Converting where necessary.
      Parameters:
      buffer - Key or record buffer containing the field value we want.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field
      round - true when we want to be rounded to nearest integer.
      Returns:
      the field converted to long
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _getString

      protected abstract String _getString(byte[] buffer, int offset, int index, boolean removeTs) throws KfException
      Get the field value as String. Converting where necessary.
      Parameters:
      buffer - Key or record buffer containing the field value we want.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field
      removeTs - true when we want the trailing spaces to be removed.
      Returns:
      the field converted to String
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _setBinary

      protected abstract void _setBinary(byte[] value, byte[] buffer, int offset, int index) throws KfException
      Set the binary on the field. Converting where necessary.
      Parameters:
      value - the binary value to be set on the field.
      buffer - Key or record buffer containing the field we want to set.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _setDouble

      protected abstract void _setDouble(double value, byte[] buffer, int offset, int index) throws KfException
      Set the double on the field. Converting where necessary.
      Parameters:
      value - the double value to be set on the field.
      buffer - Key or record buffer containing the field we want to set.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _setLong

      protected abstract void _setLong(long value, byte[] buffer, int offset, int index) throws KfException
      Set the long on the field. Converting where necessary.
      Parameters:
      value - the long value to be set on the field.
      buffer - Key or record buffer containing the field we want to set.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • _setString

      protected abstract void _setString(String value, byte[] buffer, int offset, int index) throws KfException
      Set the String on the field. Converting where necessary.
      Parameters:
      value - the String value to be set on the field.
      buffer - Key or record buffer containing the field we want to set.
      offset - The offset in previous buffer where the key or record begins
      index - Subscript to this field.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • copyKeyToRecord

      protected abstract void copyKeyToRecord(byte[] keyBuffer, int keyOffset, byte[] recordBuffer, int recordOffset) throws KfException
      Fill the information on the KeyedFile.m_recordBuffer from the m_keyBuffer.
      Parameters:
      keyBuffer - Buffer where the key information is located.
      keyOffset - Offset where the key begins on previous buffer.
      recordBuffer - Buffer where the record information has to be left.
      recordOffset - Offset where the record begins on previous buffer.
      Throws:
      KfException - When no relation exists to the main index field.
    • copyRecordToKey

      protected abstract void copyRecordToKey(byte[] recordBuffer, int recordOffset, byte[] keyBuffer, int keyOffset) throws KfException
      Fill the information on the m_keyBuffer from the KeyedFile.m_recordBuffer.
      Parameters:
      recordBuffer - Buffer where the record information is located.
      recordOffset - Offset where the record begins on previous buffer.
      keyBuffer - Buffer where the key information has to be left.
      keyOffset - Offset where the key begins on previous buffer.
      Throws:
      KfException - When no relation exists to the main index field.
    • daynoToText

      protected final String daynoToText(long dayno)
      Get the Day number long value as a formated String.
      Parameters:
      dayno - The day number as stored in Sculptor
      Returns:
      the Day number as a string.
    • getBuffer

      protected final byte[] getBuffer()
      Get buffer. Record buffer when main key or Key buffer when secondary index field
      Returns:
      the index buffer where the field comes from
    • getOffset

      protected final int getOffset(int recordOffset, int index) throws KfException
      Get the offset to the field data inside the record buffer
      Parameters:
      recordOffset - the whole record offset to add in the calculation
      index - the field index (when the field has dimensions)
      Returns:
      the field offeset in the buffer
      Throws:
      KfException - In case the index is out of bounds
    • isRealKey

      protected boolean isRealKey()
      That function is used on secondary indexes to know if the field is part of the secondary key (true) or a copy from the main index (false).
      Returns:
      the isRealKey
    • moneyToText

      protected final String moneyToText(double money)
      Get the money String formated from the double value.
      Parameters:
      money - The money as stored in Sculptor
      Returns:
      the money as a string.
    • textToDayno

      protected final long textToDayno(String text) throws KfException
      Get the dayno long value from the formated Date text.
      Parameters:
      text - the formated text to convert to long
      Returns:
      the long converted value
      Throws:
      KfException - When a formating error occurs.
    • textToDouble

      protected final double textToDouble(String text) throws KfException
      Get the double value from the formated text.
      Parameters:
      text - the formated text to convert to double
      Returns:
      the double converted value
      Throws:
      KfException - When a formating error occurs.
    • textToLong

      protected final long textToLong(String text) throws KfException
      Get the long value from the formated text.
      Parameters:
      text - the formated text to convert to long
      Returns:
      the long converted value
      Throws:
      KfException - When a formating error occurs.
    • textToMoney

      protected final double textToMoney(String text) throws KfException
      Get the money double value from the formated money text.
      Parameters:
      text - the formated text to convert to double
      Returns:
      the double converted value
      Throws:
      KfException - When a formating error occurs.
    • close

      public void close()
      Close the field and remove the field from the parent FileIndex.
      Specified by:
      close in interface AutoCloseable
    • getAdt

      public Field.ArithmeticDataType getAdt()
      Return the Field adt
      Returns:
      the adt
    • getBinary

      public final byte[] getBinary() throws KfException
      Get the binary byte array of values as stored by Sculptor.
      Returns:
      the field values as stored on the Sculptor buffer.
      Throws:
      KfException - index out of bounds.
    • getBinary

      public final byte[] getBinary(int index) throws KfException
      Get the binary byte array of values as stored by Sculptor.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field values as stored on the Sculptor buffer.
      Throws:
      KfException - index out of bounds.
    • getDim

      public int getDim()
      Return the Field dim
      Returns:
      the dim
    • getDouble

      public final double getDouble() throws KfException
      Get the field value as double. Converting where necessary.
      Returns:
      the field converted to double
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getDouble

      public final double getDouble(int index) throws KfException
      Get the field value as double. Converting where necessary.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field converted to double
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getElement

      public int getElement()
      Return the Field element
      Returns:
      the element
    • getFieldName

      public String getFieldName()
      Return the Field fieldName
      Returns:
      the fieldName
    • getFlags

      public EnumSet<Field.Flag> getFlags()
      Return the Field flags
      Returns:
      the flags
    • getFormat

      public String getFormat()
      Return the Field format
      Returns:
      the format
    • getLen

      public int getLen()
      Return the Field len
      Returns:
      the len
    • getLong

      public final long getLong() throws KfException
      Get the field value as long. Converting where necessary.
      Returns:
      the field converted to long
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getLong

      public final long getLong(int index) throws KfException
      Get the field value as long. Converting where necessary.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field converted to long
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getLongRounded

      public final long getLongRounded() throws KfException
      Get the field value as rounded long. Converting where necessary.
      Returns:
      the field converted to long
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getLongRounded

      public final long getLongRounded(int index) throws KfException
      Get the field value as rounded long. Converting where necessary.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field converted to long
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getOffset

      public int getOffset()
      Return the Field offset
      Returns:
      the offset
    • getScft

      public Field.FieldType getScft()
      Return the Field scft
      Returns:
      the scft
    • getSclt

      public Field.LogicalDataType getSclt()
      Return the Field sclt
      Returns:
      the sclt
    • getSdt

      public byte getSdt()
      Convert the new Sculptor Field Type and Sculptor Logical Type values to the old Sculptor Data Type
      Returns:
      the old Sculptor Data Type
    • getString

      public final String getString() throws KfException
      Get the field value as String removing trailing spaces. Converting where necessary.
      Returns:
      the field converted to String
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getString

      public final String getString(int index) throws KfException
      Get the field value as String removing trailing spaces. Converting where necessary.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field converted to String
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getStringTS

      public final String getStringTS() throws KfException
      Get the field value as String without removing trailing spaces. Converting where necessary.
      Returns:
      the field converted to String
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • getStringTS

      public final String getStringTS(int index) throws KfException
      Get the field value as String without removing trailing spaces. Converting where necessary.
      Parameters:
      index - the subscript on the field (1-m_dim)
      Returns:
      the field converted to String
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setBinary

      public final void setBinary(byte[] value) throws KfException
      Set the byte array value to the field directly.
      Parameters:
      value - the byte array value to set the field with.
      Throws:
      KfException - index out of bounds.
    • setBinary

      public final void setBinary(byte[] value, int index) throws KfException
      Set the byte array value to the field directly.
      Parameters:
      value - the byte array value to set the field with.
      index - the subscript on the field (1-m_dim)
      Throws:
      KfException - index out of bounds.
    • setDouble

      public final void setDouble(double value) throws KfException
      Set the double value to the field and convert it if necessary.
      Parameters:
      value - the double value to set the field with.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setDouble

      public final void setDouble(double value, int index) throws KfException
      Set the double value to the field and convert it if necessary.
      Parameters:
      value - the double value to set the field with.
      index - the subscript on the field (1-m_dim)
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setLong

      public final void setLong(long value) throws KfException
      Set the long value to the field and convert it if necessary.
      Parameters:
      value - the long value to set the field with.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setLong

      public final void setLong(long value, int index) throws KfException
      Set the long value to the field and convert it if necessary.
      Parameters:
      value - the long value to set the field with.
      index - the subscript on the field (1-m_dim)
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setString

      public final void setString(String value) throws KfException
      Set the String value to the field and convert it if necessary.
      Parameters:
      value - the String value to set the field with.
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.
    • setString

      public final void setString(String value, int index) throws KfException
      Set the String value to the field and convert it if necessary.
      Parameters:
      value - the String value to set the field with.
      index - the subscript on the field (1-m_dim)
      Throws:
      KfException - when an impossible conversion happens or index out of bounds.