KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > foundation > IntArrayList


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.foundation;
22
23 /**
24  * @exclude
25  */

26 public class IntArrayList implements Iterable4 {
27     
28     protected int[] i_content;
29     
30     private int i_count;
31     
32     public IntArrayList(){
33         this(10);
34     }
35     
36     public IntArrayList(int initialSize){
37         i_content = new int[initialSize];
38     }
39     
40     public void add(int a_value){
41         if(i_count >= i_content.length){
42             int inc = i_content.length / 2;
43             if(inc < 10){
44                 inc = 10;
45             }
46             int[] temp = new int[i_content.length + inc];
47             System.arraycopy(i_content, 0, temp, 0, i_content.length);
48             i_content = temp;
49         }
50         i_content[i_count++] = a_value;
51     }
52     
53     public int indexOf(int a_value) {
54         for (int i = 0; i < i_count; i++) {
55             if (i_content[i] == a_value){
56                 return i;
57             }
58         }
59         return -1;
60     }
61     
62     public int size(){
63         return i_count;
64     }
65     
66     public long[] asLong(){
67         long[] longs = new long[i_count];
68         for (int i = 0; i < i_count; i++) {
69             longs[i] = i_content[i];
70         }
71         return longs;
72     }
73
74     public IntIterator4 intIterator() {
75         return new IntIterator4Impl(i_content, i_count);
76     }
77     
78     public Iterator4 iterator() {
79         return intIterator();
80     }
81     
82     public int get(int index) {
83         return i_content[index];
84     }
85     
86     public void swap(int left, int right) {
87         if(left!=right) {
88             int swap=i_content[left];
89             i_content[left]=i_content[right];
90             i_content[right]=swap;
91         }
92     }
93
94 }
95
Popular Tags