01: /*
02: * Primitive Collections for Java.
03: * Copyright (C) 2002, 2003 Søren Bak
04: *
05: * This library is free software; you can redistribute it and/or
06: * modify it under the terms of the GNU Lesser General Public
07: * License as published by the Free Software Foundation; either
08: * version 2.1 of the License, or (at your option) any later version.
09: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library; if not, write to the Free Software
17: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: */
19: package bak.pcj.set;
20:
21: import bak.pcj.AbstractLongCollection;
22: import bak.pcj.LongIterator;
23: import bak.pcj.hash.DefaultLongHashFunction;
24:
25: /**
26: * This class represents an abstract base for implementing
27: * sets of long values. All operations that can be implemented
28: * using iterators and the <tt>get()</tt> and <tt>set()</tt> methods
29: * are implemented as such. In most cases, this is
30: * hardly an efficient solution, and at least some of those
31: * methods should be overridden by sub-classes.
32: *
33: * @author Søren Bak
34: * @version 1.1 2003/1/10
35: * @since 1.0
36: */
37: public abstract class AbstractLongSet extends AbstractLongCollection
38: implements LongSet {
39:
40: /** Default constructor to be invoked by sub-classes. */
41: protected AbstractLongSet() {
42: }
43:
44: public boolean equals(Object obj) {
45: if (!(obj instanceof LongSet))
46: return false;
47: LongSet s = (LongSet) obj;
48: if (s.size() != size())
49: return false;
50: return containsAll(s);
51: }
52:
53: public int hashCode() {
54: int h = 0;
55: LongIterator i = iterator();
56: while (i.hasNext())
57: h += DefaultLongHashFunction.INSTANCE.hash(i.next());
58: return h;
59: }
60:
61: }
|