Merge branch 'various-fixes' into next
[nit.git] / lib / standard / collection / abstract_collection.nit
index 0d12d90..b6e734a 100644 (file)
@@ -42,6 +42,17 @@ interface Collection[E]
        # Get a new iterator on the collection.
        fun iterator: Iterator[E] is abstract
 
+       # Iterate over each element of the collection
+       fun iterate
+               !each(e: E)
+       do
+               var i = iterator
+               while i.is_ok do
+                       each(i.item)
+                       i.next
+               end
+       end
+
        # Is there no item in the collection ?
        fun is_empty: Bool is abstract 
 
@@ -74,7 +85,7 @@ special Collection[E]
        redef fun length
        do
                var nb = 0
-               for i in self do nb += nb
+               for i in self do nb += 1 
                return nb
        end
 
@@ -198,7 +209,7 @@ end
 #    ...
 #    s.add(a)
 #    s.has(b) # --> true
-interface Set[E]
+interface Set[E: Object]
 special SimpleCollection[E]
 
        redef fun has_only(item)
@@ -227,7 +238,7 @@ special SimpleCollection[E]
        redef fun remove_all(item) do remove(item)
 end
 
-interface MapRead[K, E]
+interface MapRead[K: Object, E]
 special Collection[E]
        # Get the item at `key'.
        fun [](key: K): E is abstract
@@ -250,7 +261,7 @@ end
 #     map[u2]            # -> v2
 #     map.has_key(u1)    # -> true
 #     map.has_key(u3)    # -> false
-interface Map[K, E]
+interface Map[K: Object, E]
 special RemovableCollection[E]
 special MapRead[K, E]
        # Set the`item' at `key'.
@@ -272,7 +283,7 @@ special MapRead[K, E]
 end
 
 # Iterators for Map.
-interface MapIterator[K, E]
+interface MapIterator[K: Object, E]
 special Iterator[E]
        # The key of the current item.
        fun key: K is abstract
@@ -283,7 +294,7 @@ end
 
 # Indexed collection are ordoned collections.
 # The first item is 0. The last is `length'-1.
-interface IndexedCollectionRead[E]
+interface SequenceRead[E]
 special MapRead[Int, E]
        # Get the first item.
        # Is equivalent with `self'[0].
@@ -318,8 +329,8 @@ end
 
 # Indexed collection are ordoned collections.
 # The first item is 0. The last is `length'-1.
-interface IndexedCollection[E]
-special IndexedCollectionRead[E]
+interface Sequence[E]
+special SequenceRead[E]
 special Map[Int, E]
 special SimpleCollection[E]
        # Set the first item.
@@ -371,7 +382,7 @@ special MapIterator[Int, E]
 end
 
 # Associatives arrays that internally uses couples to represent each (key, value) pairs.
-interface CoupleMap[K, E]
+interface CoupleMap[K: Object, E]
 special Map[K, E]
        # Return the couple of the corresponding key
        # Return null if the key is no associated element
@@ -393,7 +404,7 @@ end
 # Iterator on CoupleMap
 #
 # Actually is is a wrapper around an iterator of the internal array of the map.
-class CoupleMapIterator[K, E]
+class CoupleMapIterator[K: Object, E]
 special MapIterator[K, E]
        redef fun item do return _iter.item.second