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