PageRenderTime 154ms CodeModel.GetById 148ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-0-pre5/org/gjt/sp/util/IntegerArray.java

#
Java | 77 lines | 36 code | 9 blank | 32 comment | 1 complexity | d34f24cf4dbd5251c1f0f2ff7f2a3c45 MD5 | raw file
 1/*
 2 * IntegerArray.java - Automatically growing array of ints
 3 * :tabSize=8:indentSize=8:noTabs=false:
 4 * :folding=explicit:collapseFolds=1:
 5 *
 6 * Copyright (C) 2001 Slava Pestov
 7 *
 8 * This program is free software; you can redistribute it and/or
 9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 */
22
23package org.gjt.sp.util;
24
25/**
26 * A simple collection that stores integers and grows automatically.
27 */
28public class IntegerArray
29{
30	//{{{ IntegerArray constructor
31	public IntegerArray()
32	{
33		array = new int[100];
34	} //}}}
35
36	//{{{ add() method
37	public void add(int num)
38	{
39		if(len >= array.length)
40		{
41			int[] arrayN = new int[len * 2];
42			System.arraycopy(array,0,arrayN,0,len);
43			array = arrayN;
44		}
45
46		array[len++] = num;
47	} //}}}
48
49	//{{{ get() method
50	public final int get(int index)
51	{
52		return array[index];
53	} //}}}
54
55	//{{{ getSize() method
56	public final int getSize()
57	{
58		return len;
59	} //}}}
60
61	//{{{ setSize() method
62	public final void setSize(int len)
63	{
64		this.len = len;
65	} //}}}
66
67	//{{{ clear() method
68	public final void clear()
69	{
70		len = 0;
71	} //}}}
72
73	//{{{ Private members
74	private int[] array;
75	private int len;
76	//}}}
77}