View Javadoc

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.UnmodifiableFloatIterator;
20  import org.apache.commons.collections.primitives.decorators.UnmodifiableFloatList;
21  import org.apache.commons.collections.primitives.decorators.UnmodifiableFloatListIterator;
22  
23  /**
24   * This class consists exclusively of static methods that operate on or
25   * return FloatCollections.
26   * <p>
27   * The methods of this class all throw a NullPoFloaterException if the 
28   * provided collection is null.
29   * 
30   * @version $Revision: 480460 $ $Date: 2006-11-29 03:14:21 -0500 (Wed, 29 Nov 2006) $
31   * 
32   * @author Rodney Waldhoff 
33   */
34  public final class FloatCollections {
35  
36      /**
37       * Returns an unmodifiable FloatList containing only the specified element.
38       * @param value the single value
39       * @return an unmodifiable FloatList containing only the specified element.
40       */    
41      public static FloatList singletonFloatList(float value) {
42          // TODO: a specialized implementation of FloatList may be more performant
43          FloatList list = new ArrayFloatList(1);
44          list.add(value);
45          return UnmodifiableFloatList.wrap(list);
46      }
47  
48      /**
49       * Returns an unmodifiable FloatIterator containing only the specified element.
50       * @param value the single value
51       * @return an unmodifiable FloatIterator containing only the specified element.
52       */    
53      public static FloatIterator singletonFloatIterator(float value) {
54          return singletonFloatList(value).iterator();
55      }
56  
57      /**
58       * Returns an unmodifiable FloatListIterator containing only the specified element.
59       * @param value the single value
60       * @return an unmodifiable FloatListIterator containing only the specified element.
61       */    
62      public static FloatListIterator singletonFloatListIterator(float value) {
63          return singletonFloatList(value).listIterator();
64      }
65  
66      /**
67       * Returns an unmodifiable version of the given non-null FloatList.
68       * @param list the non-null FloatList to wrap in an unmodifiable decorator
69       * @return an unmodifiable version of the given non-null FloatList
70       * @throws NullPointerException if the given FloatList is null
71       * @see org.apache.commons.collections.primitives.decorators.UnmodifiableFloatList#wrap
72       */    
73      public static FloatList unmodifiableFloatList(FloatList list) throws NullPointerException {
74          if(null == list) {
75              throw new NullPointerException();
76          }
77          return UnmodifiableFloatList.wrap(list);
78      }
79      
80      /**
81       * Returns an unmodifiable version of the given non-null FloatIterator.
82       * @param iter the non-null FloatIterator to wrap in an unmodifiable decorator
83       * @return an unmodifiable version of the given non-null FloatIterator
84       * @throws NullPointerException if the given FloatIterator is null
85       * @see org.apache.commons.collections.primitives.decorators.UnmodifiableFloatIterator#wrap
86       */    
87      public static FloatIterator unmodifiableFloatIterator(FloatIterator iter) {
88          if(null == iter) {
89              throw new NullPointerException();
90          }
91          return UnmodifiableFloatIterator.wrap(iter);
92      }
93          
94      /**
95       * Returns an unmodifiable version of the given non-null FloatListIterator.
96       * @param iter the non-null FloatListIterator to wrap in an unmodifiable decorator
97       * @return an unmodifiable version of the given non-null FloatListIterator
98       * @throws NullPointerException if the given FloatListIterator is null
99       * @see org.apache.commons.collections.primitives.decorators.UnmodifiableFloatListIterator#wrap
100      */    
101     public static FloatListIterator unmodifiableFloatListIterator(FloatListIterator iter) {
102         if(null == iter) {
103             throw new NullPointerException();
104         }
105         return UnmodifiableFloatListIterator.wrap(iter);
106     }
107     
108     /**
109      * Returns an unmodifiable, empty FloatList.
110      * @return an unmodifiable, empty FloatList.
111      * @see #EMPTY_FLOAT_LIST
112      */    
113     public static FloatList getEmptyFloatList() {
114         return EMPTY_FLOAT_LIST;
115     }
116     
117     /**
118      * Returns an unmodifiable, empty FloatIterator
119      * @return an unmodifiable, empty FloatIterator.
120      * @see #EMPTY_FLOAT_ITERATOR
121      */    
122     public static FloatIterator getEmptyFloatIterator() {
123         return EMPTY_FLOAT_ITERATOR;
124     }
125     
126     /**
127      * Returns an unmodifiable, empty FloatListIterator
128      * @return an unmodifiable, empty FloatListIterator.
129      * @see #EMPTY_FLOAT_LIST_ITERATOR
130      */    
131     public static FloatListIterator getEmptyFloatListIterator() {
132         return EMPTY_FLOAT_LIST_ITERATOR;
133     }    
134 
135     /**
136      * An unmodifiable, empty FloatList
137      * @see #getEmptyFloatList
138      */    
139     public static final FloatList EMPTY_FLOAT_LIST = unmodifiableFloatList(new ArrayFloatList(0));
140 
141     /**
142      * An unmodifiable, empty FloatIterator
143      * @see #getEmptyFloatIterator
144      */    
145     public static final FloatIterator EMPTY_FLOAT_ITERATOR = unmodifiableFloatIterator(EMPTY_FLOAT_LIST.iterator());
146 
147     /**
148      * An unmodifiable, empty FloatListIterator
149      * @see #getEmptyFloatListIterator
150      */    
151     public static final FloatListIterator EMPTY_FLOAT_LIST_ITERATOR = unmodifiableFloatListIterator(EMPTY_FLOAT_LIST.listIterator());
152 }