[52] | 1 | package geniusweb.protocol.session.mopac2.phase;
|
---|
| 2 |
|
---|
| 3 | import java.util.Arrays;
|
---|
| 4 | import java.util.List;
|
---|
| 5 | import java.util.stream.Collectors;
|
---|
| 6 |
|
---|
| 7 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
| 8 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
| 9 |
|
---|
| 10 | import geniusweb.actions.Action;
|
---|
| 11 | import geniusweb.actions.EndNegotiation;
|
---|
| 12 | import geniusweb.actions.Offer;
|
---|
| 13 | import geniusweb.actions.PartyId;
|
---|
| 14 | import geniusweb.inform.Inform;
|
---|
| 15 | import geniusweb.inform.YourTurn;
|
---|
| 16 | import geniusweb.protocol.ProtocolException;
|
---|
| 17 | import geniusweb.protocol.session.mopac2.PartyStates;
|
---|
| 18 | import geniusweb.voting.VotingEvaluatorWithValue;
|
---|
| 19 |
|
---|
| 20 | public class OfferPhase extends DefaultPhase {
|
---|
| 21 |
|
---|
| 22 | @JsonCreator
|
---|
| 23 | public OfferPhase(@JsonProperty("partyStates") PartyStates partyStates,
|
---|
| 24 | @JsonProperty("deadlinems") Long deadlinems,
|
---|
| 25 | @JsonProperty("evaluator") VotingEvaluatorWithValue evaluator) {
|
---|
| 26 | super(partyStates, deadlinems, evaluator);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | @Override
|
---|
| 30 | public OfferPhase with(PartyId actor, Action action, long timems) {
|
---|
| 31 | try {
|
---|
| 32 | checkAction(actor, action, timems);
|
---|
| 33 | } catch (ProtocolException ex) {
|
---|
| 34 | return this.with(ex);
|
---|
| 35 | }
|
---|
| 36 | return new OfferPhase(partyStates.with(action), deadline, evaluator);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | @Override
|
---|
| 40 | public Inform getInform() {
|
---|
| 41 | return new YourTurn();
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | @Override
|
---|
| 45 | public OfferPhase with(ProtocolException e) {
|
---|
| 46 | System.out.println("Party kicked because of protocol exception:" + e);
|
---|
| 47 | return new OfferPhase(partyStates.with(e), deadline, evaluator);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | @Override
|
---|
| 51 | public Phase finish() {
|
---|
| 52 | return new OfferPhase(partyStates.finish(), deadline, evaluator);
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @Override
|
---|
| 56 | public VotingPhase checkedNext(long deadln) {
|
---|
| 57 | return new VotingPhase(getOffers(), partyStates.flush(), deadln,
|
---|
| 58 | evaluator);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | protected List<Offer> getOffers() {
|
---|
| 62 | return partyStates.getActions(Offer.class).stream()
|
---|
| 63 | .collect(Collectors.toList());
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | @Override
|
---|
| 67 | public List<Class<? extends Action>> getAllowedActions() {
|
---|
| 68 | return Arrays.asList(Offer.class, EndNegotiation.class);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | }
|
---|