001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.collections.primitives; 018 019import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleIterator; 020import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleList; 021import org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleListIterator; 022 023/** 024 * This class consists exclusively of static methods that operate on or 025 * return DoubleCollections. 026 * <p> 027 * The methods of this class all throw a NullPoDoubleerException if the 028 * provided collection is null. 029 * 030 * @version $Revision: 480460 $ $Date: 2006-11-29 03:14:21 -0500 (Wed, 29 Nov 2006) $ 031 * 032 * @author Rodney Waldhoff 033 */ 034public final class DoubleCollections { 035 036 /** 037 * Returns an unmodifiable DoubleList containing only the specified element. 038 * @param value the single value 039 * @return an unmodifiable DoubleList containing only the specified element. 040 */ 041 public static DoubleList singletonDoubleList(double value) { 042 // TODO: a specialized implementation of DoubleList may be more performant 043 DoubleList list = new ArrayDoubleList(1); 044 list.add(value); 045 return UnmodifiableDoubleList.wrap(list); 046 } 047 048 /** 049 * Returns an unmodifiable DoubleIterator containing only the specified element. 050 * @param value the single value 051 * @return an unmodifiable DoubleIterator containing only the specified element. 052 */ 053 public static DoubleIterator singletonDoubleIterator(double value) { 054 return singletonDoubleList(value).iterator(); 055 } 056 057 /** 058 * Returns an unmodifiable DoubleListIterator containing only the specified element. 059 * @param value the single value 060 * @return an unmodifiable DoubleListIterator containing only the specified element. 061 */ 062 public static DoubleListIterator singletonDoubleListIterator(double value) { 063 return singletonDoubleList(value).listIterator(); 064 } 065 066 /** 067 * Returns an unmodifiable version of the given non-null DoubleList. 068 * @param list the non-null DoubleList to wrap in an unmodifiable decorator 069 * @return an unmodifiable version of the given non-null DoubleList 070 * @throws NullPointerException if the given DoubleList is null 071 * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleList#wrap 072 */ 073 public static DoubleList unmodifiableDoubleList(DoubleList list) throws NullPointerException { 074 if(null == list) { 075 throw new NullPointerException(); 076 } 077 return UnmodifiableDoubleList.wrap(list); 078 } 079 080 /** 081 * Returns an unmodifiable version of the given non-null DoubleIterator. 082 * @param iter the non-null DoubleIterator to wrap in an unmodifiable decorator 083 * @return an unmodifiable version of the given non-null DoubleIterator 084 * @throws NullPointerException if the given DoubleIterator is null 085 * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleIterator#wrap 086 */ 087 public static DoubleIterator unmodifiableDoubleIterator(DoubleIterator iter) { 088 if(null == iter) { 089 throw new NullPointerException(); 090 } 091 return UnmodifiableDoubleIterator.wrap(iter); 092 } 093 094 /** 095 * Returns an unmodifiable version of the given non-null DoubleListIterator. 096 * @param iter the non-null DoubleListIterator to wrap in an unmodifiable decorator 097 * @return an unmodifiable version of the given non-null DoubleListIterator 098 * @throws NullPointerException if the given DoubleListIterator is null 099 * @see org.apache.commons.collections.primitives.decorators.UnmodifiableDoubleListIterator#wrap 100 */ 101 public static DoubleListIterator unmodifiableDoubleListIterator(DoubleListIterator iter) { 102 if(null == iter) { 103 throw new NullPointerException(); 104 } 105 return UnmodifiableDoubleListIterator.wrap(iter); 106 } 107 108 /** 109 * Returns an unmodifiable, empty DoubleList. 110 * @return an unmodifiable, empty DoubleList. 111 * @see #EMPTY_DOUBLE_LIST 112 */ 113 public static DoubleList getEmptyDoubleList() { 114 return EMPTY_DOUBLE_LIST; 115 } 116 117 /** 118 * Returns an unmodifiable, empty DoubleIterator 119 * @return an unmodifiable, empty DoubleIterator. 120 * @see #EMPTY_DOUBLE_ITERATOR 121 */ 122 public static DoubleIterator getEmptyDoubleIterator() { 123 return EMPTY_DOUBLE_ITERATOR; 124 } 125 126 /** 127 * Returns an unmodifiable, empty DoubleListIterator 128 * @return an unmodifiable, empty DoubleListIterator. 129 * @see #EMPTY_DOUBLE_LIST_ITERATOR 130 */ 131 public static DoubleListIterator getEmptyDoubleListIterator() { 132 return EMPTY_DOUBLE_LIST_ITERATOR; 133 } 134 135 /** 136 * An unmodifiable, empty DoubleList 137 * @see #getEmptyDoubleList 138 */ 139 public static final DoubleList EMPTY_DOUBLE_LIST = unmodifiableDoubleList(new ArrayDoubleList(0)); 140 141 /** 142 * An unmodifiable, empty DoubleIterator 143 * @see #getEmptyDoubleIterator 144 */ 145 public static final DoubleIterator EMPTY_DOUBLE_ITERATOR = unmodifiableDoubleIterator(EMPTY_DOUBLE_LIST.iterator()); 146 147 /** 148 * An unmodifiable, empty DoubleListIterator 149 * @see #getEmptyDoubleListIterator 150 */ 151 public static final DoubleListIterator EMPTY_DOUBLE_LIST_ITERATOR = unmodifiableDoubleListIterator(EMPTY_DOUBLE_LIST.listIterator()); 152}