50% found this document useful (2 votes)
709 views

Fixed Format 4 J

This document discusses a Java class called MyRecord that represents fixed format records. The MyRecord class uses annotations to define fields with attributes like offset, length, and alignment. A FixedFormatManager class is used to load MyRecord objects from fixed width data strings and export MyRecord objects back to those strings. The document provides an example of loading test data into a MyRecord instance and verifying the loaded values match the original data.

Uploaded by

claes.bostrom
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
50% found this document useful (2 votes)
709 views

Fixed Format 4 J

This document discusses a Java class called MyRecord that represents fixed format records. The MyRecord class uses annotations to define fields with attributes like offset, length, and alignment. A FixedFormatManager class is used to load MyRecord objects from fixed width data strings and export MyRecord objects back to those strings. The document provides an example of loading test data into a MyRecord instance and verifying the loaded values match the original data.

Uploaded by

claes.bostrom
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

!" !# !$ !

%
!& ! !& ! ! &

'

)
*

'

@Record
public class MyRecord {

private String stringData;


private Integer integerData;
private Date dateData;
private BigDecimal bigDecimalData;

@Field(offset = 1, length = 10, align = Align.RIGHT, paddingChar = ' ')


public String getStringData() {
return stringData;
}

public void setStringData(String stringData) {


this.stringData = stringData;
}

@Field(offset = 11, length = 5, align = Align.RIGHT, paddingChar = '0')


public Integer getIntegerData() {
return integerData;
}

public void setIntegerData(Integer integerData) {


this.integerData = integerData;
}

@Field(offset = 16, length = 8)


public Date getDateData() {
return dateData;
}

public void setDateData(Date dateData) {


this.dateData = dateData;
}

http://fixedformat4j.ancientprogramming.com/ 2008-05-27
@Field(offset = 24, length = 10, align = Align.RIGHT, paddingChar = '0')
public BigDecimal getBigDecimalData() {
return bigDecimalData;
}

public void setBigDecimalData(BigDecimal bigDecimalData) {


this.bigDecimalData = bigDecimalData;
}
}

) *

...
//setup testdata
final String MY_RECORD_DATA = "some text +012320080525+000120120";
Calendar someDay = Calendar.getInstance();
someDay.set(2008, 4, 25, 0, 0, 0); //month is zerobased, hench 4 equals May
someDay.set(Calendar.MILLISECOND, 0);

//create instance of manager


FixedFormatManager = manager = new FixedFormatManagerImpl();

//load and assert that the loaded data is correct


MyRecord loadedRecord = manager.load(MyRecord.class, MY_RECORD_DATA);
Assert.equals("some text ", loadedRcord.getStringData());
Assert.equals(new Integer(123), loadedRcord.getIntegerData());
Assert.equals(someday, loadedRcord.getDateData());
Assert.equals(new BigDecimal(12.012), loadedRcord.getBigDecimalData());

//an export should bring back the exact same string as we loaded
Assert.assertEquals(MY_RECORD_DATA, manager.export(loadedRecord));

...

+
# ,
) &-

http://fixedformat4j.ancientprogramming.com/ 2008-05-27

You might also like