lib/coll: make CoupleMapIterator private
authorJean Privat <jean@pryen.org>
Thu, 20 Mar 2014 09:14:07 +0000 (05:14 -0400)
committerJean Privat <jean@pryen.org>
Thu, 20 Mar 2014 20:30:03 +0000 (16:30 -0400)
Thus introduce a protected service `CoupleMap::couple_iterator` to
factorise the instantiation.

Signed-off-by: Jean Privat <jean@pryen.org>

lib/standard/collection/abstract_collection.nit
lib/standard/collection/array.nit

index 39fe9bb..3628f5e 100644 (file)
@@ -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
        
index d242966..da1d5d3 100644 (file)
@@ -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