Home » commons-collections-3.2.1-src » org.apache.commons » collections » primitives » adapters » [javadoc | source]
    1   /*
    2    * $Header: /home/cvs/jakarta-commons/primitives/src/java/org/apache/commons/collections/primitives/adapters/AbstractCollectionFloatCollection.java,v 1.3 2003/10/16 20:49:38 scolebourne 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 INTERRUPTION) 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   
   58   package org.apache.commons.collections.primitives.adapters;
   59   
   60   import java.util.Collection;
   61   
   62   import org.apache.commons.collections.primitives.FloatCollection;
   63   import org.apache.commons.collections.primitives.FloatIterator;
   64   
   65   /**
   66    * @since Commons Primitives 1.0
   67    * @version $Revision: 1.3 $ $Date: 2003/10/16 20:49:38 $
   68    * @author Rodney Waldhoff 
   69    */
   70   abstract class AbstractCollectionFloatCollection implements FloatCollection {
   71       protected AbstractCollectionFloatCollection() {
   72       }
   73   
   74       public boolean add(float element) {
   75           return getCollection().add(new Float(element));
   76       }
   77           
   78       public boolean addAll(FloatCollection c) {
   79           return getCollection().addAll(FloatCollectionCollection.wrap(c));
   80       }
   81       
   82       public void clear() {
   83           getCollection().clear();
   84       }
   85   
   86       public boolean contains(float element) {
   87           return getCollection().contains(new Float(element));
   88       }
   89       
   90       public boolean containsAll(FloatCollection c) {
   91           return getCollection().containsAll(FloatCollectionCollection.wrap(c));
   92       }        
   93       
   94       public String toString() {
   95           return getCollection().toString();
   96       }
   97   
   98       public boolean isEmpty() {
   99           return getCollection().isEmpty();
  100       }
  101       
  102       /**
  103        * {@link IteratorFloatIterator#wrap wraps} the 
  104        * {@link java.util.Iterator Iterator}
  105        * returned by my underlying 
  106        * {@link Collection Collection}, 
  107        * if any.
  108        */
  109       public FloatIterator iterator() {
  110           return IteratorFloatIterator.wrap(getCollection().iterator());
  111       }
  112        
  113       public boolean removeElement(float element) {
  114           return getCollection().remove(new Float(element));
  115       }
  116       
  117       public boolean removeAll(FloatCollection c) {
  118           return getCollection().removeAll(FloatCollectionCollection.wrap(c));
  119       }
  120           
  121       public boolean retainAll(FloatCollection c) {
  122           return getCollection().retainAll(FloatCollectionCollection.wrap(c));
  123       }
  124       
  125       public int size() {
  126           return getCollection().size();
  127       }
  128       
  129       public float[] toArray() {
  130           Object[] src = getCollection().toArray();
  131           float[] dest = new float[src.length];
  132           for(int i=0;i<src.length;i++) {
  133               dest[i] = ((Number)(src[i])).floatValue();
  134           }
  135           return dest;
  136       }
  137       
  138       public float[] toArray(float[] dest) {
  139           Object[] src = getCollection().toArray();
  140           if(dest.length < src.length) {
  141               dest = new float[src.length];
  142           }
  143           for(int i=0;i<src.length;i++) {
  144               dest[i] = ((Number)(src[i])).floatValue();
  145           }
  146           return dest;
  147       }
  148       
  149       protected abstract Collection getCollection();
  150       
  151   }

Save This Page
Home » commons-collections-3.2.1-src » org.apache.commons » collections » primitives » adapters » [javadoc | source]