source: src/main/java/onetomany/bargainingchipsgame/interactions/Offer.java@ 307

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

abstract class BilateralProtocol created

File size: 2.0 KB
RevLine 
[253]1package onetomany.bargainingchipsgame.interactions;
[237]2
[253]3import onetomany.bargainingchipsgame.Bundle;
[274]4import onetomany.bargainingchipsgame.BundleBuilder;
[237]5
6/**
[263]7 * An offer has two parts: (1) a bundle or null, (2) a message code: `bid', `accept', `end'.
[237]8 * When the code is 'bid', the first part is checked; for the two latter codes, the first part of the offer is null.
[263]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.
[237]11 *
[274]12 * Immutable.
[237]13 */
14public class Offer
15{
[270]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 */
[277]22 private final OfferType type;
[274]23 private final Bundle bundle;
[237]24
25 /**
[298]26 * Creates an offer. Bundle and OfferType are immutable and therefore so is Offer.
27 */
28 public Offer(Bundle b, OfferType t)
29 {
30 bundle = b;
31 type = t;
32 }
[307]33
34 public Offer(Offer o)
35 {
36 this(o.bundle, o.type);
37 }
[298]38
39 /**
[274]40 * Creates a bid. Bundle is immutable and therefore so is Offer.
[237]41 */
[270]42 public Offer(Bundle b)
43 {
[298]44 this(b, OfferType.BID);
[237]45 }
46
47 /**
[270]48 * @return the proposal
[237]49 */
[270]50 public Bundle getBundle()
51 {
52 return bundle;
[237]53 }
[270]54
55 @Override
56 public String toString()
57 {
[277]58 if (type != OfferType.BID)
[270]59 return type.toString();
60 else
61 return type.toString() + ": " + bundle.toString();
[237]62 }
[274]63
64 public static Offer getSampleOffer(int qty)
65 {
66 return getSampleOffer("Red", qty);
67 }
68
69 /**
70 * Just a sample example of an offer
71 */
72 public static Offer getSampleOffer(String color, int qty)
73 {
74 Bundle bundle = new BundleBuilder()
75 .addStack(color, 7.0, qty)
76 .build();
77 return new Offer(bundle);
78 }
[284]79
80 public boolean isBid()
81 {
82 return type == OfferType.BID;
83 }
[302]84
85 public boolean isAccept()
86 {
87 return type == OfferType.ACCEPT;
88 }
[270]89}
Note: See TracBrowser for help on using the repository browser.