Closed dacdave closed 8 years ago
You can access the iterator right? Is that sufficient to build the collection on the other side? I can see wanting access to a map and so would be fine with that as an addition, but the iterator should give you access to a list of the keys?
Yes, I guess we do provide public access to the iterator. Given that, my findFirstValue could be implemented on the client side as well.
I still think a convenience function findAvailableLanguages would be helpful, and trivial to write.
And it is done. Here is the code.
public List<String> findAvailableLanguages() {
Iterator<Map.Entry<String, String>> it = this.iterator();
List<String> list = new ArrayList<String>();
while (it.hasNext()) {
Map.Entry<String, String> n = it.next();
list.add(n.getValue());
}
return list;
}
...and the test
ArrayList<String> langs = (ArrayList)lm.findAvailableLanguages();
... assertEquals(langs.size(), 3);
If there are no corrections or suggestions, I will make a pull request.
Correction...
list.add(n.getValue());
changed to
list.add(n.getKey());
I think a good improvement would be to have the library return a collection, possibly empty collection, of the languages (keys) available for a language map object.
Maybe we could even offer a method to return a full collection (key : value) for all entries in the language map.
As it is now, the user has to know the language that they want, or use my findFirstValue method, to query the map.
Dave Smith