blob: ece9e1b91540cd5b96b88fad63f223d288922ca4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
/*
Wotonomy: OpenStep design patterns for pure Java applications.
Copyright (C) 2000 Blacksmith, Inc.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see http://www.gnu.org
*/
package net.wotonomy.foundation;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
/**
* A pure java implementation of NSSet that implements Set for greater java
* interoperability.
*
* @author michael@mpowers.net
* @author $Author: cgruber $
* @version $Revision: 893 $
*/
public class NSSet<T> extends HashSet<T> {
private static final long serialVersionUID = 4211571026717957124L;
/**
* Default constructor.
*/
public NSSet() {
super();
}
/**
* Constructs a NSSet containing the objects in the specified collection.
*/
public NSSet(Collection<T> aCollection) {
super(aCollection);
}
/**
* Constructs a NSSet containing only the specified object.
*/
public NSSet(T anObject) {
super();
add(anObject);
}
/**
* Constructs a NSSet containing the objects in the specified array.
*/
public NSSet(T[] anObjectArray) {
super();
for (int i = 0; i < anObjectArray.length; i++) {
add(anObjectArray[i]);
}
}
/**
* Returns an NSArray containing all objects in the set.
*/
public NSArray<T> allObjects() {
return new NSArray<>(this);
}
/**
* Retrieve an arbitrary object from the set.
*
* @return An arbitrary object from the set
*/
public T anyObject() {
throw new RuntimeException("Not implemented yet.");
}
/**
* Returns whether this set contains the specified object.
*/
public boolean containsObject(Object anObject) {
return contains(anObject);
}
/**
* Returns the number of elements in this set.
*/
public int count() {
return size();
}
/**
* Returns whether this set has one or more elements in common with the
* specified set.
*/
public boolean intersectsSet(Set<T> aSet) {
Iterator<T> it = aSet.iterator();
while (it.hasNext()) {
if (this.containsObject(it.next())) {
return true;
}
}
return false;
}
/**
* Returns whether this set contains the same object as the specified set.
*/
public boolean isEqualToSet(Set<T> aSet) {
return equals(aSet);
}
/**
* Returns whether this set is a subset of the specified set.
*/
public boolean isSubsetOfSet(Set<T> aSet) {
return aSet.containsAll(this);
}
/**
*
*/
public Object member(Object anObject) {
throw new RuntimeException("Not implemented yet.");
}
/**
* Returns an enumerator over the objects in this set.
*/
public Enumeration<T> objectEnumerator() {
return new Vector<>(this).elements();
}
/**
* Returns a set that is the intersection of this set and the specified set.
*/
public NSSet<T> setByIntersectingSet(Set<T> aSet) {
NSSet<T> result = new NSSet<>(this);
result.retainAll(aSet);
return result;
}
/**
* Returns a set that contains all elements in this set that are not in the
* specified set.
*/
public NSSet<T> setBySubtractingSet(Set<T> aSet) {
NSSet<T> result = new NSSet<>(this);
result.removeAll(aSet);
return result;
}
/**
* Returns a set that is the union of this set and the specified set.
*/
public NSSet<T> setByUnioningSet(Set<T> aSet) {
NSSet<T> result = new NSSet<>(this);
result.addAll(aSet);
return result;
}
}
/*
* $Log$ Revision 1.2 2006/02/16 13:15:00 cgruber Check in all sources in
* eclipse-friendly maven-enabled packages.
*
* Revision 1.1.1.1 2000/12/21 15:47:45 mpowers Contributing wotonomy.
*
* Revision 1.3 2000/12/20 16:25:39 michael Added log to all files.
*
*
*/
|