Package uk.co.sculptor.kflibjava
Class Field
java.lang.Object
uk.co.sculptor.kflibjava.Field
- All Implemented Interfaces:
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)
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
Modifier and TypeClassDescriptionstatic 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 TypeMethodDescriptionprotected 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()
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
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.getAdt()
Return the Field adtfinal 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
getDim()
Return the Field dimfinal double
Get the field value as double.final double
getDouble
(int index) Get the field value as double.int
Return the Field elementReturn the Field fieldNamegetFlags()
Return the Field flagsReturn the Field formatint
getLen()
Return the Field lenfinal long
getLong()
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 offsetprotected final int
getOffset
(int recordOffset, int index) Get the offset to the field data inside the record buffergetScft()
Return the Field scftgetSclt()
Return the Field scltbyte
getSdt()
Convert the new Sculptor Field Type and Sculptor Logical Type values to the old Sculptor Data Typefinal 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
Set the String value to the field and convert it if necessary.protected final long
textToDayno
(String text) Get the dayno long value from the formated Date text.protected final double
textToDouble
(String text) Get the double value from the formated text.protected final long
textToLong
(String text) Get the long value from the formated text.protected final double
textToMoney
(String text) Get the money double value from the formated money text.
-
Method Details
-
create
Creates the correct Field type (depending on m_adt field). Can only be created from aKeyedFile
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 aKeyedFile
constructor.- Parameters:
fileIndex
- the Field index object.fieldName
- Nameformat
- Formatflags
- Attribute flagsdim
- Dimensionoffset
- Offset in record bufferelement
- For indexing main key field or cursor fieldlen
- Length in bytesadt
- 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
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 beginsindex
- Subscript to this field- Returns:
- the field converted to double
- Throws:
KfException
- when an impossible conversion happens or index out of bounds.
-
_getDouble
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 beginsindex
- 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 beginsindex
- Subscript to this fieldround
- 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 beginsindex
- Subscript to this fieldremoveTs
- 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 beginsindex
- 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 beginsindex
- 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 beginsindex
- 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 beginsindex
- 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
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
Get the offset to the field data inside the record buffer- Parameters:
recordOffset
- the whole record offset to add in the calculationindex
- 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
Get the money String formated from the double value.- Parameters:
money
- The money as stored in Sculptor- Returns:
- the money as a string.
-
textToDayno
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
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
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
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 interfaceAutoCloseable
-
getAdt
Return the Field adt- Returns:
- the adt
-
getBinary
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
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
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
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
Return the Field fieldName- Returns:
- the fieldName
-
getFlags
Return the Field flags- Returns:
- the flags
-
getFormat
Return the Field format- Returns:
- the format
-
getLen
public int getLen()Return the Field len- Returns:
- the len
-
getLong
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
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
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
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
Return the Field scft- Returns:
- the scft
-
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
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
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
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
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
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
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
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
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
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
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
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
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.
-