Java 8 RuleBasedCollator - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 RuleBasedCollator class.

This code example shows how to use the following methods:getStrength, setDecomposition, setStrength, equals
                myCollator.compare("\u00e0\u0325", "a\u0325\u0300") == 0);
    } 
 
    public void testEqualsObject() throws ParseException { 
        String rule = "< a < b < c < d < e";
        RuleBasedCollator coll = new RuleBasedCollator(rule);
 
        assertEquals(Collator.TERTIARY, coll.getStrength());
        // This is a harmony test, but it assumes that RuleBasedCollators default to 
        // NO_DECOMPOSITION, which isn't true on Android. 
        // assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition()); 
        RuleBasedCollator other = new RuleBasedCollator(rule);
        assertTrue(coll.equals(other));
 
        coll.setStrength(Collator.PRIMARY);
        assertFalse(coll.equals(other));
 
        coll.setStrength(Collator.TERTIARY);
        coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        other.setDecomposition(Collator.NO_DECOMPOSITION); // See comment above.

7
CodeRank
This code example shows how to use the following methods:getStrength, setDecomposition, setStrength, equals
                myCollator.compare("\u00e0\u0325", "a\u0325\u0300") == 0);
    } 
 
    public void testEqualsObject() throws ParseException { 
        String rule = "< a < b < c < d < e";
        RuleBasedCollator coll = new RuleBasedCollator(rule);
 
        assertEquals(Collator.TERTIARY, coll.getStrength());
        // This is a harmony test, but it assumes that RuleBasedCollators default to 
        // NO_DECOMPOSITION, which isn't true on Android. 
        // assertEquals(Collator.NO_DECOMPOSITION, coll.getDecomposition()); 
        RuleBasedCollator other = new RuleBasedCollator(rule);
        assertTrue(coll.equals(other));
 
        coll.setStrength(Collator.PRIMARY);
        assertFalse(coll.equals(other));
 
        coll.setStrength(Collator.TERTIARY);
        coll.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
        other.setDecomposition(Collator.NO_DECOMPOSITION); // See comment above.

7
CodeRank
This code example shows how to use the following methods:getDecomposition, getStrength, setDecomposition, setStrength, equals
6
CodeRank
This code example shows how to use the following methods:getRules
    String DIN5007_2_tailorings =
      "& ae , a\u0308 & AE , A\u0308"+ 
      "& oe , o\u0308 & OE , O\u0308"+ 
      "& ue , u\u0308 & UE , u\u0308"; 
 
    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();
    FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
    IOUtils.write(tailoredRules, os, "UTF-8");
    os.close();
 
    return tmpFile.getAbsolutePath();
  } 
 
  /**  
   * Test termquery with german DIN 5007-1 primary strength. 
   * In this case, ö is equivalent to o (but not oe)  
   */ 
  public void testBasicTermQuery() { 
    assertQ("Collated TQ: ", 
6
CodeRank
This code example shows how to use the following methods:getRules
    String DIN5007_2_tailorings =
      "& ae , a\u0308 & AE , A\u0308"+ 
      "& oe , o\u0308 & OE , O\u0308"+ 
      "& ue , u\u0308 & UE , u\u0308"; 
 
    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();
    FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
    IOUtils.write(tailoredRules, os, "UTF-8");
    os.close();
 
    return tmpFile.getAbsolutePath();
  } 
 
  /**  
   * Test termquery with german DIN 5007-1 primary strength. 
   * In this case, ö is equivalent to o (but not oe)  
   */ 
  public void testBasicTermQuery() { 
    assertQ("Collated TQ: ", 
6
CodeRank
This code example shows how to use the following methods:setDecomposition, setStrength
This code example shows how to use the following methods:getCollationKey
		CollationKey key1 = collator.getCollationKey("abc");
		byte[] bytes = key1.toByteArray();
		assertTrue("Not enough bytes", bytes.length >= 3);
 
		try { 
			collator = new RuleBasedCollator("= 1 , 2 ; 3 , 4 < 5 ; 6 , 7");
		} catch (ParseException e) {
			fail("ParseException");
			return; 
		} 
		bytes = collator.getCollationKey("1234567").toByteArray();
		/* 
		 * CollationElementIterator it = 
		 * ((RuleBasedCollator)collator).getCollationElementIterator("1234567"); 
		 * int order; while ((order = it.next()) != 
		 * CollationElementIterator.NULLORDER) { 
		 * System.out.println(Integer.toHexString(order)); } for (int i=0; i<bytes.length; 
		 * i+=2) { System.out.print(Integer.toHexString(bytes[i]) + 
		 * Integer.toHexString(bytes[i+1]) + " "); } System.out.println(); 
		 */ 
5
CodeRank
This code example shows how to use the following methods:getCollationElementIterator
 
	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";
5
CodeRank
This code example shows how to use the following methods:setDecomposition, setStrength
public class NameNormalizer { 
 
    private static final RuleBasedCollator sCompressingCollator;
    static { 
        sCompressingCollator = (RuleBasedCollator)Collator.getInstance(Locale.getDefault());
        sCompressingCollator.setStrength(Collator.PRIMARY);
        sCompressingCollator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);
    } 
 
    private static final RuleBasedCollator sComplexityCollator;
    static { 
        sComplexityCollator = (RuleBasedCollator)Collator.getInstance(Locale.getDefault());
        sComplexityCollator.setStrength(Collator.SECONDARY);
    } 
 
    /** 
     * Converts the supplied name to a string that can be used to perform approximate matching 
     * of names.  It ignores non-letter, non-digit characters, and removes accents. 
     */ 
    public static String normalize(String name) {
5
CodeRank
This code example shows how to use the following methods:setDecomposition, setStrength
See Code Examples for Java 8 RuleBasedCollator Methods: