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

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

UF_CloseToQuantity

Accept(Offer agreement)

File size: 2.0 KB
Line 
1package onetomany.bargainingchipsgame.interactions;
2
3import onetomany.bargainingchipsgame.Bundle;
4import 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 */
14public 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 OfferType type;
23 private final Bundle bundle;
24
25 /**
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 }
33
34 /**
35 * Creates a bid. Bundle is immutable and therefore so is Offer.
36 */
37 public Offer(Bundle b)
38 {
39 this(b, OfferType.BID);
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 (type != OfferType.BID)
54 return type.toString();
55 else
56 return type.toString() + ": " + bundle.toString();
57 }
58
59 public static Offer getSampleOffer(int qty)
60 {
61 return getSampleOffer("Red", qty);
62 }
63
64 /**
65 * Just a sample example of an offer
66 */
67 public static Offer getSampleOffer(String color, int qty)
68 {
69 Bundle bundle = new BundleBuilder()
70 .addStack(color, 7.0, qty)
71 .build();
72 return new Offer(bundle);
73 }
74
75 public boolean isBid()
76 {
77 return type == OfferType.BID;
78 }
79
80 public boolean isAccept()
81 {
82 return type == OfferType.ACCEPT;
83 }
84}
Note: See TracBrowser for help on using the repository browser.