diff options
| author | 2015-02-28 23:36:47 -0500 | |
|---|---|---|
| committer | 2015-02-28 23:36:47 -0500 | |
| commit | 88671184e20b3ad3791125cf96c83ca048cb2861 (patch) | |
| tree | 6c86f1ea61666ff2584b434d5f8df4d3fd83263c /src/cuchaz/enigma/convert/MatchesReader.java | |
| parent | switch to better-maintained version of JSyntaxPane (diff) | |
| download | enigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.tar.gz enigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.tar.xz enigma-fork-88671184e20b3ad3791125cf96c83ca048cb2861.zip | |
refactor converter a bit for upcoming convert gui
Diffstat (limited to 'src/cuchaz/enigma/convert/MatchesReader.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MatchesReader.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/MatchesReader.java b/src/cuchaz/enigma/convert/MatchesReader.java new file mode 100644 index 0000000..808f8d0 --- /dev/null +++ b/src/cuchaz/enigma/convert/MatchesReader.java | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | package cuchaz.enigma.convert; | ||
| 2 | |||
| 3 | import java.io.BufferedReader; | ||
| 4 | import java.io.File; | ||
| 5 | import java.io.FileReader; | ||
| 6 | import java.io.IOException; | ||
| 7 | import java.util.Collection; | ||
| 8 | import java.util.List; | ||
| 9 | |||
| 10 | import com.beust.jcommander.internal.Lists; | ||
| 11 | |||
| 12 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 13 | |||
| 14 | |||
| 15 | public class MatchesReader { | ||
| 16 | |||
| 17 | public static Matches read(File file) | ||
| 18 | throws IOException { | ||
| 19 | try (BufferedReader in = new BufferedReader(new FileReader(file))) { | ||
| 20 | Matches matches = new Matches(); | ||
| 21 | String line = null; | ||
| 22 | while ((line = in.readLine()) != null) { | ||
| 23 | matches.add(readMatch(line)); | ||
| 24 | } | ||
| 25 | return matches; | ||
| 26 | } | ||
| 27 | } | ||
| 28 | |||
| 29 | private static ClassMatch readMatch(String line) | ||
| 30 | throws IOException { | ||
| 31 | String[] sides = line.split(":", 2); | ||
| 32 | return new ClassMatch(readClasses(sides[0]), readClasses(sides[1])); | ||
| 33 | } | ||
| 34 | |||
| 35 | private static Collection<ClassEntry> readClasses(String in) { | ||
| 36 | List<ClassEntry> entries = Lists.newArrayList(); | ||
| 37 | for (String className : in.split(",")) { | ||
| 38 | className = className.trim(); | ||
| 39 | if (className.length() > 0) { | ||
| 40 | entries.add(new ClassEntry(className)); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | return entries; | ||
| 44 | } | ||
| 45 | } | ||