Need to choose optimal data structure for fast work with list of locations and regions.
There is simple POJO for locations(cities):
public class Location {
private String name;
private int post; //id
And for regions(districts):
public class Region {
private String name;
private int id;
private List<Location> cities;
And finally I have List of Region objects.
What I need to do:
- Search Locations name by its post(id)
- Search Locations post by its name. Note: Name is not unique, so I need to prefer some concrete Location over another in case of identical names
The question is what data structure should I use?
I am thinking of TreeMap with contains ALL the Locations from ALL regions. So I can fast get location by Name(string).
For p 1. I have solution: post of Location contains id of Region. So If Region have id=1, then its Locations post will be 10001, 10002 etc.
Or maybe I need to choose some new Collections type introduced by Guava, since it already present in project?
Add all locations to two
HashMaps:Preferably hide the two hashmaps in one class doing the lookups for you.
Or am I missing something?