1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 package org.treetank.io;
29
30 import static com.google.common.base.Objects.toStringHelper;
31
32 import java.io.DataInput;
33 import java.io.DataInputStream;
34 import java.io.DataOutput;
35 import java.io.DataOutputStream;
36 import java.io.IOException;
37
38 import org.treetank.api.IMetaEntryFactory;
39 import org.treetank.api.IDataFactory;
40 import org.treetank.bucket.DataBucket;
41 import org.treetank.bucket.BucketFactory;
42 import org.treetank.bucket.interfaces.IBucket;
43 import org.treetank.exception.TTIOException;
44
45 import com.sleepycat.bind.tuple.TupleBinding;
46 import com.sleepycat.bind.tuple.TupleInput;
47 import com.sleepycat.bind.tuple.TupleOutput;
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 public final class LogValue {
69
70 private final IBucket mComplete;
71
72 private final IBucket mModified;
73
74
75
76
77
78
79
80
81
82 public LogValue(final IBucket pComplete, final IBucket pModifying) {
83 this.mComplete = pComplete;
84 this.mModified = pModifying;
85 }
86
87
88
89
90
91
92 public IBucket getComplete() {
93 return mComplete;
94 }
95
96
97
98
99
100
101 public IBucket getModified() {
102 return mModified;
103 }
104
105
106
107
108
109 @Override
110 public String toString() {
111 return toStringHelper(this).add("mComplete", mComplete).add("mModified", mModified).toString();
112 }
113
114
115
116
117
118
119
120 static class LogValueBinding extends TupleBinding<LogValue> {
121
122 private final BucketFactory mFac;
123
124
125
126
127
128
129
130
131
132 public LogValueBinding(final IDataFactory pDataFac, final IMetaEntryFactory pMetaFac) {
133 mFac = new BucketFactory(pDataFac, pMetaFac);
134 }
135
136
137
138
139 @Override
140 public LogValue entryToObject(final TupleInput arg0) {
141 try {
142 final DataInput data = new DataInputStream(arg0);
143 final IBucket current = mFac.deserializeBucket(data);
144 final IBucket modified = mFac.deserializeBucket(data);
145 arg0.close();
146 return new LogValue(current, modified);
147 } catch (IOException | TTIOException exc) {
148 throw new RuntimeException(exc);
149 }
150 }
151
152
153
154
155 @Override
156 public void objectToEntry(final LogValue arg0, final TupleOutput arg1) {
157 try {
158 final DataOutput data = new DataOutputStream(arg1);
159 arg0.getComplete().serialize(data);
160 arg0.getModified().serialize(data);
161 arg1.close();
162 } catch (IOException | TTIOException exc) {
163 throw new RuntimeException(exc);
164 }
165 }
166 }
167
168
169
170
171 @Override
172 public int hashCode() {
173 final int prime = 80309;
174 int result = 1;
175 result = prime * result + ((mComplete == null) ? 0 : mComplete.hashCode());
176 result = prime * result + ((mModified == null) ? 0 : mModified.hashCode());
177 return result;
178 }
179
180
181
182
183 @Override
184 public boolean equals(Object obj) {
185 if (this == obj)
186 return true;
187 if (obj == null)
188 return false;
189 if (getClass() != obj.getClass())
190 return false;
191 LogValue other = (LogValue)obj;
192 if (mComplete == null) {
193 if (other.mComplete != null)
194 return false;
195 } else if (!mComplete.equals(other.mComplete))
196 return false;
197 if (mModified == null) {
198 if (other.mModified != null)
199 return false;
200 } else if (!mModified.equals(other.mModified))
201 return false;
202 return true;
203 }
204 }