summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/convert/MatchesReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/convert/MatchesReader.java')
-rw-r--r--src/cuchaz/enigma/convert/MatchesReader.java40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/MatchesReader.java b/src/cuchaz/enigma/convert/MatchesReader.java
index b43535c..1dd042d 100644
--- a/src/cuchaz/enigma/convert/MatchesReader.java
+++ b/src/cuchaz/enigma/convert/MatchesReader.java
@@ -10,6 +10,8 @@ import java.util.List;
10import com.beust.jcommander.internal.Lists; 10import com.beust.jcommander.internal.Lists;
11 11
12import cuchaz.enigma.mapping.ClassEntry; 12import cuchaz.enigma.mapping.ClassEntry;
13import cuchaz.enigma.mapping.FieldEntry;
14import cuchaz.enigma.mapping.Type;
13 15
14 16
15public class MatchesReader { 17public class MatchesReader {
@@ -42,4 +44,42 @@ public class MatchesReader {
42 } 44 }
43 return entries; 45 return entries;
44 } 46 }
47
48 public static FieldMatches readFields(File file)
49 throws IOException {
50 try (BufferedReader in = new BufferedReader(new FileReader(file))) {
51 FieldMatches matches = new FieldMatches();
52 String line = null;
53 while ((line = in.readLine()) != null) {
54 readFieldMatch(matches, line);
55 }
56 return matches;
57 }
58 }
59
60 private static void readFieldMatch(FieldMatches matches, String line) {
61 String[] parts = line.split(":", 2);
62 FieldEntry source = readField(parts[0]);
63 FieldEntry dest = readField(parts[1]);
64 if (source != null && dest != null) {
65 matches.addMatch(source, dest);
66 } else if (source != null) {
67 matches.addUnmatchedSourceField(source);
68 } else if (dest != null) {
69 matches.addUnmatchedDestField(dest);
70 }
71 }
72
73 private static FieldEntry readField(String in) {
74 if (in.length() <= 0) {
75 return null;
76 }
77 String[] parts = in.split(" ");
78 assert(parts.length == 3);
79 return new FieldEntry(
80 new ClassEntry(parts[0]),
81 parts[1],
82 new Type(parts[2])
83 );
84 }
45} 85}