source: src/main/java/bargainingchips/actions/Offer.java@ 320

Last change on this file since 320 was 320, checked in by Tim Baarslag, 5 years ago

OfferBy no longer an offer

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