From 17365c1bf397423e4973f5b431bea44bf199076a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 14 Mar 2017 00:46:04 -0400 Subject: match identification --- dslog/LogSet.java | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 dslog/LogSet.java (limited to 'dslog/LogSet.java') diff --git a/dslog/LogSet.java b/dslog/LogSet.java new file mode 100644 index 0000000..e284eba --- /dev/null +++ b/dslog/LogSet.java @@ -0,0 +1,74 @@ +package dslog; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.function.Supplier; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.ArrayList; + +public class LogSet { + public final String name; + public LogSet(String name) { + this.name = name; + } + public Path dslogPath, dseventsPath, pdplogPath; + + public String toString() { + return name+" "+verstr(this::dslog)+"/"+verstr(this::dsevents)+"/"+verstr(this::pdplog); + } + + + private static final Pattern fmsConnected = Pattern.compile("^FMS Connected: (?[A-Za-z].+) - (?[0-9:]+), Field Time: (?[0-9/]+ [0-9:]+)$"); + + public String[] matches() throws IOException { + ArrayList matches = new ArrayList(); + try (DseventsReader dsevents = dsevents()) { + if (dsevents == null) { + return matches.toArray(new String[matches.size()]); + } + while (dsevents.hasNext()) { + DseventsReader.Event event = dsevents.next(); + // do a (cheap) `.startsWith` check before doing an (expensive) regex check. + if (event.message.startsWith("FMS Connected:")) { + Matcher m = fmsConnected.matcher(event.message); + if (m.matches()) { + matches.add(m.group("matchname") + " - " + m.group("matchnumber")); + } + } + } + } + return matches.toArray(new String[matches.size()]); + } + + private static String verstr(Versioned.Supplier getter) { + try (Versioned thing = getter.get()) { + if (thing == null) { + return "␕"; + } + return ""+thing.version(); + } catch (IOException e) { + return "☠"; + } + } + + public DslogReader dslog() throws IOException { + if (dslogPath == null) { + return null; + } + return new DslogReader(Files.newInputStream(dslogPath)); + } + public DseventsReader dsevents() throws IOException { + if (dseventsPath == null) { + return null; + } + return new DseventsReader(Files.newInputStream(dseventsPath)); + } + public PdplogReader pdplog() throws IOException { + if (pdplogPath == null) { + return null; + } + return new PdplogReader(Files.newInputStream(pdplogPath)); + } +} -- cgit v1.2.3