本文整理匯總了Java中com.google.common.base.Splitter.split方法的典型用法代碼示例。如果您正苦於以下問題:Java Splitter.split方法的具體用法?Java Splitter.split怎麽用?Java Splitter.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.base.Splitter
的用法示例。
在下文中一共展示了Splitter.split方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getLanguages
import com.google.common.base.Splitter; //導入方法依賴的package包/類
/**
* Returns the sorted list of languages used in the resources.
*/
@NonNull
public SortedSet<String> getLanguages() {
SortedSet<String> set = new TreeSet<String>();
// As an optimization we could just look for values since that's typically where
// the languages are defined -- not on layouts, menus, etc -- especially if there
// are no translations for it
Set<String> qualifiers = Sets.newHashSet();
synchronized (ITEM_MAP_LOCK) {
for (ListMultimap<String, ResourceItem> map : getMap().values()) {
for (ResourceItem item : map.values()) {
qualifiers.add(item.getQualifiers());
}
}
}
Splitter splitter = Splitter.on('-');
for (String s : qualifiers) {
for (String qualifier : splitter.split(s)) {
if (qualifier.length() == 2 && Character.isLetter(qualifier.charAt(0))
&& Character.isLetter(qualifier.charAt(1))) {
set.add(qualifier);
}
}
}
return set;
}
示例2: getRegions
import com.google.common.base.Splitter; //導入方法依賴的package包/類
/**
* Returns the sorted list of regions used in the resources with the given language.
* @param currentLanguage the current language the region must be associated with.
*/
@NonNull
public SortedSet<String> getRegions(@NonNull String currentLanguage) {
SortedSet<String> set = new TreeSet<String>();
// As an optimization we could just look for values since that's typically where
// the languages are defined -- not on layouts, menus, etc -- especially if there
// are no translations for it
Set<String> qualifiers = Sets.newHashSet();
synchronized (ITEM_MAP_LOCK) {
for (ListMultimap<String, ResourceItem> map : getMap().values()) {
for (ResourceItem item : map.values()) {
qualifiers.add(item.getQualifiers());
}
}
}
Splitter splitter = Splitter.on('-');
for (String s : qualifiers) {
boolean rightLanguage = false;
for (String qualifier : splitter.split(s)) {
if (currentLanguage.equals(qualifier)) {
rightLanguage = true;
} else if (rightLanguage
&& qualifier.length() == 3
&& qualifier.charAt(0) == 'r'
&& Character.isUpperCase(qualifier.charAt(1))
&& Character.isUpperCase(qualifier.charAt(2))) {
set.add(qualifier.substring(1));
}
}
}
return set;
}
示例3: splitAuthFields
import com.google.common.base.Splitter; //導入方法依賴的package包/類
private ArrayMap<String, String> splitAuthFields(String authString) {
final ArrayMap<String, String> fields = new ArrayMap<>();
final CharMatcher trimmer = CharMatcher.anyOf("\"\t ");
final Splitter commas = Splitter.on(',').trimResults().omitEmptyStrings();
final Splitter equals = Splitter.on('=').trimResults(trimmer).limit(2);
String[] valuePair;
for (String keyPair : commas.split(authString)) {
valuePair = Iterables.toArray(equals.split(keyPair), String.class);
fields.put(valuePair[0], valuePair[1]);
}
return fields;
}