Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright (C) 2009.
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 package uk.me.parabola.imgfmt.app.mdr;
14
15 import java.util.ArrayList;
16 import java.util.LinkedHashMap;
17 import java.util.List;
18 import java.util.Map;
19
20 import uk.me.parabola.imgfmt.app.ImgFileWriter;
21
22 /**
23 * POI subtype with a reference to MDR11.
24 * These are sorted into groups based on the type, and contain the
25 * subtype.
26 *
27 * The mdr9 section contains an index to this section based on the
28 * the type groups.
29 *
30 * @author Steve Ratcliffe
31 */
32 public class Mdr10 extends MdrMapSection {
33 /** The maximum group number. Note that this is 1 based, not 0 based. */
34 private static final int MAX_GROUP_NUMBER = MdrUtils.MAX_GROUP;
35
36 private List<List<Mdr10Record>> poiTypes = new ArrayList<>();
37
38 private int numberOfPois;
39
40 public Mdr10(MdrConfig config) {
41 setConfig(config);
42 while (poiTypes.size() <= MAX_GROUP_NUMBER)
43 poiTypes.add(new ArrayList<>());
44 }
45
46 public void addPoiType(Mdr11Record poi) {
47 Mdr10Record t = new Mdr10Record();
48
49 int fullType = poi.getType();
50
51 int group = MdrUtils.getGroupForPoi(fullType);
52 if (group == 0)
53 return;
54 if (group == 1)
55 t.setSubtype(MdrUtils.getTypeFromFullType(fullType)); // cities
56 else {
57 t.setSubtype(MdrUtils.getSubtypeFromFullType(fullType));
58 }
59 t.setMdr11ref(poi);
60 poiTypes.get(group).add(t);
61 }
62
63 public void writeSectData(ImgFileWriter writer) {
64 int count = 0;
65 for (List<Mdr10Record> poiGroup : poiTypes) {
66 if (poiGroup == null)
67 continue;
68
69 poiGroup.sort(null);
70
71 String lastName = null;
72 int lastSub = -1;
73 for (Mdr10Record t : poiGroup) {
74
75 count++;
76 Mdr11Record mdr11ref = t.getMdr11ref();
77 addIndexPointer(mdr11ref.getMapIndex(), count);
78
79 writer.put1u(t.getSubtype());
80 int offset = mdr11ref.getRecordNumber();
81
82 // Top bit actually represents a non-repeated name. ie if
83 // the bit is not set, then the name is the same as the previous
84 // record.
85 String name = mdr11ref.getName();
86 boolean isNew = !(name.equals(lastName) && (t.getSubtype() == lastSub));
87 putPoiIndex(writer, offset, isNew);
88 lastName = name;
89 lastSub = t.getSubtype();
90 }
91 }
92 }
93
94 /**
95 * Get a list of the group sizes along with the group index number.
96 * @return A map that is guaranteed to iterate in the correct order for
97 * writing mdr9. The key is the group number and the value is the
98 * number of entries in that group.
99 */
100 public Map<Integer, Integer> getGroupSizes() {
101 Map<Integer, Integer> m = new LinkedHashMap<>();
102
103 for (int group = 1; group <= MAX_GROUP_NUMBER; group++) {
104 int size = poiTypes.get(group).size();
105 if (size > 0)
106 m.put(group, size);
107 }
108 return m;
109 }
110
111 /**
112 * This does not have a record size.
113 * @return Always zero to indicate that there is not a record size.
114 */
115 public int getItemSize() {
116 return 0;
117 }
118
119 protected int numberOfItems() {
120 return numberOfPois;
121 }
122
123 public void setNumberOfPois(int numberOfPois) {
124 this.numberOfPois = numberOfPois;
125 }
126
127 @Override
128 protected void releaseMemory() {
129 poiTypes = null;
130 }
131
132 public int getExtraValue() {
133 // Nothing to do here
134 return 0;
135 }
136 }