comparison org.eclipse.core.databinding.observable/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.d @ 95:6208d4f6a277

Added trees for databinding.beans and observable
author Frank Benoit <benoit@tionex.de>
date Tue, 21 Apr 2009 10:55:51 +0200
parents
children b74ac5dfcc06
comparison
equal deleted inserted replaced
94:1d37a7813832 95:6208d4f6a277
1 /*******************************************************************************
2 * Copyright (c) 2006, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors:
9 * IBM Corporation - initial API and implementation
10 * Matthew Hall - bug 208332
11 *******************************************************************************/
12
13 package org.eclipse.core.internal.databinding.observable;
14
15 import java.util.Collection;
16 import java.util.Collections;
17 import java.util.Iterator;
18 import java.util.Set;
19
20 import org.eclipse.core.databinding.observable.IChangeListener;
21 import org.eclipse.core.databinding.observable.IStaleListener;
22 import org.eclipse.core.databinding.observable.Realm;
23 import org.eclipse.core.databinding.observable.set.IObservableSet;
24 import org.eclipse.core.databinding.observable.set.ISetChangeListener;
25 import org.eclipse.core.runtime.Assert;
26
27 /**
28 * Singleton empty set
29 */
30 public class EmptyObservableSet : IObservableSet {
31
32 private static final Set emptySet = Collections.EMPTY_SET;
33
34 private Realm realm;
35 private Object elementType;
36
37 /**
38 * Creates a singleton empty set. This set may be disposed multiple times
39 * without any side-effects.
40 *
41 * @param realm
42 * the realm of the constructed set
43 */
44 public this(Realm realm) {
45 this(realm, null);
46 }
47
48 /**
49 * Creates a singleton empty set. This set may be disposed multiple times
50 * without any side-effects.
51 *
52 * @param realm
53 * the realm of the constructed set
54 * @param elementType
55 * the element type of the constructed set
56 * @since 1.1
57 */
58 public this(Realm realm, Object elementType) {
59 this.realm = realm;
60 this.elementType = elementType;
61 }
62
63 public void addSetChangeListener(ISetChangeListener listener) {
64 }
65
66 public void removeSetChangeListener(ISetChangeListener listener) {
67 }
68
69 public Object getElementType() {
70 return elementType;
71 }
72
73 public int size() {
74 checkRealm();
75 return 0;
76 }
77
78 private void checkRealm() {
79 Assert.isTrue(realm.isCurrent(),
80 "Observable cannot be accessed outside its realm"); //$NON-NLS-1$
81 }
82
83 public bool isEmpty() {
84 checkRealm();
85 return true;
86 }
87
88 public bool contains(Object o) {
89 checkRealm();
90 return false;
91 }
92
93 public Iterator iterator() {
94 checkRealm();
95 return emptySet.iterator();
96 }
97
98 public Object[] toArray() {
99 checkRealm();
100 return emptySet.toArray();
101 }
102
103 public Object[] toArray(Object[] a) {
104 return emptySet.toArray(a);
105 }
106
107 public bool add(Object o) {
108 throw new UnsupportedOperationException();
109 }
110
111 public bool remove(Object o) {
112 throw new UnsupportedOperationException();
113 }
114
115 public bool containsAll(Collection c) {
116 checkRealm();
117 return c.isEmpty();
118 }
119
120 public bool addAll(Collection c) {
121 throw new UnsupportedOperationException();
122 }
123
124 public bool retainAll(Collection c) {
125 throw new UnsupportedOperationException();
126 }
127
128 public bool removeAll(Collection c) {
129 throw new UnsupportedOperationException();
130 }
131
132 public void clear() {
133 throw new UnsupportedOperationException();
134 }
135
136 public void addChangeListener(IChangeListener listener) {
137 }
138
139 public void removeChangeListener(IChangeListener listener) {
140 }
141
142 public void addStaleListener(IStaleListener listener) {
143 }
144
145 public void removeStaleListener(IStaleListener listener) {
146 }
147
148 public bool isStale() {
149 checkRealm();
150 return false;
151 }
152
153 public void dispose() {
154 }
155
156 public Realm getRealm() {
157 return realm;
158 }
159
160 public override equals_t opEquals(Object obj) {
161 checkRealm();
162 if (obj is this)
163 return true;
164 if (obj is null)
165 return false;
166 if (!( null !is cast(Set)obj ))
167 return false;
168
169 return (cast(Set) obj).isEmpty();
170 }
171
172 public override hash_t toHash() {
173 checkRealm();
174 return 0;
175 }
176 }