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