1 package org.treetank.io;
2
3 import static com.google.common.base.Objects.toStringHelper;
4
5 import com.sleepycat.bind.tuple.TupleBinding;
6 import com.sleepycat.bind.tuple.TupleInput;
7 import com.sleepycat.bind.tuple.TupleOutput;
8
9
10
11
12
13
14
15
16
17
18
19 public class LogKey {
20
21
22 private final boolean mRootLevel;
23
24
25 private final int mLevel;
26
27
28 private final long mSeq;
29
30
31
32
33
34
35
36
37
38
39
40
41
42 public LogKey(final boolean pRootLevel, final int pLevel, final long pSeq) {
43 mRootLevel = pRootLevel;
44 mLevel = pLevel;
45 mSeq = pSeq;
46 }
47
48
49
50
51
52
53
54 public int getLevel() {
55 return mLevel;
56 }
57
58
59
60
61
62
63 public long getSeq() {
64 return mSeq;
65 }
66
67
68
69
70
71
72 public boolean isRootLevel() {
73 return mRootLevel;
74 }
75
76
77
78
79 @Override
80 public int hashCode() {
81 final int prime = 31;
82 int result = 1;
83 result = prime * result + (int)(mLevel ^ (mLevel >>> 32));
84 result = prime * result + (mRootLevel ? 1231 : 1237);
85 result = prime * result + (int)(mSeq ^ (mSeq >>> 32));
86 return result;
87 }
88
89
90
91
92 @Override
93 public boolean equals(Object obj) {
94 if (this == obj)
95 return true;
96 if (obj == null)
97 return false;
98 if (getClass() != obj.getClass())
99 return false;
100 LogKey other = (LogKey)obj;
101 if (mLevel != other.mLevel)
102 return false;
103 if (mRootLevel != other.mRootLevel)
104 return false;
105 if (mSeq != other.mSeq)
106 return false;
107 return true;
108 }
109
110
111
112
113 @Override
114 public String toString() {
115 return toStringHelper(this).add("mRootLevel", mRootLevel).add("mLevel", mLevel).add("mSeq", mSeq)
116 .toString();
117 }
118
119
120
121
122
123
124
125 static class LogKeyBinding extends TupleBinding<LogKey> {
126
127
128
129
130 @Override
131 public LogKey entryToObject(TupleInput arg0) {
132 final LogKey key = new LogKey(arg0.readBoolean(), arg0.readInt(), arg0.readLong());
133 return key;
134 }
135
136
137
138
139 @Override
140 public void objectToEntry(LogKey arg0, TupleOutput arg1) {
141 arg1.writeBoolean(arg0.isRootLevel());
142 arg1.writeInt(arg0.getLevel());
143 arg1.writeLong(arg0.getSeq());
144 }
145
146 }
147
148 }