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

Last change on this file since 100 was 100, checked in by ruud, 20 months ago

python installs also wheel to avoid error messages

File size: 1.1 KB
Line 
1from copy import copy
2from decimal import Decimal
3from typing import List, Collection
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: Collection[DiscreteValue]) :
13 self._values:List[DiscreteValue]=[]
14 for val in values:
15 if val not in self._values:
16 self._values.append(val)
17
18 def getValues(self) -> List[DiscreteValue]:
19 return list(self._values)
20
21 def contains(self, value:Value ) ->bool:
22 return value in self._values
23
24 def get(self,index:int) -> DiscreteValue :
25 return self._values[int(index)]
26
27 def size(self) -> int :
28 return len(self._values)
29
30 def __repr__(self):
31 # workaround, str(list) seems to call __repro__ isntead of _-str__....
32 return "DiscreteValueSet" + repr(self._values)
33
34 def __eq__(self, other):
35 return isinstance(other, self.__class__) and set(self._values)==set(other._values)
36
37 def __hash__(self):
38 # don't use tuple because order is irrelevant.
39 return sum([hash(val) for val in self._values])
Note: See TracBrowser for help on using the repository browser.