| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.imgfmt.app.mdr; |
| 14 |
|
| 15 |
import java.text.Collator; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 29 |
private byte nameOffset; |
| 30 |
private byte outNameOffset; |
| 31 |
private byte prefixOffset; |
| 32 |
private byte suffixOffset; |
| 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 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 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; |
| 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) |
| 169 |
return false; |
| 170 |
if (suffixOffset != other.suffixOffset) |
| 171 |
return false; |
| 172 |
return (city == other.getCity()); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 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 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 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 |
} |