Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr5Record.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.text.Collator;
16
17 /**
18 * Holds information about a city that will make its way into mdr 5.
19 * This class is used in several places as the information has to be gathered
20 * from the cities section of LBL and the points in RGN.
21 *
22 * @author Steve Ratcliffe
23 */
24 public class Mdr5Record extends RecordBase implements NamedRecord {
25 /** The city index within its own map */
26 private int cityIndex;
27
28 /** The index across all maps */
29 private int globalCityIndex;
30
31 private int regionIndex;
32 private int lblOffset;
33 private int stringOffset;
34 private String name;
35 private Mdr13Record region;
36 private Mdr14Record country;
37 private int[] mdr20;
38 private int mdr20Index;
39 private int mdr20SortPos;
40 private int mdr21SortPos;
41 private int mdr22SortPos;
42
43 public int getCityIndex() {
44 return cityIndex;
45 }
46
47 public void setCityIndex(int cityIndex) {
48 this.cityIndex = cityIndex;
49 }
50
51 public int getGlobalCityIndex() {
52 return globalCityIndex;
53 }
54
55 public void setGlobalCityIndex(int globalCityIndex) {
56 this.globalCityIndex = globalCityIndex;
57 }
58
59 public int getRegionIndex() {
60 return regionIndex;
61 }
62
63 public void setRegionIndex(int regionIndex) {
64 this.regionIndex = regionIndex;
65 }
66
67 public int getLblOffset() {
68 return lblOffset;
69 }
70
71 public void setLblOffset(int lblOffset) {
72 this.lblOffset = lblOffset;
73 }
74
75 public int getStringOffset() {
76 return stringOffset;
77 }
78
79 public void setStringOffset(int stringOffset) {
80 this.stringOffset = stringOffset;
81 }
82
83 public void setName(String name) {
84 this.name = name;
85 }
86
87 public String getName() {
88 return name;
89 }
90
91 public Mdr13Record getMdrRegion() {
92 return region;
93 }
94
95 public void setMdrRegion(Mdr13Record region) {
96 this.region = region;
97 }
98
99 public Mdr14Record getMdrCountry() {
100 return country;
101 }
102
103 public void setMdrCountry(Mdr14Record country) {
104 this.country = country;
105 }
106
107 /**
108 * Every mdr5 record contains the same array of values. It is only
109 * allowed to access the one at the index globalCityIndex. Since
110 * the array is shared, every record with the same global city index
111 * knows the correct mdr20 value, regardless of where it was set.
112 *
113 * @param mdr20 An array large enough to hold all the cities (one based index).
114 * This must be the same array for all mdr5records (in the same map set).
115 */
116 public void setMdr20set(int[] mdr20) {
117 this.mdr20 = mdr20;
118 }
119
120 /**
121 * Set the index into the mdr20 array that we use to get/set the value.
122 * @see #setMdr20set(int[])
123 */
124 public void setMdr20Index(int mdr20Index) {
125 this.mdr20Index = mdr20Index;
126 }
127
128 public int getMdr20() {
129 return mdr20[mdr20Index];
130 }
131
132 public void setMdr20(int n) {
133 int prev = mdr20[mdr20Index];
134 assert prev == 0 || prev == n : "mdr20 value changed f=" + prev + " t=" + n + " count=" + mdr20Index;
135
136 mdr20[mdr20Index] = n;
137 }
138
139 /**
140 * Is this the same city, by the rules segregating the cities in mdr5 and 20.
141 * @return True if in the same tile and has the same name for city/region/country.
142 */
143 public boolean isSameByMapAndName(Collator collator, Mdr5Record other) {
144 if (other == null)
145 return false;
146
147 return getMapIndex() == other.getMapIndex() && isSameByName(collator, other);
148 }
149
150 /**
151 * Same city by the name of the city/region/country combination.
152 *
153 * @param collator Used to sort names.
154 * @param other The other city to compare with.
155 * @return True if is the same city, maybe in a different tile.
156 */
157 public boolean isSameByName(Collator collator, Mdr5Record other) {
158 if (other == null)
159 return false;
160
161 return collator.compare(getName(), other.getName()) == 0
162 && collator.compare(getRegionName(), other.getRegionName()) == 0
163 && collator.compare(getCountryName(), other.getCountryName()) == 0;
164 }
165
166 public String toString() {
167 return String.format("%d: %s r=%s c=%s", globalCityIndex, name, getRegionName(), country.getName());
168 }
169
170 public String getRegionName() {
171 if (region == null)
172 return "";
173 else
174 return region.getName();
175 }
176
177 public String getCountryName() {
178 return country.getName();
179 }
180
181 public void setMdr20SortPos(int n) {
182 mdr20SortPos = n;
183 }
184
185 public int getMdr20SortPos() {
186 return mdr20SortPos;
187 }
188 public void setMdr21SortPos(int n) {
189 mdr21SortPos = n;
190 }
191
192 public int getMdr21SortPos() {
193 return mdr21SortPos;
194 }
195
196 public void setMdr22SortPos(int n) {
197 mdr22SortPos = n;
198 }
199
200 public int getMdr22SortPos() {
201 return mdr22SortPos;
202 }
203 }