package geniusweb.protocol.session; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeInfo; import geniusweb.protocol.tournament.Team; import geniusweb.references.Parameters; import geniusweb.references.PartyWithParameters; import geniusweb.references.PartyWithProfile; import geniusweb.references.ProfileRef; /** * Contains a functional team, eg in SHAOP a team would be a SHAOP together with * his COB partner. In SAOP this is just a SAOP party. */ @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT) public class TeamInfo { private final List parties; /** * Convenient constructor if team is only 1 party and profile * * @param party the {@link PartyWithParameters} * @param profile the ProfileRef to be used by party */ public TeamInfo(PartyWithParameters party, ProfileRef profile) { this(Arrays.asList(new PartyWithProfile(party, profile))); } @JsonCreator public TeamInfo(@JsonProperty("teams") List teams) { this.parties = teams; } /** * * @return the list of all parties involved, which is the parties in all * teams combined. */ public List getParties() { return Collections.unmodifiableList(parties); } /** * * @return the number of parties in the team. */ public Integer getSize() { return parties.size(); } @Override public String toString() { return "TeamInfo[" + parties + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((parties == null) ? 0 : parties.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; TeamInfo other = (TeamInfo) obj; if (parties == null) { if (other.parties != null) return false; } else if (!parties.equals(other.parties)) return false; return true; } /** * @param parameters a set of {@link Parameters} to be merged with the * existing parameters of the first team member. * @return updated TeamInfo */ public TeamInfo with(Parameters parameters) { List updatedparties = new ArrayList<>(parties); PartyWithProfile party1 = updatedparties.get(0); Parameters newparams1 = party1.getParty().getParameters() .with(parameters); PartyWithProfile party1update = new PartyWithProfile( party1.getParty().with(newparams1), party1.getProfile()); updatedparties.set(0, party1update); return new TeamInfo(updatedparties); } /** * @return the Team, without the profiles */ public Team getTeam() { return new Team(parties.stream().map(pwithp -> pwithp.getParty()) .collect(Collectors.toList())); } }