metamodel: rename 'universal' to 'enum'
[nit.git] / lib / standard / collection / abstract_collection.nit
index c0c895c..76ba515 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 
 
@@ -68,7 +79,7 @@ end
 # Naive implementation of collections method
 # You only have to define iterator!
 interface NaiveCollection[E]
-special Collection[E]
+       super Collection[E]
        redef fun is_empty do return length == 0
 
        redef fun length
@@ -121,7 +132,7 @@ end
 
 # A collection that contains only one item.
 class Container[E]
-special Collection[E]
+       super Collection[E]
 
        redef fun first do return _item
 
@@ -153,7 +164,7 @@ end
 
 # This iterator is quite stupid since it is used for only one item.
 class ContainerIterator[E]
-special Iterator[E]
+       super Iterator[E]
        redef fun item do return _container.item
 
        redef fun next do _is_ok = false
@@ -167,7 +178,7 @@ end
 
 # Items can be removed from this collection
 interface RemovableCollection[E]
-special Collection[E]
+       super Collection[E]
        # Remove all items
        fun clear is abstract
 
@@ -180,7 +191,7 @@ end
 
 # Items can be added to these collections.
 interface SimpleCollection[E]
-special RemovableCollection[E]
+       super RemovableCollection[E]
        # Add an item in a collection.
        # Ensure col.has(item)
        fun add(item: E) is abstract
@@ -198,8 +209,8 @@ end
 #    ...
 #    s.add(a)
 #    s.has(b) # --> true
-interface Set[E]
-special SimpleCollection[E]
+interface Set[E: Object]
+       super SimpleCollection[E]
 
        redef fun has_only(item)
        do
@@ -227,8 +238,8 @@ special SimpleCollection[E]
        redef fun remove_all(item) do remove(item)
 end
 
-interface MapRead[K, E]
-special Collection[E]
+interface MapRead[K: Object, E]
+       super Collection[E]
        # Get the item at `key'.
        fun [](key: K): E is abstract
 
@@ -250,9 +261,9 @@ end
 #     map[u2]            # -> v2
 #     map.has_key(u1)    # -> true
 #     map.has_key(u3)    # -> false
-interface Map[K, E]
-special RemovableCollection[E]
-special MapRead[K, E]
+interface Map[K: Object, E]
+       super RemovableCollection[E]
+       super MapRead[K, E]
        # Set the`item' at `key'.
        fun []=(key: K, item: E) is abstract
 
@@ -272,8 +283,8 @@ special MapRead[K, E]
 end
 
 # Iterators for Map.
-interface MapIterator[K, E]
-special Iterator[E]
+interface MapIterator[K: Object, E]
+       super Iterator[E]
        # The key of the current item.
        fun key: K is abstract
 
@@ -284,7 +295,7 @@ end
 # Indexed collection are ordoned collections.
 # The first item is 0. The last is `length'-1.
 interface SequenceRead[E]
-special MapRead[Int, E]
+       super MapRead[Int, E]
        # Get the first item.
        # Is equivalent with `self'[0].
        redef fun first
@@ -319,9 +330,9 @@ end
 # Indexed collection are ordoned collections.
 # The first item is 0. The last is `length'-1.
 interface Sequence[E]
-special SequenceRead[E]
-special Map[Int, E]
-special SimpleCollection[E]
+       super SequenceRead[E]
+       super Map[Int, E]
+       super SimpleCollection[E]
        # Set the first item.
        # Is equivalent with `self'[0] = `item'.
        fun first=(item: E)
@@ -362,7 +373,7 @@ end
 
 # Iterators on indexed collections.
 interface IndexedIterator[E]
-special MapIterator[Int, E]
+       super MapIterator[Int, E]
        # The index of the current item.
        fun index: Int is abstract
 
@@ -371,8 +382,8 @@ special MapIterator[Int, E]
 end
 
 # Associatives arrays that internally uses couples to represent each (key, value) pairs.
-interface CoupleMap[K, E]
-special Map[K, E]
+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
@@ -393,8 +404,8 @@ end
 # Iterator on CoupleMap
 #
 # Actually is is a wrapper around an iterator of the internal array of the map.
-class CoupleMapIterator[K, E]
-special MapIterator[K, E]
+class CoupleMapIterator[K: Object, E]
+       super MapIterator[K, E]
        redef fun item do return _iter.item.second
        
        #redef fun item=(e) do _iter.item.second = e