KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javassist > bytecode > LongVector


1 /*
2  * Javassist, a Java-bytecode translator toolkit.
3  * Copyright (C) 1999-2005 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     static final int SIZE = 128;
20     private int num;
21     private Object JavaDoc[] objects;
22     private LongVector next;
23
24     public LongVector() {
25         this(SIZE);
26     }
27
28     public LongVector(int initialSize) {
29         num = 0;
30         objects = new Object JavaDoc[initialSize];
31         next = null;
32     }
33
34     public void addElement(Object JavaDoc obj) {
35         LongVector p = this;
36         while (p.next != null)
37             p = p.next;
38
39         if (p.num < p.objects.length)
40             p.objects[p.num++] = obj;
41         else {
42             LongVector q = p.next = new LongVector(SIZE);
43             q.objects[q.num++] = obj;
44         }
45     }
46
47     public int size() {
48         LongVector p = this;
49         int s = 0;
50         while (p != null) {
51             s += p.num;
52             p = p.next;
53         }
54
55         return s;
56     }
57
58     public Object JavaDoc elementAt(int i) {
59         LongVector p = this;
60         while (p != null)
61             if (i < p.num)
62                 return p.objects[i];
63             else {
64                 i -= p.num;
65                 p = p.next;
66             }
67
68         return null;
69     }
70
71 /*
72     public static void main(String [] args) {
73         LongVector v = new LongVector(4);
74         int i;
75         for (i = 0; i < 128; ++i)
76             v.addElement(new Integer(i));
77
78         System.out.println(v.size());
79         for (i = 0; i < v.size(); ++i) {
80             System.out.print(v.elementAt(i));
81             System.out.print(", ");
82         }
83     }
84 */

85 }
86
Popular Tags