Search in sources :

Example 11 with SortKey

use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.

the class Mdr24 method sortCountries.

/**
 * Sort the countries by name. Duplicates are kept.
 * @param list The full list of countries.
 */
public void sortCountries(List<Mdr14Record> list) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr14Record>> keys = MdrUtils.sortList(sort, list);
    Collections.sort(keys);
    String lastName = null;
    int lastMapIndex = 0;
    int record = 0;
    for (SortKey<Mdr14Record> key : keys) {
        Mdr14Record c = key.getObject();
        // If this is a new name, then we prepare a mdr29 record for it.
        String name = c.getName();
        if (lastMapIndex != c.getMapIndex() || !name.equals(lastName)) {
            record++;
            c.getMdr29().setMdr24(record);
            countries.add(c);
            lastName = name;
            lastMapIndex = c.getMapIndex();
        }
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 12 with SortKey

use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.

the class Mdr28 method buildFromRegions.

public void buildFromRegions(List<Mdr13Record> regions) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr13Record>> keys = MdrUtils.sortList(sort, regions);
    int record = 0;
    Mdr28Record mdr28 = null;
    String lastName = null;
    for (SortKey<Mdr13Record> key : keys) {
        Mdr13Record region = key.getObject();
        String name = region.getName();
        if (!name.equals(lastName)) {
            record++;
            mdr28 = new Mdr28Record();
            mdr28.setIndex(record);
            mdr28.setName(name);
            mdr28.setStrOffset(region.getStrOffset());
            mdr28.setMdr14(region.getMdr14());
            index.add(mdr28);
            lastName = name;
        }
        assert mdr28 != null;
        region.setMdr28(mdr28);
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 13 with SortKey

use of uk.me.parabola.imgfmt.app.srt.SortKey in project mkgmap by openstreetmap.

the class Mdr29 method buildFromCountries.

public void buildFromCountries(List<Mdr14Record> countries) {
    Sort sort = getConfig().getSort();
    List<SortKey<Mdr14Record>> keys = MdrUtils.sortList(sort, countries);
    // Sorted by name, for every new name we allocate a new 29 record and set the same one in every
    // country with the same name.
    String lastName = null;
    Mdr29Record mdr29 = null;
    for (SortKey<Mdr14Record> key : keys) {
        Mdr14Record country = key.getObject();
        String name = country.getName();
        if (!name.equals(lastName)) {
            mdr29 = new Mdr29Record();
            mdr29.setName(name);
            mdr29.setStrOffset(country.getStrOff());
            index.add(mdr29);
            lastName = name;
        }
        assert mdr29 != null;
        country.setMdr29(mdr29);
    }
}
Also used : Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Aggregations

SortKey (uk.me.parabola.imgfmt.app.srt.SortKey)13 Sort (uk.me.parabola.imgfmt.app.srt.Sort)12 ArrayList (java.util.ArrayList)9 MultiSortKey (uk.me.parabola.imgfmt.app.srt.MultiSortKey)5 ByteBuffer (java.nio.ByteBuffer)1 CharBuffer (java.nio.CharBuffer)1 CharacterCodingException (java.nio.charset.CharacterCodingException)1 CharsetEncoder (java.nio.charset.CharsetEncoder)1 Collator (java.text.Collator)1 HashMap (java.util.HashMap)1 Label (uk.me.parabola.imgfmt.app.Label)1 SectionWriter (uk.me.parabola.imgfmt.app.SectionWriter)1 City (uk.me.parabola.imgfmt.app.lbl.City)1 DoubleSortKey (uk.me.parabola.imgfmt.app.srt.DoubleSortKey)1 IntegerSortKey (uk.me.parabola.imgfmt.app.srt.IntegerSortKey)1