comparison 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
comparison
equal deleted inserted replaced
83:0628aaa2996c 84:fcf926c91ca4
9 9
10 abstract class AbstractList : AbstractCollection, List { 10 abstract class AbstractList : AbstractCollection, List {
11 this(){ 11 this(){
12 } 12 }
13 13
14 public abstract void add(int index, Object element); 14 public void add(int index, Object element){
15 public abstract bool add(Object o); 15 throw new UnsupportedOperationException();
16 public abstract bool addAll(Collection c);
17 public abstract bool addAll(int index, Collection c);
18 public abstract void clear();
19 public abstract bool contains(Object o);
20 public bool contains(String str){
21 return contains(stringcast(str));
22 } 16 }
23 public abstract bool containsAll(Collection c); 17 public bool add(String o){
24 public abstract equals_t opEquals(Object o); 18 return add(stringcast(o));
25 public abstract Object get(int index); 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();
32 }
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);
26 69
27 public hash_t toHash(){ 70 public hash_t toHash(){
28 // http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html#hashCode() 71 // http://java.sun.com/j2se/1.4.2/docs/api/java/util/List.html#hashCode()
29 hash_t hashCode = 1; 72 hash_t hashCode = 1;
30 Iterator i = iterator(); 73 Iterator i = iterator();
33 hashCode = 31 * hashCode + (obj is null ? 0 : obj.toHash()); 76 hashCode = 31 * hashCode + (obj is null ? 0 : obj.toHash());
34 } 77 }
35 return hashCode; 78 return hashCode;
36 } 79 }
37 80
38 public abstract int indexOf(Object o); 81 public int indexOf(Object o){
39 public abstract bool isEmpty(); 82 auto it = listIterator();
40 public abstract Iterator iterator(); 83 int idx = 0;
41 public abstract int lastIndexOf(Object o); 84 while(it.hasNext()){
42 public abstract ListIterator listIterator(); 85 auto t = it.next();
43 public abstract ListIterator listIterator(int index); 86 if( t is null ? o is null : t == o){
44 public abstract Object remove(int index); 87 return idx;
45 protected abstract void removeRange(int fromIndex, int toIndex); 88 }
46 public abstract bool remove(Object o); 89 idx++;
47 public abstract bool remove(String o); 90 }
48 public abstract bool removeAll(Collection c); 91 return -1;
49 public abstract bool retainAll(Collection c); 92 }
50 public abstract Object set(int index, Object element); 93 public bool isEmpty(){
51 public abstract List subList(int fromIndex, int toIndex); 94 return super.isEmpty();
52 public abstract Object[] toArray(); 95 }
53 public abstract Object[] toArray(Object[] a); 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 }
54 135
136 public String toString(){
137 return super.toString();
138 }
55 } 139 }
56 140