Debian Codegraph @

src/uk/me/parabola/imgfmt/app/mdr/Mdr7Record.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 details of a single street.
19 * @author Steve Ratcliffe
20 */
21 public class Mdr7Record extends RecordBase implements NamedRecord {
22 private int labelOffset;
23 private int stringOffset;
24 private String name;
25 private int index;
26 private Mdr5Record city;
27
28 // For searching on partial names
29 private byte nameOffset; // offset into the name where matching should start
30 private byte outNameOffset; // offset into the encoded output name
31 private byte prefixOffset; // offset after 0x1e prefix
32 private byte suffixOffset; // offset just before 0x1f suffix
33
34 public int getLabelOffset() {
35 return labelOffset;
36 }
37
38 public void setLabelOffset(int labelOffset) {
39 this.labelOffset = labelOffset;
40 }
41
42 public int getStringOffset() {
43 return stringOffset;
44 }
45
46 public void setStringOffset(int stringOffset) {
47 this.stringOffset = stringOffset;
48 }
49
50 public String getName() {
51 return name;
52 }
53
54 public void setName(String name) {
55 this.name = name;
56 }
57
58 public void setIndex(int index) {
59 this.index = index;
60 }
61
62 public int getIndex() {
63 return index;
64 }
65
66 public void setCity(Mdr5Record city) {
67 this.city = city;
68 }
69
70 public Mdr5Record getCity() {
71 return city;
72 }
73
74 public int getNameOffset() {
75 return nameOffset & 0xff;
76 }
77
78 public void setNameOffset(byte nameOffset) {
79 this.nameOffset = nameOffset;
80 }
81
82 public byte getOutNameOffset() {
83 return outNameOffset;
84 }
85
86 public void setOutNameOffset(byte outNameOffset) {
87 this.outNameOffset = outNameOffset;
88 }
89
90 public void setPrefixOffset(byte prefixOffset) {
91 this.prefixOffset = prefixOffset;
92 }
93
94 public void setSuffixOffset(byte suffixOffset) {
95 this.suffixOffset = suffixOffset;
96 }
97
98 /**
99 * Get the name starting at the given nameOffset.
100 *
101 * To avoid creating unnecessary objects, a check is made for an offset of zero
102 * and the original name string is returned.
103 *
104 * @return A substring of name, starting at the nameOffset value.
105 */
106 public String getPartialName() {
107 if (nameOffset == 0 && prefixOffset == 0 && suffixOffset == 0)
108 return name;
109 else if ((suffixOffset & 0xff) > 0)
110 return name.substring((nameOffset & 0xff) + (prefixOffset & 0xff), (suffixOffset & 0xff));
111 else
112 return name.substring((nameOffset & 0xff) + (prefixOffset & 0xff));
113 }
114
115 public String getSuffix() {
116 if(suffixOffset == 0)
117 return "";
118 return name.substring(suffixOffset & 0xff);
119 }
120
121 public String getPrefix() {
122 if(prefixOffset== 0)
123 return "";
124 return name.substring(0, prefixOffset & 0xff);
125 }
126
127 public String toString() {
128 return name + " in " + city.getName();
129 }
130
131 public String getInitialPart() {
132 return name.substring(0, (nameOffset & 0xff) + (prefixOffset & 0xff));
133 }
134
135 @Override
136 public int hashCode() {
137 final int prime = 31;
138 int result = 1;
139 result = prime * result + labelOffset;
140 result = prime * result + nameOffset;
141 result = prime * result + outNameOffset;
142 result = prime * result + prefixOffset;
143 result = prime * result + stringOffset; // XXX probably not needed
144 result = prime * result + suffixOffset;
145 result = prime * result + getMapIndex();
146 return result;
147 }
148
149 @Override
150 public boolean equals(Object obj) {
151 if (this == obj)
152 return true;
153 if (obj == null)
154 return false;
155 if (getClass() != obj.getClass())
156 return false;
157 Mdr7Record other = (Mdr7Record) obj;
158 if (labelOffset != other.labelOffset)
159 return false;
160 if (getMapIndex() != other.getMapIndex())
161 return false;
162 if (nameOffset != other.nameOffset)
163 return false;
164 if (outNameOffset != other.outNameOffset)
165 return false;
166 if (prefixOffset != other.prefixOffset)
167 return false;
168 if (stringOffset != other.stringOffset) // XXX probably not needed
169 return false;
170 if (suffixOffset != other.suffixOffset)
171 return false;
172 return (city == other.getCity());
173 }
174
175 /**
176 * Calculate integer for partial + full repeat.
177 * @param last record to compare
178 * @param collator collator for compare
179 * @return 3 if full and partial repeat (Rr), 2 if only full repeat (R), 1 if partial repeat (r), 0 if no repeat
180 */
181 public int checkRepeat (Mdr7Record last, Collator collator) {
182 if (last == null)
183 return 0;
184 int res = 0;
185 int cmp = collator.compare(last.getPartialName(), getPartialName());
186 if (cmp == 0)
187 res = 1;
188 res |= checkFullRepeat(last, collator);
189 return res;
190 }
191
192 /**
193 * Calculate integer for full repeat.
194 * @param last record to compare
195 * @param collator collator for compare
196 * @return 2 if full repeat (R), 0 else
197 */
198 public int checkFullRepeat (Mdr7Record last, Collator collator) {
199 if (last == null)
200 return 0;
201 int res = 0;
202 int cmp = collator.compare(last.getName(), getName());
203 if (cmp == 0)
204 res |= 2;
205 return res;
206 }
207 }