KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > primitives > LongCollections


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.commons.collections.primitives;
18
19 import org.apache.commons.collections.primitives.decorators.UnmodifiableLongIterator;
20 import org.apache.commons.collections.primitives.decorators.UnmodifiableLongList;
21 import org.apache.commons.collections.primitives.decorators.UnmodifiableLongListIterator;
22
23 /**
24  * This class consists exclusively of static methods that operate on or
25  * return LongCollections.
26  * <p>
27  * The methods of this class all throw a NullPoLongerException if the
28  * provided collection is null.
29  *
30  * @version $Revision: 480460 $ $Date: 2006-11-29 00:14:21 -0800 (Wed, 29 Nov 2006) $
31  *
32  * @author Rodney Waldhoff
33  */

34 public final class LongCollections {
35
36     /**
37      * Returns an unmodifiable LongList containing only the specified element.
38      * @param value the single value
39      * @return an unmodifiable LongList containing only the specified element.
40      */

41     public static LongList singletonLongList(long value) {
42         // TODO: a specialized implementation of LongList may be more performant
43
LongList list = new ArrayLongList(1);
44         list.add(value);
45         return UnmodifiableLongList.wrap(list);
46     }
47
48     /**
49      * Returns an unmodifiable LongIterator containing only the specified element.
50      * @param value the single value
51      * @return an unmodifiable LongIterator containing only the specified element.
52      */

53     public static LongIterator singletonLongIterator(long value) {
54         return singletonLongList(value).iterator();
55     }
56
57     /**
58      * Returns an unmodifiable LongListIterator containing only the specified element.
59      * @param value the single value
60      * @return an unmodifiable LongListIterator containing only the specified element.
61      */

62     public static LongListIterator singletonLongListIterator(long value) {
63         return singletonLongList(value).listIterator();
64     }
65
66     /**
67      * Returns an unmodifiable version of the given non-null LongList.
68      * @param list the non-null LongList to wrap in an unmodifiable decorator
69      * @return an unmodifiable version of the given non-null LongList
70      * @throws NullPointerException if the given LongList is null
71      * @see org.apache.commons.collections.primitives.decorators.UnmodifiableLongList#wrap
72      */

73     public static LongList unmodifiableLongList(LongList list) throws NullPointerException JavaDoc {
74         if(null == list) {
75             throw new NullPointerException JavaDoc();
76         }
77         return UnmodifiableLongList.wrap(list);
78     }
79     
80     /**
81      * Returns an unmodifiable version of the given non-null LongIterator.
82      * @param iter the non-null LongIterator to wrap in an unmodifiable decorator
83      * @return an unmodifiable version of the given non-null LongIterator
84      * @throws NullPointerException if the given LongIterator is null
85      * @see org.apache.commons.collections.primitives.decorators.UnmodifiableLongIterator#wrap
86      */

87     public static LongIterator unmodifiableLongIterator(LongIterator iter) {
88         if(null == iter) {
89             throw new NullPointerException JavaDoc();
90         }
91         return UnmodifiableLongIterator.wrap(iter);
92     }
93         
94     /**
95      * Returns an unmodifiable version of the given non-null LongListIterator.
96      * @param iter the non-null LongListIterator to wrap in an unmodifiable decorator
97      * @return an unmodifiable version of the given non-null LongListIterator
98      * @throws NullPointerException if the given LongListIterator is null
99      * @see org.apache.commons.collections.primitives.decorators.UnmodifiableLongListIterator#wrap
100      */

101     public static LongListIterator unmodifiableLongListIterator(LongListIterator iter) {
102         if(null == iter) {
103             throw new NullPointerException JavaDoc();
104         }
105         return UnmodifiableLongListIterator.wrap(iter);
106     }
107     
108     /**
109      * Returns an unmodifiable, empty LongList.
110      * @return an unmodifiable, empty LongList.
111      * @see #EMPTY_LONG_LIST
112      */

113     public static LongList getEmptyLongList() {
114         return EMPTY_LONG_LIST;
115     }
116     
117     /**
118      * Returns an unmodifiable, empty LongIterator
119      * @return an unmodifiable, empty LongIterator.
120      * @see #EMPTY_LONG_ITERATOR
121      */

122     public static LongIterator getEmptyLongIterator() {
123         return EMPTY_LONG_ITERATOR;
124     }
125     
126     /**
127      * Returns an unmodifiable, empty LongListIterator
128      * @return an unmodifiable, empty LongListIterator.
129      * @see #EMPTY_LONG_LIST_ITERATOR
130      */

131     public static LongListIterator getEmptyLongListIterator() {
132         return EMPTY_LONG_LIST_ITERATOR;
133     }
134
135     /**
136      * An unmodifiable, empty LongList
137      * @see #getEmptyLongList
138      */

139     public static final LongList EMPTY_LONG_LIST = unmodifiableLongList(new ArrayLongList(0));
140
141     /**
142      * An unmodifiable, empty LongIterator
143      * @see #getEmptyLongIterator
144      */

145     public static final LongIterator EMPTY_LONG_ITERATOR = unmodifiableLongIterator(EMPTY_LONG_LIST.iterator());
146
147     /**
148      * An unmodifiable, empty LongListIterator
149      * @see #getEmptyLongListIterator
150      */

151     public static final LongListIterator EMPTY_LONG_LIST_ITERATOR = unmodifiableLongListIterator(EMPTY_LONG_LIST.listIterator());
152 }
153
Popular Tags