Mercurial > projects > dwt2
annotate base/src/java/util/AbstractList.d @ 84:fcf926c91ca4
Added base classes
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Apr 2009 09:25:29 +0200 |
parents | 1bf55a6eb092 |
children |
rev | line source |
---|---|
10
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
1 module java.util.AbstractList; |
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.Collection; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
5 import java.util.AbstractCollection; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
6 import java.util.List; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
7 import java.util.ListIterator; |
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 abstract class AbstractList : AbstractCollection, List { |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
11 this(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
12 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
13 |
84 | 14 public void add(int index, Object element){ |
15 throw new UnsupportedOperationException(); | |
16 } | |
17 public bool add(String o){ | |
18 return add(stringcast(o)); | |
19 } | |
20 public bool add(Object o){ | |
21 add(size(), o); | |
22 return true; | |
23 } | |
24 public bool addAll(Collection c){ | |
25 throw new UnsupportedOperationException(); | |
26 } | |
27 public bool addAll(int index, Collection c){ | |
28 throw new UnsupportedOperationException(); | |
29 } | |
30 public void clear(){ | |
31 throw new UnsupportedOperationException(); | |
10
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
32 } |
84 | 33 public bool contains(Object o){ return super.contains(o); } |
34 public bool contains(String str){ return contains(stringcast(str)); } | |
35 public bool containsAll(Collection c){ return super.containsAll(c); } | |
36 public equals_t opEquals(Object o){ | |
37 if( auto other = cast(List)o ){ | |
38 if( other is cast(List)this ){ | |
39 return true; | |
40 } | |
41 auto it1 = this.iterator(); | |
42 auto it2 = other.iterator(); | |
43 while(true){ | |
44 bool n1 = it1.hasNext(); | |
45 bool n2 = it2.hasNext(); | |
46 if( !n1 && !n2 ) return true; | |
47 if( (n1 && !n2) || (!n1 && n2 )) return false; | |
48 Object o1 = it1.next(); | |
49 Object o2 = it2.next(); | |
50 if( o1 is null ){ | |
51 if( o2 !is null ){ | |
52 return false; | |
53 } | |
54 } | |
55 else{ | |
56 if( o2 is null ){ | |
57 return false; | |
58 } | |
59 if( o1 != o2 ){ | |
60 return false; | |
61 } | |
62 } | |
63 } | |
64 } | |
65 return false; | |
66 } | |
67 | |
68 public abstract Object get(int index); | |
10
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
69 |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
70 public hash_t toHash(){ |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
71 // http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html#hashCode() |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
72 hash_t hashCode = 1; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
73 Iterator i = iterator(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
74 while (i.hasNext()) { |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
75 Object obj = i.next(); |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
76 hashCode = 31 * hashCode + (obj is null ? 0 : obj.toHash()); |
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 return hashCode; |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
79 } |
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
80 |
84 | 81 public int indexOf(Object o){ |
82 auto it = listIterator(); | |
83 int idx = 0; | |
84 while(it.hasNext()){ | |
85 auto t = it.next(); | |
86 if( t is null ? o is null : t == o){ | |
87 return idx; | |
88 } | |
89 idx++; | |
90 } | |
91 return -1; | |
92 } | |
93 public bool isEmpty(){ | |
94 return super.isEmpty(); | |
95 } | |
96 public Iterator iterator(){ | |
97 implMissing( __FILE__, __LINE__ ); | |
98 return null; | |
99 } | |
100 public int lastIndexOf(Object o){ | |
101 implMissing( __FILE__, __LINE__ ); | |
102 return 0; | |
103 } | |
104 public ListIterator listIterator(){ | |
105 implMissing( __FILE__, __LINE__ ); | |
106 return null; | |
107 } | |
108 public ListIterator listIterator(int index){ | |
109 implMissing( __FILE__, __LINE__ ); | |
110 return null; | |
111 } | |
112 public Object remove(int index){ | |
113 throw new UnsupportedOperationException(); | |
114 } | |
115 protected void removeRange(int fromIndex, int toIndex){ | |
116 } | |
117 public bool remove(Object o){ return super.remove(o); } | |
118 public bool remove(String o){ return super.remove(o); } | |
119 public bool removeAll(Collection c){ return super.removeAll(c); } | |
120 public bool retainAll(Collection c){ return super.retainAll(c); } | |
121 public Object set(int index, Object element){ | |
122 throw new UnsupportedOperationException(); | |
123 } | |
124 public List subList(int fromIndex, int toIndex){ | |
125 implMissing( __FILE__, __LINE__ ); | |
126 return null; | |
127 } | |
128 public Object[] toArray(){ return super.toArray(); } | |
129 public Object[] toArray(Object[] a){ return super.toArray(a); } | |
130 public String[] toArray(String[] a){ return super.toArray(a); } | |
131 public int opApply (int delegate(ref Object value) dg){ | |
132 implMissing( __FILE__, __LINE__ ); | |
133 return 0; | |
134 } | |
10
eb8ff453285d
Added java.util collection classes.
Frank Benoit <benoit@tionex.de>
parents:
diff
changeset
|
135 |
84 | 136 public String toString(){ |
137 return super.toString(); | |
138 } | |
10
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 |