use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.
the class Mdr25 method sortCities.
/**
* Cities are sorted by country and then by the mdr5 city record number.
* @param list The complete list of cities from mdr5.
*/
public void sortCities(List<Mdr5Record> list) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr5Record>> keys = new ArrayList<SortKey<Mdr5Record>>();
for (Mdr5Record c : list) {
SortKey<Mdr5Record> key = sort.createSortKey(c, c.getMdrCountry().getName(), c.getGlobalCityIndex());
keys.add(key);
}
Collections.sort(keys);
String lastName = null;
Mdr5Record lastCity = null;
int record = 0;
for (SortKey<Mdr5Record> key : keys) {
Mdr5Record city = key.getObject();
if (lastCity == null || (!city.getName().equals(lastCity.getName()) || !(city.getRegionName().equals(lastCity.getRegionName())))) {
record++;
// Record in the 29 index if there is one for this record
Mdr14Record mdrCountry = city.getMdrCountry();
Mdr29Record mdr29 = mdrCountry.getMdr29();
String name = mdr29.getName();
assert mdrCountry.getName().equals(name);
if (!name.equals(lastName)) {
mdr29.setMdr25(record);
lastName = name;
}
cities.add(city);
lastCity = city;
}
}
}
use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.
the class Mdr26 method sortMdr28.
public void sortMdr28(List<Mdr28Record> in) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr28Record>> sortList = new ArrayList<SortKey<Mdr28Record>>();
int record = 0;
for (Mdr28Record mdr28 : in) {
SortKey<Mdr28Record> key = sort.createSortKey(mdr28, mdr28.getMdr14().getName(), ++record);
sortList.add(key);
}
Collections.sort(sortList);
addToIndex(sortList);
}
use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.
the class Mdr27 method sortCities.
/**
* Cities are sorted by region and then by the mdr5 city record number.
* @param list The complete list of cities from mdr5.
*/
public void sortCities(List<Mdr5Record> list) {
Sort sort = getConfig().getSort();
List<SortKey<Mdr5Record>> keys = new ArrayList<SortKey<Mdr5Record>>();
for (Mdr5Record c : list) {
Mdr13Record mdrRegion = c.getMdrRegion();
if (mdrRegion != null) {
SortKey<Mdr5Record> key = sort.createSortKey(c, mdrRegion.getName(), c.getGlobalCityIndex());
keys.add(key);
}
}
Collections.sort(keys);
String lastName = null;
int record = 0;
for (SortKey<Mdr5Record> key : keys) {
record++;
Mdr5Record city = key.getObject();
Mdr13Record mdrRegion = city.getMdrRegion();
Mdr28Record mdr28 = mdrRegion.getMdr28();
String name = mdr28.getName();
if (!name.equals(lastName)) {
mdr28.setMdr27(record);
lastName = name;
}
cities.add(city);
}
}
use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.
the class TYPFile method writeLabels.
private void writeLabels(ImgFileWriter in) {
if (data.getIcons().isEmpty())
return;
SectionWriter writer = header.getLabels().makeSectionWriter(in);
List<SortKey<TypIconSet>> keys = new ArrayList<SortKey<TypIconSet>>();
Sort sort = data.getSort();
for (TypIconSet icon : data.getIcons()) {
String label = icon.getLabel();
if (label != null) {
SortKey<TypIconSet> key = sort.createSortKey(icon, label);
keys.add(key);
}
}
Collections.sort(keys);
// Offset 0 is reserved to mean no label.
writer.put((byte) 0);
for (SortKey<TypIconSet> key : keys) {
int off = writer.position();
TypIconSet icon = key.getObject();
int type = icon.getTypeForFile();
String label = icon.getLabel();
if (label != null) {
CharBuffer cb = CharBuffer.wrap(label);
CharsetEncoder encoder = data.getEncoder();
try {
ByteBuffer buffer = encoder.encode(cb);
writer.put(buffer);
// If we succeeded then note offsets for indexes
strToType.put(off, type);
typeToStr.put(type, off);
} catch (CharacterCodingException ignore) {
String name = encoder.charset().name();
throw new TypLabelException(name);
}
writer.put((byte) 0);
}
}
Utils.closeFile(writer);
}
use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.
the class Mdr5 method calcMdr20SortPos.
/**
* Calculate a position when sorting by name, region, and country- This is used for MDR20.
*/
private void calcMdr20SortPos() {
List<SortKey<Mdr5Record>> sortKeys = new ArrayList<>(allCities.size());
Sort sort = getConfig().getSort();
for (Mdr5Record m : allCities) {
if (m.getName() == null)
continue;
// Sort by city name, region name, and country name .
SortKey<Mdr5Record> sortKey = sort.createSortKey(m, m.getName());
SortKey<Mdr5Record> regionKey = sort.createSortKey(null, m.getRegionName());
SortKey<Mdr5Record> countryKey = sort.createSortKey(null, m.getCountryName());
sortKey = new MultiSortKey<>(sortKey, regionKey, countryKey);
sortKeys.add(sortKey);
}
Collections.sort(sortKeys);
SortKey<Mdr5Record> lastKey = null;
int pos = 0;
for (SortKey<Mdr5Record> key : sortKeys) {
Mdr5Record c = key.getObject();
if (lastKey == null || key.compareTo(lastKey) != 0)
pos++;
c.setMdr20SortPos(pos);
lastKey = key;
}
}
Aggregations