Skip to content

Commit 610a3b3

Browse files
authored
Merge pull request #19 from joutvhu/development
1.1.2
2 parents 7d16320 + 3cb1d72 commit 610a3b3

File tree

7 files changed

+89
-22
lines changed

7 files changed

+89
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Fixed Width Parser is a small library that purpose is:
1111
- If you are using Gradle just add the following dependency to your `build.gradle`.
1212

1313
```groovy
14-
compile "com.github.joutvhu:fixed-width-parser:1.1.0"
14+
compile "com.github.joutvhu:fixed-width-parser:1.1.2"
1515
```
1616

1717
- Or add the following dependency to your `pom.xml` if you are using Maven.
@@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.0"
2020
<dependency>
2121
<groupId>com.github.joutvhu</groupId>
2222
<artifactId>fixed-width-parser</artifactId>
23-
<version>1.1.0</version>
23+
<version>1.1.2</version>
2424
</dependency>
2525
```
2626

build.gradle

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = 'com.github.joutvhu'
10-
version '1.1.0'
10+
version '1.1.2'
1111
sourceCompatibility = 1.8
1212
targetCompatibility = 1.8
1313

@@ -24,26 +24,26 @@ repositories {
2424

2525
dependencies {
2626
annotationProcessor 'org.projectlombok:lombok:1.18.12'
27-
compile 'org.projectlombok:lombok:1.18.12'
27+
compileOnly 'org.projectlombok:lombok:1.18.12'
2828

29-
compile 'org.apache.commons:commons-lang3:3.11'
30-
compile 'com.google.code.findbugs:jsr305:3.0.2'
29+
implementation 'org.apache.commons:commons-lang3:3.11'
30+
implementation 'com.google.code.findbugs:jsr305:3.0.2'
3131

32-
compile 'org.apache.logging.log4j:log4j-api:2.13.3'
33-
compile 'org.apache.logging.log4j:log4j-core:2.13.3'
32+
implementation 'org.apache.logging.log4j:log4j-api:2.13.3'
33+
implementation 'org.apache.logging.log4j:log4j-core:2.13.3'
3434

35-
compile "com.google.re2j:re2j:1.4"
35+
implementation "com.google.re2j:re2j:1.4"
3636

37-
compile "org.reflections:reflections:0.9.12"
37+
implementation "org.reflections:reflections:0.9.12"
3838

39-
compile "com.fasterxml.jackson.core:jackson-core:2.11.2"
40-
compile "com.fasterxml.jackson.core:jackson-annotations:2.11.2"
41-
compile "com.fasterxml.jackson.core:jackson-databind:2.11.2"
42-
compile "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.2"
43-
compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.2"
39+
implementation "com.fasterxml.jackson.core:jackson-core:2.11.2"
40+
implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2"
41+
implementation "com.fasterxml.jackson.core:jackson-databind:2.11.2"
42+
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.2"
43+
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.2"
4444

45-
testCompile 'junit:junit:4.13'
46-
testCompile 'org.junit.jupiter:junit-jupiter-api:5.6.2'
45+
testImplementation 'junit:junit:4.13'
46+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
4747
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
4848
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.6.2'
4949

@@ -134,7 +134,7 @@ publishing {
134134
withXml {
135135
def dependenciesNode = asNode().appendNode('dependencies')
136136

137-
configurations.compile.allDependencies.each {
137+
configurations.implementation.allDependencies.each {
138138
def dependencyNode = dependenciesNode.appendNode('dependency')
139139
dependencyNode.appendNode('groupId', it.group)
140140
dependencyNode.appendNode('artifactId', it.name)

src/main/java/com/joutvhu/fixedwidth/parser/annotation/FixedField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* @return label name of the field
2323
*/
24-
String label();
24+
String label() default "";
2525

2626
/**
2727
* Setups the start position of the field

src/main/java/com/joutvhu/fixedwidth/parser/convert/validator/NumberValidator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public void validate(String value, ValidationType type) {
4545
} else {
4646
String regex = isDecimal ? "^[0-9]+(\\.[0-9]+)?$" : "^[0-9]+$";
4747
if (!Pattern.matches(regex, value)) {
48-
throw new InvalidException(info.formatMessage(
49-
"{title} with value \"{value}\" is not a {number_type}.",
48+
String message = "{title} with value \"{value}\" is not " + (isDecimal ? "a" : "an") + " {number_type}.";
49+
throw new InvalidException(info.formatMessage(message,
5050
CommonUtil.putToMap(super.getArguments(value),
5151
"{number_type}", () -> isDecimal ? "number" : "integer")));
5252
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.joutvhu.fixedwidth.parser;
2+
3+
import com.joutvhu.fixedwidth.parser.annotation.FixedField;
4+
import com.joutvhu.fixedwidth.parser.annotation.FixedObject;
5+
import com.joutvhu.fixedwidth.parser.annotation.FixedParam;
6+
import com.joutvhu.fixedwidth.parser.constraint.FixedFormat;
7+
import com.joutvhu.fixedwidth.parser.constraint.FixedOption;
8+
import org.junit.jupiter.api.Assertions;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.api.TestInstance;
11+
12+
import java.time.LocalDate;
13+
import java.util.List;
14+
15+
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
16+
public class DemoTests {
17+
@Test
18+
public void demoTest() {
19+
Food food = (Food) FixedParser
20+
.parser()
21+
.parse("00001Dragon Fruit 09/30/2020fruit ", Product.class);
22+
23+
Medicine medicine = (Medicine) FixedParser
24+
.parser()
25+
.parse("60002Golden Star Balm YCamphor Peppermint oil Menthol Tea Tree Oil", Product.class);
26+
27+
String value = FixedParser
28+
.parser()
29+
.export(food);
30+
31+
Assertions.assertNotNull(medicine);
32+
Assertions.assertNotNull(value);
33+
}
34+
35+
@FixedObject(subTypes = {
36+
@FixedObject.Type(value = Food.class, prop = "id", matchWith = "^[0-5].+$")
37+
}, defaultSubType = Medicine.class)
38+
public static class Product {
39+
@FixedField(label = "Product Id", start = 0, length = 5)
40+
private Long id;
41+
42+
@FixedField(label = "Product Name", start = 5, length = 20)
43+
private String name;
44+
}
45+
46+
@FixedObject
47+
public static class Food extends Product {
48+
@FixedFormat(format = "MM/dd/yyyy")
49+
@FixedField(label = "Expiry Date", start = 25, length = 10)
50+
private LocalDate expiryDate;
51+
52+
@FixedOption(options = {"rice ", "breads", "fruit "})
53+
@FixedField(label = "Type", start = 35, length = 6)
54+
private String type;
55+
}
56+
57+
@FixedObject
58+
public static class Medicine extends Product {
59+
@FixedFormat(format = "Y|N")
60+
@FixedField(label = "Topical", start = 25, length = 1)
61+
private Boolean topical;
62+
63+
@FixedField(label = "Ingredients", start = 26, length = 60)
64+
private List<@FixedParam(length = 15) String> ingredients;
65+
}
66+
}

src/test/java/com/joutvhu/fixedwidth/parser/ModelG.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@FixedObject
1616
public class ModelG extends ModelD {
1717
@FixedRegex(regex = "[a-zA-Z]")
18-
@FixedField(label = "FIELD-D", start = 3, length = 1)
18+
@FixedField(start = 3, length = 1)
1919
private Character fieldD;
2020

2121
public ModelG(Long fieldA, @FixedRegex(regex = "[a-zA-Z]") Character fieldD) {

src/test/java/com/joutvhu/fixedwidth/parser/ModelGTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public void read1Test() {
2222
Assertions.fail();
2323
} catch (Exception e) {
2424
Assertions.assertTrue(e instanceof InvalidException);
25+
Assertions.assertEquals("fieldD field at position 4 and length 1 does not match the /[a-zA-Z]/ regex.", e.getMessage());
2526
}
2627
}
2728

0 commit comments

Comments
 (0)