use of uk.me.parabola.imgfmt.app.srt.Sort.SrtCollator in project mkgmap by openstreetmap.
the class PrefixIndex method createFromList.
/**
* We can create an index for any type that has a name.
* @param list A list of items that have a name.
*/
public void createFromList(List<? extends NamedRecord> list, boolean grouped) {
maxIndex = list.size();
// Prefixes are equal based on the primary unaccented character, so
// we need to use the collator to test for equality and not equals().
Sort sort = getConfig().getSort();
Sort.SrtCollator collator = (SrtCollator) sort.getCollator();
collator.setStrength(Collator.PRIMARY);
String lastCountryName = null;
char[] lastPrefix = "".toCharArray();
// record number of the input list
int inRecord = 0;
// record number of the index
int outRecord = 0;
int lastMdr22SortPos = -1;
for (NamedRecord r : list) {
inRecord++;
String name;
if (r instanceof Mdr7Record) {
name = ((Mdr7Record) r).getPartialName();
if (grouped) {
int mdr22SortPos = ((Mdr7Record) r).getCity().getMdr22SortPos();
if (mdr22SortPos != lastMdr22SortPos)
lastPrefix = "".toCharArray();
lastMdr22SortPos = mdr22SortPos;
}
} else
name = r.getName();
char[] prefix = sort.getPrefix(name, prefixLength);
int cmp = collator.compareOneStrengthWithLength(prefix, lastPrefix, Collator.PRIMARY, prefixLength);
if (cmp > 0) {
outRecord++;
Mdr8Record ind = new Mdr8Record();
ind.setPrefix(prefix);
ind.setRecordNumber(inRecord);
index.add(ind);
lastPrefix = prefix;
if (grouped) {
// Peek into the real type to support the mdr17 feature of indexes sorted on country.
Mdr5Record city = ((Mdr7Record) r).getCity();
if (city != null) {
String countryName = city.getCountryName();
if (!countryName.equals(lastCountryName)) {
city.getMdrCountry().getMdr29().setMdr17(outRecord);
lastCountryName = countryName;
}
}
}
}
}
}
Aggregations