comparison dwtx/dwtxhelper/Collection.d @ 101:1082a0fc2bb8

First Draw2D example running
author Frank Benoit <benoit@tionex.de>
date Sun, 03 Aug 2008 02:17:46 +0200
parents 86617aa6b5dd
children 04b47443bb01
comparison
equal deleted inserted replaced
100:86617aa6b5dd 101:1082a0fc2bb8
2 2
3 import dwt.dwthelper.utils; 3 import dwt.dwthelper.utils;
4 4
5 static import tango.util.container.CircularList; 5 static import tango.util.container.CircularList;
6 static import tango.util.container.HashMap; 6 static import tango.util.container.HashMap;
7 static import tango.util.container.HashSet;
7 static import tango.util.container.SortedMap; 8 static import tango.util.container.SortedMap;
8 static import tango.util.container.more.Vector; 9 static import tango.util.container.more.Vector;
9 10
10 interface Iterator{ 11 interface Iterator{
11 public bool hasNext(); 12 public bool hasNext();
108 public void remove(); 109 public void remove();
109 public void set(Object o); 110 public void set(Object o);
110 } 111 }
111 class Collections { 112 class Collections {
112 113
113 public static List EMPTY_LIST; 114 private static List EMPTY_LIST_;
115 public static List EMPTY_LIST(){
116 if( EMPTY_LIST_ is null ){
117 synchronized(Collections.classinfo ){
118 if( EMPTY_LIST_ is null ){
119 EMPTY_LIST_ = new ArrayList(0);
120 }
121 }
122 }
123 return EMPTY_LIST_;
124 }
114 125
115 public static List unmodifiableList( List list ){ 126 public static List unmodifiableList( List list ){
116 return null; 127 return null;
117 } 128 }
118 public static void sort(List list){ 129 public static void sort(List list){
167 return true; 178 return true;
168 } 179 }
169 return false; 180 return false;
170 } 181 }
171 public Object get(Object key){ 182 public Object get(Object key){
172 implMissing( __FILE__, __LINE__ ); 183 if( auto v = key in map ){
184 return *v;
185 }
173 return null; 186 return null;
174 } 187 }
175 public override hash_t toHash(){ 188 public override hash_t toHash(){
176 return super.toHash(); 189 return super.toHash();
177 } 190 }
178 public bool isEmpty(){ 191 public bool isEmpty(){
179 return map.isEmpty(); 192 return map.isEmpty();
180 } 193 }
181 public Set keySet(){ 194 public Set keySet(){
182 implMissing( __FILE__, __LINE__ ); 195 HashSet res = new HashSet();
183 return null; 196 foreach( k, v; map ){
197 res.add(k);
198 }
199 return res;
184 } 200 }
185 public Object put(Object key, Object value){ 201 public Object put(Object key, Object value){
186 Object res = null; 202 Object res = null;
187 if( auto vold = key in map ){ 203 if( auto vold = key in map ){
188 res = *vold; 204 res = *vold;
308 return map.opApply( dg ); 324 return map.opApply( dg );
309 } 325 }
310 } 326 }
311 327
312 class HashSet : Set { 328 class HashSet : Set {
313 public this(){} 329 alias tango.util.container.HashSet.HashSet!(Object) SetType;
314 public this(Collection c){} 330 private SetType set;
315 public this(int initialCapacity){} 331
316 public this(int initialCapacity, float loadFactor){} 332 public this(){
333 set = new SetType();
334 }
335 public this(Collection c){
336 implMissing( __FILE__, __LINE__ );
337 }
338 public this(int initialCapacity){
339 implMissing( __FILE__, __LINE__ );
340 }
341 public this(int initialCapacity, float loadFactor){
342 implMissing( __FILE__, __LINE__ );
343 }
317 public bool add(Object o){ 344 public bool add(Object o){
318 implMissing( __FILE__, __LINE__ ); 345 return set.add(o);
319 return false;
320 } 346 }
321 public bool addAll(Collection c){ 347 public bool addAll(Collection c){
322 implMissing( __FILE__, __LINE__ ); 348 implMissing( __FILE__, __LINE__ );
323 return false; 349 return false;
324 } 350 }
325 public void clear(){ 351 public void clear(){
326 implMissing( __FILE__, __LINE__ ); 352 set.clear();
327 } 353 }
328 public bool contains(Object o){ 354 public bool contains(Object o){
329 implMissing( __FILE__, __LINE__ ); 355 return set.contains(o);
330 return false;
331 } 356 }
332 public bool containsAll(Collection c){ 357 public bool containsAll(Collection c){
333 implMissing( __FILE__, __LINE__ ); 358 implMissing( __FILE__, __LINE__ );
334 return false; 359 return false;
335 } 360 }
340 public override hash_t toHash(){ 365 public override hash_t toHash(){
341 implMissing( __FILE__, __LINE__ ); 366 implMissing( __FILE__, __LINE__ );
342 return 0; 367 return 0;
343 } 368 }
344 public bool isEmpty(){ 369 public bool isEmpty(){
345 implMissing( __FILE__, __LINE__ ); 370 return set.isEmpty();
346 return false; 371 }
372 class LocalIterator : Iterator {
373 SetType.Iterator iter;
374 Object nextElem;
375 this( SetType.Iterator iter){
376 this.iter = iter;
377 }
378 public bool hasNext(){
379 return iter.next(nextElem);
380 }
381 public Object next(){
382 return nextElem;
383 }
384 public void remove(){
385 iter.remove();
386 }
347 } 387 }
348 public Iterator iterator(){ 388 public Iterator iterator(){
349 implMissing( __FILE__, __LINE__ ); 389 return new LocalIterator(set.iterator());
350 return null;
351 } 390 }
352 public bool remove(Object o){ 391 public bool remove(Object o){
353 implMissing( __FILE__, __LINE__ ); 392 return set.remove(o);
354 return false;
355 } 393 }
356 public bool removeAll(Collection c){ 394 public bool removeAll(Collection c){
357 implMissing( __FILE__, __LINE__ ); 395 implMissing( __FILE__, __LINE__ );
358 return false; 396 return false;
359 } 397 }
360 public bool retainAll(Collection c){ 398 public bool retainAll(Collection c){
361 implMissing( __FILE__, __LINE__ ); 399 implMissing( __FILE__, __LINE__ );
362 return false; 400 return false;
363 } 401 }
364 public int size(){ 402 public int size(){
365 implMissing( __FILE__, __LINE__ ); 403 return set.size();
366 return 0;
367 } 404 }
368 public Object[] toArray(){ 405 public Object[] toArray(){
369 implMissing( __FILE__, __LINE__ ); 406 implMissing( __FILE__, __LINE__ );
370 return null; 407 return null;
371 } 408 }
937 } 974 }
938 this(Collection){ 975 this(Collection){
939 implMissing( __FILE__, __LINE__ ); 976 implMissing( __FILE__, __LINE__ );
940 } 977 }
941 void add(int index, Object element){ 978 void add(int index, Object element){
942 implMissing( __FILE__, __LINE__ ); 979 data.length = data.length +1;
980 System.arraycopy( data, index, data, index+1, data.length - index -1 );
981 data[index] = element;
943 } 982 }
944 bool add(Object o){ 983 bool add(Object o){
945 984 data ~= o;
946 implMissing( __FILE__, __LINE__ ); 985 return true;
947 return false;
948 } 986 }
949 bool addAll(Collection c){ 987 bool addAll(Collection c){
950 implMissing( __FILE__, __LINE__ ); 988 implMissing( __FILE__, __LINE__ );
951 return false; 989 return false;
952 } 990 }
953 bool addAll(int index, Collection c){ 991 bool addAll(int index, Collection c){
954 implMissing( __FILE__, __LINE__ ); 992 implMissing( __FILE__, __LINE__ );
955 return false; 993 return false;
956 } 994 }
957 void clear(){ 995 void clear(){
958 implMissing( __FILE__, __LINE__ ); 996 data.length = 0;
959 } 997 }
960 bool contains(Object o){ 998 bool contains(Object o){
961 implMissing( __FILE__, __LINE__ ); 999 foreach( v; data ){
1000 if( o is v ){
1001 return true;
1002 }
1003 if(( o is null ) || ( v is null )){
1004 continue;
1005 }
1006 if( o == v ){
1007 return true;
1008 }
1009 }
962 return false; 1010 return false;
963 } 1011 }
964 bool containsAll(Collection c){ 1012 bool containsAll(Collection c){
965 implMissing( __FILE__, __LINE__ ); 1013 implMissing( __FILE__, __LINE__ );
966 return false; 1014 return false;
1007 return -1; 1055 return -1;
1008 } 1056 }
1009 bool isEmpty(){ 1057 bool isEmpty(){
1010 return data.length is 0; 1058 return data.length is 0;
1011 } 1059 }
1060 class LocalIterator : Iterator{
1061 int idx = 0;
1062 public this(){
1063 }
1064 public bool hasNext(){
1065 return idx < data.length;
1066 }
1067 public Object next(){
1068 Object res = data[idx];
1069 idx++;
1070 return res;
1071 }
1072 public void remove(){
1073 implMissing( __FILE__, __LINE__ );
1074 this.outer.remove(idx);
1075 idx--;
1076 }
1077 }
1078
1012 Iterator iterator(){ 1079 Iterator iterator(){
1013 implMissing( __FILE__, __LINE__ ); 1080 return new LocalIterator();
1014 return null;
1015 } 1081 }
1016 int lastIndexOf(Object o){ 1082 int lastIndexOf(Object o){
1017 foreach_reverse( i, v; data ){ 1083 foreach_reverse( i, v; data ){
1018 if( data[i] is o ){ 1084 if( data[i] is o ){
1019 return i; 1085 return i;
1035 implMissing( __FILE__, __LINE__ ); 1101 implMissing( __FILE__, __LINE__ );
1036 return null; 1102 return null;
1037 } 1103 }
1038 Object remove(int index){ 1104 Object remove(int index){
1039 Object res = data[index]; 1105 Object res = data[index];
1040 data[ index .. $-1] = data[ index+1 .. $ ]; 1106 System.arraycopy( data, index+1, data, index, data.length - index - 1 );
1041 data.length = data.length -1; 1107 data.length = data.length -1;
1042 return res; 1108 return res;
1043 } 1109 }
1044 bool remove(Object o){ 1110 bool remove(Object o){
1045 implMissing( __FILE__, __LINE__ ); 1111 implMissing( __FILE__, __LINE__ );
1052 bool retainAll(Collection c){ 1118 bool retainAll(Collection c){
1053 implMissing( __FILE__, __LINE__ ); 1119 implMissing( __FILE__, __LINE__ );
1054 return false; 1120 return false;
1055 } 1121 }
1056 Object set(int index, Object element){ 1122 Object set(int index, Object element){
1057 implMissing( __FILE__, __LINE__ ); 1123 Object res = data[index];
1058 return null; 1124 data[index] = element;
1125 return res;
1059 } 1126 }
1060 int size(){ 1127 int size(){
1061 implMissing( __FILE__, __LINE__ ); 1128 return data.length;
1062 return 0;
1063 } 1129 }
1064 List subList(int fromIndex, int toIndex){ 1130 List subList(int fromIndex, int toIndex){
1065 implMissing( __FILE__, __LINE__ ); 1131 implMissing( __FILE__, __LINE__ );
1066 return null; 1132 return null;
1067 } 1133 }