"""
MakeACollectionClass.cobra

This HowTo shows the syntax and techniques for declaring an IList.
"""


class MyList<of T> implements IList<of T>

	var _items as List<of T>

	cue init
		base.init
		_items = List<of T>()

	## IEnumerable ##

	def getEnumerator as IEnumerator<of T>
		return _items.getEnumerator

	def getEnumerator as System.Collections.IEnumerator
		implements System.Collections.IEnumerable
		return .getEnumerator


	## ICollection ##

	get count as int
		return _items.count

	get isReadOnly as bool
		return false

	def add(item as T)
		_items.add(item)

	def clear
		_items.clear

	def contains(item as T) as bool
		return _items.contains(item)

	def remove(item as T) as bool
		return _items.remove(item)

	def copyTo(array as T[], index as int)
		_items.copyTo(array, index)


	## IList ##

	pro [index as int] as T
		get
			return _items[index]
		set
			_items[index] = value

	def indexOf(x as T) as int
		return _items.indexOf(x)

	def insert(index as int, x as T)
		_items.insert(index, x)

	def removeAt(index as int)
		_items.removeAt(index)


class Program

	def main is shared
		t = MyList<of int>()
		t.add(5)
		assert t.count==1
