Skip to content
This repository has been archived by the owner on Jul 22, 2023. It is now read-only.

Commit

Permalink
Add or optimize 'compose' and 'andThen' methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mkalb committed Jan 15, 2023
1 parent 8a82f2c commit 6482436
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/stexfires/examples/data/ExamplesTimeDataType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import stexfires.data.DataTypeParser;
import stexfires.data.GenericDataTypeFormatter;
import stexfires.data.GenericDataTypeParser;
import stexfires.data.NumberDataTypeFormatter;
import stexfires.data.NumberDataTypeParser;
import stexfires.data.TimeDataTypeFormatter;
import stexfires.data.TimeDataTypeParser;
import stexfires.util.function.StringUnaryOperators;

import java.text.NumberFormat;
import java.time.DateTimeException;
import java.time.DayOfWeek;
import java.time.Instant;
Expand Down Expand Up @@ -108,6 +112,19 @@ public static void main(String... args) {
System.out.println("---GenericDataTypeFormatter newInstantEpochSecondDataTypeParser newInstantEpochMilliDataTypeParser");
testParse("1673760570", GenericDataTypeParser.newInstantEpochSecondDataTypeParser(null), instantFormatter);
testParse("1673761073289", GenericDataTypeParser.newInstantEpochMilliDataTypeParser(null), instantFormatter);

System.out.println("---compose andThen NumberDataTypeFormatter toEpochMilli surround");
testFormat(Instant.now(),
new NumberDataTypeFormatter<Long>(NumberFormat.getIntegerInstance(Locale.GERMANY), null)
.compose(Instant::toEpochMilli)
.andThen(StringUnaryOperators.surround("'", "'")));

System.out.println("---compose andThen NumberDataTypeParser removeStringFromStart removeStringFromEnd ofEpochMilli");
testParse("'1.673.761.073.289'",
new NumberDataTypeParser<>(NumberFormat.getIntegerInstance(Locale.GERMANY), NumberDataTypeParser::toLong, null, null)
.compose(StringUnaryOperators.concat(StringUnaryOperators.removeStringFromStart("'"), StringUnaryOperators.removeStringFromEnd("'")))
.andThen(Instant::ofEpochMilli), instantFormatter);

}

}

0 comments on commit 6482436

Please sign in to comment.