Last change
on this file since 195 was 195, checked in by wouter, 3 years ago |
preparing python version of immutablelist
|
File size:
1.2 KB
|
Line | |
---|
1 | from decimal import Decimal, ROUND_FLOOR
|
---|
2 | import decimal
|
---|
3 | from typing import List
|
---|
4 |
|
---|
5 | from immutablelist.AbstractImmutableList import AbstractImmutableList
|
---|
6 | from immutablelist.ImmutableList import ImmutableList
|
---|
7 |
|
---|
8 |
|
---|
9 | class Range(AbstractImmutableList[Decimal]):
|
---|
10 | def __init__(self, low:Decimal, high: Decimal, step:Decimal):
|
---|
11 | self._low=low
|
---|
12 | self._high=high
|
---|
13 | self._step=step
|
---|
14 |
|
---|
15 | def getLow(self):
|
---|
16 | return self._low
|
---|
17 |
|
---|
18 | def getHigh(self):
|
---|
19 | return self._high
|
---|
20 |
|
---|
21 | def getStep(self):
|
---|
22 | return self._step
|
---|
23 |
|
---|
24 | def get(self, index:int)-> Decimal:
|
---|
25 | return self._low+ self._step * index
|
---|
26 |
|
---|
27 | def size(self) -> Decimal:
|
---|
28 | if self._low > self._high:
|
---|
29 | return Decimal(0)
|
---|
30 | return (( self._high - self._low )/self._step) \
|
---|
31 | .quantize(Decimal('1'), rounding=ROUND_FLOOR) + Decimal('1')
|
---|
32 |
|
---|
33 | def __eq__(self, other)->bool:
|
---|
34 | return isinstance(other, self.__class__) and \
|
---|
35 | self._low == other._low and \
|
---|
36 | self._high == other._high and\
|
---|
37 | self._step == other._step
|
---|
38 |
|
---|
39 | def __str__(self):
|
---|
40 | return "Range["+self._low+","+self._high+","+self._step+"]" |
---|
Note:
See
TracBrowser
for help on using the repository browser.