1 | package geniusweb.protocol.session;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.Arrays;
|
---|
5 | import java.util.Collections;
|
---|
6 | import java.util.List;
|
---|
7 | import java.util.stream.Collectors;
|
---|
8 |
|
---|
9 | import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
---|
10 | import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
|
---|
11 | import com.fasterxml.jackson.annotation.JsonCreator;
|
---|
12 | import com.fasterxml.jackson.annotation.JsonProperty;
|
---|
13 | import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
---|
14 |
|
---|
15 | import geniusweb.protocol.tournament.Team;
|
---|
16 | import geniusweb.references.Parameters;
|
---|
17 | import geniusweb.references.PartyWithParameters;
|
---|
18 | import geniusweb.references.PartyWithProfile;
|
---|
19 | import geniusweb.references.ProfileRef;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Contains a functional team, eg in SHAOP a team would be a SHAOP together with
|
---|
23 | * his COB partner. In SAOP this is just a SAOP party.
|
---|
24 | */
|
---|
25 | @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
|
---|
26 | @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
|
---|
27 | public class TeamInfo {
|
---|
28 |
|
---|
29 | private final List<PartyWithProfile> parties;
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Convenient constructor if team is only 1 party and profile
|
---|
33 | *
|
---|
34 | * @param party the {@link PartyWithParameters}
|
---|
35 | * @param profile the ProfileRef to be used by party
|
---|
36 | */
|
---|
37 | public TeamInfo(PartyWithParameters party, ProfileRef profile) {
|
---|
38 | this(Arrays.asList(new PartyWithProfile(party, profile)));
|
---|
39 | }
|
---|
40 |
|
---|
41 | @JsonCreator
|
---|
42 | public TeamInfo(@JsonProperty("teams") List<PartyWithProfile> teams) {
|
---|
43 | this.parties = teams;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | *
|
---|
48 | * @return the list of all parties involved, which is the parties in all
|
---|
49 | * teams combined.
|
---|
50 | */
|
---|
51 | public List<PartyWithProfile> getParties() {
|
---|
52 | return Collections.unmodifiableList(parties);
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | *
|
---|
57 | * @return the number of parties in the team.
|
---|
58 | */
|
---|
59 | public Integer getSize() {
|
---|
60 | return parties.size();
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public String toString() {
|
---|
65 | return "TeamInfo[" + parties + "]";
|
---|
66 | }
|
---|
67 |
|
---|
68 | @Override
|
---|
69 | public int hashCode() {
|
---|
70 | final int prime = 31;
|
---|
71 | int result = 1;
|
---|
72 | result = prime * result + ((parties == null) ? 0 : parties.hashCode());
|
---|
73 | return result;
|
---|
74 | }
|
---|
75 |
|
---|
76 | @Override
|
---|
77 | public boolean equals(Object obj) {
|
---|
78 | if (this == obj)
|
---|
79 | return true;
|
---|
80 | if (obj == null)
|
---|
81 | return false;
|
---|
82 | if (getClass() != obj.getClass())
|
---|
83 | return false;
|
---|
84 | TeamInfo other = (TeamInfo) obj;
|
---|
85 | if (parties == null) {
|
---|
86 | if (other.parties != null)
|
---|
87 | return false;
|
---|
88 | } else if (!parties.equals(other.parties))
|
---|
89 | return false;
|
---|
90 | return true;
|
---|
91 | }
|
---|
92 |
|
---|
93 | /**
|
---|
94 | * @param parameters a set of {@link Parameters} to be merged with the
|
---|
95 | * existing parameters of the first team member.
|
---|
96 | * @return updated TeamInfo
|
---|
97 | */
|
---|
98 | public TeamInfo with(Parameters parameters) {
|
---|
99 | List<PartyWithProfile> updatedparties = new ArrayList<>(parties);
|
---|
100 | PartyWithProfile party1 = updatedparties.get(0);
|
---|
101 | Parameters newparams1 = party1.getParty().getParameters()
|
---|
102 | .with(parameters);
|
---|
103 | PartyWithProfile party1update = new PartyWithProfile(
|
---|
104 | party1.getParty().with(newparams1), party1.getProfile());
|
---|
105 | updatedparties.set(0, party1update);
|
---|
106 | return new TeamInfo(updatedparties);
|
---|
107 | }
|
---|
108 |
|
---|
109 | /**
|
---|
110 | * @return the Team, without the profiles
|
---|
111 | */
|
---|
112 | public Team getTeam() {
|
---|
113 | return new Team(parties.stream().map(pwithp -> pwithp.getParty())
|
---|
114 | .collect(Collectors.toList()));
|
---|
115 | }
|
---|
116 | }
|
---|