01: package de.regnis.q.sequence.line;
02:
03: import de.regnis.q.sequence.line.simplifier.*;
04:
05: /**
06: * @author Marc Strapetz
07: */
08: public final class QSequenceLine {
09:
10: // Fields =================================================================
11:
12: private final long from;
13: private final byte[] contentBytes;
14: private final byte[] compareBytes;
15:
16: // Setup ==================================================================
17:
18: public QSequenceLine(long from, byte[] contentBytes,
19: QSequenceLineSimplifier simplifier) {
20: this .from = from;
21: this .contentBytes = contentBytes;
22: this .compareBytes = simplifier.simplify(contentBytes);
23: }
24:
25: // Accessing ==============================================================
26:
27: public long getFrom() {
28: return from;
29: }
30:
31: public long getTo() {
32: return from + contentBytes.length - 1;
33: }
34:
35: public int getContentLength() {
36: return contentBytes.length;
37: }
38:
39: public byte[] getContentBytes() {
40: return contentBytes;
41: }
42:
43: /**
44: * @deprecated
45: */
46: public byte[] getBytes() {
47: return getContentBytes();
48: }
49:
50: public int getCompareHash() {
51: return new String(compareBytes).hashCode();
52: }
53:
54: // Implemented ============================================================
55:
56: public boolean equals(Object obj) {
57: // Must be because of caching media! Find something better!
58: final byte[] otherBytes = ((QSequenceLine) obj).compareBytes;
59: if (compareBytes.length != otherBytes.length) {
60: return false;
61: }
62:
63: for (int index = 0; index < compareBytes.length; index++) {
64: if (compareBytes[index] != otherBytes[index]) {
65: return false;
66: }
67: }
68:
69: return true;
70: }
71:
72: public int hashCode() {
73: int hashCode = 0;
74: for (int index = 0; index < compareBytes.length; index++) {
75: hashCode = 31 * hashCode + compareBytes[index];
76: }
77:
78: return hashCode;
79: }
80:
81: public String toString() {
82: return new String(contentBytes);
83: }
84: }
|