1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.pack;
12
13
14
15
16 public class PackExt {
17 private static volatile PackExt/storage/pack/PackExt.html#PackExt">PackExt[] VALUES = new PackExt[] {};
18
19
20 public static final PackExt PACK = newPackExt("pack");
21
22
23 public static final PackExt INDEX = newPackExt("idx");
24
25
26 public static final PackExt KEEP = newPackExt("keep");
27
28
29 public static final PackExt BITMAP_INDEX = newPackExt("bitmap");
30
31
32 public static final PackExt REFTABLE = newPackExt("ref");
33
34
35
36
37
38
39 public static PackExt[] values() {
40 return VALUES;
41 }
42
43
44
45
46
47
48
49
50
51 public static synchronized PackExt newPackExt(String ext) {
52 PackExt[] dst = new PackExt[VALUES.length + 1];
53 for (int i = 0; i < VALUES.length; i++) {
54 PackExt packExt = VALUES[i];
55 if (packExt.getExtension().equals(ext))
56 return packExt;
57 dst[i] = packExt;
58 }
59 if (VALUES.length >= 32)
60 throw new IllegalStateException(
61 "maximum number of pack extensions exceeded");
62
63 PackExt value = new PackExt(ext, VALUES.length);
64 dst[VALUES.length] = value;
65 VALUES = dst;
66 return value;
67 }
68
69 private final String ext;
70
71 private final int pos;
72
73 private PackExt(String ext, int pos) {
74 this.ext = ext;
75 this.pos = pos;
76 }
77
78
79
80
81
82
83 public String getExtension() {
84 return ext;
85 }
86
87
88
89
90
91
92 public int getPosition() {
93 return pos;
94 }
95
96
97
98
99
100
101 public int getBit() {
102 return 1 << getPosition();
103 }
104
105
106 @Override
107 public String toString() {
108 return String.format("PackExt[%s, bit=0x%s]", getExtension(),
109 Integer.toHexString(getBit()));
110 }
111 }