[316] | 1 | package bargainingchips.actions;
|
---|
[315] | 2 |
|
---|
[316] | 3 | import bargainingchips.Bundle;
|
---|
| 4 | import bargainingchips.BundleBuilder;
|
---|
[315] | 5 |
|
---|
| 6 | /**
|
---|
[318] | 7 | * An offer has two parts: (1) a bundle or null, (2) a message code: `bid', `accept', `breakoff', or `end'.
|
---|
[315] | 8 | *
|
---|
| 9 | * Immutable.
|
---|
| 10 | */
|
---|
| 11 | public 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],
|
---|
[318] | 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]
|
---|
[315] | 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);
|
---|
[320] | 38 | }
|
---|
[315] | 39 |
|
---|
| 40 | /**
|
---|
| 41 | * @return the proposal
|
---|
| 42 | */
|
---|
| 43 | public Bundle getBundle()
|
---|
| 44 | {
|
---|
| 45 | return bundle;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | @Override
|
---|
| 49 | public String toString()
|
---|
| 50 | {
|
---|
[320] | 51 | if (bundle != null)
|
---|
| 52 | return type.toString() + ": " + bundle.toString();
|
---|
| 53 | else
|
---|
[315] | 54 | return type.toString();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
[320] | 57 | public static Bid getSampleOffer(int qty)
|
---|
[315] | 58 | {
|
---|
| 59 | return getSampleOffer("Red", qty);
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | /**
|
---|
| 63 | * Just a sample example of an offer
|
---|
| 64 | */
|
---|
[320] | 65 | public static Bid getSampleOffer(String color, int qty)
|
---|
[315] | 66 | {
|
---|
| 67 | Bundle bundle = new BundleBuilder()
|
---|
| 68 | .addStack(color, 7.0, qty)
|
---|
| 69 | .build();
|
---|
[320] | 70 | return new Bid(bundle);
|
---|
[315] | 71 | }
|
---|
| 72 |
|
---|
| 73 | public boolean isBid()
|
---|
| 74 | {
|
---|
| 75 | return type == OfferType.BID;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[318] | 78 | public boolean isBreakoff()
|
---|
[315] | 79 | {
|
---|
[318] | 80 | return type == OfferType.BREAKOFF;
|
---|
[315] | 81 | }
|
---|
| 82 |
|
---|
| 83 | public boolean isAccept()
|
---|
| 84 | {
|
---|
| 85 | return type == OfferType.ACCEPT;
|
---|
| 86 | }
|
---|
[318] | 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 | }
|
---|
[315] | 102 | } |
---|