diff --git a/example/src/main/java/com/markozajc/akiwrapper/example/AkinatorExample.java b/example/src/main/java/com/markozajc/akiwrapper/example/AkinatorExample.java index 5715aa5..be63603 100644 --- a/example/src/main/java/com/markozajc/akiwrapper/example/AkinatorExample.java +++ b/example/src/main/java/com/markozajc/akiwrapper/example/AkinatorExample.java @@ -80,9 +80,9 @@ public static void main(String[] args) throws Exception { Akiwrapper aw; try { aw = new AkiwrapperBuilder().setFilterProfanity(filterProfanity) - .setLanguage(language) - .setGuessType(guessType) - .build(); + .setLanguage(language) + .setGuessType(guessType) + .build(); } catch (ServerNotFoundException e) { System.err.println("Invalid combination of language and guess type. Try a different guess type."); return; @@ -107,8 +107,8 @@ public static void main(String[] args) throws Exception { // Displays the question. if (question.getStep() == 0) - System.out.println( - "\nAnswer with Y (yes), N (no), DK (don't know), P (probably) or PN (probably not) or go back in time with B (back)."); + System.out + .println("\nAnswer with Y (yes), N (no), DK (don't know), P (probably) or PN (probably not) or go back in time with B (back)."); // Displays the tip (only for the first time). answerQuestion(sc, aw); @@ -141,7 +141,7 @@ private static void reviewGuesses(@Nonnull Scanner sc, @Nonnull Akiwrapper aw, @ System.exit(0); } - declined.add(Long.valueOf(guess.getIdLong())); + declined.add(guess.getIdLong()); // Registers this guess as rejected. } @@ -177,16 +177,15 @@ private static void answerQuestion(@Nonnull Scanner sc, @Nonnull Akiwrapper aw) ApiKey.accquireApiKey(); } else if (answer.equals("debug")) { - System.out.println("Debug information:\n\tCurrent API server: " - + aw.getServer().getUrl() - + "\n\tCurrent guess count: " - + aw.getGuesses().size()); + System.out.println("Debug information:\n\tCurrent API server: " + aw.getServer().getUrl() + + "\n\tCurrent guess count: " + + aw.getGuesses().size()); continue; // Displays some debug information. } else { - System.out.println( - "Please answer with either [Y]ES, [N]O, [D|ONT |K]NOW, [P]ROBABLY or [P|ROBABLY |N]OT or go back one step with [B]ACK."); + System.out + .println("Please answer with either [Y]ES, [N]O, [D|ONT |K]NOW, [P]ROBABLY or [P|ROBABLY |N]OT or go back one step with [B]ACK."); continue; } @@ -224,8 +223,8 @@ private static Language getLanguage(@Nonnull Scanner sc) { EnumSet languages = EnumSet.allOf(Language.class); // Fetches all available languages. - String unsupportedLanguageMessage = "Sorry, that language isn't supported. Rather try with:" - + languages.stream().map(Enum::toString).collect(Collectors.joining("\n-", "\n-", "")); + String unsupportedLanguageMessage = "Sorry, that language isn't supported. Rather try with:" + + languages.stream().map(Enum::toString).collect(Collectors.joining("\n-", "\n-", "")); // Does some Java 8 magic to pre-prepare the error message. System.out.println("What's your language? (English)"); @@ -238,9 +237,9 @@ private static Language getLanguage(@Nonnull Scanner sc) { } Language matching = languages.stream() - .filter(l -> l.toString().toLowerCase().equals(selectedLanguage)) - .findAny() - .orElse(null); + .filter(l -> l.toString().toLowerCase().equals(selectedLanguage)) + .findAny() + .orElse(null); if (matching == null) { System.out.println(unsupportedLanguageMessage); @@ -258,8 +257,8 @@ private static GuessType getGuessType(@Nonnull Scanner sc) { EnumSet guessTypes = EnumSet.allOf(GuessType.class); // Fetches all available guess types. - String unsupportedGuessTypeMessage = "Sorry, that guess type isn't supported. Rather try with:" - + guessTypes.stream().map(Enum::toString).collect(Collectors.joining("\n-", "\n-", "")); + String unsupportedGuessTypeMessage = "Sorry, that guess type isn't supported. Rather try with:" + + guessTypes.stream().map(Enum::toString).collect(Collectors.joining("\n-", "\n-", "")); // Does some Java 8 magic to pre-prepare the error message. System.out.println("What will you be guessing? (character)"); @@ -272,9 +271,9 @@ private static GuessType getGuessType(@Nonnull Scanner sc) { } GuessType matching = guessTypes.stream() - .filter(l -> l.toString().toLowerCase().equals(selectedGuessType)) - .findAny() - .orElse(null); + .filter(l -> l.toString().toLowerCase().equals(selectedGuessType)) + .findAny() + .orElse(null); if (matching == null) { System.out.println(unsupportedGuessTypeMessage); diff --git a/pom.xml b/pom.xml index 91f82d4..bea9637 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.github.markozajc akiwrapper - 1.5.1 + 1.5.1.1 Akiwrapper A Java API wrapper for Akinator @@ -43,6 +43,8 @@ UTF-8 5.7.1 1.7.30 + 11 + 11 @@ -57,7 +59,7 @@ org.json json - 20201115 + 20210307 @@ -87,13 +89,6 @@ 3.11.11 - - - com.google.guava - guava - 30.1-jre - - org.slf4j @@ -111,7 +106,7 @@ com.github.spotbugs spotbugs-annotations - 4.2.1 + 4.2.2 @@ -125,15 +120,6 @@ - - - maven-compiler-plugin - 3.8.1 - - 11 - - - maven-javadoc-plugin @@ -169,7 +155,10 @@ org.codehaus.mojo versions-maven-plugin - 2.7 + 2.8.1 + + file://${project.basedir}/versions-ruleset.xml + diff --git a/src/main/java/com/markozajc/akiwrapper/AkiwrapperBuilder.java b/src/main/java/com/markozajc/akiwrapper/AkiwrapperBuilder.java index 170cc35..ad429a2 100644 --- a/src/main/java/com/markozajc/akiwrapper/AkiwrapperBuilder.java +++ b/src/main/java/com/markozajc/akiwrapper/AkiwrapperBuilder.java @@ -31,6 +31,21 @@ public AkiwrapperBuilder() { AkiwrapperMetadata.DEFAULT_GUESS_TYPE); } + /** + * Sets the {@link Server} or (recommended) a {@link ServerList}. It is not + * recommended to set the {@link Server} manually (unless for debugging purposes or + * as some kind of workaround where Akiwrapper's server finder fails) as Akiwrapper + * already does its best to find the most suitable one.
+ * Caution! Setting the server to a non-null value overwrites the + * {@link Language} and the {@link GuessType} with the given {@link Server}'s values. + * + * @param server + * + * @return current instance, used for chaining + * + * @see #getServer() + * @see Servers#findServers(Language, GuessType) + */ @Override public AkiwrapperBuilder setServer(Server server) { super.setServer(server); @@ -38,6 +53,15 @@ public AkiwrapperBuilder setServer(Server server) { return this; } + /** + * Sets the "filter profanity" mode. + * + * @param filterProfanity + * + * @return current instance, used for chaining + * + * @see #doesFilterProfanity() + */ @Override public AkiwrapperBuilder setFilterProfanity(boolean filterProfanity) { super.setFilterProfanity(filterProfanity); @@ -45,13 +69,35 @@ public AkiwrapperBuilder setFilterProfanity(boolean filterProfanity) { return this; } + /** + * Sets the {@link Language}.
+ * Caution! Setting the {@link Language} will set the {@link Server} to + * {@code null} (meaning it will be automatically selected). + * + * @param language + * + * @return current instance, used for chaining + * + * @see #getLanguage() + */ @Override - public AkiwrapperBuilder setLanguage(Language localization) { - super.setLanguage(localization); + public AkiwrapperBuilder setLanguage(Language language) { + super.setLanguage(language); return this; } + /** + * Sets the {@link GuessType}.
+ * Caution! Setting the {@link Language} will set the {@link Server} to + * {@code null} (meaning it will be automatically selected). + * + * @param guessType + * + * @return current instance, used for chaining + * + * @see #getLanguage() + */ @Override public AkiwrapperBuilder setGuessType(GuessType guessType) { super.setGuessType(guessType); diff --git a/src/main/java/com/markozajc/akiwrapper/core/Route.java b/src/main/java/com/markozajc/akiwrapper/core/Route.java index a2db855..04b0007 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/Route.java +++ b/src/main/java/com/markozajc/akiwrapper/core/Route.java @@ -10,7 +10,6 @@ import org.slf4j.*; import com.markozajc.akiwrapper.core.entities.Status; -import com.markozajc.akiwrapper.core.entities.Status.Level; import com.markozajc.akiwrapper.core.entities.impl.immutable.*; import com.markozajc.akiwrapper.core.exceptions.*; import com.markozajc.akiwrapper.core.impl.AkiwrapperImpl.Token; @@ -18,17 +17,8 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import kong.unirest.*; -/** - * A class defining various API endpoints. It is capable of building such - * {@link Route}s into {@link Request}s, which can then easily be executed and read. - * - * @author Marko Zajc - */ public final class Route { - /** - * A public {@link UnirestInstance} with all required default headers set. - */ public static final UnirestInstance UNIREST; static { @@ -54,9 +44,6 @@ public final class Route { // probably doesn't even store cookies right. } - /** - * The base Akinator URL, used for scraping and some API calls. - */ public static final String BASE_AKINATOR_URL = "https://en.akinator.com"; private static final String SERVER_DOWN_STATUS_MESSAGE = "server down"; private static final Pattern FILTER_ARGUMENT_PATTERN = Pattern.compile("\\{FILTER\\}"); @@ -130,18 +117,6 @@ private Route(int parameters, @Nonnull String path, @Nonnull String... filterArg this.parametersQuantity = parameters; } - /** - * Tests whether a response is a successful or a failed one. - * - * @param response - * the response to test - * - * @throws ServerUnavailableException - * throws if the status is equal to {@link Level#ERROR} and the error - * message hints that the server is down - * @throws StatusException - * thrown if the status is equal to {@link Level#ERROR} - */ public static void testResponse(@Nonnull JSONObject response) { Status completion = new StatusImpl(response); if (completion.getLevel() == Status.Level.ERROR) { @@ -152,20 +127,6 @@ public static void testResponse(@Nonnull JSONObject response) { } } - /** - * Constructs a {@link Request} for a route that can later be executed and converted - * into a {@link JSONObject}. - * - * @param baseUrl - * @param filterProfanity - * @param token - * @param parameters - * - * @return a {@link Request}. - * - * @throws IllegalArgumentException - * if you have passed too little parameters. - */ @Nonnull public Request getRequest(@Nonnull String baseUrl, boolean filterProfanity, @Nullable Token token, @Nonnull String... parameters) { @@ -207,53 +168,20 @@ public Request getRequest(@Nonnull String baseUrl, boolean filterProfanity, @Nul return new Request(baseUrl + formattedPath, jQueryCallback); } - /** - * Constructs a {@link Request} for a route that can later be executed and converted - * into a {@link JSONObject}. The resulting {@link Request} does not perform any - * session authentication with a {@link Token}. - * - * @param baseUrl - * @param filterProfanity - * @param parameters - * - * @return a {@link Request}. - * - * @throws IllegalArgumentException - * if you have passed too little parameters. - */ @Nonnull public Request getRequest(@Nonnull String baseUrl, boolean filterProfanity, @Nonnull String... parameters) { return this.getRequest(baseUrl, filterProfanity, null, parameters); } - /** - * Returns {@link Route}'s unformatted path. - * - * @return route's path. - */ @Nonnull public String getPath() { return this.path; } - /** - * Returns the minimal quantity of parameters that must be passed to - * {@link #getRequest(String, boolean, String...)} and - * {@link #getRequest(String, boolean, Token, String...)}. If the amount of passed - * parameters is lower than this number, an {@link IllegalArgumentException} is - * thrown. - * - * @return minimal quantity of parameters. - */ public int getParametersQuantity() { return this.parametersQuantity; } - /** - * An executable request. - * - * @author Marko Zajc - */ public static class Request { private static final Logger LOG = LoggerFactory.getLogger(Route.Request.class); @@ -268,35 +196,11 @@ public static class Request { this.url = url; } - /** - * Requests the server and returns the route's content as a {@link JSONObject}. - * - * @return route's content - * - * @throws ServerUnavailableException - * if the server has gone down - * @throws StatusException - * if the server returns an error response. - */ @Nonnull public JSONObject getJSON() { return getJSON(defaultRunChecks); } - /** - * Requests the server and returns the route's content as a {@link JSONObject}. - * - * @param runChecks - * whether to run checks for error status codes. - * - * @return route's content - * - * @throws ServerUnavailableException - * if the server has gone down. - * @throws StatusException - * if the server returns an error response. - * - */ @Nonnull public JSONObject getJSON(boolean runChecks) { String response = UNIREST.get(this.url).asString().getBody().replace(this.jQueryCallback, ""); diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ApiKey.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ApiKey.java index fd0b105..f9eab92 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ApiKey.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ApiKey.java @@ -7,16 +7,7 @@ import javax.annotation.Nonnull; import com.markozajc.akiwrapper.core.Route; -import com.markozajc.akiwrapper.core.exceptions.StatusException; -/** - * A class defining the session key that has to be passed to the - * {@link Route#NEW_SESSION} endpoint. It is scraped from the website as it is - * single-use and triggers a KO if reused. - * - * @author Marko Zajc - * - */ public class ApiKey { private static final Pattern API_KEY_PATTERN = @@ -34,11 +25,6 @@ public class ApiKey { this.frontAddress = frontAddress; } - /** - * Compiles this {@link ApiKey} into querystring that can be appended to an endpoint. - * - * @return compiled querystring. - */ @SuppressWarnings("null") @Nonnull public String compile() { @@ -49,17 +35,6 @@ public String compile() { } } - /** - * Finds and scrapes the API key from Akinator's website and constructs an - * {@link ApiKey} instance from it.
- * Caution!Each {@link ApiKey} is single-use! Reusing it will trigger a - * {@link StatusException} from the API server. - * - * @return an {@link ApiKey}. - * - * @throws IllegalStateException - * if the API key can't be scraped - */ @SuppressWarnings("null") public static ApiKey accquireApiKey() { Matcher matcher = diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/GuessImpl.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/GuessImpl.java index 9acbe19..9918f47 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/GuessImpl.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/GuessImpl.java @@ -4,17 +4,11 @@ import javax.annotation.*; -import org.json.*; +import org.json.JSONObject; -import com.markozajc.akiwrapper.core.Route; import com.markozajc.akiwrapper.core.entities.Guess; import com.markozajc.akiwrapper.core.utils.JSONUtils; -/** - * An implementation of {@link Guess}. - * - * @author Marko Zajc - */ public class GuessImpl implements Guess { @Nonnull @@ -28,15 +22,6 @@ public class GuessImpl implements Guess { @Nonnegative private final double probability; - /** - * Creates a new {@link GuessImpl} instance from raw parameters. - * - * @param id - * @param name - * @param description - * @param image - * @param probability - */ public GuessImpl(@Nonnull String id, @Nonnull String name, @Nullable String description, @Nullable URL image, @Nonnegative double probability) { this.id = id; @@ -46,14 +31,6 @@ public GuessImpl(@Nonnull String id, @Nonnull String name, @Nullable String desc this.probability = probability; } - /** - * Creates a new {@link GuessImpl} instance. - * - * @param json - * JSON parameters to use (acquired with {@link Route#LIST} > - * {@link JSONArray} elements > {@link JSONObject} (an index) > - * {@link JSONObject} element) - */ @SuppressWarnings("null") public GuessImpl(@Nonnull JSONObject json) { this(json.getString("id"), json.getString("name"), getDescription(json), getImage(json), diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ImmutableAkiwrapperMetadata.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ImmutableAkiwrapperMetadata.java deleted file mode 100644 index d7e813f..0000000 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ImmutableAkiwrapperMetadata.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.markozajc.akiwrapper.core.entities.impl.immutable; - -import javax.annotation.*; - -import com.markozajc.akiwrapper.core.entities.*; -import com.markozajc.akiwrapper.core.entities.Server.*; - -/** - * An immutable implementation of {@link AkiwrapperMetadata}. - * - * @author Marko Zajc - */ -public abstract class ImmutableAkiwrapperMetadata extends AkiwrapperMetadata { - - @Nullable - protected final Server server; - protected final boolean filterProfanity; - @Nonnull - protected final Language localization; - @Nonnull - protected final GuessType guessType; - - /** - * Creates a new {@link ImmutableAkiwrapperMetadata} instance. - * - * @param server - * API server that the requests will be sent to. - * @param filterProfanity - * whether to filter out NSFW {@link Question}s and {@link Guess}es. - * @param language - * {@link Language} of {@link Question}s. - * @param guessType - * {@link GuessType} of {@link Guess}es. - */ - public ImmutableAkiwrapperMetadata(@Nullable Server server, boolean filterProfanity, @Nonnull Language language, - @Nonnull GuessType guessType) { - this.server = server; - this.filterProfanity = filterProfanity; - this.localization = language; - this.guessType = guessType; - } - - @Override - public Server getServer() { - return this.server; - } - - @Override - public boolean doesFilterProfanity() { - return this.filterProfanity; - } - - @Override - public Language getLanguage() { - return this.localization; - } - - @Override - public GuessType getGuessType() { - return this.guessType; - } - -} diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/QuestionImpl.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/QuestionImpl.java index 60cc203..f249ab9 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/QuestionImpl.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/QuestionImpl.java @@ -9,11 +9,6 @@ import com.markozajc.akiwrapper.core.exceptions.MissingQuestionException; import com.markozajc.akiwrapper.core.utils.JSONUtils; -/** - * An implementation of {@link Question}. - * - * @author Marko Zajc - */ public class QuestionImpl implements Question { @Nonnull @@ -27,19 +22,6 @@ public class QuestionImpl implements Question { @Nonnegative private final double progression; - /** - * Constructs a new {@link QuestionImpl} instance from raw parameters. - * - * @param id - * @param question - * @param step - * @param gain - * @param progression - * @param status - * - * @throws MissingQuestionException - * if there are no more questions left. - */ public QuestionImpl(@Nonnull String id, @Nonnull String question, @Nonnegative int step, @Nonnegative double gain, @Nonnegative double progression, @Nonnull Status status) { checkMissingQuestion(status); @@ -51,15 +33,6 @@ public QuestionImpl(@Nonnull String id, @Nonnull String question, @Nonnegative i this.progression = progression; } - /** - * Constructs a new {@link QuestionImpl} instance from a {@link JSONObject}. - * - * @param json - * @param status - * - * @throws MissingQuestionException - * if there are no more questions left. - */ @SuppressWarnings("null") public QuestionImpl(@Nonnull JSONObject json, @Nonnull Status status) { checkMissingQuestion(status); diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ServerImpl.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ServerImpl.java index 35a449b..874cabc 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ServerImpl.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/ServerImpl.java @@ -8,11 +8,6 @@ import com.jcabi.xml.XML; import com.markozajc.akiwrapper.core.entities.Server; -/** - * An implementation of {@link Server}. - * - * @author Marko Zajc - */ public class ServerImpl implements Server { private static final String LANGUAGE_ID_XPATH = "LANGUAGE/LANG_ID/text()"; // NOSONAR not a URL @@ -25,31 +20,12 @@ public class ServerImpl implements Server { @Nonnull private final GuessType guessType; - /** - * Constructs a new instance of {@link ServerImpl}. - * - * @param url - * server's URL (for example {@code https://srv3.akinator.com:9331/ws}). - * @param localization - * server's language. - * @param guessType - * server's guess type. - */ public ServerImpl(@Nonnull String url, @Nonnull Language localization, @Nonnull GuessType guessType) { this.url = url; this.localization = localization; this.guessType = guessType; } - /** - * Constructs a {@link ServerImpl} from an {@code } XML node provided by - * the server-listing API endpoint. - * - * @param instance - * XML node. - * - * @return a {@link ServerImpl}. - */ @SuppressWarnings("null") @Nonnull public static List fromXml(@Nonnull XML instance) { diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/StatusImpl.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/StatusImpl.java index 731def1..6a63292 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/StatusImpl.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/immutable/StatusImpl.java @@ -4,14 +4,8 @@ import org.json.JSONObject; -import com.google.gson.JsonObject; import com.markozajc.akiwrapper.core.entities.Status; -/** - * An implementation of {@link Status}. - * - * @author Marko Zajc - */ public class StatusImpl implements Status { private static final long serialVersionUID = 1; @@ -24,21 +18,11 @@ public class StatusImpl implements Status { @Nonnull private final Level level; - /** - * Constructs a new {@link StatusImpl} instance from raw parameters. - * - * @param completion - */ public StatusImpl(@Nonnull String completion) { this.level = determineLevel(completion); this.reason = determineReason(completion); } - /** - * Constructs a new {@link StatusImpl} instance from a {@link JsonObject}. - * - * @param json - */ @SuppressWarnings("null") public StatusImpl(@Nonnull JSONObject json) { this(json.getString("completion")); diff --git a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/mutable/MutableAkiwrapperMetadata.java b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/mutable/MutableAkiwrapperMetadata.java index e286616..27d5b06 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/entities/impl/mutable/MutableAkiwrapperMetadata.java +++ b/src/main/java/com/markozajc/akiwrapper/core/entities/impl/mutable/MutableAkiwrapperMetadata.java @@ -4,14 +4,7 @@ import com.markozajc.akiwrapper.core.entities.*; import com.markozajc.akiwrapper.core.entities.Server.*; -import com.markozajc.akiwrapper.core.entities.impl.immutable.ImmutableAkiwrapperMetadata; -import com.markozajc.akiwrapper.core.utils.Servers; -/** - * A mutable implementation of {@link AkiwrapperMetadata}. - * - * @author Marko Zajc - */ public abstract class MutableAkiwrapperMetadata extends AkiwrapperMetadata { @Nullable @@ -22,20 +15,8 @@ public abstract class MutableAkiwrapperMetadata extends AkiwrapperMetadata { @Nonnull protected GuessType guessType; - /** - * Creates a new {@link ImmutableAkiwrapperMetadata} instance. - * - * @param server - * API server that the requests will be sent to. - * @param filterProfanity - * whether to filter out NSFW {@link Question}s and {@link Guess}es. - * @param language - * {@link Language} of {@link Question}s. - * @param guessType - * {@link GuessType} of {@link Guess}es. - */ - public MutableAkiwrapperMetadata(@Nullable Server server, boolean filterProfanity, @Nonnull Language language, - @Nonnull GuessType guessType) { + protected MutableAkiwrapperMetadata(@Nullable Server server, boolean filterProfanity, @Nonnull Language language, + @Nonnull GuessType guessType) { this.server = server; this.filterProfanity = filterProfanity; this.language = language; @@ -47,21 +28,6 @@ public Server getServer() { return this.server; } - /** - * Sets the {@link Server} or (recommended) a {@link ServerList}. It is not - * recommended to set the {@link Server} manually (unless for debugging purposes or - * as some kind of workaround where Akiwrapper's server finder fails) as Akiwrapper - * already does its best to find the most suitable one.
- * Caution! Setting the server to a non-null value overwrites the - * {@link Language} and the {@link GuessType} with the given {@link Server}'s values. - * - * @param server - * - * @return current instance, used for chaining - * - * @see #getServer() - * @see Servers#findServers(Language, GuessType) - */ @Nonnull public MutableAkiwrapperMetadata setServer(@Nullable Server server) { this.server = server; @@ -69,7 +35,6 @@ public MutableAkiwrapperMetadata setServer(@Nullable Server server) { this.language = server.getLanguage(); this.guessType = server.getGuessType(); } - return this; } @@ -78,19 +43,9 @@ public boolean doesFilterProfanity() { return this.filterProfanity; } - /** - * Sets the "filter profanity" mode. - * - * @param filterProfanity - * - * @return current instance, used for chaining - * - * @see #doesFilterProfanity() - */ @Nonnull public MutableAkiwrapperMetadata setFilterProfanity(boolean filterProfanity) { this.filterProfanity = filterProfanity; - return this; } @@ -99,22 +54,10 @@ public Language getLanguage() { return this.language; } - /** - * Sets the {@link Language}.
- * Caution! Setting the {@link Language} will set the {@link Server} to - * {@code null} (meaning it will be automatically selected). - * - * @param language - * - * @return current instance, used for chaining - * - * @see #getLanguage() - */ @Nonnull public MutableAkiwrapperMetadata setLanguage(@Nonnull Language language) { this.language = language; this.server = null; - return this; } @@ -123,17 +66,6 @@ public GuessType getGuessType() { return this.guessType; } - /** - * Sets the {@link GuessType}.
- * Caution! Setting the {@link Language} will set the {@link Server} to - * {@code null} (meaning it will be automatically selected). - * - * @param guessType - * - * @return current instance, used for chaining - * - * @see #getLanguage() - */ @Nonnull public MutableAkiwrapperMetadata setGuessType(@Nonnull GuessType guessType) { this.guessType = guessType; diff --git a/src/main/java/com/markozajc/akiwrapper/core/exceptions/MissingQuestionException.java b/src/main/java/com/markozajc/akiwrapper/core/exceptions/MissingQuestionException.java index 1c5725a..a03c1db 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/exceptions/MissingQuestionException.java +++ b/src/main/java/com/markozajc/akiwrapper/core/exceptions/MissingQuestionException.java @@ -10,7 +10,6 @@ public class MissingQuestionException extends RuntimeException { /** * Constructs a new {@link MissingQuestionException} instance. */ - public MissingQuestionException() { - } + public MissingQuestionException() {} } diff --git a/src/main/java/com/markozajc/akiwrapper/core/exceptions/ServerNotFoundException.java b/src/main/java/com/markozajc/akiwrapper/core/exceptions/ServerNotFoundException.java index e5dcc41..593be6d 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/exceptions/ServerNotFoundException.java +++ b/src/main/java/com/markozajc/akiwrapper/core/exceptions/ServerNotFoundException.java @@ -14,7 +14,6 @@ public class ServerNotFoundException extends Exception { /** * Constructs a new {@link ServerNotFoundException}. */ - public ServerNotFoundException() { - } + public ServerNotFoundException() {} } diff --git a/src/main/java/com/markozajc/akiwrapper/core/impl/AkiwrapperImpl.java b/src/main/java/com/markozajc/akiwrapper/core/impl/AkiwrapperImpl.java index b84c3e0..96a810a 100644 --- a/src/main/java/com/markozajc/akiwrapper/core/impl/AkiwrapperImpl.java +++ b/src/main/java/com/markozajc/akiwrapper/core/impl/AkiwrapperImpl.java @@ -6,28 +6,18 @@ import org.json.*; -import com.markozajc.akiwrapper.*; +import com.markozajc.akiwrapper.Akiwrapper; import com.markozajc.akiwrapper.core.Route; import com.markozajc.akiwrapper.core.entities.*; import com.markozajc.akiwrapper.core.entities.Status.Level; import com.markozajc.akiwrapper.core.entities.impl.immutable.*; import com.markozajc.akiwrapper.core.exceptions.*; -/** - * An implementation of {@link Akiwrapper}. - * - * @author Marko Zajc - */ public class AkiwrapperImpl implements Akiwrapper { private static final String NO_MORE_QUESTIONS_STATUS = "elem list is empty"; private static final String PARAMETERS_KEY = "parameters"; - /** - * A class used to define the session token. - * - * @author Marko Zajc - */ public static class Token { private static final String AUTH_QUERYSTRING = "&session=%s&signature=%s"; @@ -35,12 +25,6 @@ public static class Token { private final long signature; private final int session; - /** - * Creates a new {@link Token}. - * - * @param signature - * @param session - */ public Token(long signature, int session) { this.signature = signature; this.session = session; @@ -54,9 +38,6 @@ private int getSession() { return this.session; } - /** - * @return the compiled token - */ public String compile() { return String.format(AUTH_QUERYSTRING, "" + this.getSession(), "" + this.getSignature()); } @@ -73,16 +54,6 @@ public String compile() { @Nullable private Question currentQuestion; - /** - * Constructs a new {@link Akiwrapper} instance and creates a new API session. The - * first question can be retrieved with {@link #getCurrentQuestion()}. - * - * @param server - * {@link Server} to use. Does not work with a {@link ServerList}, - * {@link AkiwrapperBuilder} implements that functionality. - * @param filterProfanity - * whether to tell API to filter profanity. - */ @SuppressWarnings("null") public AkiwrapperImpl(@Nonnull Server server, boolean filterProfanity) { JSONObject question = Route.NEW_SESSION diff --git a/src/test/java/com/markozajc/akiwrapper/IntegrationTest.java b/src/test/java/com/markozajc/akiwrapper/IntegrationTest.java index 39d6c32..fb01edd 100644 --- a/src/test/java/com/markozajc/akiwrapper/IntegrationTest.java +++ b/src/test/java/com/markozajc/akiwrapper/IntegrationTest.java @@ -18,13 +18,16 @@ class IntegrationTest { - private static final String SERVER_GUESSTYPE_NO_MATCH = "The wanted and actual guess type of the server don't match."; + private static final String SERVER_GUESSTYPE_NO_MATCH = + "The wanted and actual guess type of the server don't match."; private static final String SERVER_LANGUAGE_NO_MATCH = "The wanted and actual language of the server don't match."; - private static final String QUESTION_CURRENT_NO_MATCH = "Current question does not match the one just returned by the API."; + private static final String QUESTION_CURRENT_NO_MATCH = + "Current question does not match the one just returned by the API."; private static final String QUESTION_WRONG_STEP = "Question was on an unexpected step."; private static final String QUESTION_EMPTY = "Question mustn't be empty."; private static final String QUESTION_NULL = "Question was null"; - private static final String QUESTION_INITIAL_NO_MATCH = "Initial question does not match the one after an equal amount of answers and undoes."; + private static final String QUESTION_INITIAL_NO_MATCH = + "Initial question does not match the one after an equal amount of answers and undoes."; @ParameterizedTest @MethodSource("generateTestAkiwrapper") diff --git a/versions-ruleset.xml b/versions-ruleset.xml new file mode 100644 index 0000000..193c626 --- /dev/null +++ b/versions-ruleset.xml @@ -0,0 +1,16 @@ + + + + + .*-alpha\d$ + .*-beta\d$ + .*-M\d$ + .*-RC\d$ + + + +