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 a {@link java.lang.Number Number}-valued
026 * {@link java.util.Collection Collection} to the
027 * {@link LongCollection LongCollection} interface.
028 * <p />
029 * This implementation delegates most methods
030 * to the provided {@link Collection Collection}
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 CollectionLongCollection extends AbstractCollectionLongCollection implements Serializable {
038 /**
039 * Create an {@link LongCollection LongCollection} wrapping
040 * the specified {@link Collection Collection}. When
041 * the given <i>collection</i> is <code>null</code>,
042 * returns <code>null</code>.
043 *
044 * @param collection the (possibly <code>null</code>) {@link Collection} to wrap
045 * @return an {@link LongCollection LongCollection} wrapping the given
046 * <i>collection</i>, or <code>null</code> when <i>collection</i> is
047 * <code>null</code>.
048 */
049 public static LongCollection wrap(Collection collection) {
050 if(null == collection) {
051 return null;
052 } else if(collection instanceof Serializable) {
053 return new CollectionLongCollection(collection);
054 } else {
055 return new NonSerializableCollectionLongCollection(collection);
056 }
057 }
058
059 /**
060 * Creates an {@link LongCollection LongCollection} wrapping
061 * the specified {@link Collection Collection}.
062 * @see #wrap
063 */
064 public CollectionLongCollection(Collection collection) {
065 _collection = collection;
066 }
067
068 protected Collection getCollection() {
069 return _collection;
070 }
071
072 private Collection _collection = null;
073 }