Map<Integer, GeoTreeItemDto> idxCountry = new HashMap<Integer, GeoTreeItemDto>();
Map<Integer, GeoTreeItemDto> idxMacroReg = new HashMap<Integer, GeoTreeItemDto>();
Map<Integer, GeoTreeItemDto> idxProvince = new HashMap<Integer, GeoTreeItemDto>();
Map<Integer, GeoTreeItemDto> idxCity = new HashMap<Integer, GeoTreeItemDto>();
GeoClassificator russia = null;
GeoTreeItemDto res = null;
for (GeoClassificator item : geolist) {
if (item instanceof GeoCountry) {
idxCountry.put(item.getId(), new GeoTreeItemDto(item));
if (item.getLatinName().equalsIgnoreCase("russia")) {
russia = item;
}
} else if (item instanceof GeoMacroRegion) {
idxMacroReg.put(item.getId(), new GeoTreeItemDto(item));
} else if (item instanceof GeoProvince) {
idxProvince.put(item.getId(), new GeoTreeItemDto(item));
} else if (item instanceof GeoCity) {
idxCity.put(item.getId(), new GeoTreeItemDto(item));
}
}
for (GeoTreeItemDto item : idxCity.values()){
GeoClassificator dbitem = item.getGeoItem();
GeoTreeItemDto parent = idxProvince.get(dbitem.getParent().getId());
if (parent != null){
parent.addChild(item);
}
}
for (GeoTreeItemDto item : idxProvince.values()){
GeoClassificator dbitem = item.getGeoItem();
GeoTreeItemDto parent = idxMacroReg.get(dbitem.getParent().getId());
if (parent != null){
parent.addChild(item);
}
}
for (GeoTreeItemDto item : idxMacroReg.values()){
GeoClassificator dbitem = item.getGeoItem();
GeoTreeItemDto parent = idxCountry.get(dbitem.getParent().getId());
if (parent != null){
parent.addChild(item);
}
}