Java tutorial
/* * Copyright 2016 CloudBans (https://cloudbans.xyz) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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 xyz.cloudbans.entities.request; import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.Collection; import java.util.Date; import java.util.Objects; import java.util.UUID; public class ServerHeartbeatRequest { @JsonProperty("server") private UUID server; @JsonProperty("time") private Date time; @JsonProperty("players") private Collection<ServerHeartbeatPlayer> players; public ServerHeartbeatRequest() { this(null, null, null); } public ServerHeartbeatRequest(UUID server, Date time, Collection<ServerHeartbeatPlayer> players) { this.server = server; this.time = time; this.players = players; } public UUID getServer() { return server; } public void setServer(UUID server) { this.server = server; } public Date getTime() { return time; } public void setTime(Date time) { this.time = time; } public Collection<ServerHeartbeatPlayer> getPlayers() { return players; } public void setPlayers(Collection<ServerHeartbeatPlayer> players) { this.players = players; } public ServerHeartbeatRequest copy() { Collection<ServerHeartbeatPlayer> originPlayers = getPlayers(); Collection<ServerHeartbeatPlayer> players = new ArrayList<>(originPlayers.size()); for (ServerHeartbeatPlayer player : originPlayers) players.add(player.copy()); return new ServerHeartbeatRequest(getServer(), getTime(), players); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ServerHeartbeatRequest)) return false; ServerHeartbeatRequest that = (ServerHeartbeatRequest) o; return Objects.equals(getServer(), that.getServer()) && Objects.equals(getTime(), that.getTime()) && Objects.equals(getPlayers(), that.getPlayers()); } @Override public int hashCode() { return Objects.hash(getServer(), getTime(), getPlayers()); } public static class ServerHeartbeatPlayer { @JsonProperty("uuid") private UUID uuid; @JsonProperty("player_name") private String playerName; public ServerHeartbeatPlayer() { this(null, null); } public ServerHeartbeatPlayer(UUID uuid, String playerName) { this.uuid = uuid; this.playerName = playerName; } public UUID getUuid() { return uuid; } public void setUuid(UUID uuid) { this.uuid = uuid; } public String getPlayerName() { return playerName; } public void setPlayerName(String playerName) { this.playerName = playerName; } public ServerHeartbeatPlayer copy() { return new ServerHeartbeatPlayer(getUuid(), getPlayerName()); } @Override public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof ServerHeartbeatPlayer)) return false; ServerHeartbeatPlayer that = (ServerHeartbeatPlayer) o; return Objects.equals(getUuid(), that.getUuid()) && Objects.equals(getPlayerName(), that.getPlayerName()); } @Override public int hashCode() { return Objects.hash(getUuid(), getPlayerName()); } } }