Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
markozajc committed Apr 2, 2021
2 parents 7902fd8 + 0312952 commit e0249a9
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 426 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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.
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -224,8 +223,8 @@ private static Language getLanguage(@Nonnull Scanner sc) {
EnumSet<Language> 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)");
Expand All @@ -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);
Expand All @@ -258,8 +257,8 @@ private static GuessType getGuessType(@Nonnull Scanner sc) {
EnumSet<GuessType> 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)");
Expand All @@ -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);
Expand Down
29 changes: 9 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.markozajc</groupId>
<artifactId>akiwrapper</artifactId>
<version>1.5.1</version>
<version>1.5.1.1</version>

<name>Akiwrapper</name>
<description>A Java API wrapper for Akinator</description>
Expand Down Expand Up @@ -43,6 +43,8 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<junit.version>5.7.1</junit.version>
<slf4j.version>1.7.30</slf4j.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -57,7 +59,7 @@
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20201115</version>
<version>20210307</version>
</dependency>

<!-- Unit tests -->
Expand Down Expand Up @@ -87,13 +89,6 @@
<version>3.11.11</version>
</dependency>

<!-- Cache -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.1-jre</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
Expand All @@ -111,7 +106,7 @@
<dependency>
<groupId>com.github.spotbugs</groupId>
<artifactId>spotbugs-annotations</artifactId>
<version>4.2.1</version>
<version>4.2.2</version>
</dependency>

<dependency>
Expand All @@ -125,15 +120,6 @@
<build>
<plugins>

<!-- Compiler -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
</configuration>
</plugin>

<!-- Javadoc -->
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
Expand Down Expand Up @@ -169,7 +155,10 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.7</version>
<version>2.8.1</version>
<configuration>
<rulesUri>file://${project.basedir}/versions-ruleset.xml</rulesUri>
</configuration>
</plugin>

</plugins>
Expand Down
50 changes: 48 additions & 2 deletions src/main/java/com/markozajc/akiwrapper/AkiwrapperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,73 @@ 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. <br>
* <b>Caution!</b> 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);

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);

return this;
}

/**
* Sets the {@link Language}.<br>
* <b>Caution!</b> 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}.<br>
* <b>Caution!</b> 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);
Expand Down
Loading

0 comments on commit e0249a9

Please sign in to comment.