78 lines
1.9 KiB
Java
78 lines
1.9 KiB
Java
package de.swingbe.ifleet.parser;
|
|
|
|
import de.swingbe.ifleet.model.Comm;
|
|
import de.swingbe.ifleet.model.Enty;
|
|
|
|
import java.util.Arrays;
|
|
|
|
class EntyParserImpl implements EntyParser {
|
|
|
|
EntyParserImpl() {
|
|
}
|
|
|
|
@Override
|
|
public Enty parse(final String input) {
|
|
|
|
String[] splits = input.split(" ");
|
|
|
|
//parse date
|
|
String date = "";
|
|
if (splits.length > 0) {
|
|
date = splits[0];
|
|
}
|
|
|
|
//parse time
|
|
String time = "";
|
|
if (splits.length > 1) {
|
|
time = splits[1];
|
|
}
|
|
|
|
//parse log level
|
|
String logLevel = "";
|
|
if (splits.length > 2) {
|
|
logLevel = splits[2];
|
|
}
|
|
|
|
//index three is empty
|
|
|
|
//parse addressPartA
|
|
String addressPartA = "";
|
|
if (splits.length > 4) {
|
|
addressPartA = splits[4].replaceFirst("\\[", "");
|
|
}
|
|
|
|
//parse addressPartB
|
|
String addressPartB = "";
|
|
if (splits.length > 5) {
|
|
addressPartB = splits[5].replaceFirst("/", "")
|
|
.replaceFirst("\\]", "");
|
|
}
|
|
|
|
//parse peer
|
|
String peer = "";
|
|
if (splits.length > 6) {
|
|
peer = splits[6];
|
|
}
|
|
//parse address next
|
|
String addressNext = "";
|
|
if (splits.length > 7) {
|
|
addressNext = splits[7].replaceFirst("/", "");
|
|
}
|
|
//parse direction
|
|
String direction = "";
|
|
if (splits.length > 8) {
|
|
direction = splits[8];
|
|
}
|
|
//parse comm
|
|
Comm comm = null;
|
|
if (splits.length > 9) {
|
|
String[] splitsSup = Arrays.copyOfRange(splits, 9, splits.length);
|
|
String inputSup = String.join(" ", splitsSup);
|
|
comm = CommParserFactory.createCommParser().parse(inputSup);
|
|
}
|
|
|
|
return new Enty(date, time, logLevel, addressPartA, addressPartB, peer,
|
|
addressNext, direction, comm);
|
|
}
|
|
}
|