1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.revplot;
12
13 import org.eclipse.jgit.lib.AnyObjectId;
14 import org.eclipse.jgit.lib.Ref;
15 import org.eclipse.jgit.revwalk.RevCommit;
16
17
18
19
20
21
22
23
24 public class PlotCommit<L extends PlotLane> extends RevCommit {
25 static final PlotCommit[] NO_CHILDREN = {};
26
27 static final PlotLane[] NO_LANES = {};
28
29 static final Ref[] NO_REFS = {};
30
31 PlotLane[] forkingOffLanes;
32
33 PlotLane[] passingLanes;
34
35 PlotLane[] mergingLanes;
36
37 PlotLane lane;
38
39 PlotCommit[] children;
40
41 Ref[] refs;
42
43
44
45
46
47
48
49 protected PlotCommit(AnyObjectId id) {
50 super(id);
51 forkingOffLanes = NO_LANES;
52 passingLanes = NO_LANES;
53 mergingLanes = NO_LANES;
54 children = NO_CHILDREN;
55 refs = NO_REFS;
56 }
57
58 void addForkingOffLane(PlotLane f) {
59 forkingOffLanes = addLane(f, forkingOffLanes);
60 }
61
62 void addPassingLane(PlotLane c) {
63 passingLanes = addLane(c, passingLanes);
64 }
65
66 void addMergingLane(PlotLane m) {
67 mergingLanes = addLane(m, mergingLanes);
68 }
69
70 private static PlotLane[] addLane(PlotLane l, PlotLane[] lanes) {
71 final int cnt = lanes.length;
72 switch (cnt) {
73 case 0:
74 lanes = new PlotLane[] { l };
75 break;
76 case 1:
77 lanes = new PlotLane[] { lanes[0], l };
78 break;
79 default:
80 final PlotLane[] n = new PlotLane[cnt + 1];
81 System.arraycopy(lanes, 0, n, 0, cnt);
82 n[cnt] = l;
83 lanes = n;
84 break;
85 }
86 return lanes;
87 }
88
89 void addChild(PlotCommit c) {
90 final int cnt = children.length;
91 switch (cnt) {
92 case 0:
93 children = new PlotCommit[] { c };
94 break;
95 case 1:
96 if (!c.getId().equals(children[0].getId()))
97 children = new PlotCommit[] { children[0], c };
98 break;
99 default:
100 for (PlotCommit pc : children)
101 if (c.getId().equals(pc.getId()))
102 return;
103 final PlotCommit[] n = new PlotCommit[cnt + 1];
104 System.arraycopy(children, 0, n, 0, cnt);
105 n[cnt] = c;
106 children = n;
107 break;
108 }
109 }
110
111
112
113
114
115
116 public final int getChildCount() {
117 return children.length;
118 }
119
120
121
122
123
124
125
126
127
128
129
130 public final PlotCommit getChild(int nth) {
131 return children[nth];
132 }
133
134
135
136
137
138
139
140
141 public final boolean isChild(PlotCommit c) {
142 for (PlotCommit a : children)
143 if (a == c)
144 return true;
145 return false;
146 }
147
148
149
150
151
152
153 public final int getRefCount() {
154 return refs.length;
155 }
156
157
158
159
160
161
162
163
164
165
166
167 public final Ref getRef(int nth) {
168 return refs[nth];
169 }
170
171
172
173
174
175
176 @SuppressWarnings("unchecked")
177 public final L getLane() {
178 return (L) lane;
179 }
180
181
182 @Override
183 public void reset() {
184 forkingOffLanes = NO_LANES;
185 passingLanes = NO_LANES;
186 mergingLanes = NO_LANES;
187 children = NO_CHILDREN;
188 lane = null;
189 super.reset();
190 }
191 }