From: Jean Privat Date: Thu, 20 Mar 2014 09:14:07 +0000 (-0400) Subject: lib/coll: make CoupleMapIterator private X-Git-Tag: v0.6.5~19^2~2 X-Git-Url: http://nitlanguage.org lib/coll: make CoupleMapIterator private Thus introduce a protected service `CoupleMap::couple_iterator` to factorise the instantiation. Signed-off-by: Jean Privat --- diff --git a/lib/standard/collection/abstract_collection.nit b/lib/standard/collection/abstract_collection.nit index 39fe9bb..3628f5e 100644 --- a/lib/standard/collection/abstract_collection.nit +++ b/lib/standard/collection/abstract_collection.nit @@ -790,12 +790,20 @@ interface IndexedIterator[E] end # Associative arrays that internally uses couples to represent each (key, value) pairs. +# This is an helper class that some specific implementation of Map may implements. interface CoupleMap[K: Object, E] super Map[K, E] + # Return the couple of the corresponding key # Return null if the key is no associated element protected fun couple_at(key: K): nullable Couple[K, E] is abstract + # Return a new iteralot on all couples + # Used to provide `iterator` and others + protected fun couple_iterator: Iterator[Couple[K,E]] is abstract + + redef fun iterator do return new CoupleMapIterator[K,E](couple_iterator) + redef fun [](key) do var c = couple_at(key) @@ -809,8 +817,8 @@ end # Iterator on CoupleMap # -# Actually is is a wrapper around an iterator of the internal array of the map. -class CoupleMapIterator[K: Object, E] +# Actually it is a wrapper around an iterator of the internal array of the map. +private class CoupleMapIterator[K: Object, E] super MapIterator[K, E] redef fun item do return _iter.item.second diff --git a/lib/standard/collection/array.nit b/lib/standard/collection/array.nit index d242966..da1d5d3 100644 --- a/lib/standard/collection/array.nit +++ b/lib/standard/collection/array.nit @@ -463,7 +463,7 @@ class ArrayMap[K: Object, E] # O(1) redef fun length do return _items.length - redef fun iterator: CoupleMapIterator[K, E] do return new CoupleMapIterator[K, E](_items.iterator) + redef fun couple_iterator do return _items.iterator redef fun is_empty do return _items.is_empty