comparison org.eclipse.core.databinding/src/org/eclipse/core/internal/databinding/observable/EmptyObservableSet.d @ 78:0a55d2d5a946

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