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     */
017    package org.apache.commons.collections.primitives.adapters;
018    
019    import java.io.Serializable;
020    import java.util.Collection;
021    
022    import org.apache.commons.collections.primitives.BooleanCollection;
023    
024    /**
025     * Adapts an {@link org.apache.commons.collections.primitives.BooleanCollection
026     * BooleanCollection} to the {@link java.util.Collection Collection} interface.
027     * <p />
028     * This implementation delegates most methods to the provided {@link
029     * org.apache.commons.collections.primitives.BooleanCollection
030     * BooleanCollection} implementation in the "obvious" way.
031     * 
032     * @since Commons Primitives 1.1
033     * @version $Revision: 480462 $ $Date: 2006-11-29 09:15:00 +0100 (Wed, 29 Nov 2006) $
034     */
035    final public class BooleanCollectionCollection extends
036            AbstractBooleanCollectionCollection implements Serializable
037    {
038        
039        /**
040         * Create a {@link java.util.Collection Collection} wrapping the specified
041         * {@link org.apache.commons.collections.primitives.BooleanCollection
042         * BooleanCollection}.  When the given <i>collection</i> is <code>null
043         * </code>, returns <code>null</code>.
044         * 
045         * @param collection the (possibly <code>null</code>) 
046         *        {@link org.apache.commons.collections.primitives.BooleanCollection
047         *        BooleanCollection} to wrap
048         * @return a {@link java.util.Collection Collection} wrapping the given
049         *         <i>collection</i>, or <code>null</code> when <i>collection</i> is
050         *         <code>null</code>.
051         */
052        public static Collection wrap(BooleanCollection collection) {
053            if(null == collection) {
054                return null;
055            } else if(collection instanceof Serializable) {
056                return new BooleanCollectionCollection(collection);
057            } else {
058                return new NonSerializableBooleanCollectionCollection(collection);
059            }
060        }
061        
062        /**
063         * Creates a {@link java.util.Collection Collection} wrapping the specified
064         * {@link org.apache.commons.collections.primitives.BooleanCollection
065         * BooleanCollection}.
066         * @see #wrap
067         */
068        public BooleanCollectionCollection(BooleanCollection collection) {
069            _collection = collection;
070        }
071        
072    
073        protected BooleanCollection getBooleanCollection() {
074            return _collection;
075        }
076            
077        private BooleanCollection _collection = null;
078    }