Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr22.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.util.ArrayList;
17 import java.util.Collections;
18 import java.util.List;
19
20 /**
21 * Index of streets by country.
22 *
23 * There is no pointer from the country section into this like there is with
24 * cities.
25 *
26 * @author Steve Ratcliffe
27 * @author Gerd Petermann
28 */
29 public class Mdr22 extends Mdr2x {
30
31 public Mdr22(MdrConfig config) {
32 setConfig(config);
33 }
34
35 /**
36 * We need to sort the streets by the name of the country. Within a country
37 * the streets are ordered by their own index.
38 *
39 * Also have to set the record number of the first record in this section
40 * on the country.
41 *
42 * @param inStreets The list of streets from mdr7.
43 */
44 public void buildFromStreets(List<Mdr7Record> inStreets) {
45 ArrayList<Mdr7Record> sorted = new ArrayList<>(inStreets.size());
46 for (Mdr7Record street : inStreets) {
47 if (street.getCity() != null) {
48 assert street.getCity().getCountryName() != null;
49 sorted.add(street);
50 }
51 }
52 sorted.sort((o1, o2) -> {
53 int d = Integer.compare(o1.getCity().getMdr22SortPos(), o2.getCity().getMdr22SortPos());
54 if (d != 0)
55 return d;
56 return Integer.compare(o1.getIndex(), o2.getIndex());
57 });
58
59 int lastIndex = -1;
60 int record = 0;
61 for (Mdr7Record street : sorted) {
62 if (street.getIndex() != lastIndex) {
63 record++;
64 streets.add(street);
65
66 // Include in the mdr29 index if we have one for this record.
67 Mdr14Record mdrCountry = street.getCity().getMdrCountry();
68 if (mdrCountry != null) {
69 Mdr29Record mdr29 = mdrCountry.getMdr29();
70 mdr29.setMdr22(record);
71 }
72
73 lastIndex = street.getIndex();
74 }
75 }
76 }
77
78 protected boolean sameGroup(Mdr7Record street1, Mdr7Record street2) {
79 return true;
80 }
81
82 public List<Mdr7Record> getStreets() {
83 return Collections.unmodifiableList(streets);
84 }
85
86 /**
87 * Unknown flag
88 */
89 public int getExtraValue() {
90 int magic;
91 if (isForDevice()) {
92 magic = 0x0000e;
93 if (!getConfig().getSort().isMulti())
94 magic |= 0xc0000; // used to be 0x6000, maybe two different flags ?
95 } else {
96 magic = 0x11000;
97 }
98 return magic;
99 }
100 }