Mercurial > projects > dwt2
annotate java/src/java/util/ArrayList.d @ 10:eb8ff453285d
Added java.util collection classes.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Fri, 13 Mar 2009 16:57:07 +0100 |
parents | |
children | 9b96950f2c3c |
rev | line source |
---|---|
10
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
1 module java.util.ArrayList; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
2 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
3 import java.lang.all; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
4 import java.util.AbstractList; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 import java.util.List; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 import java.util.ListIterator; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 import java.util.Collection; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
8 import java.util.Iterator; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
9 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
10 static import tango.core.Array; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 class ArrayList : AbstractList, List { |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 private Object[] data; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
14 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
15 this(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
16 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
17 this(int size){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
18 data.length = size; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
19 data.length = 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
20 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
21 this(Collection col){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
22 this(cast(int)(col.size*1.1)); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
23 addAll(col); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
24 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
25 void add(int index, Object element){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
26 data.length = data.length +1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
27 System.arraycopy( data, index, data, index+1, data.length - index -1 ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
28 data[index] = element; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
29 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
30 bool add(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
31 data ~= o; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 return true; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
33 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
34 public bool add(String o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
35 return add(stringcast(o)); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
36 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
37 bool addAll(Collection c){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
38 if( c.size() is 0 ) return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
39 uint idx = data.length; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
40 data.length = data.length + c.size(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
41 foreach( o; c ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
42 data[ idx++ ] = o; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
43 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
44 return true; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
45 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
46 bool addAll(int index, Collection c){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
47 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
48 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
49 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
50 void clear(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
51 data.length = 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
52 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
53 ArrayList clone(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
54 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
55 return null; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
56 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
57 bool contains(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
58 foreach( v; data ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
59 if( o is v ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
60 return true; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
61 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
62 if(( o is null ) || ( v is null )){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
63 continue; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
64 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
65 if( o == v ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
66 return true; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
67 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
68 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
69 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
70 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
71 bool contains(String o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
72 return contains(stringcast(o)); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
73 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
74 bool containsAll(Collection c){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
75 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
76 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
77 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
78 int opEquals(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
79 if( auto other = cast(ArrayList)o ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
80 if( data.length !is other.data.length ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
81 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
82 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
83 for( int i = 0; i < data.length; i++ ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
84 if( data[i] is other.data[i] ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
85 continue; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
86 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
87 if(( data[i] is null ) || ( other.data[i] is null )){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
88 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
89 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
90 if( data[i] == other.data[i] ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
91 continue; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
92 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
93 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
94 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
95 return true; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
96 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
97 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
98 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
99 Object get(int index){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
100 return data[index]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
101 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
102 public override hash_t toHash(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
103 return super.toHash(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
104 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
105 int indexOf(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
106 foreach( i, v; data ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
107 if( data[i] is o ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
108 return i; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
109 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
110 if(( data[i] is null ) || ( o is null )){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
111 continue; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
112 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
113 if( data[i] == o ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
114 return i; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
115 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
116 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
117 return -1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
118 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
119 bool isEmpty(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
120 return data.length is 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
121 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
122 class LocalIterator : Iterator{ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
123 int idx = -1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
124 public this(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
125 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
126 public bool hasNext(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
127 return idx+1 < data.length; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
128 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
129 public Object next(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
130 idx++; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
131 Object res = data[idx]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
132 return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
133 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
134 public void remove(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
135 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
136 this.outer.remove(idx); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
137 idx--; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
138 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
139 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
140 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
141 Iterator iterator(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
142 return new LocalIterator(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
143 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
144 int lastIndexOf(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
145 foreach_reverse( i, v; data ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
146 if( data[i] is o ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
147 return i; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
148 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
149 if(( data[i] is null ) || ( o is null )){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
150 continue; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
151 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
152 if( data[i] == o ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
153 return i; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
154 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
155 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
156 return -1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
157 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
158 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
159 class LocalListIterator : ListIterator { |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
160 int idx_next = 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
161 public bool hasNext(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
162 return idx_next < data.length; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
163 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
164 public Object next(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
165 Object res = data[idx_next]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
166 idx_next++; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
167 return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
168 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
169 public void remove(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
170 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
171 this.outer.remove(idx_next); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
172 idx_next--; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
173 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
174 public void add(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
175 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
176 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
177 public bool add(String o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
178 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
179 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
180 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
181 public bool hasPrevious(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
182 return idx_next > 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
183 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
184 public int nextIndex(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
185 return idx_next; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
186 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
187 public Object previous(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
188 idx_next--; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
189 Object res = data[idx_next]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
190 return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
191 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
192 public int previousIndex(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
193 return idx_next-1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
194 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
195 public void set(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
196 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
197 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
198 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
199 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
200 ListIterator listIterator(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
201 return new LocalListIterator(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
202 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
203 ListIterator listIterator(int index){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
204 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
205 return null; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
206 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
207 Object remove(int index){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
208 Object res = data[index]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
209 System.arraycopy( data, index+1, data, index, data.length - index - 1 ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
210 data.length = data.length -1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
211 return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
212 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
213 bool remove(Object o){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
214 return tango.core.Array.remove(data, o) !is 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
215 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
216 public bool remove(String key){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
217 return remove(stringcast(key)); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
218 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
219 bool removeAll(Collection c){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
220 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
221 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
222 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
223 bool retainAll(Collection c){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
224 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
225 return false; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
226 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
227 protected void removeRange(int fromIndex, int toIndex){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
228 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
229 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
230 Object set(int index, Object element){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
231 Object res = data[index]; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
232 data[index] = element; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
233 return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
234 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
235 int size(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
236 return data.length; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
237 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
238 List subList(int fromIndex, int toIndex){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
239 implMissing( __FILE__, __LINE__ ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
240 return null; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
241 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
242 Object[] toArray(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
243 return data.dup; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
244 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
245 Object[] toArray(Object[] a){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
246 if( data.length <= a.length ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
247 a[ 0 .. data.length ] = data; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
248 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
249 else{ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
250 return data.dup; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
251 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
252 if( data.length < a.length ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
253 a[data.length] = null; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
254 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
255 return a; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
256 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
257 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
258 // only for D |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
259 public int opApply (int delegate(ref Object value) dg){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
260 foreach( o; data ){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
261 auto res = dg( o ); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
262 if( res ) return res; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
263 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
264 return 0; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
265 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
266 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
267 |