| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package uk.me.parabola.imgfmt.app.labelenc; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
public class EncodedText { |
| 29 |
private final int hashCode; |
| 30 |
private final byte[] ctext; |
| 31 |
private final int length; |
| 32 |
private final char[] chars; |
| 33 |
|
| 34 |
public EncodedText(byte[] buf, int len, char[] chars) { |
| 35 |
this.ctext = buf; |
| 36 |
this.length = len; |
| 37 |
this.chars = chars; |
| 38 |
|
| 39 |
assert chars == null || chars.length == 0 || chars[chars.length - 1] != 0 : "found trailing 0 in chars"; |
| 40 |
int hc = 0; |
| 41 |
for (int i = 0; i < length; i++) |
| 42 |
hc = 31*hc + ctext[i]; |
| 43 |
hashCode = hc; |
| 44 |
} |
| 45 |
|
| 46 |
public byte[] getCtext() { |
| 47 |
return ctext; |
| 48 |
} |
| 49 |
|
| 50 |
public int getLength() { |
| 51 |
return length; |
| 52 |
} |
| 53 |
|
| 54 |
public char[] getChars() { |
| 55 |
return chars; |
| 56 |
} |
| 57 |
|
| 58 |
public boolean equals(Object o) { |
| 59 |
if (this == o) return true; |
| 60 |
if (o == null || getClass() != o.getClass()) return false; |
| 61 |
|
| 62 |
EncodedText that = (EncodedText) o; |
| 63 |
|
| 64 |
if (length != that.length) return false; |
| 65 |
for (int i = 0; i < length; i++) |
| 66 |
if (ctext[i] != that.ctext[i]) |
| 67 |
return false; |
| 68 |
|
| 69 |
return true; |
| 70 |
} |
| 71 |
|
| 72 |
public int hashCode() { |
| 73 |
return hashCode; |
| 74 |
} |
| 75 |
} |