KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > util > IntList


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24
25 package org.aspectj.util;
26
27
28 import java.util.*;
29
30 public class IntList {
31     private final int BASE_SIZE = 256;
32     
33     private int[] data;
34     private int size;
35     
36     public IntList() {
37         size = 0;
38         data = new int[BASE_SIZE];
39     }
40     
41     private void ensureSize(int needsSize) {
42         if (needsSize <= data.length) return;
43         
44         int[] newData = new int[data.length*2];
45         System.arraycopy(data, 0, newData, 0, data.length);
46         data = newData;
47     }
48     
49     public void add(int value) {
50         ensureSize(size+1);
51         data[size++] = value;
52     }
53     
54     public int[] toIntArray() {
55         int[] ret = new int[size];
56         System.arraycopy(data, 0, ret, 0, size);
57         return ret;
58     }
59 }
60
Popular Tags