Revision: 13185
http://sourceforge.net/p/foray/code/13185
Author: victormote
Date: 2023-08-28 09:28:40 +0000 (Mon, 28 Aug 2023)
Log Message:
-----------
Conform to aXSL change: Add method indicating whether one WritingSystem can satisfy the requirements of another.
Modified Paths:
--------------
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2023-08-27 13:13:13 UTC (rev 13184)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Country4a.java 2023-08-28 09:28:40 UTC (rev 13185)
@@ -498,6 +498,9 @@
@Override
public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
if (! (other instanceof Country)) {
return false;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java 2023-08-27 13:13:13 UTC (rev 13184)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Language4a.java 2023-08-28 09:28:40 UTC (rev 13185)
@@ -850,6 +850,9 @@
@Override
public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
if (! (other instanceof Language)) {
return false;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2023-08-27 13:13:13 UTC (rev 13184)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/Script4a.java 2023-08-28 09:28:40 UTC (rev 13185)
@@ -636,6 +636,9 @@
@Override
public boolean equals(final Object other) {
+ if (other == null) {
+ return false;
+ }
if (! (other instanceof Script)) {
return false;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java 2023-08-27 13:13:13 UTC (rev 13184)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/i18n/WritingSystem4a.java 2023-08-28 09:28:40 UTC (rev 13185)
@@ -105,10 +105,10 @@
* @param country The country.
* @param script The script.
*/
- private WritingSystem4a(final Language4a language, final Country4a country, final Script4a script) {
+ private WritingSystem4a(final Language4a language, final Script4a script, final Country4a country) {
this.language = language;
+ this.script = script;
this.country = country;
- this.script = script;
/* Cache the hash code for performance. */
this.hash = ObjectUtils.HASH_CODE_SEED;
@@ -125,9 +125,12 @@
* @return The writing system for the given parameters.
*/
public static WritingSystem4a find(final Language4a language, final Script4a script, final Country4a country) {
- final Language4a languageToUse = language == null ? Language4a.UNDETERMINED : language;
+ if (language == null) {
+ throw new NullPointerException("Language cannot be null.");
+ }
+
final Country4a countryToUse = country == null ? Country4a.UNDETERMINED : country;
- Script4a scriptToUse = script == null ? languageToUse.getDefaultScript(countryToUse) : script;
+ Script4a scriptToUse = script == null ? language.getDefaultScript(countryToUse) : script;
scriptToUse = scriptToUse == null ? Script4a.UNDETERMINED : scriptToUse;
Map<Language4a, Map<Country4a, WritingSystem4a>> scriptMap = REGISTRATION_MAP.get(scriptToUse);
@@ -135,14 +138,14 @@
scriptMap = new HashMap<Language4a, Map<Country4a, WritingSystem4a>>();
REGISTRATION_MAP.put(scriptToUse, scriptMap);
}
- Map<Country4a, WritingSystem4a> languageMap = scriptMap.get(languageToUse);
+ Map<Country4a, WritingSystem4a> languageMap = scriptMap.get(language);
if (languageMap == null) {
languageMap = new HashMap<Country4a, WritingSystem4a>();
- scriptMap.put(languageToUse, languageMap);
+ scriptMap.put(language, languageMap);
}
WritingSystem4a writingSystem = languageMap.get(countryToUse);
if (writingSystem == null) {
- writingSystem = new WritingSystem4a(languageToUse, countryToUse, scriptToUse);
+ writingSystem = new WritingSystem4a(language, scriptToUse, countryToUse);
languageMap.put(countryToUse, writingSystem);
}
return writingSystem;
@@ -358,4 +361,61 @@
return null;
}
+ @Override
+ public boolean satisfies(final WritingSystem other) {
+ if (other == null) {
+ return false;
+ }
+
+ /* Language must match. */
+ if (this.language == null
+ || other.getLanguage() == null) {
+ return false;
+ }
+ if (! this.language.equals(other.getLanguage())) {
+ return false;
+ }
+
+ /* Script must either match or both be null. */
+ final Script thisScript = this.script == null ? this.language.getDefaultScript(this.country) : this.script;
+ final Script otherScript = other.getScript() == null ?
+ other.getLanguage().getDefaultScript(other.getCountry()) : other.getScript();
+ if (thisScript == null) {
+ if (otherScript == null) {
+ /* Both are null. Continue. */
+ } else {
+ return false;
+ }
+ } else {
+ if (otherScript == null) {
+ return false;
+ } else {
+ if (! thisScript.equals(otherScript)) {
+ return false;
+ }
+ }
+ }
+
+ /* Country must either match or both be null. */
+ final Country thisCountry = this.country;
+ final Country otherCountry = other.getCountry();
+ if (thisCountry == null) {
+ if (otherCountry == null) {
+ /* Both are null. Continue. */
+ } else {
+ return false;
+ }
+ } else {
+ if (otherCountry == null) {
+ return false;
+ } else {
+ if (! thisCountry.equals(otherCountry)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|