diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 000000000..13566b81b
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/checkstyle-idea.xml b/.idea/checkstyle-idea.xml
new file mode 100644
index 000000000..72c925187
--- /dev/null
+++ b/.idea/checkstyle-idea.xml
@@ -0,0 +1,18 @@
+
+
+
+ 10.23.0
+ JavaOnly
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 000000000..81c33a4ee
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 000000000..aa00ffab7
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 000000000..712ab9d98
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 000000000..9533805e8
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 000000000..35eb1ddfb
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/translation/InLabByHandTranslator.java b/src/main/java/org/translation/InLabByHandTranslator.java
index bcf55adf4..706b872c0 100644
--- a/src/main/java/org/translation/InLabByHandTranslator.java
+++ b/src/main/java/org/translation/InLabByHandTranslator.java
@@ -3,7 +3,7 @@
import java.util.ArrayList;
import java.util.List;
-// TODO Task: modify this class so that it also supports the Spanish language code "es" and
+// TOD Task: modify this class so that it also supports the Spanish language code "es" and
// one more language code of your choice. Each member of your group should add
// support for one additional langauge code on a branch; then push and create a pull request on GitHub.
@@ -11,27 +11,24 @@
/**
* An implementation of the Translator interface which translates
- * the country code "can" to several languages.
+ * the country code COUNTRY_CANADA to several languages.
*/
public class InLabByHandTranslator implements Translator {
- /**
- * Returns the language abbreviations for all languages whose translations are
- * available for the given country.
- *
- * @param country the country
- * @return list of language abbreviations which are available for this country
- */
+
+ public static final String COUNTRY_CANADA = "can";
+
@Override
+
public List getCountryLanguages(String country) {
- // TODO Checkstyle: The String "can" appears 4 times in the file.
- if ("can".equals(country)) {
- return new ArrayList<>(List.of("de", "en", "zh"));
+
+ // TOD Checkstyle: The String COUNTRY_CANADA appears 4 times in the file.
+ if (COUNTRY_CANADA.equals(country)) {
+ return new ArrayList<>(List.of("de", "en", "zh", "es"));
}
return new ArrayList<>();
}
- // TODO Checkstyle: Static variable definition in wrong order.
- public static final String CANADA = "can";
+ // TOD Checkstyle: Static variable definition in wrong order.
/**
* Returns the country abbreviations for all countries whose translations are
@@ -41,34 +38,32 @@ public List getCountryLanguages(String country) {
*/
@Override
public List getCountries() {
- return new ArrayList<>(List.of("can"));
+ return new ArrayList<>(List.of(COUNTRY_CANADA));
}
- /**
- * Returns the name of the country based on the specified country abbreviation and language abbreviation.
- *
- * @param country the country
- * @param language the language
- * @return the name of the country in the given language or null if no translation is available
- */
@Override
+
public String translate(String country, String language) {
- // TODO Checkstyle: Return count is 5 (max allowed for non-void methods/ lambdas is 2).
- // TODO Checkstyle: String literal expressions should be on the left side of an equals comparison
- if (!country.equals("can")) {
+ /* 1️⃣ first (early-exit) return */
+ if (!COUNTRY_CANADA.equals(country)) {
return null;
}
- if (language.equals("de")) {
- return "Kanada";
+
+ /* 2️⃣ all remaining logic uses a single return */
+ String result = null;
+ if ("de".equals(language)) {
+ result = "Kanada";
}
- else if (language.equals("en")) {
- return "Canada";
+ else if ("en".equals(language)) {
+ result = "Canada";
}
else if ("zh".equals(language)) {
- return "加拿大";
+ result = "加拿大";
}
- else {
- return null;
+ else if ("es".equals(language)) {
+ result = "Canadá";
}
+ return result;
}
+
}