source: geniuswebcore/geniusweb/inform/Agreements.py@ 59

Last change on this file since 59 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: 1.7 KB
Line 
1from __future__ import annotations
2
3from typing import Any, Dict
4
5from pyson.JsonValue import JsonValue
6
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.issuevalue.Bid import Bid
9
10
11class Agreements:
12 '''
13 There can be multiple agreements from a single negotiation. This object
14 contains the agreements. Each party can agree only on 1 bid and there are
15 always at least 2 parties agreeing on a bid.
16 '''
17 def __init__(self, agreements:Dict[PartyId, Bid] = {} ) :
18 '''
19 @param agrees a map, with the bid that was agreed on by a party
20 HACK Must be Dict[PartyId, Bid]
21 '''
22 if type(agreements)!=dict:
23 raise ValueError("Agreements must be a dict")
24 self._agreements = agreements
25
26 @JsonValue()
27 def getAgreements(self)->Dict[PartyId, Bid]:
28 return self._agreements
29
30 def With(self, other:Agreements ) ->Agreements :
31 '''
32 * @param other {@link Agreements}
33 * @return a new Agreement containing this plus other agreements
34 * @throws IllegalArgumentException if parties in other are already in this
35 * agreement.
36 '''
37 newagrees = self._agreements.copy()
38 for pid in other._agreements.keys():
39 if pid in newagrees:
40 raise ValueError("party " + str(pid) + " already has agreement");
41 newagrees[pid]=other._agreements[pid]
42 return Agreements(newagrees);
43
44 def getMap(self)-> Dict[PartyId,Bid]:
45 '''
46 @return actual agreemenets contained here
47 '''
48 return self._agreements.copy()
49
50
51 def __repr__(self):
52 return "Agreements" + str(self._agreements)
53
54 def __eq__(self, other):
55 return isinstance(other, self.__class__) and self._agreements == other._agreements
56
57
58 def __hash__(self):
59 return sum([ hash(k) + 31 * hash(v) for (k,v) in self._agreements.items()])
Note: See TracBrowser for help on using the repository browser.