Skip to content

Commit

Permalink
Added missing java-doc and deleted unused class file.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Oct 12, 2023
1 parent 9cf19df commit 572ab2b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
* @param servers The servers on the BetaCraft server list.
*/
public record BCServerList(List<BCServerInfoSpec> servers) {

/**
* Sends a request to the BetaCraft server list and returns the response as a {@link BCServerList} object.
*
* @param httpClient The HttpClient to use for the request.
* @param gson The Gson instance to use for the request.
* @param uri The URI of the request. This is the URI of the BetaCraft server list.
* @param infoSpec The class of the server info specification. This is the class that will be used to parse the JSON response.
* @return A CompletableFuture containing the response.
*/
public static CompletableFuture<BCServerList> get(final HttpClient httpClient, final Gson gson, final URI uri, final Class<? extends BCServerInfoSpec> infoSpec) {
return CompletableFuture.supplyAsync(() -> new BCServerList(gson.fromJson(httpClient.sendAsync(HttpRequest.newBuilder(uri).build(), BodyHandlers.ofString()).join().body(), JsonArray.class)
.asList()
Expand All @@ -49,16 +59,34 @@ public List<BCServerInfoSpec> servers() {
return Collections.unmodifiableList(this.servers);
}

/**
* Returns a list of servers that have the given version category.
*
* @param version The version category to filter by.
* @return A list of servers that have the given version category.
*/
public List<BCServerInfoSpec> serversOfVersionCategory(final BCVersionCategory version) {
final List<BCServerInfoSpec> serverListCopy = this.servers();

return serverListCopy.stream().filter(s -> s.versionCategory().equals(version)).toList();
}

/**
* Returns a list of servers that have the given version category.
*
* @param on Whether the servers should be online mode or not.
* @return A list of servers that have the given version category.
*/
public List<BCServerInfoSpec> serversWithOnlineMode(final boolean on) {
return this.servers().stream().filter(s -> s.onlineMode() == on).toList();
}

/**
* Returns a list of servers that have the given version category.
*
* @param connectVersion The connect version to filter by.
* @return A list of servers that have the given version category.
*/
public List<BCServerInfoSpec> withConnectVersion(final String connectVersion) {
return this.servers().stream().filter(s -> s.connectVersion().equals(connectVersion)).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

package de.florianmichael.classic4j.request.betacraft;

import com.google.gson.Gson;
import de.florianmichael.classic4j.model.betacraft.BCServerInfoSpec;
import de.florianmichael.classic4j.model.betacraft.BCServerList;
import de.florianmichael.classic4j.model.betacraft.impl.BCServerInfov1;
import de.florianmichael.classic4j.model.betacraft.impl.BCServerInfov2;

import java.net.URI;
import java.net.http.HttpClient;
import java.util.concurrent.CompletableFuture;

public enum BCServerListRequest implements BCServerListRequestInterface {
public enum BCServerListRequest {
V1(URI.create("https://api.betacraft.uk/server_list.jsp"), BCServerInfov1.class),
V2(URI.create("https://api.betacraft.uk/v2/server_list"), BCServerInfov2.class);

Expand All @@ -35,13 +39,14 @@ public enum BCServerListRequest implements BCServerListRequestInterface {
this.infoSpec = infoSpec;
}

@Override
public URI uri() {
return this.uri;
}

@Override
public Class<? extends BCServerInfoSpec> infoSpec() {
return this.infoSpec;
/**
* Sends the request to the BetaCraft server list and returns the response as a {@link BCServerList} object.
*
* @param client The HttpClient to use for the request.
* @param gson The Gson instance to use for the request.
* @return A CompletableFuture containing the response.
*/
public CompletableFuture<BCServerList> send(final HttpClient client, final Gson gson) {
return BCServerList.get(client, gson, this.uri, this.infoSpec);
}
}

This file was deleted.

0 comments on commit 572ab2b

Please sign in to comment.