View Javadoc

1   /*
2    * Copyright (c) 2003, Henri Yandell
3    * All rights reserved.
4    * 
5    * Redistribution and use in source and binary forms, with or 
6    * without modification, are permitted provided that the 
7    * following conditions are met:
8    * 
9    * + Redistributions of source code must retain the above copyright notice, 
10   *   this list of conditions and the following disclaimer.
11   * 
12   * + Redistributions in binary form must reproduce the above copyright notice, 
13   *   this list of conditions and the following disclaimer in the documentation 
14   *   and/or other materials provided with the distribution.
15   * 
16   * + Neither the name of Genjava-Core nor the names of its contributors 
17   *   may be used to endorse or promote products derived from this software 
18   *   without specific prior written permission.
19   * 
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
23   * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
30   * POSSIBILITY OF SUCH DAMAGE.
31   */
32  package com.generationjava.collections;
33  
34  import java.util.Set;
35  import java.util.Collection;
36  import java.util.Iterator;
37  
38  /***
39   * A Set which wraps another Set. Intended mainly to 
40   * be used as a superclass.
41   */
42  public class ProxySet implements Set {
43  
44      private Set set;
45      
46      public ProxySet(Set set) {
47          this.set = set;
48      }
49  
50      public boolean add(Object obj) {
51       // Adds the specified element to this set if it is not already present (optional operation).	 
52          return this.set.add(obj);
53      }
54  
55      public boolean addAll(Collection c) {
56       // Adds all of the elements in the specified collection to this set if they're not already present (optional operation).	 
57          return this.set.addAll(c);
58      }
59  
60      public void clear() {
61       // Removes all of the elements from this set (optional operation).	 
62          this.set.clear();
63      }
64  
65      public boolean contains(Object obj) {
66       // Returns true if this set contains the specified element.	 
67          return this.set.contains(obj);
68      }
69  
70      public boolean containsAll(Collection c) {
71       // Returns true if this set contains all of the elements of the specified collection.	 
72          return this.set.containsAll(c);
73      }
74  
75      public boolean equals(Object obj) {
76       // Compares the specified object with this set for equality.
77          return this.set.equals(obj);
78      }
79  
80      public int hashCode() {
81       // Returns the hash code value for this this.set.	 
82          return this.set.hashCode();
83      }
84  
85      public boolean isEmpty() {
86       // Returns true if this set contains no elements.	 
87          return this.set.isEmpty();
88      }
89  
90      public Iterator iterator() {
91       // Returns an iterator over the elements in this this.set.	 
92          return this.set.iterator();
93      }
94  
95      public boolean remove(Object obj) {
96       // Removes the specified element from this set if it is present (optional operation).	 
97          return this.set.remove(obj);
98      }
99  
100     public boolean removeAll(Collection c) {
101      // Removes from this set all of its elements that are contained in the specified collection (optional operation).	 
102         return this.set.removeAll(c);
103     }
104 
105     public boolean retainAll(Collection c) {
106      // Retains only the elements in this set that are contained in the specified collection (optional operation).	 
107         return this.set.retainAll(c);
108     }
109 
110     public int size() {
111      // Returns the number of elements in this set (its cardinality).	 
112         return this.set.size();
113     }
114 
115     public Object[] toArray() {	      
116      // Returns an array containing all of the elements in this this.set.	 
117         return this.set.toArray();
118     }
119 
120     public Object[] toArray(Object[] arr) {	      
121      // Returns an array containing all of the elements in this set whose runtime type is that of the specified array.
122         return this.set.toArray(arr);
123     }
124 
125 }