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

Last change on this file since 1284 was 1169, checked in by wouter, 3 months ago

#368 utilitiespy is now py.typed

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