# Naive implementation of collections method
# You only have to define iterator!
-interface NaiveCollection[E: Object]
+interface NaiveCollection[E]
special Collection[E]
redef meth is_empty do return length == 0
meth add(item: E) is abstract
# Add each item of `coll`.
- meth add_all(coll: Collection[E]) do if coll != null then for i in coll do add(i)
+ meth add_all(coll: Collection[E]) do for i in coll do add(i)
end
# Abstract sets.
meth push(e: E) is abstract
# Add each item of `coll` after the last.
- meth append(coll: Collection[E]) do if coll != null then for i in coll do push(i)
+ meth append(coll: Collection[E]) do for i in coll do push(i)
# Remove the last item.
meth pop: E is abstract
special Map[K, E]
# Return the couple of the corresponding key
# Return null if the key is no associated element
- protected meth couple_at(key: K): Couple[K, E] is abstract
+ protected meth couple_at(key: K): nullable Couple[K, E] is abstract
redef meth [](key)
do
var c = couple_at(key)
if c == null then
- return null
+ abort
else
return c.second
end
redef meth next
do
_iter.next
- while _iter.is_ok and _iter.item == null do _iter.next
end
attr _iter: Iterator[Couple[K,E]]