A String splitter util for Java.
Feature | Status |
---|---|
Unit Tests | |
Coverage |
Java 8 or later.
- Modifying the internal splitter mechanism
- More unit testing added
- Implemented Float splitter
- Implemented Double splitter
- Implemented exception flow tests on Date classes
- Javadoc Documentation and other documentation fixed
- Updated Javadoc documentation for packages
- Updated this page with date examples
- Organized packages into primitives, dates and string
- Implemented LocalDate splitter
- Implemented LocalTime splitter
- Implemented LocalDateTime splitter
- Implemented Date splitter
- Implemented Calendar splitter
- Javadoc Documentation and other documentation fixed
- Updated Javadoc documentation for packages
- Updated this page with date examples
String data = "Collect THIS text";
// Only the text
String result = StringSplit
.newStringSplit(7, 11)
.split(data);
// Lower Case
String resultUpperCase = StringSplit
.newStringSplit(7, 11, WordCase.LOWER_CASE)
.split(data);
// Trimmed
String resultUpperCase = StringSplit
.newStringSplit(7, 12, true)
.split(data);
// Lower Case and Trimmed
String resultUpperCase = StringSplit
.newStringSplit(7, 12, WordCase.LOWER_CASE, true)
.split(data);
String data = "STRINGSPLITTER";
StringArraySplit StringArraySplit = new StringArraySplit();
StringArraySplit splitter = new StringArraySplit();
StringSplit stringSplit1 = StringSplit.newSplit(0, 6);
StringSplit stringSplit2 = StringSplit.newSplit(6);
splitter.addSplit(stringSplit1);
splitter.addSplit(stringSplit2);
List<String> result = splitter.split(data);
Or using a builder:
String data = "STRINGSPLITTER";
List<String> result =
StringArraySplitterBuilder
.newSplitter()
.addStringSplit(0, 6)
.addStringSplit(6)
.build()
.split(data);
String data = "FAILED SUCCESS";
Function conversionFunction<String, Boolean> = myTrue => {
if(myTrue.equals("FAILED ") {
return Boolean.FALSE;
}
if(myTrue.equals("SUCCESS") {
return Boolean.TRUE;
}
return Boolean.FALSE;
};
BooleanSplit booleanSplit = BooleanSplit.newBooleanSplit(0, 7, conversionFunction);
boolean hasCompleted = booleanSplit.split(data);
String data = "textfile.txt 40KB";
ByteSplit byteSplit = ByteSplit.newByteSplit(12, 16);
byte fileSizeInKB = byteSplit.split(data);
String data = "↑↑↓↓←→←→BA";
CharacterSplit characterSplit = CharacterSplit.newCharacterSplit(1);
char direction = characterSplit.split(data);
String data = "BANK BRAND25892";
ShortSplit shortSplit = ShortSplit.newShortSplit(10, 14);
short agencyNumber = shortSplit.split(data);
String data = "FANCY LAPTOP i7 2,300";
IntegerSplit split = IntegerSplit.newIntegerSplit(20, ",");
int productPrice = split.split(data);
String data = "EARTH 149600000"
LongSplit longSplit = LongSplit.newLongSplit(10);
long distanceFromTheSun = longSplit.split(data);
String data = "2.67DATA"
FloatSplit floatSplit = FloatSplit.newFloatSplit(0, 4);
float price = floatSplit.split(data);
String data = "2.67DATA"
DoubleSplit doubleSplit = DoubleSplit.newDoubleSplit(0, 4);
double price = doubleSplit.split(data);
Without format:
String data = "157374145700014/11/2019 14:24:17"
DateSplit dateSplit = DateSplit.fromLong(0, 13);
Date dateRecorded = dateSplit.split(data);
With format:
String data = "157374145700014/11/2019 14:24:17"
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
DateSplit dateSplit = DateSplit.fromFormatted(13, format);
Date dateRecorded = dateSplit.split(data);
Without format:
String data = "157374145700014/11/2019 14:24:17"
CalendarSplit dateSplit = CalendarSplit.fromLong(0, 13);
Date dateRecorded = dateSplit.split(data);
With format:
String data = "157374145700014/11/2019 14:24:17"
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
CalendarSplit dateSplit = CalendarSplit.fromFormatted(13, format);
Date dateRecorded = dateSplit.split(data);
Using the default format:
String data = "14/12/19771977-12-14"
LocalDateSplit localDateSplit = LocalDateSplit.newLocalDateSplit(10);
LocalDate dateRecorded = localDateSplit.split(data);
Using a DateTimeFormatter
:
String data = "14/12/19771977-12-14"
DateTimeFormatter format = new DateTimeFormatterBuilder()
.appendValue(ChronoField.DAY_OF_MONTH, 2)
.appendLiteral('/')
.appendValue((ChronoField.MONTH_OF_YEAR), 2)
.appendLiteral('/')
.appendValue(ChronoField.YEAR, 2, 4, SignStyle.NEVER)
.toFormatter();
LocalDateSplit localDateSplit = LocalDateSplit.fromFormatted(0, 10, format).split(data);
LocalDate dateRecorded = localDateSplit.split(data);
Using the default format:
String data = "01:56:35 PM00:40:00.12"
LocalTimeSplit localTimeSplit = LocalTimeSplit.newLocalTimeSplit(11);
LocalTime timeRecorded = localTimeSplit.split(data);
Using a DateTimeFormatter
:
String data = "01:56:35 PM00:40:00.12"
DateTimeFormatter format = DateTimeFormatter.ofPattern("hh:mm:ss a");
LocalTimeSplit localTimeSplit = LocalTimeSplit.fromFormatted(0, 11, format);
LocalTime timeRecorded = localTimeSplit.split(data);
Using the default format:
String data = "Thursday, 14 November 2019, 11:172019-11-14T11:17:39.049"
LocalDateTimeSplit localDateTimeSplit = LocalDateTimeSplit.newLocalDateTimeSplit(33);
LocalDateTime timestampRecorded = LocalDateTimeSplit.split(data);
Using a DateTimeFormatter
:
String data = "Thursday, 14 November 2019, 11:172019-11-14T11:17:39.049"
DateTimeFormatter format = DateTimeFormatter.ofPattern("EEEE, dd MMMM yyyy, HH:mm");
LocalDateTimeSplit localDateTimeSplit = LocalDateTimeSplit.newLocalDateTimeSplit(0, 33, format);
LocalDateTime timestampRecorded = LocalDateTimeSplit.split(data);
The following table shows the plans to evolve the framework:
Release | Feature | Status | Tasks Link |
---|---|---|---|
1 | Framework architecture | Implemented | |
2 | StringSplit, StringArraySplit, CharacterSplit, ByteSplit, ShortSplit, IntegerSplit, LongSplit | Implemented | |
3 | LocalDateSplit, LocalTimeSplit, LocalDateTimeSplit, DateSplit and CalendarSplit | Implemented | Tasks |
4 | FloatSplit and DoubleSplit | Implemented | Tasks |
4.1 | Refactorings, improvements, bugifxing and testing | Implemented | Tasks |
5 | EntityBuilder, FieldSplit, Wiki pages (better documentation) and Issues fixing | v5 |
Setters, Method Handles, and Java 11