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