Rev | Line | |
---|
[222] | 1 | from decimal import Decimal
|
---|
| 2 | from typing import TypeVar
|
---|
| 3 |
|
---|
| 4 | from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
|
---|
| 5 |
|
---|
| 6 |
|
---|
| 7 | E = TypeVar('E')
|
---|
| 8 | class ItemIterator:
|
---|
| 9 | def __init__(self, l:ImmutableList[E]):
|
---|
| 10 | self._l = l
|
---|
| 11 | # member variable to keep track of current index
|
---|
[243] | 12 | self._index = 0
|
---|
[222] | 13 | def __next__(self):
|
---|
| 14 | '''Returns the next value from team object's lists '''
|
---|
| 15 | if self._index >= self._l.size():
|
---|
| 16 | # End of Iteration
|
---|
| 17 | raise StopIteration
|
---|
| 18 | val=self._l.get(self._index)
|
---|
[243] | 19 | self._index += 1
|
---|
[222] | 20 | return val
|
---|
| 21 |
|
---|
| 22 | class AbstractImmutableList(ImmutableList[E]):
|
---|
[285] | 23 | _PRINT_LIMIT = 20;
|
---|
| 24 |
|
---|
[222] | 25 | def __iter__(self):
|
---|
[285] | 26 | return ItemIterator(self)
|
---|
| 27 |
|
---|
| 28 | def __repr__(self) :
|
---|
| 29 | if self.size() > self._PRINT_LIMIT:
|
---|
| 30 | end = self._PRINT_LIMIT;
|
---|
| 31 | else:
|
---|
| 32 | end = self.size()
|
---|
| 33 |
|
---|
| 34 | string = "[";
|
---|
| 35 | for n in range(end):
|
---|
| 36 | string += ( "," if n!=0 else "") + str(self.get(n))
|
---|
| 37 |
|
---|
| 38 | remain = self.size() - end
|
---|
| 39 | if remain > 0:
|
---|
| 40 | string += ",..." + str(remain) + " more..."
|
---|
| 41 |
|
---|
| 42 | string += "]";
|
---|
| 43 | return string;
|
---|
| 44 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.