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