Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr20.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2011.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13
14 package uk.me.parabola.imgfmt.app.mdr;
15
16 import java.text.Collator;
17 import java.util.ArrayList;
18 import java.util.List;
19
20 /**
21 * This is a list of streets that belong to each city.
22 *
23 * It is sorted with each group of streets that belong to a city in the same
24 * order as the cities, within each group the sort is by street id in mdr7.
25 *
26 * Streets that do not have an associated city are not included.
27 *
28 * There is a subsection in the mdr1 reverse index for this section, however
29 * the map index is not saved as part of this record.
30 *
31 * @author Steve Ratcliffe
32 */
33 public class Mdr20 extends Mdr2x {
34
35 public Mdr20(MdrConfig config) {
36 setConfig(config);
37 }
38
39 /**
40 * We need to sort the streets by the name of the city. Within a city
41 * group the streets are ordered by their own index.
42 *
43 * Also have to set the record number of the first record in this section
44 * on the city.
45 *
46 * @param inStreets The list of streets from mdr7, must have Mdr7.index set
47 * @param list
48 */
49 public void buildFromStreets(List<Mdr7Record> inStreets) {
50 ArrayList<Mdr7Record> sorted = new ArrayList<>(inStreets);
51 sorted.sort((o1, o2) -> {
52 int d = Integer.compare(o1.getCity().getMdr20SortPos(), o2.getCity().getMdr20SortPos());
53 if (d != 0)
54 return d;
55 return Integer.compare(o1.getIndex(), o2.getIndex());
56 });
57
58 Collator collator = getConfig().getSort().getCollator();
59 collator.setStrength(Collator.SECONDARY);
60
61 Mdr5Record lastCity = null;
62 Mdr7Record lastStreet = null;
63 int record = 0;
64 int cityRecord = 1;
65
66 for (Mdr7Record street : sorted) {
67 Mdr5Record city = street.getCity();
68 boolean citySameByName = lastCity != null && city.getMdr20SortPos() == lastCity.getMdr20SortPos();
69 int rr = street.checkRepeat(lastStreet, collator);
70 // Only save a single copy of each street name.
71 if (!citySameByName || rr != 3 || lastStreet.getIndex() != street.getIndex()) {
72 record++;
73 streets.add(street);
74 }
75
76 // The mdr20 value changes for each new city name
77 if (citySameByName) {
78 assert cityRecord!=0;
79 city.setMdr20(cityRecord);
80 } else {
81 // New city name, this marks the start of a new section in mdr20
82 assert cityRecord != 0;
83 cityRecord = record;
84 city.setMdr20(cityRecord);
85 lastCity = city;
86 }
87 lastStreet = street;
88 }
89 }
90
91 /**
92 * Two streets are in the same group if they have the same mdr20 id.
93 */
94 protected boolean sameGroup(Mdr7Record street1, Mdr7Record street2) {
95 return street2 != null && street1.getCity().getMdr20() == street2.getCity().getMdr20();
96 }
97
98 /**
99 * Unknown.
100 */
101 public int getExtraValue() {
102 return isForDevice() ? 0xe : 0x8800;
103 }
104 }