Mercurial > projects > dwt-addons
comparison dwtx/dwtxhelper/Collection.d @ 184:26589d623405
Added ListIterator for ArrayList
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 18 Oct 2008 15:02:28 +0200 |
parents | 41471f9968be |
children | 293a2f22f944 |
comparison
equal
deleted
inserted
replaced
183:c36336245fb1 | 184:26589d623405 |
---|---|
2025 } | 2025 } |
2026 bool isEmpty(){ | 2026 bool isEmpty(){ |
2027 return data.length is 0; | 2027 return data.length is 0; |
2028 } | 2028 } |
2029 class LocalIterator : Iterator{ | 2029 class LocalIterator : Iterator{ |
2030 int idx = 0; | 2030 int idx = -1; |
2031 public this(){ | 2031 public this(){ |
2032 } | 2032 } |
2033 public bool hasNext(){ | 2033 public bool hasNext(){ |
2034 return idx < data.length; | 2034 return idx+1 < data.length; |
2035 } | 2035 } |
2036 public Object next(){ | 2036 public Object next(){ |
2037 idx++; | |
2037 Object res = data[idx]; | 2038 Object res = data[idx]; |
2038 idx++; | |
2039 return res; | 2039 return res; |
2040 } | 2040 } |
2041 public void remove(){ | 2041 public void remove(){ |
2042 implMissing( __FILE__, __LINE__ ); | 2042 implMissing( __FILE__, __LINE__ ); |
2043 this.outer.remove(idx); | 2043 this.outer.remove(idx); |
2060 return i; | 2060 return i; |
2061 } | 2061 } |
2062 } | 2062 } |
2063 return -1; | 2063 return -1; |
2064 } | 2064 } |
2065 | |
2066 class LocalListIterator : ListIterator { | |
2067 int idx_next = 0; | |
2068 public bool hasNext(){ | |
2069 return idx_next < data.length; | |
2070 } | |
2071 public Object next(){ | |
2072 Object res = data[idx_next]; | |
2073 idx_next++; | |
2074 return res; | |
2075 } | |
2076 public void remove(){ | |
2077 implMissing( __FILE__, __LINE__ ); | |
2078 this.outer.remove(idx_next); | |
2079 idx_next--; | |
2080 } | |
2081 public void add(Object o){ | |
2082 implMissing( __FILE__, __LINE__ ); | |
2083 } | |
2084 public bool add(String o){ | |
2085 implMissing( __FILE__, __LINE__ ); | |
2086 return false; | |
2087 } | |
2088 public bool hasPrevious(){ | |
2089 return idx_next > 0; | |
2090 } | |
2091 public int nextIndex(){ | |
2092 return idx_next; | |
2093 } | |
2094 public Object previous(){ | |
2095 idx_next--; | |
2096 Object res = data[idx_next]; | |
2097 return res; | |
2098 } | |
2099 public int previousIndex(){ | |
2100 return idx_next-1; | |
2101 } | |
2102 public void set(Object o){ | |
2103 implMissing( __FILE__, __LINE__ ); | |
2104 } | |
2105 } | |
2106 | |
2065 ListIterator listIterator(){ | 2107 ListIterator listIterator(){ |
2066 implMissing( __FILE__, __LINE__ ); | 2108 return new LocalListIterator(); |
2067 return null; | |
2068 } | 2109 } |
2069 ListIterator listIterator(int index){ | 2110 ListIterator listIterator(int index){ |
2070 implMissing( __FILE__, __LINE__ ); | 2111 implMissing( __FILE__, __LINE__ ); |
2071 return null; | 2112 return null; |
2072 } | 2113 } |