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

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

Added support for PreAccept and FinalAccept

File size: 2.1 KB
RevLine 
[316]1package bargainingchips.actions;
[315]2
[316]3import bargainingchips.Bundle;
4import bargainingchips.BundleBuilder;
[315]5
6/**
[337]7 * An offer has two parts:
8 * (1) a bundle or null,
9 * (2) a message code: `bid', `accept', `breakoff', or `end'.
[315]10 *
11 * Immutable.
12 */
13public class Offer
14{
15 /**
16 * Message codes:
17 * (1) `bid' [body contains a bundle],
[337]18 * (2) `accept' (pre or final) [agree with the deal (based on the rules); agreement body],
[318]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]
[315]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);
[320]40 }
[315]41
42 /**
43 * @return the proposal
44 */
45 public Bundle getBundle()
46 {
47 return bundle;
48 }
49
50 @Override
51 public String toString()
52 {
[320]53 if (bundle != null)
54 return type.toString() + ": " + bundle.toString();
55 else
[315]56 return type.toString();
57 }
58
[320]59 public static Bid getSampleOffer(int qty)
[315]60 {
61 return getSampleOffer("Red", qty);
62 }
63
64 /**
65 * Just a sample example of an offer
66 */
[320]67 public static Bid getSampleOffer(String color, int qty)
[315]68 {
69 Bundle bundle = new BundleBuilder()
70 .addStack(color, 7.0, qty)
71 .build();
[320]72 return new Bid(bundle);
[315]73 }
74
75 public boolean isBid()
76 {
77 return type == OfferType.BID;
78 }
79
[318]80 public boolean isBreakoff()
[315]81 {
[318]82 return type == OfferType.BREAKOFF;
[315]83 }
84
[337]85 public boolean isPreAccept()
[315]86 {
[337]87 return type == OfferType.PREACCEPT;
[315]88 }
[318]89
[337]90 public boolean isFinalAccept()
91 {
92 return type == OfferType.FINALACCEPT;
93 }
94
[318]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 }
[315]109}
Note: See TracBrowser for help on using the repository browser.