# 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
# A collection that contains only one item.
class Container[E]
-special Collection[E]
+ super Collection[E]
redef fun first do return _item
# 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
# Items can be removed from this collection
interface RemovableCollection[E]
-special Collection[E]
+ super Collection[E]
# Remove all items
fun clear is abstract
# 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
# s.add(a)
# s.has(b) # --> true
interface Set[E: Object]
-special SimpleCollection[E]
+ super SimpleCollection[E]
redef fun has_only(item)
do
end
interface MapRead[K: Object, E]
-special Collection[E]
+ super Collection[E]
# Get the item at `key'.
fun [](key: K): E is abstract
# map.has_key(u1) # -> true
# map.has_key(u3) # -> false
interface Map[K: Object, E]
-special RemovableCollection[E]
-special MapRead[K, E]
+ super RemovableCollection[E]
+ super MapRead[K, E]
# Set the`item' at `key'.
fun []=(key: K, item: E) is abstract
# Iterators for Map.
interface MapIterator[K: Object, E]
-special Iterator[E]
+ super Iterator[E]
# The key of the current item.
fun key: K is abstract
# 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
# 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)
# 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
# Associatives arrays that internally uses couples to represent each (key, value) pairs.
interface CoupleMap[K: Object, E]
-special Map[K, 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
#
# Actually is is a wrapper around an iterator of the internal array of the map.
class CoupleMapIterator[K: Object, E]
-special MapIterator[K, E]
+ super MapIterator[K, E]
redef fun item do return _iter.item.second
#redef fun item=(e) do _iter.item.second = e