01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com> and
03: * JR Boyens <gnu-jrb[remove] at gmx dot net>
04: * Distributed under the terms of either:
05: * - the common development and distribution license (CDDL), v1.0; or
06: * - the GNU Lesser General Public License, v2.1 or later
07: * $Id: ManyToManySet.java 3634 2007-01-08 21:42:24Z gbevin $
08: */
09: package com.uwyn.rife.database.querymanagers.generic;
10:
11: import java.util.Collection;
12: import java.util.HashSet;
13: import java.util.Iterator;
14: import java.util.Set;
15:
16: class ManyToManySet<E> extends AbstractManyToManyCollection<E>
17: implements Set<E> {
18: private Set<E> mDelegate;
19:
20: ManyToManySet(AbstractGenericQueryManager manager,
21: String columnName1, int objectId,
22: ManyToManyDeclaration declaration) {
23: super (manager, columnName1, objectId, declaration);
24: }
25:
26: protected void ensurePopulatedDelegate() {
27: if (null == mDelegate) {
28: mDelegate = new HashSet<E>(restoreManyToManyMappings());
29: }
30: }
31:
32: public int size() {
33: ensurePopulatedDelegate();
34: return mDelegate.size();
35: }
36:
37: public boolean isEmpty() {
38: ensurePopulatedDelegate();
39: return mDelegate.isEmpty();
40: }
41:
42: public boolean contains(Object o) {
43: ensurePopulatedDelegate();
44: return mDelegate.contains(o);
45: }
46:
47: public Iterator<E> iterator() {
48: ensurePopulatedDelegate();
49: return mDelegate.iterator();
50: }
51:
52: public Object[] toArray() {
53: ensurePopulatedDelegate();
54: return mDelegate.toArray();
55: }
56:
57: public <T extends Object> T[] toArray(T[] a) {
58: ensurePopulatedDelegate();
59: return mDelegate.toArray(a);
60: }
61:
62: public boolean add(E o) {
63: ensurePopulatedDelegate();
64: return mDelegate.add(o);
65: }
66:
67: public boolean remove(Object o) {
68: ensurePopulatedDelegate();
69: return mDelegate.remove(o);
70: }
71:
72: public boolean containsAll(Collection<?> c) {
73: ensurePopulatedDelegate();
74: return mDelegate.containsAll(c);
75: }
76:
77: public boolean addAll(Collection<? extends E> c) {
78: ensurePopulatedDelegate();
79: return mDelegate.addAll(c);
80: }
81:
82: public boolean removeAll(Collection<?> c) {
83: ensurePopulatedDelegate();
84: return mDelegate.removeAll(c);
85: }
86:
87: public boolean retainAll(Collection<?> c) {
88: ensurePopulatedDelegate();
89: return mDelegate.retainAll(c);
90: }
91:
92: public void clear() {
93: ensurePopulatedDelegate();
94: mDelegate.clear();
95: }
96: }
|