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