Map Initialisation
No fear, it's easy to build - and the Adept library has a Map helper class in the util package with two static load() methods. One to create a HashMap and another where the map is provided so that you can use another variant such as a LinkedHashMap. Both methods use arrays to provide the information to load the map.
Examples
Map fieldTranslation = Maps.load( new Object[]
{
"integer", "integer",
"aLong", "anotherLong",
});
Map pronounce = Maps.load( new LinkedHashMap(),
new Object[]
{
"a", "aye",
"b", "bee",
"c", "see",
"d", "dee",
...
});
Sets
Sometimes maps are used as sets - being a collection of keys without values. The library class com.marringtons.util.Maps has two methods for working with map sets.
FileReader fileReader = new FileReader();
fileReader.setArchive(
"com/marringtons/util/system.resourceTest.zip");
String[] files = fileReader.listArchive();
Map map = Maps.loadSet( files);
assertTrue( map.containsKey(
"level1/level2/test in zip.txt"));
assertTrue( map.containsKey(
"META-INF/PATH-BASE.TXT"));
assertTrue( map.containsKey(
"META-INF/PROPERTIES.TXT"));
assertTrue( map.containsKey(
"level1/system.properties.txt"));
String[] files = fileReader.listArchive();
Arrays.sort( files);
Map map = Maps.loadSet( new LinkedHashMap(), files);








0 Comments:
Post a Comment
<< Home