本文整理匯總了Java中com.google.common.base.Splitter.on方法的典型用法代碼示例。如果您正苦於以下問題:Java Splitter.on方法的具體用法?Java Splitter.on怎麽用?Java Splitter.on使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.base.Splitter
的用法示例。
在下文中一共展示了Splitter.on方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleBothToolsAttributePresent
import com.google.common.base.Splitter; //導入方法依賴的package包/類
/**
* Handles tools: namespace attributes presence in both documents.
* @param higherPriority the higherPriority attribute
*/
private void handleBothToolsAttributePresent(
XmlAttribute higherPriority) {
// do not merge tools:node attributes, the higher priority one wins.
if (getName().getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)) {
return;
}
// everything else should be merged, duplicates should be eliminated.
Splitter splitter = Splitter.on(',');
ImmutableSet.Builder<String> targetValues = ImmutableSet.builder();
targetValues.addAll(splitter.split(higherPriority.getValue()));
targetValues.addAll(splitter.split(getValue()));
higherPriority.getXml().setValue(Joiner.on(',').join(targetValues.build()));
}
示例2: read
import com.google.common.base.Splitter; //導入方法依賴的package包/類
private static List<MprEntry> read(Reader reader) throws IOException {
Splitter splitter = Splitter.on('\t');
List<MprEntry> result = new ArrayList<>();
BufferedReader bufferedReader = new BufferedReader(reader);
String line;
while ((line = bufferedReader.readLine()) != null) {
Iterator<String> i = splitter.split(line).iterator();
MprEntry mprEntry = new MprEntry();
mprEntry.seedId = Integer.parseInt(i.next());
mprEntry.interactionId = Integer.parseInt(i.next());
mprEntry.bin = Integer.parseInt(i.next());
mprEntry.score = Double.parseDouble(i.next());
result.add(mprEntry);
}
return result;
}
示例3: loadFromRealData
import com.google.common.base.Splitter; //導入方法依賴的package包/類
@Override
public void loadFromRealData() throws Exception {
TreeMap<String, V> map = new TreeMap<>();
long t1 = System.currentTimeMillis();
MynlpResource resource = environment.getMynlpResourceFactory().load(dicFilePath());
Splitter splitter = Splitter.on(Pattern.compile("\\s"));
try (CharSourceLineReader reader = resource.openLineReader()) {
while (reader.hasNext()) {
String line = reader.next();
List<String> params = splitter.splitToList(line);
if (!params.isEmpty()) {
List<String> attrs = params.subList(1, params.size());
V attribute = parseLine(attrs);
map.put(params.get(0), attribute);
}
}
}
filtermap(map);
DoubleArrayTrieBuilder<V> builder = new DoubleArrayTrieBuilder<>();
this.trie = builder.build(map);
}
示例4: DictionaryAidedDepluralizer
import com.google.common.base.Splitter; //導入方法依賴的package包/類
DictionaryAidedDepluralizer(String[] exceptions) {
Map<String, String> map = Maps.newHashMapWithExpectedSize(exceptions.length);
Splitter splitter = Splitter.on(':');
for (String s : exceptions) {
List<String> parts = splitter.splitToList(s.toLowerCase());
if (parts.size() == 1) {
// simple no-depluratization exception
map.put(parts.get(0), parts.get(0));
} else if (parts.size() == 2) {
// singular, then plural, so mapping plural->singular
map.put(parts.get(1), parts.get(0));
}
}
this.dictionary = ImmutableMap.copyOf(map);
}
示例5: doExtensiveTest
import com.google.common.base.Splitter; //導入方法依賴的package包/類
private void doExtensiveTest(String resourceName) throws IOException {
Splitter splitter = Splitter.on(CharMatcher.whitespace());
URL url = getClass().getResource(resourceName);
for (String line : Resources.readLines(url, UTF_8)) {
Iterator<String> iterator = splitter.split(line).iterator();
String input = iterator.next();
String expectedOutput = iterator.next();
assertFalse(iterator.hasNext());
assertEquals(expectedOutput, simplifyPath(input));
}
}
示例6: 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;
}
示例7: 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;
}
示例8: format
import com.google.common.base.Splitter; //導入方法依賴的package包/類
private String format(String pattern, String value) {
Splitter splitter = Splitter.on("%1$s");
Joiner joiner = Joiner.on(value);
return joiner.join(splitter.split(pattern));
}
示例9: generateSplitter
import com.google.common.base.Splitter; //導入方法依賴的package包/類
@Generates private Splitter generateSplitter() {
return Splitter.on(generateString());
}