package geniusweb.protocol.session.saop; 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; public class SAOPSettings 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 deadline of the negotiation */ @JsonCreator public SAOPSettings( @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 SAOP(new SAOPState(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 Integer getTeamSize() { return 1; } @Override public String toString() { return "SAOPSettings" + 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; SAOPSettings other = (SAOPSettings) 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( "Team must be size 1 but found " + team); List newparts = new LinkedList<>(participants); newparts.add(team); return new SAOPSettings(newparts, deadline); } }