Skip to content

Commit

Permalink
ICU4J clear up imports and variable names in listFormat and pluralRul…
Browse files Browse the repository at this point in the history
…es (unicode-org#265)

* Add plural rules to CPP

* Add the Rust datetime fmt code

* Rust datetime fmt and updates to ICU4C and NodeJS (unicode-org#240)

* Add plural rules to CPP

* Starting ICU4X datetime fmt

* DateTime format: Set default timezone explicitly

* Fix formatting

* Added ICU4X timezone computation - not working yet!

* DateTime generator updated to ISO formatted string

* DateTime updates for Node and ICU4C.

* Formatted src/datetimefmt.rs

* Updated using CustomTimeZone in ICU4X date time fmt

* Cargo clippified

* Remove unused function

* Update version to ~1.3

* Clean up imports and variable names - listFormat and pluralRules
  • Loading branch information
sven-oly authored Aug 5, 2024
1 parent 4832ddb commit ad78cbb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@

public class ListFormatterInputJson implements ITestTypeInputJson {

public String test_type;
public String testType;

public String label;

public String locale;

public ListFormatterType list_type;
public ListFormatterType listType;

public ListFormatterWidth style; // e.g., SHORT

public Collection<String> input_list;
public Collection<String> inputList;

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@

import java.util.Collection;

import java.util.HashMap;
import org.unicode.conformance.ExecutorUtils;
import org.unicode.conformance.testtype.ITestType;
import org.unicode.conformance.testtype.ITestTypeInputJson;
import org.unicode.conformance.testtype.ITestTypeOutputJson;
import org.unicode.conformance.testtype.numberformatter.NumberFormatterTestOptionKey;
import org.unicode.conformance.testtype.numberformatter.StyleVal;

public class ListFormatterTester implements ITestType {

Expand All @@ -29,16 +26,16 @@ public ITestTypeInputJson inputMapToJson(Map<String, Object> inputMapData) {
result.label = (String) inputMapData.get("label", null);
result.locale = (String) inputMapData.get("locale", null);

java.util.Map<String,Object> input_options = (java.util.Map<String,Object>) inputMapData.get("options", null);
java.util.Map<String,Object> inputOptions = (java.util.Map<String,Object>) inputMapData.get("options", null);

result.list_type = ListFormatterType.getFromString(
"" + input_options.get("list_type")
result.listType = ListFormatterType.getFromString(
"" + inputOptions.get("list_type")
);
result.style = ListFormatterWidth.getFromString(
"" + input_options.get("style")
"" + inputOptions.get("style")
);

result.input_list = (Collection<String>) inputMapData.get("input_list", null);
result.inputList = (Collection<String>) inputMapData.get("input_list", null);

return result;
}
Expand Down Expand Up @@ -82,32 +79,32 @@ public String formatOutputJson(ITestTypeOutputJson outputJson) {
}

public String getListFormatResultString(ListFormatterInputJson input) {
ListFormatter.Type list_type;
ListFormatter.Width list_width;
ListFormatter.Type listType;
ListFormatter.Width listWidth;
ULocale locale = ULocale.forLanguageTag(input.locale);

switch (input.list_type) {
case DISJUNCTION: list_type = Type.OR;
switch (input.listType) {
case DISJUNCTION: listType = Type.OR;
break;
case UNIT: list_type = Type.UNITS;
case UNIT: listType = Type.UNITS;
break;
default:
case CONJUNCTION: list_type = Type.AND;
case CONJUNCTION: listType = Type.AND;
break;
}

switch (input.style) {
case NARROW: list_width = Width.NARROW;
case NARROW: listWidth = Width.NARROW;
break;
case SHORT: list_width = Width.SHORT;
case SHORT: listWidth = Width.SHORT;
break;
default:
case LONG: list_width = Width.WIDE;
case LONG: listWidth = Width.WIDE;
break;
}

ListFormatter lf = ListFormatter.getInstance(locale, list_type, list_width);
ListFormatter lf = ListFormatter.getInstance(locale, listType, listWidth);

return lf.format(input.input_list);
return lf.format(input.inputList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class PluralRulesInputJson implements ITestTypeInputJson {

public String locale;

public PluralRulesType plural_type;
public PluralRulesType pluralType;

public double sample;
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,15 @@
package org.unicode.conformance.testtype.pluralrules;

import com.ibm.icu.util.ULocale;
import com.ibm.icu.text.PluralRules.PluralType;
import com.ibm.icu.text.PluralRules;

import io.lacuna.bifurcan.IMap;
import io.lacuna.bifurcan.Map;

import java.util.Collection;

import java.util.HashMap;
import org.unicode.conformance.ExecutorUtils;
import org.unicode.conformance.testtype.ITestType;
import org.unicode.conformance.testtype.ITestTypeInputJson;
import org.unicode.conformance.testtype.ITestTypeOutputJson;
import org.unicode.conformance.testtype.pluralrules.PluralRulesInputJson;
import org.unicode.conformance.testtype.pluralrules.PluralRulesOutputJson;


public class PluralRulesTester implements ITestType {
Expand All @@ -28,14 +22,14 @@ public ITestTypeInputJson inputMapToJson(Map<String, Object> inputMapData) {
result.label = (String) inputMapData.get("label", null);
result.locale = (String) inputMapData.get("locale", null);

result.plural_type = PluralRulesType.getFromString(
result.pluralType = PluralRulesType.getFromString(
"" + inputMapData.get("plural_type", null)
);

// Consider compact number format, too.
String sample_string = (String) inputMapData.get("sample", null);
String sampleString = (String) inputMapData.get("sample", null);
// Convert this to a number.
result.sample = Double.parseDouble(sample_string);
result.sample = Double.parseDouble(sampleString);

return result;
}
Expand Down Expand Up @@ -78,21 +72,21 @@ public IMap<String, Object> convertOutputToMap(ITestTypeOutputJson outputJson) {
}

public String getPluralRulesResultString(PluralRulesInputJson input) {
PluralRules.PluralType plural_type;
PluralRules.PluralType pluralType;
ULocale locale = ULocale.forLanguageTag(input.locale);

switch (input.plural_type) {
switch (input.pluralType) {
case ORDINAL:
plural_type = PluralRules.PluralType.ORDINAL;
pluralType = PluralRules.PluralType.ORDINAL;
break;
default:
case CARDINAL:
plural_type = PluralRules.PluralType.CARDINAL;
pluralType = PluralRules.PluralType.CARDINAL;
break;
}

PluralRules pl_rules = PluralRules.forLocale(locale, plural_type);
PluralRules pluralRules = PluralRules.forLocale(locale, pluralType);

return pl_rules.select(input.sample);
return pluralRules.select(input.sample);
}
}

0 comments on commit ad78cbb

Please sign in to comment.