diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/BurmeseBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/BurmeseBreakEngine.java index 3447945b6d95..2ed8af3b7765 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/BurmeseBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/BurmeseBreakEngine.java @@ -71,7 +71,7 @@ public int hashCode() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean handles(int c) { int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); return (script == UScript.MYANMAR); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/DictionaryBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/DictionaryBreakEngine.java index 2e2bb62ed163..6d490aed4cf3 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/DictionaryBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/DictionaryBreakEngine.java @@ -178,7 +178,12 @@ public DictionaryBreakEngine() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean isFor(ULocale locale) { + return true; // by default, we handle all locales. + } + + @Override + public boolean handles(int c) { return fSet.contains(c); // we recognize the character } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/KhmerBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/KhmerBreakEngine.java index 675891ba75bf..8629bb5804b4 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/KhmerBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/KhmerBreakEngine.java @@ -79,7 +79,7 @@ public int hashCode() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean handles(int c) { int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); return (script == UScript.KHMER); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LSTMBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LSTMBreakEngine.java index 9a5568467385..ec29a5fd8362 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LSTMBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LSTMBreakEngine.java @@ -238,7 +238,7 @@ public int hashCode() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean handles(int c) { return fScript == UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LanguageBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LanguageBreakEngine.java index f6059d68ad93..801f05882348 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LanguageBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LanguageBreakEngine.java @@ -18,10 +18,15 @@ public interface LanguageBreakEngine { /** * @param c A Unicode codepoint value - * @param locale A locale * @return true if the engine can handle this character, false otherwise */ - boolean handles(int c, ULocale locale); + boolean handles(int c); + + /** + * @param locale A locale + * @return true if the engine is for this Locale, false otherwise + */ + boolean isFor(ULocale locale); /** * Implements the actual breaking logic. Find any breaks within a run in the supplied text. diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LaoBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LaoBreakEngine.java index fdd0c0b33319..97c1dda351a7 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LaoBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/LaoBreakEngine.java @@ -79,7 +79,7 @@ public int hashCode() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean handles(int c) { int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); return (script == UScript.LAO); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/ThaiBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/ThaiBreakEngine.java index d513cb4b8d5b..3acf252116cf 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/ThaiBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/ThaiBreakEngine.java @@ -90,7 +90,7 @@ public int hashCode() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean handles(int c) { int script = UCharacter.getIntPropertyValue(c, UProperty.SCRIPT); return (script == UScript.THAI); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/UnhandledBreakEngine.java b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/UnhandledBreakEngine.java index dbdbf2fa293b..f2c54919eca7 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/UnhandledBreakEngine.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/impl/breakiter/UnhandledBreakEngine.java @@ -39,7 +39,11 @@ public UnhandledBreakEngine() { } @Override - public boolean handles(int c, ULocale locale) { + public boolean isFor(ULocale locale) { + return true; // Handle all locales + } + @Override + public boolean handles(int c) { return fHandled.contains(c); } diff --git a/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java b/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java index ea72c02bdd4e..b08db7acf3c5 100644 --- a/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java +++ b/icu4j/main/core/src/main/java/com/ibm/icu/text/RuleBasedBreakIterator.java @@ -728,7 +728,7 @@ private LanguageBreakEngine getLanguageBreakEngine(int c) { // We have a dictionary character. // Does an already instantiated break engine handle it? for (LanguageBreakEngine candidate : fBreakEngines) { - if (candidate.handles(c, getRequestedLocale())) { + if (candidate.isFor(getRequestedLocale()) && candidate.handles(c)) { return candidate; } } @@ -738,7 +738,7 @@ private LanguageBreakEngine getLanguageBreakEngine(int c) { // Check the global list, another break iterator may have instantiated the // desired engine. for (LanguageBreakEngine candidate : gAllBreakEngines) { - if (candidate.handles(c, getRequestedLocale())) { + if (candidate.isFor(getRequestedLocale()) && candidate.handles(c)) { fBreakEngines.add(candidate); return candidate; } @@ -1094,8 +1094,12 @@ public static void registerExternalBreakEngine(ExternalBreakEngine engine) { synchronized(gAllBreakEngines) { gAllBreakEngines.add(0, new LanguageBreakEngine() { @Override - public boolean handles(int c, ULocale locale) { - return engine.isFor(c, locale); + public boolean handles(int c) { + return engine.handles(c); + } + @Override + public boolean isFor(ULocale locale) { + return engine.isFor(locale); } @Override public int findBreaks(CharacterIterator text, int startPos, int endPos, @@ -1917,15 +1921,14 @@ void dumpCache() { public interface ExternalBreakEngine { /** - *

Indicate whether this engine handles a particular character when - * the RuleBasedBreakIterator is used for a particular locale. This method is used - * by the RuleBasedBreakIterator to find a break engine.

- * @param c A character which begins a run that the engine might handle. + *

Indicate whether this engine is used for a particular locale. + * This method is used by the RuleBasedBreakIterator to find a break engine.

+ * * @param locale The locale. * @return true if this engine handles the particular character for that locale. * @internal ICU 75 technology preview */ - public boolean isFor(int c, ULocale locale); + public boolean isFor(ULocale locale); /** *

Indicate whether this engine handles a particular character.This method is diff --git a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java index 3410455c8983..5889c2170d89 100644 --- a/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java +++ b/icu4j/main/core/src/test/java/com/ibm/icu/dev/test/rbbi/RBBITest.java @@ -1023,10 +1023,10 @@ public void TestExternalBreakEngineWithFakeYue() { RuleBasedBreakIterator.registerExternalBreakEngine( new RuleBasedBreakIterator.ExternalBreakEngine() { UnicodeSet block = new UnicodeSet(0x4e00, 0x9FFF); - public boolean isFor(int c, ULocale locale) { + public boolean isFor(ULocale locale) { // We implmement this for any locale with "yue" such as // "yue", "yue-CN", "yue-Hant-CN", etc. - return handles(c) && locale.getLanguage().equals("yue"); + return locale.getLanguage().equals("yue"); } public boolean handles(int c) { return block.contains(c); @@ -1076,8 +1076,8 @@ public void TestExternalBreakEngineWithFakeTaiLe() { new RuleBasedBreakIterator.ExternalBreakEngine() { UnicodeSet block = new UnicodeSet(0x1950, 0x197f); UnicodeSet tones = new UnicodeSet(0x1970, 0x1974); - public boolean isFor(int c, ULocale locale) { - return handles(c); + public boolean isFor(ULocale locale) { + return true; // Handle all locales } public boolean handles(int c) { return block.contains(c);