source: utilitiespy/tudelft/utilities/immutablelist/AbstractImmutableList.py@ 742

Last change on this file since 742 was 285, checked in by wouter, 3 years ago

#97 added Outer and FixedList plus tests. Version now 1.0.1

File size: 1.1 KB
RevLine 
[222]1from decimal import Decimal
2from typing import TypeVar
3
4from tudelft.utilities.immutablelist.ImmutableList import ImmutableList
5
6
7E = TypeVar('E')
8class 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
22class 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.