当前位置: 首页>>代码示例>>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;未经允许,请勿转载。