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

Last change on this file since 1306 was 1169, checked in by wouter, 8 weeks ago

#368 utilitiespy is now py.typed

File size: 1.1 KB
Line 
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
11 self._index = 0
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)
18 self._index += 1
19 return val
20 def __iter__(self):
21 return self
22
23class AbstractImmutableList(ImmutableList[E]):
24 _PRINT_LIMIT = 20;
25
26 def __iter__(self):
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.