View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.collections.primitives.adapters;
18  
19  import java.util.Collection;
20  
21  import org.apache.commons.collections.primitives.BooleanIterator;
22  import org.apache.commons.collections.primitives.BooleanCollection;
23  
24  
25  /**
26   * @since Commons Primitives 1.1
27   * @version $Revision: 480462 $ $Date: 2006-11-29 03:15:00 -0500 (Wed, 29 Nov 2006) $
28   */
29  abstract class AbstractCollectionBooleanCollection
30          implements BooleanCollection {
31  
32      protected AbstractCollectionBooleanCollection() {
33      }
34  
35      public boolean add(boolean element) {
36          return getCollection().add(new Boolean(element));
37      }
38          
39      public boolean addAll(BooleanCollection c) {
40          return getCollection().addAll(BooleanCollectionCollection.wrap(c));
41      }
42      
43      public void clear() {
44          getCollection().clear();
45      }
46  
47      public boolean contains(boolean element) {
48          return getCollection().contains(new Boolean(element));
49      }
50      
51      public boolean containsAll(BooleanCollection c) {
52          return getCollection().containsAll(
53                  BooleanCollectionCollection.wrap(c));
54      }        
55      
56      public String toString() {
57          return getCollection().toString();
58      }
59  
60      public boolean isEmpty() {
61          return getCollection().isEmpty();
62      }
63      
64      /**
65       * {@link IteratorBooleanIterator#wrap wraps} the {@link java.util.Iterator
66       * Iterator} returned by my underlying {@link java.util.Collection
67       * Collection}, if any.
68       */
69      public BooleanIterator iterator() {
70          return IteratorBooleanIterator.wrap(getCollection().iterator());
71      }
72       
73      public boolean removeElement(boolean element) {
74          return getCollection().remove(new Boolean(element));
75      }
76      
77      public boolean removeAll(BooleanCollection c) {
78          return getCollection().removeAll(BooleanCollectionCollection.wrap(c));
79      }
80          
81      public boolean retainAll(BooleanCollection c) {
82          return getCollection().retainAll(BooleanCollectionCollection.wrap(c));
83      }
84      
85      public int size() {
86          return getCollection().size();
87      }
88      
89      public boolean[] toArray() {
90          Object[] src = getCollection().toArray();
91          boolean[] dest = new boolean[src.length];
92          for(int i=0;i<src.length;i++) {
93              dest[i] = ((Boolean)(src[i])).booleanValue();
94          }
95          return dest;
96      }
97      
98      public boolean[] toArray(boolean[] dest) {
99          Object[] src = getCollection().toArray();
100         if(dest.length < src.length) {
101             dest = new boolean[src.length];
102         }
103         for(int i=0;i<src.length;i++) {
104             dest[i] = ((Boolean)(src[i])).booleanValue();
105         }
106         return dest;
107     }
108     
109     protected abstract Collection getCollection();
110     
111 }