KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > bak > pcj > IntCollection


1 /*
2  * Primitive Collections for Java.
3  * Copyright (C) 2002 Søren Bak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package bak.pcj;
20
21 /**
22  * This interface defines collections of int values.
23  *
24  * @see java.util.Collection
25  *
26  * @author Søren Bak
27  * @version 1.1 2002/30/12
28  * @since 1.0
29  */

30 public interface IntCollection {
31
32     /**
33      * Adds an element to this collection.
34      *
35      * @param v
36      * the element to add to this collection.
37      *
38      * @return <tt>true</tt> if this collection was modified
39      * as a result of adding <tt>v</tt>; returns
40      * <tt>false</tt> otherwise.
41      *
42      * @throws UnsupportedOperationException
43      * if the operation is not supported by this
44      * collection.
45      *
46      * @see #addAll(IntCollection)
47      */

48     boolean add(int v);
49
50     /**
51      * Adds all the elements of a specified collection to
52      * this collection.
53      *
54      * @param c
55      * the collection whose elements to add to this
56      * collection.
57      *
58      * @return <tt>true</tt> if this collection was modified
59      * as a result of adding the elements of <tt>c</tt>;
60      * returns <tt>false</tt> otherwise.
61      *
62      * @throws UnsupportedOperationException
63      * if the operation is not supported by this
64      * collection.
65      *
66      * @throws NullPointerException
67      * if <tt>c</tt> is <tt>null</tt>.
68      *
69      * @see #add(int)
70      */

71     boolean addAll(IntCollection c);
72
73     /**
74      * Clears this collection.
75      *
76      * @throws UnsupportedOperationException
77      * if the operation is not supported by this
78      * collection.
79      */

80     void clear();
81
82     /**
83      * Indicates whether this collection contains a specified
84      * element.
85      *
86      * @param v
87      * the element to test for containment.
88      *
89      * @return <tt>true</tt> if <tt>v</tt> is contained in this
90      * collection; returns <tt>false</tt> otherwise.
91      *
92      * @see #containsAll(IntCollection)
93      */

94     boolean contains(int v);
95
96     /**
97      * Indicates whether all elements of a specified
98      * collection is contained in this collection.
99      *
100      * @param c
101      * the collection whose elements to test for
102      * containment.
103      *
104      * @return <tt>true</tt> if all the elements of <tt>c</tt>
105      * are contained in this collection; returns
106      * <tt>false</tt> otherwise.
107      *
108      * @throws NullPointerException
109      * if <tt>c</tt> is <tt>null</tt>.
110      *
111      * @see #contains(int)
112      */

113     boolean containsAll(IntCollection c);
114
115     /**
116      * Indicates whether this collection is equal to some object.
117      *
118      * @param obj
119      * the object with which to compare this collection.
120      *
121      * @return <tt>true</tt> if this collection is equals to
122      * <tt>obj</tt>; returns <tt>false</tt> otherwise.
123      */

124     boolean equals(Object JavaDoc obj);
125
126     /**
127      * Returns a hash code value for this collection.
128      *
129      * @return a hash code value for this collection.
130      */

131     int hashCode();
132
133     /**
134      * Indicates whether this collection is empty.
135      *
136      * @return <tt>true</tt> if this collection is empty; returns
137      * <tt>false</tt> otherwise.
138      */

139     boolean isEmpty();
140
141     /**
142      * Returns an iterator over this collection.
143      *
144      * @return an iterator over this collection.
145      */

146     IntIterator iterator();
147
148     /**
149      * Removes a specified element from this collection.
150      *
151      * @param v
152      * the int value to remove from this collection.
153      *
154      * @return <tt>true</tt> if this collection was modified
155      * as a result of removing <tt>v</tt>; returns
156      * <tt>false</tt> otherwise.
157      *
158      * @throws UnsupportedOperationException
159      * if the operation is not supported by this
160      * collection.
161      */

162     boolean remove(int v);
163
164     /**
165      * Removes all the elements of a specified collection from
166      * this collection.
167      *
168      * @param c
169      * the collection whose elements to remove from this
170      * collection.
171      *
172      * @return <tt>true</tt> if this collection was modified
173      * as a result of removing the elements of <tt>c</tt>;
174      * returns <tt>false</tt> otherwise.
175      *
176      * @throws UnsupportedOperationException
177      * if the operation is not supported by this
178      * collection.
179      *
180      * @throws NullPointerException
181      * if <tt>c</tt> is <tt>null</tt>.
182      */

183     boolean removeAll(IntCollection c);
184
185     /**
186      * Retains only the elements of a specified collection in
187      * this collection.
188      *
189      * @param c
190      * the collection whose elements to retain in this
191      * collection.
192      *
193      * @return <tt>true</tt> if this collection was modified
194      * as a result of removing the elements not contained
195      * in <tt>c</tt>;
196      * returns <tt>false</tt> otherwise.
197      *
198      * @throws UnsupportedOperationException
199      * if the operation is not supported by this
200      * collection.
201      *
202      * @throws NullPointerException
203      * if <tt>c</tt> is <tt>null</tt>.
204      */

205     boolean retainAll(IntCollection c);
206
207     /**
208      * Returns the number of elements in this collection.
209      *
210      * @return the number of elements in this collection.
211      */

212     int size();
213
214     /**
215      * Returns the elements of this collection as an array.
216      *
217      * @return a new array containing the elements of this
218      * collection.
219      */

220     int[] toArray();
221
222     /**
223      * Returns the elements of this collection as an array.
224      *
225      * @param a
226      * an array to fill with the elements of this
227      * collection; if <tt>a</tt> is <tt>null</tt> or not
228      * big enough to contain all the elements of this
229      * collection, an new array is allocated,
230      * and <tt>a</tt> is not changed.
231      *
232      * @return <tt>a</tt>, if <tt>a</tt> has room for all the
233      * elements of this collection; otherwise a new
234      * array is allocated, filled with the elements of
235      * this collection, and returned.
236      */

237     int[] toArray(int[] a);
238
239     /**
240      * Minimizes the memory used by this collection. The exact
241      * operation of this method depends on the class implementing it.
242      * Implementors may choose to ignore it completely.
243      */

244     void trimToSize();
245
246 }
Popular Tags