13
0
geforkt von Mirrors/Velocity

Clarifications, same for QueryResponse.

Dieser Commit ist enthalten in:
Andrew Steinborn 2018-12-29 14:21:20 -05:00
Ursprung 5cf96aabdd
Commit a2d9a9f1d8
3 geänderte Dateien mit 92 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -1,5 +1,6 @@
package com.velocitypowered.api.proxy.server; package com.velocitypowered.api.proxy.server;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.MoreObjects; import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -8,6 +9,7 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull; import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
@ -28,7 +30,8 @@ public final class QueryResponse {
private final String proxyVersion; private final String proxyVersion;
private final Collection<PluginInformation> plugins; private final Collection<PluginInformation> plugins;
private QueryResponse(String hostname, String gameVersion, String map, int currentPlayers, @VisibleForTesting
QueryResponse(String hostname, String gameVersion, String map, int currentPlayers,
int maxPlayers, String proxyHost, int proxyPort, Collection<String> players, int maxPlayers, String proxyHost, int proxyPort, Collection<String> players,
String proxyVersion, Collection<PluginInformation> plugins) { String proxyVersion, Collection<PluginInformation> plugins) {
this.hostname = hostname; this.hostname = hostname;
@ -138,7 +141,10 @@ public final class QueryResponse {
/** /**
* Creates a new {@link Builder} instance from data represented by this response. * Creates a new {@link Builder} instance from data represented by this response, so that you
* may create a new {@link QueryResponse} with new data. It is guaranteed that
* {@code queryResponse.toBuilder().build().equals(queryResponse)}: that is, if no other
* changes are made to the returned builder, the built instance will equal the original instance.
* *
* @return {@link QueryResponse} builder * @return {@link QueryResponse} builder
*/ */
@ -165,6 +171,50 @@ public final class QueryResponse {
return new Builder(); return new Builder();
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
QueryResponse response = (QueryResponse) o;
return currentPlayers == response.currentPlayers
&& maxPlayers == response.maxPlayers
&& proxyPort == response.proxyPort
&& hostname.equals(response.hostname)
&& gameVersion.equals(response.gameVersion)
&& map.equals(response.map)
&& proxyHost.equals(response.proxyHost)
&& players.equals(response.players)
&& proxyVersion.equals(response.proxyVersion)
&& plugins.equals(response.plugins);
}
@Override
public int hashCode() {
return Objects
.hash(hostname, gameVersion, map, currentPlayers, maxPlayers, proxyHost, proxyPort, players,
proxyVersion, plugins);
}
@Override
public String toString() {
return "QueryResponse{"
+ "hostname='" + hostname + '\''
+ ", gameVersion='" + gameVersion + '\''
+ ", map='" + map + '\''
+ ", currentPlayers=" + currentPlayers
+ ", maxPlayers=" + maxPlayers
+ ", proxyHost='" + proxyHost + '\''
+ ", proxyPort=" + proxyPort
+ ", players=" + players
+ ", proxyVersion='" + proxyVersion + '\''
+ ", plugins=" + plugins
+ '}';
}
/** /**
* A builder for {@link QueryResponse} objects. * A builder for {@link QueryResponse} objects.
*/ */
@ -392,5 +442,22 @@ public final class QueryResponse {
.add("version", version) .add("version", version)
.toString(); .toString();
} }
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
PluginInformation that = (PluginInformation) o;
return name.equals(that.name) && Objects.equals(version, that.version);
}
@Override
public int hashCode() {
return Objects.hash(name, version);
}
} }
} }

Datei anzeigen

@ -33,6 +33,7 @@ public final class ServerPing {
/** /**
* Constructs a ServerPing instance. * Constructs a ServerPing instance.
*
* @param version the version of the server * @param version the version of the server
* @param players the players on the server * @param players the players on the server
* @param description the MOTD for the server * @param description the MOTD for the server
@ -102,6 +103,9 @@ public final class ServerPing {
/** /**
* Returns a copy of this {@link ServerPing} instance as a builder so that it can be modified. * Returns a copy of this {@link ServerPing} instance as a builder so that it can be modified.
* It is guaranteed that {@code ping.asBuilder().ping().equals(ping)}: that is, if no other
* changes are made to the returned builder, the built instance will equal the original instance.
*
* @return a copy of this instance as a {@link Builder} * @return a copy of this instance as a {@link Builder}
*/ */
public Builder asBuilder() { public Builder asBuilder() {

Datei anzeigen

@ -0,0 +1,19 @@
package com.velocitypowered.api.proxy.server;
import static org.junit.jupiter.api.Assertions.*;
import com.google.common.collect.ImmutableList;
import com.velocitypowered.api.proxy.server.QueryResponse.PluginInformation;
import org.junit.jupiter.api.Test;
class QueryResponseTest {
@Test
void toBuilderConsistency() {
QueryResponse response = new QueryResponse("test", "test", "test",
1, 2, "test", 1234, ImmutableList.of("tuxed"),
"0.0.1", ImmutableList.of(new PluginInformation("test", "1.0.0"),
new PluginInformation("test2", null)));
assertEquals(response, response.toBuilder().build());
}
}