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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 package org.eclipse.jgit.lfs.lib;
45
46 import java.io.IOException;
47 import java.io.ObjectInputStream;
48 import java.io.ObjectOutputStream;
49 import java.io.Serializable;
50
51 import org.eclipse.jgit.lfs.errors.InvalidLongObjectIdException;
52 import org.eclipse.jgit.util.NB;
53 import org.eclipse.jgit.util.RawParseUtils;
54
55
56
57
58
59
60
61
62 public class LongObjectId extends AnyLongObjectId implements Serializable {
63 private static final long serialVersionUID = 1L;
64
65 private static final LongObjectId ZEROID;
66
67 private static final String ZEROID_STR;
68
69 static {
70 ZEROID = new LongObjectId(0L, 0L, 0L, 0L);
71 ZEROID_STR = ZEROID.name();
72 }
73
74
75
76
77
78
79 public static final LongObjectId zeroId() {
80 return ZEROID;
81 }
82
83
84
85
86
87
88
89
90
91
92
93 public static final boolean isId(String id) {
94 if (id.length() != Constants.LONG_OBJECT_ID_STRING_LENGTH)
95 return false;
96 try {
97 for (int i = 0; i < Constants.LONG_OBJECT_ID_STRING_LENGTH; i++) {
98 RawParseUtils.parseHexInt4((byte) id.charAt(i));
99 }
100 return true;
101 } catch (ArrayIndexOutOfBoundsException e) {
102 return false;
103 }
104 }
105
106
107
108
109
110
111
112
113 public static final String toString(LongObjectId i) {
114 return i != null ? i.name() : ZEROID_STR;
115 }
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 public static boolean equals(final byte[] firstBuffer, final int fi,
133 final byte[] secondBuffer, final int si) {
134 return firstBuffer[fi] == secondBuffer[si]
135 && firstBuffer[fi + 1] == secondBuffer[si + 1]
136 && firstBuffer[fi + 2] == secondBuffer[si + 2]
137 && firstBuffer[fi + 3] == secondBuffer[si + 3]
138 && firstBuffer[fi + 4] == secondBuffer[si + 4]
139 && firstBuffer[fi + 5] == secondBuffer[si + 5]
140 && firstBuffer[fi + 6] == secondBuffer[si + 6]
141 && firstBuffer[fi + 7] == secondBuffer[si + 7]
142 && firstBuffer[fi + 8] == secondBuffer[si + 8]
143 && firstBuffer[fi + 9] == secondBuffer[si + 9]
144 && firstBuffer[fi + 10] == secondBuffer[si + 10]
145 && firstBuffer[fi + 11] == secondBuffer[si + 11]
146 && firstBuffer[fi + 12] == secondBuffer[si + 12]
147 && firstBuffer[fi + 13] == secondBuffer[si + 13]
148 && firstBuffer[fi + 14] == secondBuffer[si + 14]
149 && firstBuffer[fi + 15] == secondBuffer[si + 15]
150 && firstBuffer[fi + 16] == secondBuffer[si + 16]
151 && firstBuffer[fi + 17] == secondBuffer[si + 17]
152 && firstBuffer[fi + 18] == secondBuffer[si + 18]
153 && firstBuffer[fi + 19] == secondBuffer[si + 19]
154 && firstBuffer[fi + 20] == secondBuffer[si + 20]
155 && firstBuffer[fi + 21] == secondBuffer[si + 21]
156 && firstBuffer[fi + 22] == secondBuffer[si + 22]
157 && firstBuffer[fi + 23] == secondBuffer[si + 23]
158 && firstBuffer[fi + 24] == secondBuffer[si + 24]
159 && firstBuffer[fi + 25] == secondBuffer[si + 25]
160 && firstBuffer[fi + 26] == secondBuffer[si + 26]
161 && firstBuffer[fi + 27] == secondBuffer[si + 27]
162 && firstBuffer[fi + 28] == secondBuffer[si + 28]
163 && firstBuffer[fi + 29] == secondBuffer[si + 29]
164 && firstBuffer[fi + 30] == secondBuffer[si + 30]
165 && firstBuffer[fi + 31] == secondBuffer[si + 31];
166 }
167
168
169
170
171
172
173
174
175
176 public static final LongObjectId fromRaw(byte[] bs) {
177 return fromRaw(bs, 0);
178 }
179
180
181
182
183
184
185
186
187
188
189
190 public static final LongObjectId fromRaw(byte[] bs, int p) {
191 final long a = NB.decodeInt64(bs, p);
192 final long b = NB.decodeInt64(bs, p + 8);
193 final long c = NB.decodeInt64(bs, p + 16);
194 final long d = NB.decodeInt64(bs, p + 24);
195 return new LongObjectId(a, b, c, d);
196 }
197
198
199
200
201
202
203
204
205
206 public static final LongObjectId fromRaw(long[] is) {
207 return fromRaw(is, 0);
208 }
209
210
211
212
213
214
215
216
217
218
219
220 public static final LongObjectId fromRaw(long[] is, int p) {
221 return new LongObjectId(is[p], is[p + 1], is[p + 2], is[p + 3]);
222 }
223
224
225
226
227
228
229
230
231
232
233
234 public static final LongObjectId fromString(byte[] buf, int offset) {
235 return fromHexString(buf, offset);
236 }
237
238
239
240
241
242
243
244
245 public static LongObjectId fromString(String str) {
246 if (str.length() != Constants.LONG_OBJECT_ID_STRING_LENGTH)
247 throw new InvalidLongObjectIdException(str);
248 return fromHexString(org.eclipse.jgit.lib.Constants.encodeASCII(str),
249 0);
250 }
251
252 private static final LongObjectId fromHexString(byte[] bs, int p) {
253 try {
254 final long a = RawParseUtils.parseHexInt64(bs, p);
255 final long b = RawParseUtils.parseHexInt64(bs, p + 16);
256 final long c = RawParseUtils.parseHexInt64(bs, p + 32);
257 final long d = RawParseUtils.parseHexInt64(bs, p + 48);
258 return new LongObjectId(a, b, c, d);
259 } catch (ArrayIndexOutOfBoundsException e1) {
260 throw new InvalidLongObjectIdException(bs, p,
261 Constants.LONG_OBJECT_ID_STRING_LENGTH);
262 }
263 }
264
265 LongObjectId(final long new_1, final long new_2, final long new_3,
266 final long new_4) {
267 w1 = new_1;
268 w2 = new_2;
269 w3 = new_3;
270 w4 = new_4;
271 }
272
273
274
275
276
277
278
279
280
281
282
283 protected LongObjectId(AnyLongObjectId src) {
284 w1 = src.w1;
285 w2 = src.w2;
286 w3 = src.w3;
287 w4 = src.w4;
288 }
289
290
291 @Override
292 public LongObjectId toObjectId() {
293 return this;
294 }
295
296 private void writeObject(ObjectOutputStream os) throws IOException {
297 os.writeLong(w1);
298 os.writeLong(w2);
299 os.writeLong(w3);
300 os.writeLong(w4);
301 }
302
303 private void readObject(ObjectInputStream ois) throws IOException {
304 w1 = ois.readLong();
305 w2 = ois.readLong();
306 w3 = ois.readLong();
307 w4 = ois.readLong();
308 }
309 }