Skip to content

Commit

Permalink
Implement the rest of the TODOs. (#84)
Browse files Browse the repository at this point in the history
* Implement the rest of the TODOs.

* Update CHANGELOG.

* Oops
  • Loading branch information
matanlurey committed Mar 13, 2018
1 parent c0f85b2 commit 2e1473f
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 125 deletions.
3 changes: 1 addition & 2 deletions CHANGELOG.md
@@ -1,8 +1,7 @@
## 1.14.7-dev

* Only the Dart 2 dev SDK (`>=2.0.0-dev.22.0`) is now supported.
* Add support for `Map.{addEntries|entries}` for Dart 2.0.
* Add support for `Iterable|List|Map|Set|Queue.{cast|retype}` for Dart 2.0.
* Added support for all Dart 2 SDK methods that threw `UnimplementedError`.

## 1.14.6

Expand Down
28 changes: 10 additions & 18 deletions lib/src/canonicalized_map.dart
Expand Up @@ -102,12 +102,8 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {

int get length => _base.length;

// TODO: Dart 2.0 requires this method to be implemented.
Map<K2, V2> map<K2, V2>(Object transform(K key, V value)) {
// Change Object to MapEntry<K2, V2> when
// the MapEntry class has been added.
throw new UnimplementedError('map');
}
Map<K2, V2> map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) =>
_base.map((_, pair) => transform(pair.first, pair.last));

V putIfAbsent(K key, V ifAbsent()) {
return _base
Expand All @@ -121,22 +117,18 @@ class CanonicalizedMap<C, K, V> implements Map<K, V> {
return pair == null ? null : pair.last;
}

// TODO: Dart 2.0 requires this method to be implemented.
void removeWhere(bool test(K key, V value)) {
throw new UnimplementedError('removeWhere');
}
void removeWhere(bool test(K key, V value)) =>
_base.removeWhere((_, pair) => test(pair.first, pair.last));

Map<K2, V2> retype<K2, V2>() => _base.retype<K2, V2>();

// TODO: Dart 2.0 requires this method to be implemented.
V update(K key, V update(V value), {V ifAbsent()}) {
throw new UnimplementedError('update');
}
V update(K key, V update(V value), {V ifAbsent()}) => _base
.update(_canonicalize(key), (pair) => new Pair(key, update(pair.last)),
ifAbsent: ifAbsent == null ? null : () => new Pair(key, ifAbsent()))
.last;

// TODO: Dart 2.0 requires this method to be implemented.
void updateAll(V update(K key, V value)) {
throw new UnimplementedError('updateAll');
}
void updateAll(V update(K key, V value)) => _base.updateAll(
(_, pair) => new Pair(pair.first, update(pair.first, pair.last)));

Iterable<V> get values => _base.values.map((pair) => pair.last);

Expand Down
58 changes: 17 additions & 41 deletions lib/src/typed_wrappers.dart
Expand Up @@ -40,10 +40,8 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
_base.fold(initialValue,
(previousValue, element) => combine(previousValue, element as E));

// TODO: Dart 2.0 requires this method to be implemented.
Iterable<E> followedBy(Iterable<E> other) {
throw new UnimplementedError('followedBy');
}
Iterable<E> followedBy(Iterable<E> other) =>
new TypeSafeIterable<E>(_base.followedBy(other));

void forEach(void f(E element)) => _base.forEach(_validate(f));

Expand Down Expand Up @@ -72,8 +70,7 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
E get single => _base.single as E;

E singleWhere(bool test(E element), {E orElse()}) {
if (orElse != null) throw new UnimplementedError('singleWhere:orElse');
return _base.singleWhere(_validate(test)) as E;
return _base.singleWhere(_validate(test), orElse: orElse) as E;
}

Iterable<E> skip(int n) => new TypeSafeIterable<E>(_base.skip(n));
Expand All @@ -94,10 +91,7 @@ abstract class _TypeSafeIterableBase<E> implements Iterable<E> {
Iterable<E> where(bool test(E element)) =>
new TypeSafeIterable<E>(_base.where(_validate(test)));

// TODO: Dart 2.0 requires this method to be implemented.
Iterable<T> whereType<T>() {
throw new UnimplementedError('whereType');
}
Iterable<T> whereType<T>() => _base.whereType<T>();

String toString() => _base.toString();

Expand Down Expand Up @@ -132,10 +126,7 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
_listBase[index] = value;
}

// TODO: Dart 2.0 requires this method to be implemented.
List<E> operator +(List<E> other) {
throw new UnimplementedError('+');
}
List<E> operator +(List<E> other) => new TypeSafeList<E>(_listBase + other);

void add(E value) {
_listBase.add(value);
Expand All @@ -157,7 +148,6 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
_listBase.fillRange(start, end, fillValue);
}

// TODO: Dart 2.0 requires this method to be implemented.
set first(E value) {
if (this.isEmpty) throw new RangeError.index(0, this);
this[0] = value;
Expand All @@ -168,10 +158,8 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {

int indexOf(E element, [int start = 0]) => _listBase.indexOf(element, start);

// TODO: Dart 2.0 requires this method to be implemented.
int indexWhere(bool test(E element), [int start = 0]) {
throw new UnimplementedError('indexWhere');
}
int indexWhere(bool test(E element), [int start = 0]) =>
_listBase.indexWhere((e) => test(e as E), start);

void insert(int index, E element) {
_listBase.insert(index, element);
Expand All @@ -181,7 +169,6 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
_listBase.insertAll(index, iterable);
}

// TODO: Dart 2.0 requires this method to be implemented.
set last(E value) {
if (this.isEmpty) throw new RangeError.index(0, this);
this[this.length - 1] = value;
Expand All @@ -190,10 +177,8 @@ class TypeSafeList<E> extends TypeSafeIterable<E> implements DelegatingList<E> {
int lastIndexOf(E element, [int start]) =>
_listBase.lastIndexOf(element, start);

// TODO: Dart 2.0 requires this method to be implemented.
int lastIndexWhere(bool test(E element), [int start]) {
throw new UnimplementedError('lastIndexWhere');
}
int lastIndexWhere(bool test(E element), [int start]) =>
_listBase.lastIndexWhere((e) => test(e as E), start);

set length(int newLength) {
_listBase.length = newLength;
Expand Down Expand Up @@ -399,21 +384,16 @@ class TypeSafeMap<K, V> implements DelegatingMap<K, V> {

int get length => _base.length;

// TODO: Dart 2.0 requires this method to be implemented.
Map<K2, V2> map<K2, V2>(Object transform(K key, V value)) {
// Change Object to MapEntry<K2, V2> when
// the MapEntry class has been added.
throw new UnimplementedError('map');
Map<K2, V2> map<K2, V2>(dynamic transform(K key, V value)) {
return _base as dynamic;
}

V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent) as V;

V remove(Object key) => _base.remove(key) as V;

// TODO: Dart 2.0 requires this method to be implemented.
void removeWhere(bool test(K key, V value)) {
throw new UnimplementedError('removeWhere');
}
void removeWhere(bool test(K key, V value)) =>
_base.removeWhere((k, v) => test(k as K, v as V));

Map<K2, V2> retype<K2, V2>() =>
new TypeSafeMap<K2, V2>(_base.retype<K2, V2>());
Expand All @@ -422,13 +402,9 @@ class TypeSafeMap<K, V> implements DelegatingMap<K, V> {

String toString() => _base.toString();

// TODO: Dart 2.0 requires this method to be implemented.
V update(K key, V update(V value), {V ifAbsent()}) {
throw new UnimplementedError('update');
}
V update(K key, V update(V value), {V ifAbsent()}) =>
_base.update(key, (v) => update(v as V), ifAbsent: ifAbsent);

// TODO: Dart 2.0 requires this method to be implemented.
void updateAll(V update(K key, V value)) {
throw new UnimplementedError('updateAll');
}
void updateAll(V update(K key, V value)) =>
_base.updateAll((k, v) => update(k, v));
}
83 changes: 19 additions & 64 deletions lib/src/wrappers.dart
Expand Up @@ -21,7 +21,6 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {

bool any(bool test(E element)) => _base.any(test);

// TODO: Dart 2.0 requires this method to be implemented.
Iterable<T> cast<T>() => _base.cast<T>();

bool contains(Object element) => _base.contains(element);
Expand All @@ -40,10 +39,7 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {
T fold<T>(T initialValue, T combine(T previousValue, E element)) =>
_base.fold(initialValue, combine);

// TODO: Dart 2.0 requires this method to be implemented.
Iterable<E> followedBy(Iterable<E> other) {
throw new UnimplementedError('followedBy');
}
Iterable<E> followedBy(Iterable<E> other) => _base.followedBy(other);

void forEach(void f(E element)) => _base.forEach(f);

Expand Down Expand Up @@ -71,8 +67,7 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {
E get single => _base.single;

E singleWhere(bool test(E element), {E orElse()}) {
if (orElse != null) throw new UnimplementedError('singleWhere:orElse');
return _base.singleWhere(test);
return _base.singleWhere(test, orElse: orElse);
}

Iterable<E> skip(int n) => _base.skip(n);
Expand All @@ -89,10 +84,7 @@ abstract class _DelegatingIterableBase<E> implements Iterable<E> {

Iterable<E> where(bool test(E element)) => _base.where(test);

// TODO: Dart 2.0 requires this method to be implemented.
Iterable<T> whereType<T>() {
throw new UnimplementedError("whereType");
}
Iterable<T> whereType<T>() => _base.whereType<T>();

String toString() => _base.toString();
}
Expand Down Expand Up @@ -151,10 +143,7 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
_listBase[index] = value;
}

// TODO: Dart 2.0 requires this method to be implemented.
List<E> operator +(List<E> other) {
throw new UnimplementedError('+');
}
List<E> operator +(List<E> other) => _listBase + other;

void add(E value) {
_listBase.add(value);
Expand All @@ -176,7 +165,6 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
_listBase.fillRange(start, end, fillValue);
}

// TODO: Dart 2.0 requires this method to be implemented.
set first(E value) {
if (this.isEmpty) throw new RangeError.index(0, this);
this[0] = value;
Expand All @@ -186,10 +174,8 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {

int indexOf(E element, [int start = 0]) => _listBase.indexOf(element, start);

// TODO: Dart 2.0 requires this method to be implemented.
int indexWhere(bool test(E element), [int start = 0]) {
throw new UnimplementedError('indexWhere');
}
int indexWhere(bool test(E element), [int start = 0]) =>
_listBase.indexWhere(test, start);

void insert(int index, E element) {
_listBase.insert(index, element);
Expand All @@ -199,7 +185,6 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
_listBase.insertAll(index, iterable);
}

// TODO: Dart 2.0 requires this method to be implemented.
set last(E value) {
if (this.isEmpty) throw new RangeError.index(0, this);
this[this.length - 1] = value;
Expand All @@ -208,10 +193,8 @@ class DelegatingList<E> extends DelegatingIterable<E> implements List<E> {
int lastIndexOf(E element, [int start]) =>
_listBase.lastIndexOf(element, start);

// TODO: Dart 2.0 requires this method to be implemented.
int lastIndexWhere(bool test(E element), [int start]) {
throw new UnimplementedError('lastIndexWhere');
}
int lastIndexWhere(bool test(E element), [int start]) =>
_listBase.lastIndexWhere(test, start);

set length(int newLength) {
_listBase.length = newLength;
Expand Down Expand Up @@ -291,10 +274,7 @@ class DelegatingSet<E> extends DelegatingIterable<E> implements Set<E> {
_setBase.addAll(elements);
}

// TODO: Dart 2.0 requires this method to be implemented.
Set<T> cast<T>() {
throw new UnimplementedError('cast');
}
Set<T> cast<T>() => _setBase.cast<T>();

void clear() {
_setBase.clear();
Expand Down Expand Up @@ -373,10 +353,7 @@ class DelegatingQueue<E> extends DelegatingIterable<E> implements Queue<E> {
_baseQueue.addLast(value);
}

// TODO: Dart 2.0 requires this method to be implemented.
Queue<T> cast<T>() {
throw new UnimplementedError('cast');
}
Queue<T> cast<T>() => _baseQueue.cast<T>();

void clear() {
_baseQueue.clear();
Expand Down Expand Up @@ -441,10 +418,7 @@ class DelegatingMap<K, V> implements Map<K, V> {
_base.clear();
}

// TODO: Dart 2.0 requires this method to be implemented.
Map<K2, V2> cast<K2, V2>() {
throw new UnimplementedError('cast');
}
Map<K2, V2> cast<K2, V2>() => _base.cast<K2, V2>();

bool containsKey(Object key) => _base.containsKey(key);

Expand All @@ -464,38 +438,25 @@ class DelegatingMap<K, V> implements Map<K, V> {

int get length => _base.length;

// TODO: Dart 2.0 requires this method to be implemented.
Map<K2, V2> map<K2, V2>(Object transform(K key, V value)) {
// Change Object to MapEntry<K2, V2> when
// the MapEntry class has been added.
throw new UnimplementedError('map');
}
Map<K2, V2> map<K2, V2>(MapEntry<K2, V2> transform(K key, V value)) =>
_base.map(transform);

V putIfAbsent(K key, V ifAbsent()) => _base.putIfAbsent(key, ifAbsent);

V remove(Object key) => _base.remove(key);

// TODO: Dart 2.0 requires this method to be implemented.
void removeWhere(bool test(K key, V value)) {
throw new UnimplementedError('removeWhere');
}
void removeWhere(bool test(K key, V value)) => _base.removeWhere(test);

// TODO: Dart 2.0 requires this method to be implemented.
Map<K2, V2> retype<K2, V2>() => _base.retype<K2, V2>();

Iterable<V> get values => _base.values;

String toString() => _base.toString();

// TODO: Dart 2.0 requires this method to be implemented.
V update(K key, V update(V value), {V ifAbsent()}) {
throw new UnimplementedError('update');
}
V update(K key, V update(V value), {V ifAbsent()}) =>
_base.update(key, update, ifAbsent: ifAbsent);

// TODO: Dart 2.0 requires this method to be implemented.
void updateAll(V update(K key, V value)) {
throw new UnimplementedError('updateAll');
}
void updateAll(V update(K key, V value)) => _base.updateAll(update);
}

/// An unmodifiable [Set] view of the keys of a [Map].
Expand Down Expand Up @@ -553,10 +514,7 @@ class MapKeySet<E> extends _DelegatingIterableBase<E>
E lookup(Object element) =>
throw new UnsupportedError("MapKeySet doesn't support lookup().");

// TODO: Dart 2.0 requires this method to be implemented.
Set<T> retype<T>() {
throw new UnimplementedError('retype');
}
Set<T> retype<T>() => _baseMap.keys.toSet().retype<T>();

/// Returns a new set which contains all the elements of [this] and [other].
///
Expand Down Expand Up @@ -702,10 +660,7 @@ class MapValueSet<K, V> extends _DelegatingIterableBase<V> implements Set<V> {
void retainWhere(bool test(V element)) =>
removeWhere((element) => !test(element));

// TODO: Dart 2.0 requires this method to be implemented.
Set<T> retype<T>() {
throw new UnimplementedError('retype');
}
Set<T> retype<T>() => toSet().retype<T>();

/// Returns a new set which contains all the elements of [this] and [other].
///
Expand Down

0 comments on commit 2e1473f

Please sign in to comment.