-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSet.java
69 lines (53 loc) · 1.63 KB
/
Set.java
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
// $Id$
//
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <[email protected]>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// Set
// Encapsulate a mathematical "Set" ADT using java's
// hash table. Just a convenience wrapper of the java.util.Hashtable class.
package EDU.Washington.grad.gjb.cassowary;
import java.util.*;
class Set {
public Set()
{ hash = new Hashtable(); }
public Set(int i)
{ hash = new Hashtable(i); }
public Set(int i, float f)
{ hash = new Hashtable(i,f); }
public Set(Hashtable h)
{ hash = h; }
public boolean containsKey(Object o)
{ return hash.containsKey(o); }
public boolean insert(Object o)
{ return hash.put(o,o) == null? true: false; }
public boolean remove(Object o)
{ return hash.remove(o) == null? true: false; }
public void clear()
{ hash.clear(); }
public int size()
{ return hash.size(); }
public boolean isEmpty()
{ return hash.isEmpty(); }
public Object clone()
{ return new Set((Hashtable) hash.clone()); }
public Enumeration elements()
{ return hash.elements(); }
public String toString()
{
StringBuffer bstr = new StringBuffer("{ ");
Enumeration e = hash.keys();
if (e.hasMoreElements())
bstr.append(e.nextElement().toString());
while ( e.hasMoreElements() ) {
bstr.append(", " + e.nextElement());
}
bstr.append(" }\n");
return bstr.toString();
}
private Hashtable hash;
}