Skip to content

Commit bc8d5f1

Browse files
authored
Merge pull request #10 from joutvhu/development
Release 1.0.0
2 parents 1bf4adc + 10d89e0 commit bc8d5f1

28 files changed

+414
-22
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,19 @@ Fixed Width Parser is a small library that purpose is:
55
- Parse fixed width string to java object.
66

77
- Export java object to fixed width string.
8+
9+
## Installation
10+
11+
- Add dependency
12+
13+
```groovy
14+
compile "com.github.joutvhu:fixed-width-parser:1.0.0"
15+
```
16+
17+
```xml
18+
<dependency>
19+
<groupId>com.github.joutvhu</groupId>
20+
<artifactId>fixed-width-parser</artifactId>
21+
<version>1.0.0</version>
22+
</dependency>
23+
```

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = 'com.github.joutvhu'
10-
version '0.0.10-SNAPSHOT'
10+
version '1.0.0'
1111
sourceCompatibility = 1.8
1212
targetCompatibility = 1.8
1313

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.lang.annotation.*;
88

99
/**
10+
* Used to annotate the fixed width field
11+
*
1012
* @author Giao Ho
1113
* @since 1.0.0
1214
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.lang.annotation.*;
88

99
/**
10+
* Used to annotate the fixed width object
11+
*
1012
* @author Giao Ho
1113
* @since 1.0.0
1214
*/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import java.lang.annotation.*;
88

99
/**
10+
* Used to annotate the fixed width param
11+
*
1012
* @author Giao Ho
1113
* @since 1.0.0
1214
*/

src/main/java/com/joutvhu/fixedwidth/parser/constraint/FixedFormat.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.lang.annotation.*;
44

55
/**
6+
* Setups constraint for value by format
7+
*
68
* @author Giao Ho
79
* @since 1.0.0
810
*/

src/main/java/com/joutvhu/fixedwidth/parser/constraint/FixedOption.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.lang.annotation.*;
44

55
/**
6+
* Setups constraint for value by options
7+
*
68
* @author Giao Ho
79
* @since 1.0.0
810
*/

src/main/java/com/joutvhu/fixedwidth/parser/constraint/FixedRegex.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.lang.annotation.*;
44

55
/**
6+
* Setups constraint for value by regular expression
7+
*
68
* @author Giao Ho
79
* @since 1.0.0
810
*/

src/main/java/com/joutvhu/fixedwidth/parser/convert/FixedWidthReader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.joutvhu.fixedwidth.parser.support.FixedTypeInfo;
55

66
/**
7+
* Fixed width reader
8+
*
9+
* @param <T> result type
710
* @author Giao Ho
811
* @since 1.0.0
912
*/

src/main/java/com/joutvhu/fixedwidth/parser/convert/FixedWidthValidator.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.joutvhu.fixedwidth.parser.util.CommonUtil;
66

77
/**
8+
* Fixed width validator
9+
*
810
* @author Giao Ho
911
* @since 1.0.0
1012
*/
@@ -13,6 +15,15 @@ public FixedWidthValidator(FixedTypeInfo info, FixedParseStrategy strategy) {
1315
super(info, strategy);
1416
}
1517

18+
/**
19+
* Get error message
20+
*
21+
* @param message native message or message template
22+
* @param nativeMessage the message is native message
23+
* @param defaultMessage use this message if the message is blank
24+
* @param arguments the arguments
25+
* @return message
26+
*/
1627
protected String getMessage(String message, boolean nativeMessage, String defaultMessage, Object... arguments) {
1728
if (CommonUtil.isBlank(message)) {
1829
message = defaultMessage;

src/main/java/com/joutvhu/fixedwidth/parser/convert/FixedWidthWriter.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import com.joutvhu.fixedwidth.parser.support.FixedTypeInfo;
55

66
/**
7+
* Fixed width writer
8+
*
9+
* @param <T> input type
710
* @author Giao Ho
811
* @since 1.0.0
912
*/

src/main/java/com/joutvhu/fixedwidth/parser/convert/ParsingApprover.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import com.joutvhu.fixedwidth.parser.support.FixedTypeInfo;
66

77
/**
8+
* Parsing approver
9+
*
810
* @author Giao Ho
911
* @since 1.0.0
1012
*/
@@ -17,6 +19,9 @@ public ParsingApprover(FixedTypeInfo info, FixedParseStrategy strategy) {
1719
this.strategy = strategy;
1820
}
1921

22+
/**
23+
* Can't use this class to read, write or validate fixed width string
24+
*/
2025
protected void reject() {
2126
throw new FixedException("Can't use this class.");
2227
}

src/main/java/com/joutvhu/fixedwidth/parser/convert/StringReader.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@
33
import com.joutvhu.fixedwidth.parser.support.StringAssembler;
44

55
/**
6+
* Deserialization
7+
* Fixed width string reader
8+
*
69
* @author Giao Ho
710
* @since 1.0.0
811
*/
912
public interface StringReader<T> {
13+
/**
14+
* Deserialize
15+
* Read object value from {@link StringAssembler}
16+
*
17+
* @param assembler the {@link StringAssembler}
18+
* @return object value
19+
*/
1020
T read(StringAssembler assembler);
1121
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
package com.joutvhu.fixedwidth.parser.convert;
22

33
/**
4+
* Fixed width validator
5+
*
46
* @author Giao Ho
57
* @since 1.0.0
68
*/
79
public interface StringValidator {
8-
boolean validate(String value, ValidationType type);
10+
/**
11+
* Validate string value
12+
*
13+
* @param value is string value
14+
* @param type the {@link ValidationType}
15+
*/
16+
void validate(String value, ValidationType type);
917
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
package com.joutvhu.fixedwidth.parser.convert;
22

33
/**
4+
* Serialization
5+
* Fixed width string writer
6+
*
47
* @author Giao Ho
58
* @since 1.0.0
69
*/
710
public interface StringWriter<T> {
11+
/**
12+
* Serialize
13+
* Write object to string
14+
*
15+
* @param value object
16+
* @return string
17+
*/
818
String write(T value);
919
}

src/main/java/com/joutvhu/fixedwidth/parser/convert/ValidationType.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.joutvhu.fixedwidth.parser.convert;
22

33
/**
4+
* Validation type enum, before read or after write
5+
*
46
* @author Giao Ho
57
* @since 1.0.0
68
*/

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.List;
1414

1515
/**
16+
* Boolean validator
17+
*
1618
* @author Giao Ho
1719
* @since 1.0.0
1820
*/
@@ -31,14 +33,13 @@ public void setOptions(String[] options) {
3133
}
3234

3335
@Override
34-
public boolean validate(String value, ValidationType type) {
36+
public void validate(String value, ValidationType type) {
3537
if (splitOptions(fixedFormat.format()) && !options.contains(value)) {
3638
String message = getMessage(fixedFormat.message(),
3739
fixedFormat.nativeMessage(),
3840
"{title} should be equal to one of the following value(s): {0}.",
3941
"\"" + StringUtils.join(options, "\", \"") + "\"");
4042
throw new InvalidException(message);
4143
}
42-
return true;
4344
}
4445
}

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

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import com.joutvhu.fixedwidth.parser.util.TypeConstants;
99

1010
/**
11+
* Date time validator
12+
*
1113
* @author Giao Ho
1214
* @since 1.0.0
1315
*/
@@ -19,19 +21,14 @@ public DateValidator(FixedTypeInfo info, FixedParseStrategy strategy) {
1921
}
2022

2123
@Override
22-
public boolean validate(String value, ValidationType type) {
23-
if (CommonUtil.isNotBlank(value)) {
24-
if (CommonUtil.isNotBlank(fixedFormat.format()) &&
25-
!CommonUtil.isDateValid(value, fixedFormat.format(), true)) {
26-
String message = getMessage(fixedFormat.message(),
27-
fixedFormat.nativeMessage(),
28-
"{title} should be in format {0}.",
29-
fixedFormat.format());
30-
throw new InvalidException(message);
31-
}
32-
} else {
33-
24+
public void validate(String value, ValidationType type) {
25+
if (CommonUtil.isNotBlank(fixedFormat.format()) &&
26+
!CommonUtil.isDateValid(value, fixedFormat.format(), true)) {
27+
String message = getMessage(fixedFormat.message(),
28+
fixedFormat.nativeMessage(),
29+
"{title} should be in format {0}.",
30+
fixedFormat.format());
31+
throw new InvalidException(message);
3432
}
35-
return true;
3633
}
3734
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import com.joutvhu.fixedwidth.parser.support.FixedTypeInfo;
77

88
/**
9+
* Validator for {@link FixedFormat} annotation
10+
*
911
* @author Giao Ho
1012
* @since 1.0.0
1113
*/

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import java.util.List;
1313

1414
/**
15+
* Validator for {@link FixedOption} annotation
16+
*
1517
* @author Giao Ho
1618
* @since 1.0.0
1719
*/
@@ -25,7 +27,7 @@ public OptionValidator(FixedTypeInfo info, FixedParseStrategy strategy) {
2527
}
2628

2729
@Override
28-
public boolean validate(String value, ValidationType type) {
30+
public void validate(String value, ValidationType type) {
2931
if (CommonUtil.isNotBlank(fixedOption.options())) {
3032
List<String> options = CommonUtil.listOf(fixedOption.options());
3133
if (!options.contains(value)) {
@@ -36,6 +38,5 @@ public boolean validate(String value, ValidationType type) {
3638
throw new InvalidException(message);
3739
}
3840
}
39-
return true;
4041
}
4142
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.joutvhu.fixedwidth.parser.util.CommonUtil;
1111

1212
/**
13+
* Validator for {@link FixedRegex} annotation
14+
*
1315
* @author Giao Ho
1416
* @since 1.0.0
1517
*/
@@ -23,14 +25,13 @@ public RegexValidator(FixedTypeInfo info, FixedParseStrategy strategy) {
2325
}
2426

2527
@Override
26-
public boolean validate(String value, ValidationType type) {
28+
public void validate(String value, ValidationType type) {
2729
if (CommonUtil.isNotBlank(fixedRegex.regex()) && !Pattern.matches(fixedRegex.regex(), value)) {
2830
String message = getMessage(fixedRegex.message(),
2931
fixedRegex.nativeMessage(),
3032
"{title} doesn't match by /{0}/ regex.",
3133
fixedRegex.regex());
3234
throw new InvalidException(message);
3335
}
34-
return true;
3536
}
3637
}

0 commit comments

Comments
 (0)