本文整理匯總了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 );
}
示例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;
}
示例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;
}
示例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);
}
示例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));
}
示例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);
}
示例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;
}
};
}
示例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;
}
示例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.");
}
示例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);
}