1 | package bargainingchips.actions;
|
---|
2 |
|
---|
3 | import bargainingchips.Bundle;
|
---|
4 | import bargainingchips.BundleBuilder;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * An offer has two parts:
|
---|
8 | * (1) a bundle or null,
|
---|
9 | * (2) a message code: `bid', `accept', `breakoff', or `end'.
|
---|
10 | *
|
---|
11 | * Immutable.
|
---|
12 | */
|
---|
13 | public class Offer
|
---|
14 | {
|
---|
15 | /**
|
---|
16 | * Message codes:
|
---|
17 | * (1) `bid' [body contains a bundle],
|
---|
18 | * (2) `accept' (pre or final) [agree with the deal (based on the rules); agreement body],
|
---|
19 | * (3) `breakoff' [propose to quit the negotiation; null body]
|
---|
20 | *
|
---|
21 | * Special:
|
---|
22 | * (4) `end' [poison message to signal the agents that the negotiation is over;
|
---|
23 | * null body for no agreement, bundle body for agreement]
|
---|
24 | */
|
---|
25 | private final OfferType type;
|
---|
26 | private final Bundle bundle;
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Creates an offer. Bundle and OfferType are immutable and therefore so is Offer.
|
---|
30 | */
|
---|
31 | public Offer(Bundle b, OfferType t)
|
---|
32 | {
|
---|
33 | bundle = b;
|
---|
34 | type = t;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public Offer(Offer o)
|
---|
38 | {
|
---|
39 | this(o.bundle, o.type);
|
---|
40 | }
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * @return the proposal
|
---|
44 | */
|
---|
45 | public Bundle getBundle()
|
---|
46 | {
|
---|
47 | return bundle;
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public String toString()
|
---|
52 | {
|
---|
53 | if (bundle != null)
|
---|
54 | return type.toString() + ": " + bundle.toString();
|
---|
55 | else
|
---|
56 | return type.toString();
|
---|
57 | }
|
---|
58 |
|
---|
59 | public static Bid getSampleOffer(int qty)
|
---|
60 | {
|
---|
61 | return getSampleOffer("Red", qty);
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Just a sample example of an offer
|
---|
66 | */
|
---|
67 | public static Bid getSampleOffer(String color, int qty)
|
---|
68 | {
|
---|
69 | Bundle bundle = new BundleBuilder()
|
---|
70 | .addStack(color, 7.0, qty)
|
---|
71 | .build();
|
---|
72 | return new Bid(bundle);
|
---|
73 | }
|
---|
74 |
|
---|
75 | public boolean isBid()
|
---|
76 | {
|
---|
77 | return type == OfferType.BID;
|
---|
78 | }
|
---|
79 |
|
---|
80 | public boolean isBreakoff()
|
---|
81 | {
|
---|
82 | return type == OfferType.BREAKOFF;
|
---|
83 | }
|
---|
84 |
|
---|
85 | public boolean isPreAccept()
|
---|
86 | {
|
---|
87 | return type == OfferType.PREACCEPT;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public boolean isFinalAccept()
|
---|
91 | {
|
---|
92 | return type == OfferType.FINALACCEPT;
|
---|
93 | }
|
---|
94 |
|
---|
95 | public boolean isEnd()
|
---|
96 | {
|
---|
97 | return type == OfferType.END;
|
---|
98 | }
|
---|
99 |
|
---|
100 | public boolean isAgreement()
|
---|
101 | {
|
---|
102 | return isEnd() && bundle != null;
|
---|
103 | }
|
---|
104 |
|
---|
105 | public boolean isDisagreement()
|
---|
106 | {
|
---|
107 | return isEnd() && bundle == null;
|
---|
108 | }
|
---|
109 | } |
---|