当前位置: 首页>>代码示例>>Java>>正文


Java Collator.setStrength方法代码示例

本文整理汇总了Java中java.text.Collator.setStrength方法的典型用法代码示例。如果您正苦于以下问题:Java Collator.setStrength方法的具体用法?Java Collator.setStrength怎么用?Java Collator.setStrength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.text.Collator的用法示例。


在下文中一共展示了Collator.setStrength方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: keyToString

import java.text.Collator; //导入方法依赖的package包/类
/**
 * Construct a key based on the key columns:
 * Single key: Use the value as key
 * Multiple keys: Serialize the key using a JSON map.
 */
private String keyToString(String[] columnNames, Object[] columnValues) {
	if ( columnNames.length == 1 ) {
		return columnValues[0].toString();
	}

	Collator collator = Collator.getInstance( Locale.ENGLISH );
	collator.setStrength( Collator.SECONDARY );

	Map<String, Object> idObject = new TreeMap<>( collator );

	for ( int i = 0; i < columnNames.length; i++ ) {
		idObject.put( columnNames[i], columnValues[i] );
	}

	return strategy.serialize( idObject );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:22,代码来源:AbstractRedisDialect.java

示例2: buildUpdates

import java.text.Collator; //导入方法依赖的package包/类
private Component buildUpdates() {
  XJTable tblUpdates = new XJTable(updatesModel);
  tblUpdates.getColumnModel().getColumn(0)
      .setCellRenderer(new CheckBoxTableCellRenderer());
  tblUpdates.setSortable(false);
  tblUpdates.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  tblUpdates.getColumnModel().getColumn(0).setMaxWidth(100);
  tblUpdates.getColumnModel().getColumn(2).setMaxWidth(100);
  tblUpdates.getColumnModel().getColumn(3).setMaxWidth(100);

  tblUpdates.getColumnModel().getColumn(1)
      .setCellEditor(new JTextPaneTableCellRenderer());

  tblUpdates.setSortable(true);
  tblUpdates.setSortedColumn(1);
  Collator collator = Collator.getInstance(Locale.ENGLISH);
  collator.setStrength(Collator.TERTIARY);
  tblUpdates.setComparator(1, collator);

  JScrollPane scroller = new JScrollPane(tblUpdates);
  scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  return scroller;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:24,代码来源:PluginUpdateManager.java

示例3: getSupportedCountries

import java.text.Collator; //导入方法依赖的package包/类
/** @return The list of supported countries sorted by their localized display names. */
public static List<DropdownKeyValue> getSupportedCountries() {
    List<String> countryCodes = new ArrayList<>();
    List<String> countryNames = new ArrayList<>();
    List<DropdownKeyValue> countries = new ArrayList<>();

    nativeGetSupportedCountries(countryCodes, countryNames);

    for (int i = 0; i < countryCodes.size(); i++) {
        countries.add(new DropdownKeyValue(countryCodes.get(i), countryNames.get(i)));
    }

    final Collator collator = Collator.getInstance(Locale.getDefault());
    collator.setStrength(Collator.PRIMARY);
    Collections.sort(countries, new Comparator<DropdownKeyValue>() {
        @Override
        public int compare(DropdownKeyValue lhs, DropdownKeyValue rhs) {
            int result = collator.compare(lhs.getValue(), rhs.getValue());
            if (result == 0) result = lhs.getKey().compareTo(rhs.getKey());
            return result;
        }
    });

    return countries;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:26,代码来源:AutofillProfileBridge.java

示例4: 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

示例5: 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

示例6: getPlaylistCursor

import java.text.Collator; //导入方法依赖的package包/类
public static Cursor getPlaylistCursor(AsyncQueryHandler async,
                                       String filterstring, Context context) {

    StringBuilder where = new StringBuilder();
    where.append(MediaStore.Audio.Playlists.NAME + " != ''");

    // Add in the filtering constraints
    String[] keywords = null;
    if (filterstring != null) {
        String[] searchWords = filterstring.split(" ");
        keywords = new String[searchWords.length];
        Collator col = Collator.getInstance();
        col.setStrength(Collator.PRIMARY);
        for (int i = 0; i < searchWords.length; i++) {
            keywords[i] = '%' + searchWords[i] + '%';
        }
        for (int i = 0; i < searchWords.length; i++) {
            where.append(" AND ");
            where.append(MediaStore.Audio.Playlists.NAME + " LIKE ?");
        }
    }

    String whereclause = where.toString();

    if (async != null) {
        async.startQuery(0, null,
                MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols,
                whereclause, keywords, MediaStore.Audio.Playlists.NAME);
        return null;
    }
    Cursor c;
    c = MusicUtils.query(context,
            MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, mCols,
            whereclause, keywords, MediaStore.Audio.Playlists.NAME);

    return filterCursor(c);
}
 
开发者ID:89luca89,项目名称:ThunderMusic,代码行数:38,代码来源:PlaylistBrowserActivity.java

示例7: HostInfoImpl

import java.text.Collator; //导入方法依赖的package包/类
HostInfoImpl() {
    Collator collator = Collator.getInstance(Locale.US);
    collator.setStrength(Collator.PRIMARY);
    Map<String, String> env = new TreeMap<>(collator);
    env.putAll(System.getenv());

    // Use os.arch to detect bitness.
    // Another way is described in the following article:
    // http://blogs.msdn.com/david.wang/archive/2006/03/26/HOWTO-Detect-Process-Bitness.aspx
    osBitness = ("x86".equals(System.getProperty("os.arch"))) ? Bitness._32 : Bitness._64; // NOI18N
    osFamily = OSFamily.WINDOWS;
    osVersion = System.getProperty("os.version"); // NOI18N
    osName = System.getProperty("os.name"); // NOI18N
    cpuFamily = CpuFamily.X86;
    int _cpuNum = 1;

    try {
        _cpuNum = Integer.parseInt(env.get("NUMBER_OF_PROCESSORS")); // NOI18N
    } catch (Exception ex) {
    }

    cpuNum = _cpuNum;
    hostname = env.get("COMPUTERNAME"); // NOI18N
    shell = WindowsSupport.getInstance().getShell();

    if (shell != null) {
        String path = new File(shell).getParent();
        env.put("PATH", path + ";" + env.get("PATH")); // NOI18N
    }

    environment = Collections.unmodifiableMap(env);

    os = new OS() {

        @Override
        public OSFamily getFamily() {
            return osFamily;
        }

        @Override
        public String getName() {
            return osName;
        }

        @Override
        public String getVersion() {
            return osVersion;
        }

        @Override
        public Bitness getBitness() {
            return osBitness;
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:WindowsHostInfoProvider.java

示例8: 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

示例9: 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

示例10: doAudioSearch

import java.text.Collator; //导入方法依赖的package包/类
private Cursor doAudioSearch(SQLiteDatabase db, SQLiteQueryBuilder qb,
        Uri uri, String[] projectionIn, String selection,
        String[] selectionArgs, String sort, int mode,
        String limit) {

    String mSearchString = uri.getPath().endsWith("/") ? "" : uri.getLastPathSegment();
    mSearchString = mSearchString.replaceAll("  ", " ").trim().toLowerCase();

    String [] searchWords = mSearchString.length() > 0 ?
            mSearchString.split(" ") : new String[0];
    String [] wildcardWords = new String[searchWords.length];
    Collator col = Collator.getInstance();
    col.setStrength(Collator.PRIMARY);
    int len = searchWords.length;
    for (int i = 0; i < len; i++) {
        // Because we match on individual words here, we need to remove words
        // like 'a' and 'the' that aren't part of the keys.
        String key = MediaStore.Audio.keyFor(searchWords[i]);
        key = key.replace("\\", "\\\\");
        key = key.replace("%", "\\%");
        key = key.replace("_", "\\_");
        wildcardWords[i] =
            (searchWords[i].equals("a") || searchWords[i].equals("an") ||
                    searchWords[i].equals("the")) ? "%" : "%" + key + "%";
    }

    String where = "";
    for (int i = 0; i < searchWords.length; i++) {
        if (i == 0) {
            where = "match LIKE ? ESCAPE '\\'";
        } else {
            where += " AND match LIKE ? ESCAPE '\\'";
        }
    }

    qb.setTables("search");
    String [] cols;
    if (mode == AUDIO_SEARCH_FANCY) {
        cols = mSearchColsFancy;
    } else if (mode == AUDIO_SEARCH_BASIC) {
        cols = mSearchColsBasic;
    } else if (mode == AUDIO_SEARCH_ARCHOS) {
        cols = mSearchColsArchos;
        qb.setTables("search_archos");
    } else {
        cols = mSearchColsLegacy;
    }
    return qb.query(db, cols, where, wildcardWords, null, null, null, limit);
}
 
开发者ID:archos-sa,项目名称:aos-MediaLib,代码行数:50,代码来源:MusicProvider.java


注:本文中的java.text.Collator.setStrength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。