source: src/main/java/genius/core/actions/DefaultActionWithBid.java

Last change on this file was 1, checked in by Wouter Pasman, 7 years ago

Initial import : Genius 9.0.0

File size: 1.7 KB
Line 
1package genius.core.actions;
2
3import genius.core.AgentID;
4import genius.core.Bid;
5
6/**
7 * Default implementation for ActionWithBid
8 *
9 * @author W.Pasman
10 *
11 */
12public abstract class DefaultActionWithBid extends DefaultAction implements
13 ActionWithBid {
14 /** The involved bid. */
15 protected Bid bid;
16
17 /**
18 * Creates an action symbolizing an offer for the opponent.
19 *
20 * @param agentID
21 * id of the agent which created the offer.
22 * @param bid
23 * for the opponent.
24 */
25 public DefaultActionWithBid(AgentID agentID, Bid bid) {
26 super(agentID);
27 if (bid == null) {
28 throw new NullPointerException("bid can not be null");
29 }
30 // FIXME we need to check actual Bid class; but we want junit tests to
31 // work.
32 // if (bid.getClass() != Bid.class) {
33 // throw new IllegalArgumentException("Extending Bid is not allowed");
34 // }
35 this.bid = bid;
36 }
37
38 /**
39 * Returns the bid offered by the agent which created this offer.
40 *
41 * @return bid to offer.
42 */
43 public Bid getBid() {
44 return bid;
45 }
46
47 /**
48 * @return hashcode of this object.
49 */
50 @Override
51 public int hashCode() {
52 final int prime = 31;
53 int result = 1;
54 result = prime * result + ((bid == null) ? 0 : bid.hashCode());
55 return result;
56 }
57
58 /**
59 * @param obj
60 * object to which this object is compared.
61 * @return true if this object is equal to the given object.
62 */
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj)
66 return true;
67 if (obj == null)
68 return false;
69 if (getClass() != obj.getClass())
70 return false;
71 Offer other = (Offer) obj;
72 if (bid == null) {
73 if (other.bid != null)
74 return false;
75 } else if (!bid.equals(other.bid))
76 return false;
77 return true;
78 }
79
80 public String getContent() {
81 return " bid:" + bid;
82 }
83
84}
Note: See TracBrowser for help on using the repository browser.