-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,712 additions
and
1,669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
package net.teamfruit.sushida.data; | ||
|
||
import com.google.common.base.Charsets; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.yaml.snakeyaml.Yaml; | ||
import org.yaml.snakeyaml.constructor.CustomClassLoaderConstructor; | ||
|
||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Stream; | ||
|
||
public class Word { | ||
public final ImmutableMap<String, Map<String, String>> mappings; | ||
public final ImmutableMap<String, ImmutableList<ImmutableList<Map.Entry<String, String>>>> mappings; | ||
|
||
public Word(ImmutableMap<String, Map<String, String>> mappings) { | ||
public Word(ImmutableMap<String, ImmutableList<ImmutableList<Map.Entry<String, String>>>> mappings) { | ||
this.mappings = mappings; | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Word load(InputStream input) { | ||
try { | ||
Yaml cfg = new Yaml(new CustomClassLoaderConstructor(Word.class.getClassLoader())); | ||
WordData data = cfg.loadAs(new InputStreamReader(input, Charsets.UTF_8), WordData.class); | ||
return new Word(ImmutableMap.copyOf(data.word)); | ||
return new Word(data.word.entrySet().stream() | ||
.collect(ImmutableMap.toImmutableMap( | ||
Map.Entry::getKey, | ||
e -> e.getValue().stream() | ||
.map(f -> ((f instanceof List) | ||
? ((List<Map<String, String>>) f).stream() | ||
: Stream.of((Map<String, String>) f) | ||
) | ||
.map(g -> g.entrySet().stream().findFirst().get()) | ||
.collect(ImmutableList.toImmutableList()) | ||
) | ||
.collect(ImmutableList.toImmutableList()) | ||
)) | ||
); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Word load error", e); | ||
} | ||
} | ||
|
||
public static class WordData { | ||
public Map<String, Map<String, String>> word; | ||
public Map<String, List<Object>> word; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.