1. /*
  2. * $Header: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/DoubleCollections.java,v 1.1 2003/10/29 19:39:12 rwaldhoff Exp $
  3. * ====================================================================
  4. * The Apache Software License, Version 1.1
  5. *
  6. * Copyright (c) 2003 The Apache Software Foundation. All rights
  7. * reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * 3. The end-user documentation included with the redistribution, if
  22. * any, must include the following acknowledgement:
  23. * "This product includes software developed by the
  24. * Apache Software Foundation (http://www.apache.org/)."
  25. * Alternately, this acknowledgement may appear in the software itself,
  26. * if and wherever such third-party acknowledgements normally appear.
  27. *
  28. * 4. The names "The Jakarta Project", "Commons", and "Apache Software
  29. * Foundation" must not be used to endorse or promote products derived
  30. * from this software without prior written permission. For written
  31. * permission, please contact apache@apache.org.
  32. *
  33. * 5. Products derived from this software may not be called "Apache"
  34. * nor may "Apache" appear in their names without prior written
  35. * permission of the Apache Software Foundation.
  36. *
  37. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  38. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  39. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  41. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  43. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  44. * USE, DATA, OR PROFITS; OR BUSINESS DoubleERRUPTION) HOWEVER CAUSED AND
  45. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  46. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  47. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  48. * SUCH DAMAGE.
  49. * ====================================================================
  50. *
  51. * This software consists of voluntary contributions made by many
  52. * individuals on behalf of the Apache Software Foundation. For more
  53. * information on the Apache Software Foundation, please see
  54. * <http://www.apache.org/>.
  55. *
  56. */
  57. package org.apache.commons.collections.primitives;
  58. import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleIterator;
  59. import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleList;
  60. import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleListIterator;
  61. /**
  62. * This class consists exclusively of static methods that operate on or
  63. * return DoubleCollections.
  64. * <p>
  65. * The methods of this class all throw a NullPoDoubleerException if the
  66. * provided collection is null.
  67. *
  68. * @version $Revision: 1.1 $ $Date: 2003/10/29 19:39:12 $
  69. *
  70. * @author Rodney Waldhoff
  71. */
  72. public final class DoubleCollections {
  73. /**
  74. * Returns an unmodifiable DoubleList containing only the specified element.
  75. * @param value the single value
  76. * @return an unmodifiable DoubleList containing only the specified element.
  77. */
  78. public static DoubleList singletonDoubleList(double value) {
  79. // TODO: a specialized implementation of DoubleList may be more performant
  80. DoubleList list = new ArrayDoubleList(1);
  81. list.add(value);
  82. return UnmodifiableDoubleList.wrap(list);
  83. }
  84. /**
  85. * Returns an unmodifiable DoubleIterator containing only the specified element.
  86. * @param value the single value
  87. * @return an unmodifiable DoubleIterator containing only the specified element.
  88. */
  89. public static DoubleIterator singletonDoubleIterator(double value) {
  90. return singletonDoubleList(value).iterator();
  91. }
  92. /**
  93. * Returns an unmodifiable DoubleListIterator containing only the specified element.
  94. * @param value the single value
  95. * @return an unmodifiable DoubleListIterator containing only the specified element.
  96. */
  97. public static DoubleListIterator singletonDoubleListIterator(double value) {
  98. return singletonDoubleList(value).listIterator();
  99. }
  100. /**
  101. * Returns an unmodifiable version of the given non-null DoubleList.
  102. * @param list the non-null DoubleList to wrap in an unmodifiable decorator
  103. * @return an unmodifiable version of the given non-null DoubleList
  104. * @throws NullPoDoubleerException if the given DoubleList is null
  105. * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleList#wrap
  106. */
  107. public static DoubleList unmodifiableDoubleList(DoubleList list) throws NullPointerException {
  108. if(null == list) {
  109. throw new NullPointerException();
  110. }
  111. return UnmodifiableDoubleList.wrap(list);
  112. }
  113. /**
  114. * Returns an unmodifiable version of the given non-null DoubleIterator.
  115. * @param iter the non-null DoubleIterator to wrap in an unmodifiable decorator
  116. * @return an unmodifiable version of the given non-null DoubleIterator
  117. * @throws NullPoDoubleerException if the given DoubleIterator is null
  118. * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleIterator#wrap
  119. */
  120. public static DoubleIterator unmodifiableDoubleIterator(DoubleIterator iter) {
  121. if(null == iter) {
  122. throw new NullPointerException();
  123. }
  124. return UnmodifiableDoubleIterator.wrap(iter);
  125. }
  126. /**
  127. * Returns an unmodifiable version of the given non-null DoubleListIterator.
  128. * @param iter the non-null DoubleListIterator to wrap in an unmodifiable decorator
  129. * @return an unmodifiable version of the given non-null DoubleListIterator
  130. * @throws NullPoDoubleerException if the given DoubleListIterator is null
  131. * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleListIterator#wrap
  132. */
  133. public static DoubleListIterator unmodifiableDoubleListIterator(DoubleListIterator iter) {
  134. if(null == iter) {
  135. throw new NullPointerException();
  136. }
  137. return UnmodifiableDoubleListIterator.wrap(iter);
  138. }
  139. /**
  140. * Returns an unmodifiable, empty DoubleList.
  141. * @return an unmodifiable, empty DoubleList.
  142. * @see #EMPTY_DOUBLE_LIST
  143. */
  144. public static DoubleList getEmptyDoubleList() {
  145. return EMPTY_DOUBLE_LIST;
  146. }
  147. /**
  148. * Returns an unmodifiable, empty DoubleIterator
  149. * @return an unmodifiable, empty DoubleIterator.
  150. * @see #EMPTY_DOUBLE_ITERATOR
  151. */
  152. public static DoubleIterator getEmptyDoubleIterator() {
  153. return EMPTY_DOUBLE_ITERATOR;
  154. }
  155. /**
  156. * Returns an unmodifiable, empty DoubleListIterator
  157. * @return an unmodifiable, empty DoubleListIterator.
  158. * @see #EMPTY_DOUBLE_LIST_ITERATOR
  159. */
  160. public static DoubleListIterator getEmptyDoubleListIterator() {
  161. return EMPTY_DOUBLE_LIST_ITERATOR;
  162. }
  163. /**
  164. * An unmodifiable, empty DoubleList
  165. * @see #getEmptyDoubleList
  166. */
  167. public static final DoubleList EMPTY_DOUBLE_LIST = unmodifiableDoubleList(new ArrayDoubleList(0));
  168. /**
  169. * An unmodifiable, empty DoubleIterator
  170. * @see #getEmptyDoubleIterator
  171. */
  172. public static final DoubleIterator EMPTY_DOUBLE_ITERATOR = unmodifiableDoubleIterator(EMPTY_DOUBLE_LIST.iterator());
  173. /**
  174. * An unmodifiable, empty DoubleListIterator
  175. * @see #getEmptyDoubleListIterator
  176. */
  177. public static final DoubleListIterator EMPTY_DOUBLE_LIST_ITERATOR = unmodifiableDoubleListIterator(EMPTY_DOUBLE_LIST.listIterator());
  178. }