public void testPrevious() { RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(Locale.US); String text = "abc"; CollationElementIterator iterator = coll .getCollationElementIterator(text); int[] orders = new int[text.length()]; int order = iterator.next(); int i = 0; while (order != CollationElementIterator.NULLORDER) { orders[i++] = order; order = iterator.next(); } int offset = iterator.getOffset(); assertEquals(text.length(), offset); order = iterator.previous(); while (order != CollationElementIterator.NULLORDER) { assertEquals(orders[--i], order); order = iterator.previous(); } assertEquals(0, iterator.getOffset()); }
public void testNext() { String text = "abc"; CollationElementIterator iterator = coll .getCollationElementIterator(text); int[] orders = new int[text.length()]; int order = iterator.next(); int i = 0; while (order != CollationElementIterator.NULLORDER) { orders[i++] = order; order = iterator.next(); } int offset = iterator.getOffset(); assertEquals(text.length(), offset); order = iterator.previous(); while (order != CollationElementIterator.NULLORDER) { assertEquals(orders[--i], order); order = iterator.previous(); } assertEquals(0, iterator.getOffset()); }
public void testReset() { String text = "abc"; CollationElementIterator iterator = coll .getCollationElementIterator(text); int[] orders = new int[text.length()]; int order = iterator.next(); int i = 0; while (order != CollationElementIterator.NULLORDER) { orders[i++] = order; order = iterator.next(); } int offset = iterator.getOffset(); assertEquals(text.length(), offset); iterator.reset(); assertEquals(0, iterator.getOffset()); }
public void testTertiaryOrder() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("fr", "FR")); String text = "abAB"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); int order = iterator.next(); int tOrder1 = CollationElementIterator.tertiaryOrder(order); order = iterator.next(); int tOrder2 = CollationElementIterator.tertiaryOrder(order); assertEquals(tOrder1, tOrder2); order = iterator.next(); tOrder1 = CollationElementIterator.tertiaryOrder(order); order = iterator.next(); tOrder2 = CollationElementIterator.tertiaryOrder(order); assertEquals(tOrder1, tOrder2); }
private void assertCollationElementIterator(CollationElementIterator it, Integer... offsets) { for (int offset : offsets) { assertEquals(offset, it.getOffset()); it.next(); } assertEquals(CollationElementIterator.NULLORDER, it.next()); }
public void testGetOffset() { String text = "abc"; CollationElementIterator iterator = coll .getCollationElementIterator(text); int[] offsets = { 0, 1, 2, 3 }; int offset = iterator.getOffset(); int i = 0; assertEquals(offsets[i++], offset); while (offset != text.length()) { iterator.next(); offset = iterator.getOffset(); assertEquals(offsets[i++], offset); } }
public void testGetMaxExpansion() { String text = "cha"; RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); CollationElementIterator iterator = rbColl .getCollationElementIterator(text); int order = iterator.next(); while (order != CollationElementIterator.NULLORDER) { assertEquals(1, iterator.getMaxExpansion(order)); order = iterator.next(); } }
public void testPrimaryOrder() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("de", "DE")); String text = "\u00e6"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); int order = iterator.next(); int pOrder = CollationElementIterator.primaryOrder(order); CollationElementIterator iterator2 = rbColl .getCollationElementIterator("ae"); int order2 = iterator2.next(); int pOrder2 = CollationElementIterator.primaryOrder(order2); assertEquals(pOrder, pOrder2); }
public void testSecondaryOrder() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("fr", "FR")); String text = "a\u00e0"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); int order = iterator.next(); int sOrder1 = CollationElementIterator.secondaryOrder(order); order = iterator.next(); int sOrder2 = CollationElementIterator.secondaryOrder(order); assertEquals(sOrder1, sOrder2); }
public void testSetOffset() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "cha"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); }
public void testSetTextString() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "caa"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); iterator.setText("cha"); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); }
public void testSetTextCharacterIterator() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "caa"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); iterator.setText(new StringCharacterIterator("cha")); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); }
public void testSetOffset() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "cha"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(0, iterator.getOffset()); }
public void testSetTextString() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "caa"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); iterator.setText("cha"); iterator.setOffset(1); assertEquals(0, iterator.getOffset()); }
public void testSetTextCharacterIterator() { RuleBasedCollator rbColl = (RuleBasedCollator) Collator .getInstance(new Locale("es", "", "TRADITIONAL")); String text = "caa"; CollationElementIterator iterator = rbColl .getCollationElementIterator(text); iterator.setOffset(1); assertEquals(1, iterator.getOffset()); iterator.setText(new StringCharacterIterator("cha")); iterator.setOffset(1); assertEquals(0, iterator.getOffset()); }
private final int[] getFirstCaseDiff(final String text, final String pattern, final Locale locale){ final CollationElementIterator targIter = m_collator.getCollationElementIterator(text); final CollationElementIterator patIter = m_collator.getCollationElementIterator(pattern); int startTarg = -1; int endTarg = -1; int startPatt = -1; int endPatt = -1; final int done = getElement(CollationElementIterator.NULLORDER); int patternElement = 0, targetElement = 0; boolean getPattern = true, getTarget = true; while (true) { if (getPattern){ startPatt = patIter.getOffset(); patternElement = getElement(patIter.next()); endPatt = patIter.getOffset(); } if ((getTarget)){ startTarg = targIter.getOffset(); targetElement = getElement(targIter.next()); endTarg = targIter.getOffset(); } getTarget = getPattern = true; if ((patternElement == done) ||( targetElement == done)) { return null; } else if (targetElement == 0) { getPattern = false; } else if (patternElement == 0) { getTarget = false; } else if (targetElement != patternElement) {// mismatch if((startPatt < endPatt) && (startTarg < endTarg)){ final String subText = text.substring(startTarg, endTarg); final String subPatt = pattern.substring(startPatt, endPatt); final String subTextUp = subText.toUpperCase(locale); final String subPattUp = subPatt.toUpperCase(locale); if(m_collator.compare(subTextUp, subPattUp) != 0){ // not case diffference continue; } int diff[] = {UNKNOWN_CASE, UNKNOWN_CASE}; if(m_collator.compare(subText, subTextUp) == 0){ diff[0] = UPPER_CASE; }else if(m_collator.compare(subText, subText.toLowerCase(locale)) == 0){ diff[0] = LOWER_CASE; } if(m_collator.compare(subPatt, subPattUp) == 0){ diff[1] = UPPER_CASE; }else if(m_collator.compare(subPatt, subPatt.toLowerCase(locale)) == 0){ diff[1] = LOWER_CASE; } if(((diff[0] == UPPER_CASE) && ( diff[1] == LOWER_CASE)) || ((diff[0] == LOWER_CASE) && ( diff[1] == UPPER_CASE))){ return diff; }else{// not case diff continue; } }else{ continue; } } } }
/** * This method translates the string into a series of collation elements. * These elements will get used in the like method. * * @return an array of collation elements for the string * @throws StandardException */ int[] getCollationElementsForString() throws StandardException { if (stringData.isNull()) { return (int[]) null; } // Caching of collationElementsForString is not working properly, in // order to cache it needs to get invalidated everytime the container // type's value is changed - through any interface, eg: readExternal, // setValue, ... To get proper behavior, disabling caching, and will // file a performance enhancement to implement correct caching. collationElementsForString = null; countOfCollationElements = 0; if (collationElementsForString != null) { return collationElementsForString; } // countOfCollationElements should always be 0 when // collationElementsForString is null if (SanityManager.DEBUG) { if (countOfCollationElements != 0) { SanityManager.THROWASSERT( "countOfCollationElements expected to be 0, not " + countOfCollationElements); } } collationElementsForString = new int[stringData.getLength()]; CollationElementIterator cei = collatorForCharacterDatatypes.getCollationElementIterator( stringData.getString()); int nextInt; while ((nextInt = cei.next()) != CollationElementIterator.NULLORDER) { /* Believe it or not, a String might have more * collation elements than characters. * So, we handle that case by increasing the int array * by 5 and copying array elements. */ if (countOfCollationElements == collationElementsForString.length) { int[] expandedArray = new int[countOfCollationElements + 5]; System.arraycopy(collationElementsForString, 0, expandedArray, 0, collationElementsForString.length); collationElementsForString = expandedArray; } collationElementsForString[countOfCollationElements++] = nextInt; } return collationElementsForString; }