Last active
August 29, 2015 14:03
-
-
Save sztanko/229f788b7bb7b70543ca to your computer and use it in GitHub Desktop.
SnakeYaml problem
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
mapping: | |
nature: | |
wetland: | |
buffer: [5.0] | |
mappings: | |
natural: [wetland, mud] | |
meadow: | |
buffer: [5.0] | |
mappings: | |
landuse: [grass, meadow] | |
natural: [fell, grassland] | |
landmark: | |
castle: | |
buffer: [-5.0, 30.0, 50.0] | |
mappings: | |
bridge: [drawbridge] | |
historic: [castle] |
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
import java.util.List; | |
import java.util.Map; | |
import org.yaml.snakeyaml.Yaml; | |
import org.yaml.snakeyaml.constructor.Constructor; | |
public class SnakeTest { | |
public static class TagMapping { | |
public static class Mapping { | |
public List<Double> buffer; | |
public Map<String, List<String>> mappings; | |
} | |
public Map<String, Map<String, Mapping>> mapping; | |
} | |
public static TagMapping parse(String str) { | |
Yaml yaml = new Yaml(new Constructor(TagMapping.class)); | |
TagMapping mapping = (TagMapping) yaml.load(str); | |
return mapping; | |
} | |
public static void main(String... args) | |
{ | |
String testString = | |
"mapping:\n"+ | |
" nature:\n"+ | |
" wetland:\n"+ | |
" buffer: [5.0]\n"+ | |
" mappings:\n"+ | |
" natural: [wetland, mud]\n"+ | |
" meadow:\n"+ | |
" buffer: [5.0]\n"+ | |
" mappings:\n"+ | |
" landuse: [grass, meadow]\n"+ | |
" natural: [fell, grassland]\n"+ | |
" landmark:\n"+ | |
" castle:\n"+ | |
" buffer: [-5.0, 30.0, 50.0]\n"+ | |
" mappings:\n"+ | |
" bridge: [drawbridge]\n"+ | |
" historic: [castle]"; | |
TagMapping m = parse(testString); | |
System.out.println(m.mapping.get("nature").get("wetland").mappings.get("natural").get(0)); | |
} | |
} |
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
public static class TagMapping { | |
public static class Mapping { | |
public List<Double> buffer; | |
public Map<String, List<String>> mappings; | |
} | |
public Map<String, Map<String, Mapping>> mapping; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment