78
|
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 208858
|
|
11 * Matthew Hall - bug 208332
|
|
12 *******************************************************************************/
|
|
13
|
|
14 module org.eclipse.core.internal.databinding.observable.EmptyObservableList;
|
|
15
|
|
16 import java.lang.all;
|
|
17
|
|
18 import java.util.Collection;
|
|
19 import java.util.Collections;
|
|
20 import java.util.Iterator;
|
|
21 import java.util.List;
|
|
22 import java.util.ListIterator;
|
|
23
|
|
24 import org.eclipse.core.databinding.observable.IChangeListener;
|
|
25 import org.eclipse.core.databinding.observable.IStaleListener;
|
|
26 import org.eclipse.core.databinding.observable.Realm;
|
|
27 import org.eclipse.core.databinding.observable.list.IListChangeListener;
|
|
28 import org.eclipse.core.databinding.observable.list.IObservableList;
|
|
29 import org.eclipse.core.runtime.Assert;
|
|
30
|
|
31 /**
|
|
32 * Singleton empty list
|
|
33 */
|
|
34 public class EmptyObservableList : IObservableList {
|
85
|
35 // DWT start: additional methods in List
|
|
36 public bool add(String o) {
|
|
37 return add(stringcast(o));
|
|
38 }
|
|
39 public bool remove(String o) {
|
|
40 return remove(stringcast(o));
|
|
41 }
|
|
42 public bool contains(String o) {
|
|
43 return contains(stringcast(o));
|
|
44 }
|
|
45 public int opApply (int delegate(ref Object value) dg){
|
|
46 auto it = iterator();
|
|
47 while(it.hasNext()){
|
|
48 auto v = it.next();
|
|
49 int res = dg( v );
|
|
50 if( res ) return res;
|
|
51 }
|
|
52 return 0;
|
|
53 }
|
|
54 public String[] toArray( String[] a ){
|
|
55 auto d = toArray();
|
|
56 if( a.length < d.length ){
|
|
57 a.length = d.length;
|
|
58 }
|
|
59 for( int i = 0; i < d.length; i++ ){
|
|
60 a[i] = stringcast(d[i]);
|
|
61 }
|
|
62 return a;
|
|
63 }
|
|
64 // DWT end: additional methods in List
|
78
|
65
|
85
|
66 private static List emptyList;
|
|
67 static this(){
|
|
68 emptyList = Collections.EMPTY_LIST;
|
|
69 }
|
78
|
70
|
|
71 private Realm realm;
|
|
72 private Object elementType;
|
|
73
|
|
74 /**
|
|
75 * Creates an empty list. This list may be disposed multiple times
|
|
76 * without any side-effects.
|
|
77 *
|
|
78 * @param realm
|
|
79 * the realm of the constructed list
|
|
80 */
|
|
81 public this(Realm realm) {
|
|
82 this(realm, null);
|
|
83 }
|
|
84
|
|
85 /**
|
|
86 * Creates an empty list. This list may be disposed multiple times
|
|
87 * without any side-effects.
|
|
88 *
|
|
89 * @param realm
|
|
90 * the realm of the constructed list
|
|
91 * @param elementType
|
|
92 * the element type of the constructed list
|
|
93 * @since 1.1
|
|
94 */
|
|
95 public this(Realm realm, Object elementType) {
|
|
96 this.realm = realm;
|
|
97 this.elementType = elementType;
|
|
98 }
|
|
99
|
|
100 public void addListChangeListener(IListChangeListener listener) {
|
|
101 // ignore
|
|
102 }
|
|
103
|
|
104 public void removeListChangeListener(IListChangeListener listener) {
|
|
105 // ignore
|
|
106 }
|
|
107
|
|
108 public Object getElementType() {
|
|
109 return elementType;
|
|
110 }
|
|
111
|
|
112 public int size() {
|
|
113 checkRealm();
|
|
114 return 0;
|
|
115 }
|
|
116
|
|
117 void checkRealm() {
|
|
118 Assert.isTrue(realm.isCurrent(),
|
|
119 "Observable cannot be accessed outside its realm"); //$NON-NLS-1$
|
|
120 }
|
|
121
|
|
122 public bool isEmpty() {
|
|
123 checkRealm();
|
|
124 return true;
|
|
125 }
|
|
126
|
|
127 public bool contains(Object o) {
|
|
128 checkRealm();
|
|
129 return false;
|
|
130 }
|
|
131
|
|
132 public Iterator iterator() {
|
|
133 checkRealm();
|
|
134 return emptyList.iterator();
|
|
135 }
|
|
136
|
|
137 public Object[] toArray() {
|
|
138 checkRealm();
|
|
139 return emptyList.toArray();
|
|
140 }
|
|
141
|
|
142 public Object[] toArray(Object[] a) {
|
|
143 return emptyList.toArray(a);
|
|
144 }
|
|
145
|
|
146 public bool add(Object o) {
|
|
147 throw new UnsupportedOperationException();
|
|
148 }
|
|
149
|
|
150 public bool remove(Object o) {
|
|
151 throw new UnsupportedOperationException();
|
|
152 }
|
|
153
|
|
154 public bool containsAll(Collection c) {
|
|
155 checkRealm();
|
|
156 return c.isEmpty();
|
|
157 }
|
|
158
|
|
159 public bool addAll(Collection c) {
|
|
160 throw new UnsupportedOperationException();
|
|
161 }
|
|
162
|
|
163 public bool retainAll(Collection c) {
|
|
164 throw new UnsupportedOperationException();
|
|
165 }
|
|
166
|
|
167 public bool removeAll(Collection c) {
|
|
168 throw new UnsupportedOperationException();
|
|
169 }
|
|
170
|
|
171 public void clear() {
|
|
172 throw new UnsupportedOperationException();
|
|
173 }
|
|
174
|
|
175 public void addChangeListener(IChangeListener listener) {
|
|
176 }
|
|
177
|
|
178 public void removeChangeListener(IChangeListener listener) {
|
|
179 }
|
|
180
|
|
181 public void addStaleListener(IStaleListener listener) {
|
|
182 }
|
|
183
|
|
184 public void removeStaleListener(IStaleListener listener) {
|
|
185 }
|
|
186
|
|
187 public bool isStale() {
|
|
188 checkRealm();
|
|
189 return false;
|
|
190 }
|
|
191
|
|
192 public void dispose() {
|
|
193 }
|
|
194
|
|
195 public bool addAll(int index, Collection c) {
|
|
196 throw new UnsupportedOperationException();
|
|
197 }
|
|
198
|
|
199 public Object get(int index) {
|
|
200 return emptyList.get(index);
|
|
201 }
|
|
202
|
|
203 public int indexOf(Object o) {
|
|
204 return -1;
|
|
205 }
|
|
206
|
|
207 public int lastIndexOf(Object o) {
|
|
208 return -1;
|
|
209 }
|
|
210
|
|
211 public ListIterator listIterator() {
|
|
212 return emptyList.listIterator();
|
|
213 }
|
|
214
|
|
215 public ListIterator listIterator(int index) {
|
|
216 return emptyList.listIterator(index);
|
|
217 }
|
|
218
|
|
219 public Object remove(int index) {
|
|
220 throw new UnsupportedOperationException();
|
|
221 }
|
|
222
|
|
223 public Object set(int index, Object element) {
|
|
224 throw new UnsupportedOperationException();
|
|
225 }
|
|
226
|
|
227 public Object move(int oldIndex, int newIndex) {
|
|
228 throw new UnsupportedOperationException();
|
|
229 }
|
|
230
|
|
231 public List subList(int fromIndex, int toIndex) {
|
|
232 return emptyList.subList(fromIndex, toIndex);
|
|
233 }
|
|
234
|
|
235 public void add(int index, Object o) {
|
|
236 throw new UnsupportedOperationException();
|
|
237 }
|
|
238
|
|
239 public Realm getRealm() {
|
|
240 return realm;
|
|
241 }
|
|
242
|
85
|
243 public override equals_t opEquals(Object obj) {
|
78
|
244 checkRealm();
|
|
245 if (obj is this)
|
|
246 return true;
|
|
247 if (obj is null)
|
|
248 return false;
|
|
249 if (!( null !is cast(List)obj ))
|
|
250 return false;
|
|
251
|
|
252 return (cast(List) obj).isEmpty();
|
|
253 }
|
|
254
|
85
|
255 public hash_t toHash() {
|
78
|
256 checkRealm();
|
|
257 return 1;
|
|
258 }
|
|
259 }
|