/Users/lyon/j4p/src/javassist/bytecode/LongVector.java
|
1 /*
2 * Javassist, a Java-bytecode translator toolkit.
3 * Copyright (C) 1999-2003 Shigeru Chiba. All Rights Reserved.
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. Alternatively, the contents of this file may be used under
8 * the terms of the GNU Lesser General Public License Version 2.1 or later.
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 */
15
16 package javassist.bytecode;
17
18 final class LongVector {
19 private int num;
20 private Object[] objects;
21 private LongVector next;
22
23 public LongVector(int initialSize) {
24 num = 0;
25 objects = new Object[initialSize];
26 next = null;
27 }
28
29 public void addElement(Object obj) {
30 LongVector p = this;
31 while (p.next != null)
32 p = p.next;
33
34 if (p.num < p.objects.length)
35 p.objects[p.num++] = obj;
36 else {
37 LongVector q = p.next = new LongVector(p.objects.length);
38 q.objects[q.num++] = obj;
39 }
40 }
41
42 public int size() {
43 LongVector p = this;
44 int s = 0;
45 while (p != null) {
46 s += p.num;
47 p = p.next;
48 }
49
50 return s;
51 }
52
53 public Object elementAt(int i) {
54 LongVector p = this;
55 while (p != null)
56 if (i < p.num)
57 return p.objects[i];
58 else {
59 i -= p.num;
60 p = p.next;
61 }
62
63 return null;
64 }
65
66 /*
67 public static void main(String [] args) {
68 LongVector v = new LongVector(4);
69 int i;
70 for (i = 0; i < 128; ++i)
71 v.addElement(new Integer(i));
72
73 System.out.println(v.size());
74 for (i = 0; i < v.size(); ++i) {
75 System.out.print(v.elementAt(i));
76 System.out.print(", ");
77 }
78 }
79 */
80 }
81