source: geniuswebcore/geniusweb/issuevalue/DiscreteValueSet.py@ 63

Last change on this file since 63 was 59, checked in by Wouter Pasman, 3 years ago

#44 manual commit of first public release, because this will cause the dist directory to move

File size: 952 bytes
Line 
1from copy import copy
2from decimal import Decimal
3from typing import List
4
5from geniusweb.issuevalue.DiscreteValue import DiscreteValue
6from geniusweb.issuevalue.Value import Value
7from geniusweb.issuevalue.ValueSet import ValueSet
8
9
10class DiscreteValueSet (ValueSet):
11
12 def __init__(self, values: List[DiscreteValue]) :
13 self._values= copy(values)
14
15 def getValues(self) -> List[DiscreteValue]:
16 return copy(self._values)
17
18 def contains(self, value:Value ) ->bool:
19 return value in self._values
20
21 def get(self,index:Decimal) -> DiscreteValue :
22 return self._values[int(index)]
23
24 def size(self) -> Decimal :
25 return Decimal(len(self._values))
26
27 def __repr__(self):
28 # workaround, str(list) seems to call __repro__ isntead of _-str__....
29 return "DiscreteValueSet" + repr(self._values)
30
31 def __eq__(self, other):
32 return isinstance(other, self.__class__) and self._values==other._values
33
34 def __hash__(self):
35 return hash((tuple(self._values)))
Note: See TracBrowser for help on using the repository browser.