package geniusweb.protocol.session.amop; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import geniusweb.deadline.Deadline; import geniusweb.protocol.session.SessionProtocol; import geniusweb.protocol.session.SessionSettings; import geniusweb.protocol.session.TeamInfo; import geniusweb.references.PartyWithProfile; import tudelft.utilities.logging.Reporter; /** * Settings for AMOP negotiation. */ public class AMOPSettings implements SessionSettings { private final List participants; private final Deadline deadline; /** * * @param participants the list of {@link PartyWithProfile} in clockwise * order. There must be at least 2 to run the SAOP * protocol. But SAOP can be initialized with less, for * use in TournamentSettings. * @param deadline the {@link Deadline} of the negotiation */ @JsonCreator public AMOPSettings( @JsonProperty("participants") List participants, @JsonProperty("deadline") Deadline deadline) { this.participants = participants; this.deadline = deadline; if (participants == null) { throw new IllegalArgumentException("participants must not be null"); } if (deadline == null) { throw new IllegalArgumentException("deadline must not be null"); } } @Override public Double getMaxRunTime() { return deadline.getDuration() / 1000d; } @Override public SessionProtocol getProtocol(Reporter logger) { return new AMOP(new AMOPState(this), logger); } @Override public List getTeams() { return Collections.unmodifiableList(participants); } /** * @return the deadline for this negotiation */ public Deadline getDeadline() { return deadline; } @Override public List getAllParties() { return participants.stream() .map(particip -> particip.getParties().get(0)) .collect(Collectors.toList()); } @Override public String toString() { return "AMOPSettings" + participants + "," + deadline + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((deadline == null) ? 0 : deadline.hashCode()); result = prime * result + ((participants == null) ? 0 : participants.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AMOPSettings other = (AMOPSettings) obj; if (deadline == null) { if (other.deadline != null) return false; } else if (!deadline.equals(other.deadline)) return false; if (participants == null) { if (other.participants != null) return false; } else if (!participants.equals(other.participants)) return false; return true; } @Override public SessionSettings with(TeamInfo team) { if (team.getSize() != 1) throw new IllegalArgumentException( "Added team must be just 1 party but got " + team); List newparts = new LinkedList<>( participants); newparts.add(team); return new AMOPSettings(newparts, deadline); } @Override public Integer getTeamSize() { return 1; } }