Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/main/java/org/translation/CountryCodeConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
// TODO CheckStyle: Wrong lexicographical order for 'java.util.HashMap' import (remove this comment once resolved)
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
Expand All @@ -15,6 +14,8 @@
public class CountryCodeConverter {

// TODO Task: pick appropriate instance variable(s) to store the data necessary for this class
private final Map<String, String> codeToCountry;
private final Map<String, String> countryToCode;

/**
* Default constructor which will load the country codes from "country-codes.txt"
Expand All @@ -31,6 +32,9 @@ public CountryCodeConverter() {
*/
public CountryCodeConverter(String filename) {

this.codeToCountry = new HashMap<>();
this.countryToCode = new HashMap<>();

try {
List<String> lines = Files.readAllLines(Paths.get(getClass()
.getClassLoader().getResource(filename).toURI()));
Expand Down
38 changes: 18 additions & 20 deletions src/main/java/org/translation/InLabByHandTranslator.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@
* the country code "can" to several languages.
*/
public class InLabByHandTranslator implements Translator {

public static final String CANADA = "can";
/**
* 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
*/

@Override
public List<String> getCountryLanguages(String country) {
// TODO Checkstyle: The String "can" appears 4 times in the file.
if ("can".equals(country)) {
if (CANADA.equals(country)) {
return new ArrayList<>(List.of("de", "en", "zh"));
}
return new ArrayList<>();
}

// TODO Checkstyle: Static variable definition in wrong order.
public static final String CANADA = "can";

/**
* Returns the country abbreviations for all countries whose translations are
* available from this Translator.
Expand All @@ -53,22 +53,20 @@ public List<String> getCountries() {
*/
@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")) {
return null;
}
if (language.equals("de")) {
return "Kanada";
}
else if (language.equals("en")) {
return "Canada";
}
else if ("zh".equals(language)) {
return "加拿大";
}
else {
return null;
String translation = null;

if (CANADA.equals(country)) {
if ("de".equals(language)) {
translation = "Kanada";
}
else if ("en".equals(language)) {
translation = "Canada";
}
else if ("zh".equals(language)) {
translation = "加拿大";
}
}

return translation;
}
}