Last change
on this file since 69 was 67, checked in by Bart Vastenhouw, 3 years ago |
Added SAOP and simplerunner to GeniusWebPython. Several minor fixes.
|
File size:
1.1 KB
|
Rev | Line | |
---|
[67] | 1 | from copy import copy
|
---|
| 2 | from decimal import Decimal
|
---|
| 3 | from typing import List, Collection
|
---|
| 4 |
|
---|
| 5 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
| 6 | from geniusweb.issuevalue.Value import Value
|
---|
| 7 | from geniusweb.issuevalue.ValueSet import ValueSet
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | class 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.