Source Code Cross Referenced for IntegerList.java in  » Parser » chaperon-3.0 » net » sourceforge » chaperon » common » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Parser » chaperon 3.0 » net.sourceforge.chaperon.common 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Copyright (C) Chaperon. All rights reserved.
003:         *  -------------------------------------------------------------------------
004:         *  This software is published under the terms of the Apache Software License
005:         *  version 1.1, a copy of which has been included  with this distribution in
006:         *  the LICENSE file.
007:         */
008:
009:        package net.sourceforge.chaperon.common;
010:
011:        /**
012:         * This class represents a list of integers values.
013:         *
014:         * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
015:         * @version CVS $Id: IntegerList.java,v 1.4 2003/12/09 19:55:52 benedikta Exp $
016:         */
017:        public class IntegerList implements  IntegerCollection {
018:            private int capacityIncrement = 100;
019:            private int elementCount = 0;
020:            private int[] list = new int[10];
021:            private int dummy;
022:
023:            /**
024:             * Constructs a empty list of integer values.
025:             */
026:            public IntegerList() {
027:            }
028:
029:            /**
030:             * Add a value to the list.
031:             *
032:             * @param value Integer value, which should be added.
033:             *
034:             * @return Index of this value.
035:             */
036:            public int add(int value) {
037:                ensureCapacity(elementCount + 1);
038:                list[elementCount++] = value;
039:                return elementCount - 1;
040:            }
041:
042:            /**
043:             * Add a collection of values to this list.
044:             *
045:             * @param collection Collection of values.
046:             */
047:            public void add(IntegerCollection collection) {
048:                for (int i = 0; i < collection.getCount(); i++)
049:                    add(collection.get(i));
050:            }
051:
052:            /**
053:             * Add the values of an array to this list.
054:             *
055:             * @param array Array of integer values.
056:             */
057:            public void add(int[] array) {
058:                for (int i = 0; i < array.length; i++)
059:                    add(array[i]);
060:            }
061:
062:            /**
063:             * Removes a value giving by an index.
064:             *
065:             * @param index Index of the integer value.
066:             */
067:            public void remove(int index) {
068:                if (index >= elementCount)
069:                    throw new ArrayIndexOutOfBoundsException(index);
070:
071:                elementCount--;
072:                if (index < elementCount)
073:                    System.arraycopy(list, index + 1, list, index, elementCount
074:                            - index);
075:
076:                list[elementCount] = 0;
077:            }
078:
079:            /**
080:             * Replace a value given by an index.
081:             *
082:             * @param index Index of the value, which should be replaced.
083:             * @param value The new value.
084:             */
085:            public void set(int index, int value) {
086:                if (index >= elementCount)
087:                    throw new ArrayIndexOutOfBoundsException(index);
088:
089:                list[index] = value;
090:            }
091:
092:            /**
093:             * Return a value from this list given by an index.
094:             *
095:             * @param index Index of the value.
096:             *
097:             * @return Integer value.
098:             */
099:            public int get(int index) {
100:                if (index >= elementCount)
101:                    throw new ArrayIndexOutOfBoundsException(index);
102:
103:                return list[index];
104:            }
105:
106:            /**
107:             * Returns the count of values in this list
108:             *
109:             * @return Count of integer values.
110:             */
111:            public int getCount() {
112:                return elementCount;
113:            }
114:
115:            /**
116:             * Return the index of a value, otherwise -1.
117:             *
118:             * @param value Value, which should found in this list.
119:             *
120:             * @return Index of this value.
121:             */
122:            public int indexOf(int value) {
123:                for (int i = 0; i < elementCount; i++)
124:                    if (list[i] == value)
125:                        return i;
126:
127:                return -1;
128:            }
129:
130:            /**
131:             * If the list contains a value.
132:             *
133:             * @param value Value, which should be found in this list.
134:             *
135:             * @return True, if this list contains the value.
136:             */
137:            public boolean contains(int value) {
138:                for (int i = 0; i < elementCount; i++)
139:                    if (list[i] == value)
140:                        return true;
141:
142:                return false;
143:            }
144:
145:            /**
146:             * Removes a value from this list.
147:             *
148:             * @param value Value to remove.
149:             */
150:            public void removeValue(int value) {
151:                int index;
152:
153:                while ((index = indexOf(value)) != -1)
154:                    remove(index);
155:            }
156:
157:            /**
158:             * If this list contains no values.
159:             *
160:             * @return True, if this list is empty.
161:             */
162:            public boolean isEmpty() {
163:                return (elementCount <= 0);
164:            }
165:
166:            /**
167:             * Pops a value of the end of this list.
168:             *
169:             * @return Value from the end of this list.
170:             */
171:            public int pop() {
172:                if (0 >= elementCount)
173:                    throw new java.util.EmptyStackException();
174:
175:                return list[--elementCount];
176:            }
177:
178:            /**
179:             * Pushs a value on top to this list
180:             *
181:             * @param value Value, which should be added.
182:             */
183:            public void push(int value) {
184:                add(value);
185:            }
186:
187:            /**
188:             * Push values from an array.
189:             *
190:             * @param values Array of integer values.
191:             */
192:            public void push(int[] values) {
193:                add(values);
194:            }
195:
196:            /**
197:             * Peek a value of the end of this list.
198:             *
199:             * @return Integer value.
200:             */
201:            public int peek() {
202:                if (0 >= elementCount)
203:                    throw new java.util.EmptyStackException();
204:
205:                return list[elementCount - 1];
206:            }
207:
208:            /**
209:             * Removes all values from this list.
210:             */
211:            public void clear() {
212:                elementCount = 0;
213:            }
214:
215:            /**
216:             * Swaps two values from this list.
217:             *
218:             * @param index1 Index from the first value.
219:             * @param index2 Index from the second value.
220:             */
221:            public void swap(int index1, int index2) {
222:                dummy = list[index1];
223:                list[index1] = list[index2];
224:                list[index2] = dummy;
225:            }
226:
227:            /**
228:             * Return a string representation of the collection.
229:             *
230:             * @return String representation of the collection.
231:             */
232:            public String toString() {
233:                StringBuffer buffer = new StringBuffer();
234:
235:                buffer.append("[");
236:                for (int i = 0; i < elementCount; i++) {
237:                    buffer.append(String.valueOf(list[i]));
238:                    if (i < (elementCount - 1))
239:                        buffer.append(",");
240:                }
241:
242:                buffer.append("]");
243:                return buffer.toString();
244:            }
245:
246:            /**
247:             * Ensure the capacity for adding values
248:             *
249:             * @param minCapacity Minimum capacity.
250:             */
251:            private void ensureCapacity(int minCapacity) {
252:                if (list.length >= minCapacity)
253:                    return;
254:
255:                int newCapacity = list.length + capacityIncrement;
256:
257:                if (capacityIncrement <= 0)
258:                    newCapacity = list.length * 2;
259:
260:                int[] newArray = new int[Math.max(newCapacity, minCapacity)];
261:
262:                System.arraycopy(list, 0, newArray, 0, list.length);
263:                list = newArray;
264:            }
265:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.