}
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof Multimap)) {
- return false;
- }
- Multimap<?,?> other = (Multimap<?,?>) obj;
- return map.equals(other.map);
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && map.equals(((Multimap<?,?>) obj).map));
}
@Override
public int hashCode() {
- // Not designed, return an arbitrary constant -123 for now
- assert false;
- return -123;
+ return map.hashCode();
}
}
}
-// 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();
canonicalName = new File(relativeFileName).getCanonicalPath();
} catch (Exception e1) {
throw new ICUUncheckedIOException("Couldn't open file: " + file + "; relative to class: "
- + className, e);
+ + className, e);
}
throw new ICUUncheckedIOException("Couldn't open file " + file + "; in path " + canonicalName + "; relative to class: "
- + className, e);
+ + className, e);
}
}
public static String getRelativeFileName(Class<?> class1, String filename) {
URL resource = class1 == null ?
FileUtilities.class.getResource(filename) : class1.getResource(filename);
- String resourceString = resource.toString();
- if (resourceString.startsWith("file:")) {
- return resourceString.substring(5);
- } else if (resourceString.startsWith("jar:file:")) {
- return resourceString.substring(9);
- } else {
- throw new ICUUncheckedIOException("File not found: " + resourceString);
- }
+ String resourceString = resource.toString();
+ if (resourceString.startsWith("file:")) {
+ return resourceString.substring(5);
+ } else if (resourceString.startsWith("jar:file:")) {
+ return resourceString.substring(9);
+ } else {
+ throw new ICUUncheckedIOException("File not found: " + resourceString);
+ }
}
}
// #1 is language
// #2 is script
// #3 is region
-// static final String pat =
-// "language_id = (unicode_language_subtag)"
-// + "(?:sep(unicode_script_subtag))?"
-// + "(?:sep(unicode_region_subtag))?;\n"
-// + "unicode_language_subtag = alpha{2,3}|alpha{5,8};\n"
-// + "unicode_script_subtag = alpha{4};\n"
-// + "unicode_region_subtag = alpha{2}|digit{3};\n"
-// + "sep = [-_];\n"
-// + "digit = [0-9];\n"
-// + "alpha = [A-Za-z];\n"
-// ;
-// static {
-// System.out.println(pat);
-// System.out.println(new UnicodeRegex().compileBnf(pat));
-// }
-// static final Pattern LANGUAGE_PATTERN = Pattern.compile(
-// "([a-zA-Z0-9]+)" // (?:[-_]([a-zA-Z0-9]+))?(?:[-_]([a-zA-Z0-9]+))?"
-// //new UnicodeRegex().compileBnf(pat)
-// );
-//
+ // static final String pat =
+ // "language_id = (unicode_language_subtag)"
+ // + "(?:sep(unicode_script_subtag))?"
+ // + "(?:sep(unicode_region_subtag))?;\n"
+ // + "unicode_language_subtag = alpha{2,3}|alpha{5,8};\n"
+ // + "unicode_script_subtag = alpha{4};\n"
+ // + "unicode_region_subtag = alpha{2}|digit{3};\n"
+ // + "sep = [-_];\n"
+ // + "digit = [0-9];\n"
+ // + "alpha = [A-Za-z];\n"
+ // ;
+ // static {
+ // System.out.println(pat);
+ // System.out.println(new UnicodeRegex().compileBnf(pat));
+ // }
+ // static final Pattern LANGUAGE_PATTERN = Pattern.compile(
+ // "([a-zA-Z0-9]+)" // (?:[-_]([a-zA-Z0-9]+))?(?:[-_]([a-zA-Z0-9]+))?"
+ // //new UnicodeRegex().compileBnf(pat)
+ // );
+ //
// TODO: fix this to check for format. Not required, since this is only called internally, but safer for the future.
static LSR from(String languageIdentifier) {
String[] parts = languageIdentifier.split("[-_]");
}
@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)
+ LSR other;
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && language.equals((other = (LSR) obj).language)
&& script.equals(other.script)
- && region.equals(other.region);
+ && region.equals(other.region));
}
@Override
public int hashCode() {
Maker maker = Maker.TREEMAP;
Map<String, Map<String, Map<String, LSR>>> result = maker.make();
-// Splitter bar = Splitter.on('_');
-// int last = -1;
+ // Splitter bar = Splitter.on('_');
+ // int last = -1;
// set the base data
Map<LSR,LSR> internCache = new HashMap<LSR,LSR>();
for (Entry<String, String> sourceTarget : rawData.entrySet()) {
set(result, language, script, region, languageTarget, scriptTarget, regionTarget, internCache);
// now add aliases
Collection<String> languageAliases = LSR.LANGUAGE_ALIASES.getAliases(language);
-// if (languageAliases.isEmpty()) {
-// languageAliases = Collections.singleton(language);
-// }
+ // if (languageAliases.isEmpty()) {
+ // languageAliases = Collections.singleton(language);
+ // }
Collection<String> regionAliases = LSR.REGION_ALIASES.getAliases(region);
-// if (regionAliases.isEmpty()) {
-// regionAliases = Collections.singleton(region);
-// }
+ // if (regionAliases.isEmpty()) {
+ // regionAliases = Collections.singleton(region);
+ // }
for (String languageAlias : languageAliases) {
for (String regionAlias : regionAliases) {
if (languageAlias.equals(language) && regionAlias.equals(region)) {
return result;
}
-// private void getAliasInfo(Map<String, R2<List<String>, String>> aliasInfo, Multimap<String, String> canonicalToAlias) {
-// for (Entry<String, R2<List<String>, String>> e : aliasInfo.entrySet()) {
-// final String alias = e.getKey();
-// if (alias.contains("_")) {
-// continue; // only do simple aliasing
-// }
-// String canonical = getCanonical(e.getValue());
-// canonicalToAlias.put(canonical, alias);
-// }
-// }
-
-// private static String getCanonical(R2<List<String>, String> aliasAndReason) {
-// if (aliasAndReason == null) {
-// return null;
-// }
-// if (aliasAndReason.get1().equals("overlong")) {
-// return null;
-// }
-// List<String> value = aliasAndReason.get0();
-// if (value.size() != 1) {
-// return null;
-// }
-// final String canonical = value.iterator().next();
-// if (canonical.contains("_")) {
-// return null; // only do simple aliasing
-// }
-// return canonical;
-// }
+ // private void getAliasInfo(Map<String, R2<List<String>, String>> aliasInfo, Multimap<String, String> canonicalToAlias) {
+ // for (Entry<String, R2<List<String>, String>> e : aliasInfo.entrySet()) {
+ // final String alias = e.getKey();
+ // if (alias.contains("_")) {
+ // continue; // only do simple aliasing
+ // }
+ // String canonical = getCanonical(e.getValue());
+ // canonicalToAlias.put(canonical, alias);
+ // }
+ // }
+
+ // private static String getCanonical(R2<List<String>, String> aliasAndReason) {
+ // if (aliasAndReason == null) {
+ // return null;
+ // }
+ // if (aliasAndReason.get1().equals("overlong")) {
+ // return null;
+ // }
+ // List<String> value = aliasAndReason.get0();
+ // if (value.size() != 1) {
+ // return null;
+ // }
+ // final String canonical = value.iterator().next();
+ // if (canonical.contains("_")) {
+ // return null; // only do simple aliasing
+ // }
+ // return canonical;
+ // }
private void set(Map<String, Map<String, Map<String, LSR>>> langTable, final String language, final String script, final String region,
final String languageTarget, final String scriptTarget, final String regionTarget, Map<LSR, LSR> internCache) {
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);
}
ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo");
ICUResourceBundle writtenParadigmLocales = (ICUResourceBundle) languageMatchingInfo.get("written")
.get("paradigmLocales");
-// paradigmLocales{ "en", "en-GB",... }
+ // paradigmLocales{ "en", "en-GB",... }
HashSet<String> paradigmLocales = new HashSet<String>(Arrays.asList(writtenParadigmLocales.getStringArray()));
return Collections.unmodifiableSet(paradigmLocales);
}
ICUResourceBundle languageMatchingInfo = suppData.findTopLevel("languageMatchingInfo");
ICUResourceBundle writtenMatchVariables = (ICUResourceBundle) languageMatchingInfo.get("written")
.get("matchVariable");
-// matchVariable{ americas{"019"} cnsar{"HK+MO"} ...}
+ // matchVariable{ americas{"019"} cnsar{"HK+MO"} ...}
HashMap<String,String> matchVariables = new HashMap<String,String>();
for (Enumeration<String> enumer = writtenMatchVariables.getKeys(); enumer.hasMoreElements(); ) {
.putAll("QO", "AQ", "BV", "CC", "CX", "GS", "HM", "IO", "TF", "UM", "AC", "CP", "DG", "TA")
;
//Can't use following, because data from CLDR is discarded
-// ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData();
-// UResourceBundle territoryContainment = suppData.get("territoryContainment");
-// for (int i = 0 ; i < territoryContainment.getSize(); i++) {
-// UResourceBundle mapping = territoryContainment.get(i);
-// String parent = mapping.getKey();
-// for (int j = 0 ; j < mapping.getSize(); j++) {
-// String child = mapping.getString(j);
-// containment.put(parent,child);
-// System.out.println(parent + " => " + child);
-// }
-// }
+ // ICUResourceBundle suppData = LocaleMatcher.getICUSupplementalData();
+ // UResourceBundle territoryContainment = suppData.get("territoryContainment");
+ // for (int i = 0 ; i < territoryContainment.getSize(); i++) {
+ // UResourceBundle mapping = territoryContainment.get(i);
+ // String parent = mapping.getKey();
+ // for (int j = 0 ; j < mapping.getSize(); j++) {
+ // String child = mapping.getString(j);
+ // containment.put(parent,child);
+ // System.out.println(parent + " => " + child);
+ // }
+ // }
TreeMultimap<String,String> containmentResolved = TreeMultimap.create();
fill("001", containment, containmentResolved);
return ImmutableMultimap.copyOf(containmentResolved);
static final Multimap<String,String> CONTAINER_TO_CONTAINED;
static final Multimap<String,String> CONTAINER_TO_CONTAINED_FINAL;
static {
-// Multimap<String, String> containerToContainedTemp = xGetContainment();
-// fill(Region.getInstance("001"), containerToContainedTemp);
+ // Multimap<String, String> containerToContainedTemp = xGetContainment();
+ // fill(Region.getInstance("001"), containerToContainedTemp);
CONTAINER_TO_CONTAINED = xGetContainment();
Multimap<String, String> containerToFinalContainedBuilder = TreeMultimap.create();
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof DistanceNode)) {
- return false;
- }
- DistanceNode other = (DistanceNode) obj;
- return distance == other.distance
- && this.getClass().equals(other.getClass());
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && distance == ((DistanceNode) obj).distance);
}
@Override
public int hashCode() {
}
@Override
public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!(obj instanceof IdMakerFull)) {
- return false;
- }
- IdMakerFull<?> other = (IdMakerFull<?>) obj;
- return intToObject.equals(other.intToObject);
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && intToObject.equals(((IdMakerFull<?>) obj).intToObject));
}
@Override
public int hashCode() {
@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
+ StringDistanceNode other;
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && distance == (other = (StringDistanceNode) obj).distance
&& Utility.equals(distanceTable, other.distanceTable)
- && super.equals(other);
+ && super.equals(other));
}
@Override
public int hashCode() {
@Override
public boolean equals(Object obj) {
- if (!(obj instanceof StringDistanceTable)) {
- return false;
- }
- StringDistanceTable other = (StringDistanceTable) obj;
- return subtables.equals(other.subtables);
+ return this == obj ||
+ (obj != null
+ && obj.getClass() == this.getClass()
+ && subtables.equals(((StringDistanceTable) obj).subtables));
}
@Override
public int hashCode() {
// + "\" 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]);