}
@Override
public boolean equals(Object obj) {
- Multimap<K,V> other = (Multimap) obj;
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof Multimap)) {
+ return false;
+ }
+ Multimap<?,?> other = (Multimap<?,?>) obj;
return map.equals(other.map);
}
+
+ @Override
+ public int hashCode() {
+ // Not designed, return an arbitrary constant -123 for now
+ assert false;
+ return -123;
+ }
}
public static class Multimaps {
}
- public static class Counter<T> implements Iterable<T>{
- private Map<T,Long> data;
- @Override
- public Iterator<T> iterator() {
- return data.keySet().iterator();
- }
- public long get(T s) {
- Long result = data.get(s);
- return result != null ? result : 0L;
- }
- public void add(T item, int count) {
- Long result = data.get(item);
- data.put(item, result == null ? count : result + count);
- }
- }
+// public static class Counter<T> implements Iterable<T>{
+// private Map<T,Long> data;
+// @Override
+// public Iterator<T> iterator() {
+// return data.keySet().iterator();
+// }
+// public long get(T s) {
+// Long result = data.get(s);
+// return result != null ? result : 0L;
+// }
+// public void add(T item, int count) {
+// Long result = data.get(item);
+// data.put(item, result == null ? count : result + count);
+// }
+// }
public static <T> String join(T[] source, String separator) {
StringBuilder result = new StringBuilder();
}
}
public static String getRelativeFileName(Class<?> class1, String filename) {
- URL resource = class1.getResource(filename);
+ URL resource = class1 == null ?
+ FileUtilities.class.getResource(filename) : class1.getResource(filename);
String resourceString = resource.toString();
if (resourceString.startsWith("file:")) {
return resourceString.substring(5);
return DEFAULT;
}
+ @SuppressWarnings("unchecked")
static abstract class Maker {
abstract <V> V make();
- @SuppressWarnings("unchecked")
public <K,V> V getSubtable(Map<K, V> langTable, final K language) {
V scriptTable = langTable.get(language);
if (scriptTable == null) {
static final Maker HASHMAP = new Maker() {
@Override
- @SuppressWarnings("unchecked")
public Map<Object,Object> make() {
return new HashMap<Object,Object>();
}
static final Maker TREEMAP = new Maker() {
@Override
- @SuppressWarnings("unchecked")
public Map<Object,Object> make() {
return new TreeMap<Object,Object>();
}
}
@Override
public boolean equals(Object obj) {
+ if (this == obj) {
+ return false;
+ }
+ if (!(obj instanceof LSR)) {
+ return false;
+ }
LSR other = (LSR) obj;
return language.equals(other.language)
&& script.equals(other.script)
private void set(Map<String, Map<String, Map<String, LSR>>> langTable, final String language, final String script, final String region, LSR newValue) {
Map<String, Map<String, LSR>> scriptTable = Maker.TREEMAP.getSubtable(langTable, language);
Map<String, LSR> regionTable = Maker.TREEMAP.getSubtable(scriptTable, script);
- LSR oldValue = regionTable.get(region);
- if (oldValue != null) {
- int debug = 0;
- }
+// LSR oldValue = regionTable.get(region);
+// if (oldValue != null) {
+// int debug = 0;
+// }
regionTable.put(region, newValue);
}
/**
* Convenience methods
- * @param source
- * @return
*/
public LSR maximize(String source) {
return maximize(ULocale.forLanguageTag(source));
}
}
+ @SuppressWarnings("unused")
private LSR minimizeSubtags(String languageIn, String scriptIn, String regionIn, Minimize fieldToFavor) {
LSR result = maximize(languageIn, scriptIn, regionIn);
if (result.script.equals(value00.script)) { //script is default
if (result.region.equals(value00.region)) {
return result.replace(null, "", "");
- } else if (fieldToFavor == fieldToFavor.FAVOR_REGION) {
+ } else if (fieldToFavor == Minimize.FAVOR_REGION) {
return result.replace(null, "", null);
} else {
favorRegionOk = true;
return result;
}
- private static <V> StringBuilder show(Map<String,V> map, String indent, StringBuilder output) {
+ private static StringBuilder show(Map<?,?> map, String indent, StringBuilder output) {
String first = indent.isEmpty() ? "" : "\t";
- for (Entry<String,V> e : map.entrySet()) {
- String key = e.getKey();
- V value = e.getValue();
+ for (Entry<?,?> e : map.entrySet()) {
+ String key = e.getKey().toString();
+ Object value = e.getValue();
output.append(first + (key.isEmpty() ? "∅" : key));
if (value instanceof Map) {
- show((Map)value, indent+"\t", output);
+ show((Map<?,?>)value, indent+"\t", output);
} else {
output.append("\t" + Utility.toString(value)).append("\n");
}
return Collections.unmodifiableList(distanceList);
}
+ @SuppressWarnings("unused")
private static Set<String> xGetParadigmLocales() {
ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData();
ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo");
return Collections.unmodifiableSet(paradigmLocales);
}
+ @SuppressWarnings("unused")
private static Map<String, String> xGetMatchVariables() {
ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData();
ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo");
return false;
}
DistanceNode other = (DistanceNode) obj;
- return distance == other.distance;
+ return distance == other.distance
+ && this.getClass().equals(other.getClass());
}
@Override
public int hashCode() {
}
@Override
public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
if (!(obj instanceof IdMakerFull)) {
return false;
}
- IdMakerFull<T> other = (IdMakerFull) obj;
+ IdMakerFull<?> other = (IdMakerFull<?>) obj;
return intToObject.equals(other.intToObject);
}
@Override
@Override
public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
if (!(obj instanceof StringDistanceNode)) {
return false;
}
StringDistanceNode other = (StringDistanceNode) obj;
- return distance == other.distance && Utility.equals(distanceTable, other.distanceTable);
+ return distance == other.distance
+ && Utility.equals(distanceTable, other.distanceTable)
+ && super.equals(other);
}
@Override
public int hashCode() {
defaultRegionDistance = regionNode.distance;
}
+ @SuppressWarnings("rawtypes")
private static Map newMap() { // for debugging
return new TreeMap();
}
StringDistanceTable(Map<String, Map<String, DistanceNode>> tables) {
subtables = tables;
}
+ @SuppressWarnings("unchecked")
StringDistanceTable() {
this(newMap());
}
for (Entry<String, Map<String, DistanceNode>> e1 : other.subtables.entrySet()) {
for (Entry<String, DistanceNode> e2 : e1.getValue().entrySet()) {
DistanceNode value = e2.getValue();
+ @SuppressWarnings("unused")
DistanceNode subNode = addSubtable(e1.getKey(), e2.getKey(), value.distance);
}
}
}
+ @SuppressWarnings("unchecked")
DistanceNode addSubtable(String desired, String supported, int distance) {
Map<String, DistanceNode> sub2 = subtables.get(desired);
if (sub2 == null) {
public void addSubtables(
String desired, String supported,
Predicate<DistanceNode> action) {
- int count = 0;
DistanceNode node = getNode(desired, supported);
if (node == null) {
// get the distance it would have
int percentage) {
// add to all the values that have the matching desiredLang and supportedLang
+ @SuppressWarnings("unused")
boolean haveKeys = false;
for (Entry<String, Map<String, DistanceNode>> e1 : subtables.entrySet()) {
String key1 = e1.getKey();
int percentage) {
// add to all the values that have the matching desiredLang and supportedLang
+ @SuppressWarnings("unused")
boolean haveKeys = false;
for (Entry<String, Map<String, DistanceNode>> e1 : subtables.entrySet()) {
String key1 = e1.getKey();
/**
* Returns distance, from 0 to ABOVE_THRESHOLD.
* ULocales must be in canonical, addLikelySubtags format. Returns distance
- * @param desired
- * @param supported
- * @param distanceOption
- * @return
*/
public int distanceRaw(LSR desired, LSR supported, int threshold, DistanceOption distanceOption) {
return distanceRaw(desired.language, supported.language,
Splitter bar = Splitter.on('_');
+ @SuppressWarnings({"unchecked", "rawtypes"})
List<Row.R4<List<String>, List<String>, Integer, Boolean>>[] sorted = new ArrayList[3];
sorted[0] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
sorted[1] = new ArrayList<Row.R4<List<String>, List<String>, Integer, Boolean>>();
}
for (List<Row.R4<List<String>, List<String>, Integer, Boolean>> item1 : sorted) {
- int debug = 0;
for (Row.R4<List<String>, List<String>, Integer, Boolean> item2 : item1) {
List<String> desired = item2.get0();
List<String> supported = item2.get1();
// + "\" distance=\""
// + rule[2]
// + "\"/>");
- if (rule[0].equals("en_*_*") || rule[1].equals("*_*_*")) {
- int debug = 0;
- }
+// if (rule[0].equals("en_*_*") || rule[1].equals("*_*_*")) {
+// int debug = 0;
+// }
List<String> desiredBase = new ArrayList<String>(bar.splitToList(rule[0]));
List<String> supportedBase = new ArrayList<String>(bar.splitToList(rule[1]));
Integer distance = 100-Integer.parseInt(rule[2]);
DEFAULT = new XLocaleDistance(defaultDistanceTable.compact(), defaultRegionMapper);
- if (false && PRINT_OVERRIDES) {
+ if (PRINT_OVERRIDES) {
System.out.println(defaultRegionMapper);
System.out.println(defaultDistanceTable);
throw new IllegalArgumentException();
private static String fixedName(List<String> match) {
List<String> alt = new ArrayList<String>(match);
+ int size = alt.size();
+ assert size >= 1 && size <= 3;
+
StringBuilder result = new StringBuilder();
- switch(alt.size()) {
- case 3:
+
+ if (size >= 3) {
String region = alt.get(2);
if (region.equals("*") || region.startsWith("$")) {
result.append(region);
} else {
result.append(english.regionDisplayName(region));
}
- case 2:
+ }
+ if (size >= 2) {
String script = alt.get(1);
if (script.equals("*")) {
result.insert(0, script);
} else {
result.insert(0, english.scriptDisplayName(script));
}
- case 1:
+ }
+ if (size >= 1) {
String language = alt.get(0);
if (language.equals("*")) {
result.insert(0, language);
final Map<String,String> regionToPartition;
/**
* Used to support es_419 compared to es_AR, etc.
- * @param variableToPartitionIn
- * @param regionToPartitionIn
*/
final Multimap<String,String> macroToPartitions;
/**
}
return new StringDistanceTable(compact(item.subtables, 0));
}
+ @SuppressWarnings({ "unchecked", "rawtypes" })
<K,T> Map<K,T> compact(Map<K,T> item, int level) {
if (toId(item) != null) {
- return (Map<K,T>)intern(item);
+ return (Map<K, T>) intern(item);
}
Map<K,T> copy = new LinkedHashMap<K,T>();
for (Entry<K,T> entry : item.entrySet()) {
private DistanceOption distanceOption;
/**
* @param languagePriorityList the languagePriorityList to set
- * @return
+ * @return this Builder object
*/
public Builder setSupportedLocales(String languagePriorityList) {
this.supportedLanguagesList = asSet(LocalePriorityList.add(languagePriorityList).build());
/**
* @param thresholdDistance the thresholdDistance to set, with -1 = default
- * @return
+ * @return this Builder object
*/
public Builder setThresholdDistance(int thresholdDistance) {
this.thresholdDistance = thresholdDistance;
}
/**
* @param demotionPerAdditionalDesiredLocale the demotionPerAdditionalDesiredLocale to set, with -1 = default
- * @return
+ * @return this Builder object
*/
public Builder setDemotionPerAdditionalDesiredLocale(int demotionPerAdditionalDesiredLocale) {
this.demotionPerAdditionalDesiredLocale = demotionPerAdditionalDesiredLocale;
/**
* @param localeDistance the localeDistance to set, with default = XLocaleDistance.getDefault().
- * @return
+ * @return this Builder object
*/
public Builder setLocaleDistance(XLocaleDistance localeDistance) {
this.localeDistance = localeDistance;
/**
* Set the default language, with null = default = first supported language
- * @param defaultLanguage
- * @return
+ * @param defaultLanguage the default language
+ * @return this Builder object
*/
public Builder setDefaultLanguage(ULocale defaultLanguage) {
this.defaultLanguage = defaultLanguage;
/**
* If true, then the language differences are smaller than than script differences.
* This is used in situations (such as maps) where it is better to fall back to the same script than a similar language.
- * @param distanceOption
- * @return
+ * @param distanceOption the distance option
+ * @return this Builder object
*/
public Builder setDistanceOption(DistanceOption distanceOption) {
this.distanceOption = distanceOption;
/**
* Returns a builder used in chaining parameters for building a Locale Matcher.
- * @return
+ * @return this Builder object
*/
public static Builder builder() {
return new Builder();
* @param desiredLanguages Typically the supplied user's languages, in order of preference, with best first.
* @param outputBestDesired The one of the desired languages that matched best.
* Set to null if the best match was not below the threshold distance.
- * @return
+ * @return the best match.
*/
public ULocale getBestMatch(Set<ULocale> desiredLanguages, Output<ULocale> outputBestDesired) {
// fast path for singleton
/**
* Get the best match between the desired languages and supported languages
- * @param desiredLanguages Typically the supplied user's languages, in order of preference, with best first.
+ * @param desiredLocale the supplied user's language.
* @param outputBestDesired The one of the desired languages that matched best.
* Set to null if the best match was not below the threshold distance.
- * @return
+ * @return the best match.
*/
public ULocale getBestMatch(ULocale desiredLocale, Output<ULocale> outputBestDesired) {
int bestDistance = Integer.MAX_VALUE;
}
// @ Test Disabled because of Linux; need to investigate.
+ @SuppressWarnings("unused")
public void testTiming() {
List<Arguments> testArgs = new ArrayList<Arguments>();
for (List<String> line : tfh.getLines()) {
return new XLocaleMatcher(LocalePriorityList.add(string).build());
}
+ @SuppressWarnings("unused")
private XLocaleMatcher newXLocaleMatcher(LocalePriorityList string, int d) {
return XLocaleMatcher.builder().setSupportedLocales(string).setThresholdDistance(d).build();
}
private static final Splitter COMMA_SPACE = Splitter.on(Pattern.compile(",\\s*|\\s+")).trimResults();
private static final Joiner JOIN_COMMA_SPACE = Joiner.on(", ");
+ @SuppressWarnings("unused")
private static final UnicodeSet DIGITS = new UnicodeSet("[0-9]").freeze();
class MyTestFileHandler extends DataDrivenTestHelper {