Search in sources :

Example 6 with RuleBasedCollator

use of java.text.RuleBasedCollator in project robovm by robovm.

the class CollatorTest method test_Harmony_1352.

public void test_Harmony_1352() throws Exception {
    // of an earlier failure.
    try {
        new RuleBasedCollator("< a< b< c< d").getCollationElementIterator((CharacterIterator) null);
        fail("NullPointerException expected");
    } catch (NullPointerException expected) {
    }
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator)

Example 7 with RuleBasedCollator

use of java.text.RuleBasedCollator in project robovm by robovm.

the class CollatorTest method assertGetCollationElementIteratorCharacterIterator.

private void assertGetCollationElementIteratorCharacterIterator(Locale l, String s, Integer... offsets) {
    RuleBasedCollator coll = (RuleBasedCollator) Collator.getInstance(l);
    CharacterIterator it = new StringCharacterIterator(s);
    assertCollationElementIterator(coll.getCollationElementIterator(it), offsets);
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator) StringCharacterIterator(java.text.StringCharacterIterator) StringCharacterIterator(java.text.StringCharacterIterator) CharacterIterator(java.text.CharacterIterator)

Example 8 with RuleBasedCollator

use of java.text.RuleBasedCollator in project robovm by robovm.

the class CollatorTest method testEqualsObject.

public void testEqualsObject() throws ParseException {
    String rule = "< a < b < c < d < e";
    RuleBasedCollator coll = new RuleBasedCollator(rule);
    assertEquals(Collator.TERTIARY, coll.getStrength());
    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);
    // See comment above.
    other.setDecomposition(Collator.NO_DECOMPOSITION);
    assertFalse(coll.equals(other));
}
Also used : RuleBasedCollator(java.text.RuleBasedCollator)

Example 9 with RuleBasedCollator

use of java.text.RuleBasedCollator in project lucene-solr by apache.

the class TestCollationField method setupSolrHome.

/**
   * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
   * These are largish files, and jvm-specific (as our documentation says, you should always
   * look out for jvm differences with collation).
   * So it's preferable to create this file on-the-fly.
   */
public static String setupSolrHome() throws Exception {
    // make a solr home underneath the test's TEMP_DIR
    File tmpFile = createTempDir("collation1").toFile();
    // make data and conf dirs
    new File(tmpFile, "data").mkdir();
    File confDir = new File(tmpFile + "/collection1", "conf");
    confDir.mkdirs();
    // copy over configuration files
    FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-basic.xml"), new File(confDir, "solrconfig.xml"));
    FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"), new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
    FileUtils.copyFile(getFile("solr/collection1/conf/schema-collate.xml"), new File(confDir, "schema.xml"));
    // generate custom collation rules (DIN 5007-2), saving to customrules.dat
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new Locale("de", "DE"));
    String DIN5007_2_tailorings = "& ae , ä & AE , Ä" + "& oe , ö & OE , Ö" + "& ue , ü & UE , ü";
    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();
}
Also used : Locale(java.util.Locale) RuleBasedCollator(java.text.RuleBasedCollator) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 10 with RuleBasedCollator

use of java.text.RuleBasedCollator in project lucene-solr by apache.

the class TestCollationFieldDocValues method setupSolrHome.

/**
   * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
   * These are largish files, and jvm-specific (as our documentation says, you should always
   * look out for jvm differences with collation).
   * So it's preferable to create this file on-the-fly.
   */
public static String setupSolrHome() throws Exception {
    // make a solr home underneath the test's TEMP_DIR
    File tmpFile = createTempDir("collation1").toFile();
    // make data and conf dirs
    new File(tmpFile, "data").mkdir();
    File confDir = new File(tmpFile + "/collection1", "conf");
    confDir.mkdirs();
    // copy over configuration files
    FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig-basic.xml"), new File(confDir, "solrconfig.xml"));
    FileUtils.copyFile(getFile("solr/collection1/conf/solrconfig.snippet.randomindexconfig.xml"), new File(confDir, "solrconfig.snippet.randomindexconfig.xml"));
    FileUtils.copyFile(getFile("solr/collection1/conf/schema-collate-dv.xml"), new File(confDir, "schema.xml"));
    // generate custom collation rules (DIN 5007-2), saving to customrules.dat
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new Locale("de", "DE"));
    String DIN5007_2_tailorings = "& ae , ä & AE , Ä" + "& oe , ö & OE , Ö" + "& ue , ü & UE , ü";
    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();
}
Also used : Locale(java.util.Locale) RuleBasedCollator(java.text.RuleBasedCollator) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

RuleBasedCollator (java.text.RuleBasedCollator)11 Collator (java.text.Collator)3 ParseException (java.text.ParseException)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 Locale (java.util.Locale)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 CharacterIterator (java.text.CharacterIterator)1 CollationElementIterator (java.text.CollationElementIterator)1 CollationKey (java.text.CollationKey)1 StringCharacterIterator (java.text.StringCharacterIterator)1 CollationKeyAnalyzer (org.apache.lucene.collation.CollationKeyAnalyzer)1 SolrException (org.apache.solr.common.SolrException)1