diff options
Diffstat (limited to 'src/cuchaz/enigma/convert/MatchesReader.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MatchesReader.java | 40 |
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; | |||
| 10 | import com.beust.jcommander.internal.Lists; | 10 | import com.beust.jcommander.internal.Lists; |
| 11 | 11 | ||
| 12 | import cuchaz.enigma.mapping.ClassEntry; | 12 | import cuchaz.enigma.mapping.ClassEntry; |
| 13 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 14 | import cuchaz.enigma.mapping.Type; | ||
| 13 | 15 | ||
| 14 | 16 | ||
| 15 | public class MatchesReader { | 17 | public 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 | } |