/*
*******************************************************************************
- * Copyright (C) 2014-2015, International Business Machines Corporation and
+ * Copyright (C) 2014-2016, International Business Machines Corporation and
* others. All Rights Reserved.
*******************************************************************************
*/
/**
* filter set to store all exceptions
*/
- private HashSet<String> filterSet;
+ private HashSet<String> filterSet = new HashSet<String>();
static final int PARTIAL = (1 << 0); // < partial - need to run through forward trie
static final int MATCH = (1 << 1); // < exact match - skip this one.
ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(
ICUResourceBundle.ICU_BRKITR_BASE_NAME, loc);
ICUResourceBundle exceptions = rb.findWithFallback("exceptions");
- ICUResourceBundle breaks = exceptions.findWithFallback("SentenceBreak");
-
- filterSet = new HashSet<String>();
- if (breaks != null) {
- for (int index = 0, size = breaks.getSize(); index < size; ++index) {
- ICUResourceBundle b = (ICUResourceBundle) breaks.get(index);
- String br = b.getString();
- filterSet.add(br);
+ if (exceptions != null) {
+ ICUResourceBundle breaks = exceptions.findWithFallback("SentenceBreak");
+
+ if (breaks != null) {
+ for (int index = 0, size = breaks.getSize(); index < size; ++index) {
+ ICUResourceBundle b = (ICUResourceBundle) breaks.get(index);
+ String br = b.getString();
+ filterSet.add(br);
+ }
}
- }
+ } // else - no exceptions.
}
/**
@Override
public BreakIterator build(BreakIterator adoptBreakIterator) {
+ if( filterSet.isEmpty() ) {
+ // Short circuit - nothing to except.
+ return adoptBreakIterator;
+ }
+
CharsTrieBuilder builder = new CharsTrieBuilder();
CharsTrieBuilder builder2 = new CharsTrieBuilder();
/*
*******************************************************************************
- * Copyright (C) 1996-2014, International Business Machines Corporation and *
+ * Copyright (C) 1996-2016, International Business Machines Corporation and *
* others. All Rights Reserved. *
*******************************************************************************
*/
}
}
+ /**
+ * At present, Japanese doesn't have exceptions.
+ * However, this still should not fail.
+ */
+ public void TestFilteredJapanese() {
+ ULocale loc = ULocale.JAPANESE;
+ BreakIterator brk = FilteredBreakIteratorBuilder
+ .createInstance(loc)
+ .build(BreakIterator.getSentenceInstance(loc));
+ brk.setText("OKです。");
+ assertEquals("Starting point", 0, brk.current());
+ assertEquals("Next point", 5, brk.next());
+ assertEquals("Last point", BreakIterator.DONE, brk.next());
+ }
+
/*
* Test case for Ticket#10721. BreakIterator factory method should throw NPE
* when specified locale is null.