From 9e7f5e317d566a2a686f38309cc70430d9634517 Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Thu, 20 Mar 2014 05:14:07 -0400 Subject: [PATCH] lib/coll: make CoupleMapIterator private Thus introduce a protected service `CoupleMap::couple_iterator` to factorise the instantiation. Signed-off-by: Jean Privat --- lib/standard/collection/abstract_collection.nit | 12 ++++++++++-- lib/standard/collection/array.nit | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) 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 -- 1.7.9.5