source: geniuswebcore/geniusweb/inform/Voting.py

Last change on this file was 111, checked in by ruud, 2 months ago

Modifications for automatic java to python conversion. Overloaded methods now have different names.

File size: 2.2 KB
Line 
1# Generated from java by J2P
2from __future__ import annotations
3from geniusweb.actions.Offer import Offer
4from geniusweb.actions.PartyId import PartyId
5from geniusweb.inform.Inform import Inform
6from tudelft.utilities.tools.safehash import safehash
7from typing import Any
8from typing import Dict
9from typing import List
10from typing import Optional
11from typing import cast
12
13
14class Voting(Inform):
15 '''
16 Informs a party that it's time to do voting.
17
18 '''
19
20 def __init__(self, offers:List[Offer], powers:Dict[PartyId,int]):
21 self.__offers:List[Offer] = list()
22 self.__powers:Dict[PartyId,int] = dict()
23 super().__init__()
24 if ((offers is None) or None in offers):
25 raise ValueError("offers must be not null and contain no null")
26 if (((powers is None) or None in powers.keys()) or None in powers.values()):
27 raise ValueError("powers must be not null and contain no null")
28 self.__offers.extend(offers)
29 self.__powers.update(powers)
30
31 def getOffers(self) -> List[Offer]:
32 '''
33 @return list of offers to be voted on
34
35 '''
36 return list(self.__offers)
37
38 def getPowers(self) -> Dict[PartyId,int]:
39 '''
40
41 @return map with the power of each party in the negotiation. This map may
42 contain parties that are already finished, eg they reached an
43 agreement or walked away.
44
45 '''
46 return dict(self.__powers)
47
48 #Override
49 def __hash__(self) -> int:
50 prime:int = 31
51 result:int = 1
52 result=((prime * result) + (0 if ((self.__offers is None)) else safehash(self.__offers)))
53 result=((prime * result) + (0 if ((self.__powers is None)) else safehash(self.__powers)))
54 return result
55
56 #Override
57 def __eq__(self,obj:Optional[Any]) -> bool:
58 if (self is obj):
59 return True
60 if (obj is None):
61 return False
62 if (type(self) is not type(obj)):
63 return False
64 other:Optional[Voting] = cast(Voting,obj)
65 if (self.__offers is None):
66 if (other.__offers is not None):
67 return False
68 else:
69 if not(self.__offers == other.__offers):
70 return False
71 if (self.__powers is None):
72 if (other.__powers is not None):
73 return False
74 else:
75 if not(self.__powers == other.__powers):
76 return False
77 return True
78
79 #Override
80 def __repr__(self) -> str:
81 return "Voting[" + str(self.__offers) + "," + str(self.__powers) + "]"
Note: See TracBrowser for help on using the repository browser.