本文整理汇总了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;
}