Search in sources :

Example 1 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort 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;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 2 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort 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);
}
Also used : ArrayList(java.util.ArrayList) Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 3 with Sort

use of uk.me.parabola.imgfmt.app.srt.Sort 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);
    }
}
Also used : ArrayList(java.util.ArrayList) Sort(uk.me.parabola.imgfmt.app.srt.Sort) SortKey(uk.me.parabola.imgfmt.app.srt.SortKey)

Example 4 with Sort

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

the class SrtTextReader method main.

/**
 * Read in a sort description text file and create a SRT from it.
 * @param args First arg is the text input file, the second is the name of the output file. The defaults are
 * in.txt and out.srt.
 */
public static void main(String[] args) throws IOException {
    String infile = "in.txt";
    if (args.length > 0)
        infile = args[0];
    String outfile = "out.srt";
    if (args.length > 1)
        outfile = args[1];
    try {
        Files.delete(Paths.get(outfile, ""));
    } catch (Exception e) {
    }
    ImgChannel chan = new FileImgChannel(outfile, "rw");
    SRTFile sf = new SRTFile(chan);
    SrtTextReader tr = new SrtTextReader(infile);
    Sort sort1 = tr.getSort();
    sf.setSort(sort1);
    sf.write();
    sf.close();
    chan.close();
}
Also used : FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) ImgChannel(uk.me.parabola.imgfmt.fs.ImgChannel) SRTFile(uk.me.parabola.imgfmt.app.srt.SRTFile) Sort(uk.me.parabola.imgfmt.app.srt.Sort) FileImgChannel(uk.me.parabola.imgfmt.sys.FileImgChannel) CharacterCodingException(java.nio.charset.CharacterCodingException) ExitException(uk.me.parabola.imgfmt.ExitException) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) IOException(java.io.IOException)

Example 5 with Sort

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

the class SrtTextReader method sortForCodepage.

/**
 * Find and read in the default sort description for the given codepage.
 */
public static Sort sortForCodepage(int codepage) {
    String name = "sort/cp" + codepage + ".txt";
    InputStream is = Sort.class.getClassLoader().getResourceAsStream(name);
    if (is == null) {
        if (codepage == 1252)
            throw new ExitException("No sort description for code-page 1252 available");
        Sort defaultSort = SrtTextReader.sortForCodepage(1252);
        defaultSort.setCodepage(codepage);
        defaultSort.setDescription("Default sort");
        return defaultSort;
    }
    try {
        InputStreamReader r = new InputStreamReader(is, "utf-8");
        SrtTextReader sr = new SrtTextReader(r);
        return sr.getSort();
    } catch (IOException e) {
        return SrtTextReader.sortForCodepage(codepage);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Sort(uk.me.parabola.imgfmt.app.srt.Sort) IOException(java.io.IOException) ExitException(uk.me.parabola.imgfmt.ExitException)

Aggregations

Sort (uk.me.parabola.imgfmt.app.srt.Sort)26 SortKey (uk.me.parabola.imgfmt.app.srt.SortKey)12 ArrayList (java.util.ArrayList)9 ExitException (uk.me.parabola.imgfmt.ExitException)4 MultiSortKey (uk.me.parabola.imgfmt.app.srt.MultiSortKey)4 IOException (java.io.IOException)3 Map (java.util.Map)3 FileExistsException (uk.me.parabola.imgfmt.FileExistsException)3 SRTFile (uk.me.parabola.imgfmt.app.srt.SRTFile)3 ImgChannel (uk.me.parabola.imgfmt.fs.ImgChannel)3 CharacterCodingException (java.nio.charset.CharacterCodingException)2 Collator (java.text.Collator)2 FileNotWritableException (uk.me.parabola.imgfmt.FileNotWritableException)2 FileSystemParam (uk.me.parabola.imgfmt.FileSystemParam)2 FileImgChannel (uk.me.parabola.imgfmt.sys.FileImgChannel)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1