1 | package onetomany.bargainingchipsgame.interactions;
|
---|
2 |
|
---|
3 | import onetomany.bargainingchipsgame.Bundle;
|
---|
4 | import onetomany.bargainingchipsgame.BundleBuilder;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * An offer has two parts: (1) a bundle or null, (2) a message code: `bid', `accept', `end'.
|
---|
8 | * When the code is 'bid', the first part is checked; for the two latter codes, the first part of the offer is null.
|
---|
9 | * In other words, message `bid' means that offer contains a bundle which is proposed, `accept' means offer contains no bundle to propose,
|
---|
10 | * but an agreement with the deal (the received offer), and `end' again means that nothing to propose, and quitting the negotiation.
|
---|
11 | *
|
---|
12 | * Immutable.
|
---|
13 | */
|
---|
14 | public class Offer
|
---|
15 | {
|
---|
16 | /**
|
---|
17 | * Message codes:
|
---|
18 | * (1) `bid' [body contains a bundle],
|
---|
19 | * (2) `accept' [agree with the deal (based on the rules); null body],
|
---|
20 | * (3) `end' [quitting the negotiation; null body]
|
---|
21 | */
|
---|
22 | private final MessageType type;
|
---|
23 | private final Bundle bundle;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Creates a bid. Bundle is immutable and therefore so is Offer.
|
---|
27 | */
|
---|
28 | public Offer(Bundle b)
|
---|
29 | {
|
---|
30 | bundle = b;
|
---|
31 | type = MessageType.BID;
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | * @return the proposal
|
---|
36 | */
|
---|
37 | public Bundle getBundle()
|
---|
38 | {
|
---|
39 | return bundle;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public String toString()
|
---|
44 | {
|
---|
45 | if (type != MessageType.BID)
|
---|
46 | return type.toString();
|
---|
47 | else
|
---|
48 | return type.toString() + ": " + bundle.toString();
|
---|
49 | }
|
---|
50 |
|
---|
51 | public static Offer getSampleOffer(int qty)
|
---|
52 | {
|
---|
53 | return getSampleOffer("Red", qty);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Just a sample example of an offer
|
---|
58 | */
|
---|
59 | public static Offer getSampleOffer(String color, int qty)
|
---|
60 | {
|
---|
61 | Bundle bundle = new BundleBuilder()
|
---|
62 | .addStack(color, 7.0, qty)
|
---|
63 | .build();
|
---|
64 | return new Offer(bundle);
|
---|
65 | }
|
---|
66 | } |
---|