當前位置: 首頁>>代碼示例>>Java>>正文


Java Collator.setDecomposition方法代碼示例

本文整理匯總了Java中java.text.Collator.setDecomposition方法的典型用法代碼示例。如果您正苦於以下問題:Java Collator.setDecomposition方法的具體用法?Java Collator.setDecomposition怎麽用?Java Collator.setDecomposition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.text.Collator的用法示例。


在下文中一共展示了Collator.setDecomposition方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setCollator

import java.text.Collator; //導入方法依賴的package包/類
/**
 * Convenience method to set a compatator for a property using a {@link Collator} setup with
 * the given strength and decomposition values.
 *
 * @param propertyName the property
 * @param collatorStrength the stregth to use or null to leave as the default for the
 * default locale
 * @param collatorDecomposition the decomposition to use or null to leave as the default for the
 * default locale
 * @see #setComparator(String, Comparator)
 */
public void setCollator(
  String        propertyName,
  Strength      collatorStrength,
  Decomposition collatorDecomposition)
{
  Locale locale = null;

  RequestContext reqCtx = RequestContext.getCurrentInstance();
  if (reqCtx != null)
  {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (facesContext != null)
    {
      locale = _getLocale(reqCtx, facesContext);
    }
  }

  Collator collator = locale == null ? Collator.getInstance() : Collator.getInstance(locale);
  if (collatorDecomposition != null)
  {
    collator.setDecomposition(collatorDecomposition.getIntValue());
  }

  if (collatorStrength != null)
  {
    collator.setStrength(collatorStrength.getIntValue());
  }

  setComparator(propertyName, collator);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:42,代碼來源:SortableModel.java

示例2: localeCompare

import java.text.Collator; //導入方法依賴的package包/類
/**
 * ECMA 15.5.4.9 String.prototype.localeCompare (that)
 * @param self self reference
 * @param that comparison object
 * @return result of locale sensitive comparison operation between {@code self} and {@code that}
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static double localeCompare(final Object self, final Object that) {

    final String   str      = checkObjectToString(self);
    final Collator collator = Collator.getInstance(Global.getEnv()._locale);

    collator.setStrength(Collator.IDENTICAL);
    collator.setDecomposition(Collator.CANONICAL_DECOMPOSITION);

    return collator.compare(str, JSType.toString(that));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:18,代碼來源:NativeString.java

示例3: buildSenseCollectionAsSynstes

import java.text.Collator; //導入方法依賴的package包/類
public Collection<Sense> buildSenseCollectionAsSynstes(List<Sense> sense, String sortFrase) {
        Collection<Sense> synsets = new ArrayList<Sense>();
        if (!sense.isEmpty()) {
            for (Sense senseItem : sense) {
//                if (senseItem.getSenseToSynset().getSenseIndex() == 0) {
//                    synsets.add(senseItem);
//                }
//                if (senseItem.getLexicon().getId() == 2
//                        && senseItem.getSenseToSynset().getSenseIndex() == 1) {
//                    synsets.add(senseItem);
//                }
            }
        }

        Collator collator = Collator.getInstance(Locale.US);
        String rules = ((RuleBasedCollator) collator).getRules();
        try {
            RuleBasedCollator correctedCollator
                    = new RuleBasedCollator(rules.replaceAll("<'\u005f'", "<' '<'\u005f'"));
            collator = correctedCollator;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        collator.setStrength(Collator.PRIMARY);
        collator.setDecomposition(Collator.NO_DECOMPOSITION);

        final Collator myFavouriteCollator = collator;

        Comparator<Sense> senseComparator = new Comparator<Sense>() {
            @Override
            public int compare(Sense a, Sense b) {
                String aa = a.getWord().getWord().toLowerCase();
                String bb = b.getWord().getWord().toLowerCase();

                int c = myFavouriteCollator.compare(aa, bb);
                if (c == 0) {
                    aa = a.getPartOfSpeech().getId().toString();
                    bb = b.getPartOfSpeech().getId().toString();
                    c = myFavouriteCollator.compare(aa, bb);
                }
                if (c == 0) {
                    if (a.getVariant() == b.getVariant()) {
                        c = 0;
                    }
                    if (a.getVariant() > b.getVariant()) {
                        c = 1;
                    }
                    if (a.getVariant() < b.getVariant()) {
                        c = -1;
                    }
                }
                if (c == 0) {
                    aa = a.getLexicon().getId().toString();
                    bb = b.getLexicon().getId().toString();
                    c = myFavouriteCollator.compare(aa, bb);
                }
                return c;
            }
        };

        //Items starting with frase
        List<Sense> withFraseOnBegining = new ArrayList<>();
        //Other items
        List<Sense> other = new ArrayList<>();

        for (Sense se : synsets) {
            if (se.getWord().toString().startsWith(sortFrase.toLowerCase())) {
                withFraseOnBegining.add(se);
            } else {
                other.add(se);
            }
        }
        Collections.sort(withFraseOnBegining, senseComparator);
        Collections.sort(other, senseComparator);
        withFraseOnBegining.addAll(other);
        return withFraseOnBegining;
    }
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:78,代碼來源:GenericListModel.java

示例4: TestProperty

import java.text.Collator; //導入方法依賴的package包/類
public final void TestProperty( )
{
    Collator col = null;
    try {
        col = Collator.getInstance(Locale.ROOT);
        logln("The property tests begin : ");
        logln("Test ctors : ");
        doAssert(col.compare("ab", "abc") < 0, "ab < abc comparison failed");
        doAssert(col.compare("ab", "AB") < 0, "ab < AB comparison failed");
        doAssert(col.compare("black-bird", "blackbird") > 0, "black-bird > blackbird comparison failed");
        doAssert(col.compare("black bird", "black-bird") < 0, "black bird < black-bird comparison failed");
        doAssert(col.compare("Hello", "hello") > 0, "Hello > hello comparison failed");

        logln("Test ctors ends.");
        logln("testing Collator.getStrength() method ...");
        doAssert(col.getStrength() == Collator.TERTIARY, "collation object has the wrong strength");
        doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");

        logln("testing Collator.setStrength() method ...");
        col.setStrength(Collator.SECONDARY);
        doAssert(col.getStrength() != Collator.TERTIARY, "collation object's strength is secondary difference");
        doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
        doAssert(col.getStrength() == Collator.SECONDARY, "collation object has the wrong strength");

        logln("testing Collator.setDecomposition() method ...");
        col.setDecomposition(Collator.NO_DECOMPOSITION);
        doAssert(col.getDecomposition() != Collator.FULL_DECOMPOSITION, "collation object's strength is secondary difference");
        doAssert(col.getDecomposition() != Collator.CANONICAL_DECOMPOSITION, "collation object's strength is primary difference");
        doAssert(col.getDecomposition() == Collator.NO_DECOMPOSITION, "collation object has the wrong strength");
    } catch (Exception foo) {
        errln("Error : " + foo.getMessage());
        errln("Default Collator creation failed.");
    }
    logln("Default collation property test ended.");
    logln("Collator.getRules() testing ...");
    doAssert(((RuleBasedCollator)col).getRules().length() != 0, "getRules() result incorrect" );
    logln("getRules tests end.");
    try {
        col = Collator.getInstance(Locale.FRENCH);
        col.setStrength(Collator.PRIMARY);
        logln("testing Collator.getStrength() method again ...");
        doAssert(col.getStrength() != Collator.TERTIARY, "collation object has the wrong strength");
        doAssert(col.getStrength() == Collator.PRIMARY, "collation object's strength is not primary difference");

        logln("testing French Collator.setStrength() method ...");
        col.setStrength(Collator.TERTIARY);
        doAssert(col.getStrength() == Collator.TERTIARY, "collation object's strength is not tertiary difference");
        doAssert(col.getStrength() != Collator.PRIMARY, "collation object's strength is primary difference");
        doAssert(col.getStrength() != Collator.SECONDARY, "collation object's strength is secondary difference");

    } catch (Exception bar) {
        errln("Error :  " + bar.getMessage());
        errln("Creating French collation failed.");
    }

    logln("Create junk collation: ");
    Locale abcd = new Locale("ab", "CD", "");
    Collator junk = null;
    try {
        junk = Collator.getInstance(abcd);
    } catch (Exception err) {
        errln("Error : " + err.getMessage());
        errln("Junk collation creation failed, should at least return the collator for the base bundle.");
    }
    try {
        col = Collator.getInstance(Locale.ROOT);
        doAssert(col.equals(junk), "The base bundle's collation should be returned.");
    } catch (Exception exc) {
        errln("Error : " + exc.getMessage());
        errln("Default collation comparison, caching not working.");
    }

    logln("Collator property test ended.");
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:75,代碼來源:APITest.java


注:本文中的java.text.Collator.setDecomposition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。