| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // TODO(nweiz): when all implementations we target have the same name for the | |
| 6 // coreimpl implementation of List<E>, extend that rather than wrapping. | |
| 7 class _ListWrapper<E> implements List<E> { | |
| 8 List _list; | |
| 9 | |
| 10 _ListWrapper(List this._list); | |
| 11 | |
| 12 Iterator<E> iterator() => _list.iterator(); | |
| 13 | |
| 14 void forEach(void f(E element)) => _list.forEach(f); | |
| 15 | |
| 16 Collection map(f(E element)) => _list.map(f); | |
| 17 | |
| 18 List<E> filter(bool f(E element)) => _list.filter(f); | |
| 19 | |
| 20 bool every(bool f(E element)) => _list.every(f); | |
| 21 | |
| 22 bool some(bool f(E element)) => _list.some(f); | |
| 23 | |
| 24 bool isEmpty() => _list.isEmpty(); | |
| 25 | |
| 26 int get length() => _list.length; | |
| 27 | |
| 28 E operator [](int index) => _list[index]; | |
| 29 | |
| 30 void operator []=(int index, E value) { _list[index] = value; } | |
| 31 | |
| 32 void set length(int newLength) { _list.length = newLength; } | |
| 33 | |
| 34 void add(E value) => _list.add(value); | |
| 35 | |
| 36 void addLast(E value) => _list.addLast(value); | |
| 37 | |
| 38 void addAll(Collection<E> collection) => _list.addAll(collection); | |
| 39 | |
| 40 void sort(int compare(E a, E b)) => _list.sort(compare); | |
| 41 | |
| 42 int indexOf(E element, [int start = 0]) => _list.indexOf(element, start); | |
| 43 | |
| 44 int lastIndexOf(E element, [int start = 0]) => | |
| 45 _list.lastIndexOf(element, start); | |
| 46 | |
| 47 void clear() => _list.clear(); | |
| 48 | |
| 49 E removeLast() => _list.removeLast(); | |
| 50 | |
| 51 E last() => _list.last(); | |
| 52 | |
| 53 List<E> getRange(int start, int rangeLength) => | |
| 54 _list.getRange(start, rangeLength); | |
| 55 | |
| 56 void setRange(int start, int rangeLength, List<E> from, [int startFrom = 0]) | |
| 57 => _list.setRange(start, rangeLength, from, startFrom); | |
| 58 | |
| 59 void removeRange(int start, int rangeLength) => | |
| 60 _list.removeRange(start, rangeLength); | |
| 61 | |
| 62 void insertRange(int start, int rangeLength, [E initialValue = null]) => | |
| 63 _list.insertRange(start, rangeLength, initialValue); | |
| 64 | |
| 65 E get first() => _list[0]; | |
| 66 } | |
| 67 | |
| 68 /** | |
| 69 * This class is used to insure the results of list operations are NodeLists | |
| 70 * instead of lists. | |
| 71 */ | |
| 72 class _NodeListWrapper extends _ListWrapper<Node> implements NodeList { | |
| 73 _NodeListWrapper(List list) : super(list); | |
| 74 | |
| 75 NodeList filter(bool f(Node element)) => | |
| 76 new _NodeListWrapper(_list.filter(f)); | |
| 77 | |
| 78 NodeList getRange(int start, int rangeLength) => | |
| 79 new _NodeListWrapper(_list.getRange(start, rangeLength)); | |
| 80 } | |
| 81 | |
| 82 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | |
| 83 _NodeImpl _parent; | |
| 84 | |
| 85 // -- start List<Node> mixins. | |
| 86 // Node is the element type. | |
| 87 | |
| 88 // From Iterable<Node>: | |
| 89 | |
| 90 Iterator<Node> iterator() { | |
| 91 // Note: NodeLists are not fixed size. And most probably length shouldn't | |
| 92 // be cached in both iterator _and_ forEach method. For now caching it | |
| 93 // for consistency. | |
| 94 return new _FixedSizeListIterator<Node>(this); | |
| 95 } | |
| 96 | |
| 97 // From Collection<Node>: | |
| 98 | |
| 99 void add(_NodeImpl value) { | |
| 100 _parent.$dom_appendChild(value); | |
| 101 } | |
| 102 | |
| 103 void addLast(_NodeImpl value) { | |
| 104 _parent.$dom_appendChild(value); | |
| 105 } | |
| 106 | |
| 107 void addAll(Collection<_NodeImpl> collection) { | |
| 108 for (_NodeImpl node in collection) { | |
| 109 _parent.$dom_appendChild(node); | |
| 110 } | |
| 111 } | |
| 112 | |
| 113 _NodeImpl removeLast() { | |
| 114 final result = this.last(); | |
| 115 if (result != null) { | |
| 116 _parent.$dom_removeChild(result); | |
| 117 } | |
| 118 return result; | |
| 119 } | |
| 120 | |
| 121 void clear() { | |
| 122 _parent.text = ''; | |
| 123 } | |
| 124 | |
| 125 void operator []=(int index, _NodeImpl value) { | |
| 126 _parent.$dom_replaceChild(value, this[index]); | |
| 127 } | |
| 128 | |
| 129 void forEach(void f(Node element)) => _Collections.forEach(this, f); | |
| 130 | |
| 131 Collection map(f(Node element)) => _Collections.map(this, [], f); | |
| 132 | |
| 133 Collection<Node> filter(bool f(Node element)) => | |
| 134 new _NodeListWrapper(_Collections.filter(this, <Node>[], f)); | |
| 135 | |
| 136 bool every(bool f(Node element)) => _Collections.every(this, f); | |
| 137 | |
| 138 bool some(bool f(Node element)) => _Collections.some(this, f); | |
| 139 | |
| 140 bool isEmpty() => this.length == 0; | |
| 141 | |
| 142 // From List<Node>: | |
| 143 | |
| 144 void sort(int compare(Node a, Node b)) { | |
| 145 throw new UnsupportedOperationException("Cannot sort immutable List."); | |
| 146 } | |
| 147 | |
| 148 int indexOf(Node element, [int start = 0]) => | |
| 149 _Lists.indexOf(this, element, start, this.length); | |
| 150 | |
| 151 int lastIndexOf(Node element, [int start = 0]) => | |
| 152 _Lists.lastIndexOf(this, element, start); | |
| 153 | |
| 154 Node last() => this[length - 1]; | |
| 155 Node get first() => this[0]; | |
| 156 | |
| 157 // FIXME: implement thesee. | |
| 158 void setRange(int start, int rangeLength, List<Node> from, [int startFrom]) { | |
| 159 throw new UnsupportedOperationException("Cannot setRange on immutable List."
); | |
| 160 } | |
| 161 void removeRange(int start, int rangeLength) { | |
| 162 throw new UnsupportedOperationException("Cannot removeRange on immutable Lis
t."); | |
| 163 } | |
| 164 void insertRange(int start, int rangeLength, [Node initialValue]) { | |
| 165 throw new UnsupportedOperationException("Cannot insertRange on immutable Lis
t."); | |
| 166 } | |
| 167 NodeList getRange(int start, int rangeLength) => | |
| 168 new _NodeListWrapper(_Lists.getRange(this, start, rangeLength, <Node>[])); | |
| 169 | |
| 170 // -- end List<Node> mixins. | |
| 171 | |
| 172 $!MEMBERS | |
| 173 } | |
| OLD | NEW |