FLDA supports reading data as well as writing data of records with a fix size.
Fix size means:
- each record has n Attributes. An Attribute has an index.
- or: each record has a fix length. An Attribute has an index and a length.
This project is only the core. For some usages of this project see:
Fixed-length data consists of attributes that each have a specific position and length. Hence, every n-th attribute begins at the same character-index. In this example, every name of an item begins at character-index 10 and every amount of items begins at character-index 16:
Fruit Cherry30
Fruit Apple 5
VegetablePotato23
Character-separated data consists of attributes that are separated by a character. In this example, the attributes
are semicolon-separated and each record consists of three Attributes. The record type is List<String>
.
Fruit;Cherry;30
Fruit;Apple;5
Vegetable;Potato;23
To use FLDA, include the following artifact:
<dependency>
<groupId>com.github.tinosteinort</groupId>
<artifactId>flda-core</artifactId>
<version>2.0.0</version>
</dependency>
The Automatic Module Name of this library is:
com.github.tinosteinort.flda.accessor
Within the Accessor Concept there are different parts:
- the fixed size data record
- the definition of an attribute
- an accessor
This is just the part of data to read from or to write to.
This is the information how an attribute is addressed. There are different questions to answer:
- of which type is the attribute?
- on which index is the attribute located?
- how long (e.g. in characters or bytes) is the attribute?
For some record types not all questions are relevant. For an index based record type, there is no need to know the size of one attribute.
Example of a FixedLengthString
attribute with index and length:
FixedLengthStringAttribute<String> FIRST_NAME = new FixedLengthStringAttribute<>(String.class, 0, 10);
A ReadAccessor
reads from a record and a WriteAccessor
writes to the record. Therefore an attribute definition
is needed. An AccessorConfig
is needed too.
Read Example:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = ...
ReadAccessor<FixedLengthString, FixedLengthStringAttribute<?>> readAccessor = new ReadAccessor<>(config, datarecord)
String firstname = readAccessor.read(FIRST_NAME)
Example for write a record:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = ...
WriteAccessor<FixedLengthString, FixedLengthStringAttribute<?>> writeAccessor = new WriteAccessor<>(config, record);
writeAccessor.write(PersonDescriptor.FIRST_NAME, person.getFirstname());
A record factory is used by AccessorConfig.createNewRecord
. To use this
method it is required to register a record factory:
AccessorConfig<FixedLengthString, FixedLengthStringAttribute<?>> config = new AccessorConfigBuilder<FixedLengthString, FixedLengthStringAttribute<?>>()
// ...
.withRecordFactory(new FixedLengthStringFactory(23, ' '))
.build();
The advantage of using a record factory is, that the code to create a new record is in one place.
There are different predefined record factories:
FixedLengthString
=>FixedLengthStringFactory
StringList
=>StringListFactory
It is possible to validate the records automatically. Just register the desired validators:
SizeValidator validator = new SizeValidator(5);
AccessorConfig<List<String>, StringListAttribute<?>> config =
new AccessorConfigBuilder<List<String>, StringListAttribute<?>>()
// ...
.withReadValidator(validator)
.withWriteValidator(validator)
.build();
There are different predefined validators:
FixedLengthString
=>LengthValidator
StringList
=>SizeValidator
- Move
StringFitter
fromcom.github.tinosteinort.flda.interfaces.fixedlengthstring.writer
tocom.github.tinosteinort.flda.interfaces.fixedlengthstring
StringFitter
is renamed toStringUtils
- Extract
StringFitter.Alignment
into own Class:com.github.tinosteinort.flda.interfaces.fixedlengthstring.Alignment
- Remove
Alignment
Class from FixedLengthString Writer Classes intocom.github.tinosteinort.flda.interfaces.fixedlengthstring.FixedLengthStringAttribute
- Remove
filler
char from FixedLengthString Writer Classes intocom.github.tinosteinort.flda.interfaces.fixedlengthstring.FixedLengthStringAttribute
- Method
FixedLengthString#getString()
replaced byFixedLengthString#toString()
- Output of old
FixedLengthString#toString()
Method is not supported anymore
- Output of old
- Class
StringReader
is replaced by MethodStringUtils#readAndTrim()
FixedLenghtString
implementsCharSequence
- API Update: move filler char and alignment into
FixedLengthStringAttribute
- split project
flda
inflda-core
,flda-fixedlengthstring
andflda-stringlist
- introduce own
RecordFactory<T>
interface.Supplier<T>
was used before - change
AccessorConfig
from interface to abstract class. Needed to clean up the API