All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.gamelift.model.Player Maven / Gradle / Ivy

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.gamelift.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.traits.MapTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructMap;
import software.amazon.awssdk.core.util.SdkAutoConstructMap;
import software.amazon.awssdk.utils.CollectionUtils;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Represents a player in matchmaking. When starting a matchmaking request, a player has a player ID, attributes, and * may have latency data. Team information is added after a match has been successfully completed. *

*/ @Generated("software.amazon.awssdk:codegen") public final class Player implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField PLAYER_ID_FIELD = SdkField. builder(MarshallingType.STRING) .getter(getter(Player::playerId)).setter(setter(Builder::playerId)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PlayerId").build()).build(); private static final SdkField> PLAYER_ATTRIBUTES_FIELD = SdkField .> builder(MarshallingType.MAP) .getter(getter(Player::playerAttributes)) .setter(setter(Builder::playerAttributes)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("PlayerAttributes").build(), MapTrait.builder() .keyLocationName("key") .valueLocationName("value") .valueFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(AttributeValue::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("value").build()).build()).build()).build(); private static final SdkField TEAM_FIELD = SdkField. builder(MarshallingType.STRING) .getter(getter(Player::team)).setter(setter(Builder::team)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Team").build()).build(); private static final SdkField> LATENCY_IN_MS_FIELD = SdkField .> builder(MarshallingType.MAP) .getter(getter(Player::latencyInMs)) .setter(setter(Builder::latencyInMs)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LatencyInMs").build(), MapTrait.builder() .keyLocationName("key") .valueLocationName("value") .valueFieldInfo( SdkField. builder(MarshallingType.INTEGER) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("value").build()).build()).build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(PLAYER_ID_FIELD, PLAYER_ATTRIBUTES_FIELD, TEAM_FIELD, LATENCY_IN_MS_FIELD)); private static final long serialVersionUID = 1L; private final String playerId; private final Map playerAttributes; private final String team; private final Map latencyInMs; private Player(BuilderImpl builder) { this.playerId = builder.playerId; this.playerAttributes = builder.playerAttributes; this.team = builder.team; this.latencyInMs = builder.latencyInMs; } /** *

* A unique identifier for a player *

* * @return A unique identifier for a player */ public String playerId() { return playerId; } /** * Returns true if the PlayerAttributes property was specified by the sender (it may be empty), or false if the * sender did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS * service. */ public boolean hasPlayerAttributes() { return playerAttributes != null && !(playerAttributes instanceof SdkAutoConstructMap); } /** *

* A collection of key:value pairs containing player information for use in matchmaking. Player attribute keys must * match the playerAttributes used in a matchmaking rule set. Example: * "PlayerAttributes": {"skill": {"N": "23"}, "gameMode": {"S": "deathmatch"}}. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* You can use {@link #hasPlayerAttributes()} to see if a value was sent in this field. *

* * @return A collection of key:value pairs containing player information for use in matchmaking. Player attribute * keys must match the playerAttributes used in a matchmaking rule set. Example: * "PlayerAttributes": {"skill": {"N": "23"}, "gameMode": {"S": "deathmatch"}}. */ public Map playerAttributes() { return playerAttributes; } /** *

* Name of the team that the player is assigned to in a match. Team names are defined in a matchmaking rule set. *

* * @return Name of the team that the player is assigned to in a match. Team names are defined in a matchmaking rule * set. */ public String team() { return team; } /** * Returns true if the LatencyInMs property was specified by the sender (it may be empty), or false if the sender * did not specify the value (it will be empty). For responses returned by the SDK, the sender is the AWS service. */ public boolean hasLatencyInMs() { return latencyInMs != null && !(latencyInMs instanceof SdkAutoConstructMap); } /** *

* Set of values, expressed in milliseconds, indicating the amount of latency that a player experiences when * connected to AWS Regions. If this property is present, FlexMatch considers placing the match only in Regions for * which latency is reported. *

*

* If a matchmaker has a rule that evaluates player latency, players must report latency in order to be matched. If * no latency is reported in this scenario, FlexMatch assumes that no Regions are available to the player and the * ticket is not matchable. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* You can use {@link #hasLatencyInMs()} to see if a value was sent in this field. *

* * @return Set of values, expressed in milliseconds, indicating the amount of latency that a player experiences when * connected to AWS Regions. If this property is present, FlexMatch considers placing the match only in * Regions for which latency is reported.

*

* If a matchmaker has a rule that evaluates player latency, players must report latency in order to be * matched. If no latency is reported in this scenario, FlexMatch assumes that no Regions are available to * the player and the ticket is not matchable. */ public Map latencyInMs() { return latencyInMs; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(playerId()); hashCode = 31 * hashCode + Objects.hashCode(playerAttributes()); hashCode = 31 * hashCode + Objects.hashCode(team()); hashCode = 31 * hashCode + Objects.hashCode(latencyInMs()); return hashCode; } @Override public boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof Player)) { return false; } Player other = (Player) obj; return Objects.equals(playerId(), other.playerId()) && Objects.equals(playerAttributes(), other.playerAttributes()) && Objects.equals(team(), other.team()) && Objects.equals(latencyInMs(), other.latencyInMs()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("Player").add("PlayerId", playerId()).add("PlayerAttributes", playerAttributes()) .add("Team", team()).add("LatencyInMs", latencyInMs()).build(); } public Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "PlayerId": return Optional.ofNullable(clazz.cast(playerId())); case "PlayerAttributes": return Optional.ofNullable(clazz.cast(playerAttributes())); case "Team": return Optional.ofNullable(clazz.cast(team())); case "LatencyInMs": return Optional.ofNullable(clazz.cast(latencyInMs())); default: return Optional.empty(); } } @Override public List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((Player) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* A unique identifier for a player *

* * @param playerId * A unique identifier for a player * @return Returns a reference to this object so that method calls can be chained together. */ Builder playerId(String playerId); /** *

* A collection of key:value pairs containing player information for use in matchmaking. Player attribute keys * must match the playerAttributes used in a matchmaking rule set. Example: * "PlayerAttributes": {"skill": {"N": "23"}, "gameMode": {"S": "deathmatch"}}. *

* * @param playerAttributes * A collection of key:value pairs containing player information for use in matchmaking. Player attribute * keys must match the playerAttributes used in a matchmaking rule set. Example: * "PlayerAttributes": {"skill": {"N": "23"}, "gameMode": {"S": "deathmatch"}}. * @return Returns a reference to this object so that method calls can be chained together. */ Builder playerAttributes(Map playerAttributes); /** *

* Name of the team that the player is assigned to in a match. Team names are defined in a matchmaking rule set. *

* * @param team * Name of the team that the player is assigned to in a match. Team names are defined in a matchmaking * rule set. * @return Returns a reference to this object so that method calls can be chained together. */ Builder team(String team); /** *

* Set of values, expressed in milliseconds, indicating the amount of latency that a player experiences when * connected to AWS Regions. If this property is present, FlexMatch considers placing the match only in Regions * for which latency is reported. *

*

* If a matchmaker has a rule that evaluates player latency, players must report latency in order to be matched. * If no latency is reported in this scenario, FlexMatch assumes that no Regions are available to the player and * the ticket is not matchable. *

* * @param latencyInMs * Set of values, expressed in milliseconds, indicating the amount of latency that a player experiences * when connected to AWS Regions. If this property is present, FlexMatch considers placing the match only * in Regions for which latency is reported.

*

* If a matchmaker has a rule that evaluates player latency, players must report latency in order to be * matched. If no latency is reported in this scenario, FlexMatch assumes that no Regions are available * to the player and the ticket is not matchable. * @return Returns a reference to this object so that method calls can be chained together. */ Builder latencyInMs(Map latencyInMs); } static final class BuilderImpl implements Builder { private String playerId; private Map playerAttributes = DefaultSdkAutoConstructMap.getInstance(); private String team; private Map latencyInMs = DefaultSdkAutoConstructMap.getInstance(); private BuilderImpl() { } private BuilderImpl(Player model) { playerId(model.playerId); playerAttributes(model.playerAttributes); team(model.team); latencyInMs(model.latencyInMs); } public final String getPlayerId() { return playerId; } @Override public final Builder playerId(String playerId) { this.playerId = playerId; return this; } public final void setPlayerId(String playerId) { this.playerId = playerId; } public final Map getPlayerAttributes() { return playerAttributes != null ? CollectionUtils.mapValues(playerAttributes, AttributeValue::toBuilder) : null; } @Override public final Builder playerAttributes(Map playerAttributes) { this.playerAttributes = PlayerAttributeMapCopier.copy(playerAttributes); return this; } public final void setPlayerAttributes(Map playerAttributes) { this.playerAttributes = PlayerAttributeMapCopier.copyFromBuilder(playerAttributes); } public final String getTeam() { return team; } @Override public final Builder team(String team) { this.team = team; return this; } public final void setTeam(String team) { this.team = team; } public final Map getLatencyInMs() { return latencyInMs; } @Override public final Builder latencyInMs(Map latencyInMs) { this.latencyInMs = LatencyMapCopier.copy(latencyInMs); return this; } public final void setLatencyInMs(Map latencyInMs) { this.latencyInMs = LatencyMapCopier.copy(latencyInMs); } @Override public Player build() { return new Player(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy