2 * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org
.spearce
.jgit
.revwalk
;
40 import java
.util
.AbstractList
;
43 * An ordered list of {@link RevObject} subclasses.
46 * type of subclass of RevObject the list is storing.
48 public class RevObjectList
<E
extends RevObject
> extends AbstractList
<E
> {
49 static final int BLOCK_SHIFT
= 8;
51 static final int BLOCK_SIZE
= 1 << BLOCK_SHIFT
;
57 /** Create an empty object list. */
58 public RevObjectList() {
62 public void add(final int index
, final E element
) {
64 throw new UnsupportedOperationException("Not add-at-end: " + index
);
69 public E
set(int index
, E element
) {
71 while (index
>> s
.shift
>= BLOCK_SIZE
) {
72 s
= new Block(s
.shift
+ BLOCK_SHIFT
);
73 s
.contents
[0] = contents
;
77 final int i
= index
>> s
.shift
;
78 index
-= i
<< s
.shift
;
79 if (s
.contents
[i
] == null)
80 s
.contents
[i
] = new Block(s
.shift
- BLOCK_SHIFT
);
81 s
= (Block
) s
.contents
[i
];
83 final Object old
= s
.contents
[index
];
84 s
.contents
[index
] = element
;
88 public E
get(int index
) {
90 if (index
>> s
.shift
>= 1024)
92 while (s
!= null && s
.shift
> 0) {
93 final int i
= index
>> s
.shift
;
94 index
-= i
<< s
.shift
;
95 s
= (Block
) s
.contents
[i
];
97 return s
!= null ?
(E
) s
.contents
[index
] : null;
105 public void clear() {
106 contents
= new Block(0);
111 final Object
[] contents
= new Object
[BLOCK_SIZE
];