本文整理汇总了Java中com.google.common.base.Splitter类的典型用法代码示例。如果您正苦于以下问题:Java Splitter类的具体用法?Java Splitter怎么用?Java Splitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Splitter类属于com.google.common.base包,在下文中一共展示了Splitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildMongoClientFactoryBean
import com.google.common.base.Splitter; //导入依赖的package包/类
/**
* 生成mongoClientFacotryBean
*
* @param mythMongoConfig 配置信息
* @return bean
*/
private MongoClientFactoryBean buildMongoClientFactoryBean(MythMongoConfig mythMongoConfig) {
MongoClientFactoryBean clientFactoryBean = new MongoClientFactoryBean();
MongoCredential credential = MongoCredential.createScramSha1Credential(mythMongoConfig.getMongoUserName(),
mythMongoConfig.getMongoDbName(),
mythMongoConfig.getMongoUserPwd().toCharArray());
clientFactoryBean.setCredentials(new MongoCredential[]{
credential
});
List<String> urls = Splitter.on(",").trimResults().splitToList(mythMongoConfig.getMongoDbUrl());
final ServerAddress[] sds = urls.stream().map(url -> {
List<String> adds = Splitter.on(":").trimResults().splitToList(url);
InetSocketAddress address = new InetSocketAddress(adds.get(0), Integer.parseInt(adds.get(1)));
return new ServerAddress(address);
}).collect(Collectors.toList()).toArray(new ServerAddress[]{});
clientFactoryBean.setReplicaSetSeeds(sds);
return clientFactoryBean;
}
示例2: getTopic
import com.google.common.base.Splitter; //导入依赖的package包/类
@Override
public String getTopic(String uuid)
{
HierarchyTopic ht = null;
boolean isDynamicTopic = false;
for( String uuidValue : Splitter.on(',').omitEmptyStrings().split(uuid) )
{
final String[] uv = uuidValue.split(":", 2);
ht = hierarchyService.getHierarchyTopicByUuid(uv[0]);
if( uv.length > 1 )
{
isDynamicTopic = true;
}
}
PropBagEx xml = new PropBagEx();
buildXmlFromTopic(xml, ht, isDynamicTopic, uuid);
return xml.getSubtree("topic").toString();
}
示例3: unpackQueryString
import com.google.common.base.Splitter; //导入依赖的package包/类
/**
* Unpack the querystring from the given url
* Returns an empty map if there is no querystring
*
* @param url The url to parse
* @param isPureQueryString Supply true if the url is just the query string or false for complete urls
* @return A Map containing the key-value pairs
*/
public static Map<String, String> unpackQueryString(String url, boolean isPureQueryString) {
if (url != null) {
String query = null;
if (isPureQueryString) {
query = url;
} else {
int qidIndex = url.indexOf(QUERY_IDENTIFIER);
if (qidIndex > -1) {
query = url.substring(qidIndex + 1);
}
}
if (query != null) {
return Splitter
.on(QUERY_PAIR_SEPARATOR)
.trimResults()
.withKeyValueSeparator(QUERY_KEY_VALUE_SEPARATOR)
.split(query);
}
}
return new HashMap<>();
}
示例4: decode
import com.google.common.base.Splitter; //导入依赖的package包/类
@Nullable
public static GraphiteMetric decode(@Nullable final String metric) {
if (metric == null || metric.isEmpty()) {
return null;
}
final List<String> parts = Splitter.on(CharMatcher.BREAKING_WHITESPACE)
.trimResults().omitEmptyStrings().splitToList(metric);
if (parts.isEmpty() || parts.size() != 3) {
return null;
}
final double value = Double.parseDouble(parts.get(1));
final long timestamp = Long.parseUnsignedLong(parts.get(2));
return new GraphiteMetric(parts.get(0), value, timestamp);
}
示例5: getPath
import com.google.common.base.Splitter; //导入依赖的package包/类
@Override
public String getPath(Charset charset) {
StringBuilder path = new StringBuilder();
boolean slash = false;
for (String segment : getSegments()) {
if (slash) {
path.append('/');
}
if (segment.indexOf('/') != -1) {
Url url = new Url(Splitter.on('/').splitToList(segment), Charsets.UTF_8);
path.append(url.getPath());
} else {
path.append(UrlEncoder.PATH_INSTANCE.encode(segment, charset));
}
slash = true;
}
return path.toString();
}
示例6: handleRequest
import com.google.common.base.Splitter; //导入依赖的package包/类
public void handleRequest(LogRequest logRequest, LogParams logParams) {
List<String> entries = Lists.newArrayList();
entries.add(logRequest.uri);
if (logRequest.clientApplication != null) {
entries.add("Client: " + logRequest.clientApplication);
}
if (logRequest.user != null) {
entries.add("User: " + logRequest.user);
}
if (logParams.logHeaders && logRequest.headers != null) {
entries.add("Headers: " + getHeaders(logRequest.headers, logParams)
);
}
if (logParams.logResponseEntity && ! Strings.isNullOrEmpty(logRequest.entity)) {
List<String> lines = Splitter.on('\n').splitToList(logRequest.entity)
.stream()
.map(String::trim)
.collect(Collectors.toList());
String compactedEntity = Joiner.on(' ').join(lines);
entries.add("Entity: " + compactedEntity);
}
String logString = Joiner.on(", ").join(entries);
LogUtil.doLog(logString, logParams.logLevel, log);
}
示例7: onLogin
import com.google.common.base.Splitter; //导入依赖的package包/类
@Override
public CompletableFuture<Long> onLogin(ChannelHandlerContext ctx, SocketASK ask) {
// 整个消息就是 token
ByteString tokenArg = ask.getBody().getArgs(0);
if (tokenArg == null) {
logger.info("Token arg must be input.");
return null;
}
String token = tokenArg.toStringUtf8();
if (Strings.isNullOrEmpty(token)) {
logger.info("Token arg must be input.");
return null;
}
return CompletableFuture.supplyAsync(() -> {
String parseToken = new String(BaseEncoding.base64Url().decode(token));
List<String> tokenChars = Splitter.on('|').splitToList(parseToken);
Long userId = Long.valueOf(tokenArg.toStringUtf8());
RoomGroup.getRoomManger().onOnline(ctx, userId);
return userId;
});
}
示例8: create
import com.google.common.base.Splitter; //导入依赖的package包/类
/**
* 1.0.0 -> 1 00 00
* 2.3.4 -> 2 03 04
* 2.3.40 -> 2 03 40
* 2.4.40 -> 2 04 40
* 20.3.40 -> 20 03 40
*
* @param version
* @return
*/
public static int create(String version) {
List<String> items = Splitter.on('.').splitToList(version);
if (items.size() > 3 || items.size() < 1) {
throw new RuntimeException("仅支持99.99.99为最大版本号");
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < items.size(); i++) {
if (items.get(i).length() > 2) {
throw new RuntimeException("仅支持99.99.99为最大版本号");
}
if (i > 0 && items.get(i).length() == 1) {
buffer.append('0');
}
buffer.append(items.get(i));
}
return Integer.valueOf(buffer.toString());
}
示例9: 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()));
}
示例10: print
import com.google.common.base.Splitter; //导入依赖的package包/类
public static void print(Object toJson) {
if (!ENABLED) return;
synchronized (sGson) {
String json = sGson.toJson(toJson);
Iterable<String> lines = Splitter.on(CharMatcher.anyOf("\r\n")).omitEmptyStrings().split(json);
int count = 0;
Log.v(TAG, "┏");
for (String line : lines) {
Log.v(TAG, "┃ " + line);
/**
* delay the log output to avoid exceeding kernel log buffer size
*/
if (count++ % 64 == 0) {
try {
Thread.sleep(1);
} catch (InterruptedException ignored) {
}
}
}
Log.v(TAG, "┗");
}
}
示例11: deseralise
import com.google.common.base.Splitter; //导入依赖的package包/类
public void deseralise(String sceneData) {
String[] data = sceneData.split(deliminator); //careful for regex
SceneName = data[0];
PosX = Integer.parseInt(data[1]);
PosY = Integer.parseInt(data[2]);
NumOfTimesPlayerHasBeenHere = Integer.parseInt(data[3]);
currentBackground= data[4];
DynamicOverlayCSS= data[5];
StaticOverlayCSS = data[6];
hasNotBeenCurrentYet=Boolean.parseBoolean(data[7]);
//add dependantSceneNames!
String sequence = data[8];
if (sequence!=null && !sequence.isEmpty()){
dependantSceneNames = Sets.newHashSet(Splitter.on(',').trimResults().split(sequence)); //convert coma seperated strings to a hashset. Thanks guava!
}
}
示例12: read
import com.google.common.base.Splitter; //导入依赖的package包/类
public void read(String path, String prefix) {
LogInfo.begin_track("Reading parameters from %s", path);
try {
BufferedReader in = IOUtils.openIn(path);
String line;
while ((line = in.readLine()) != null) {
String[] pair = Lists.newArrayList(Splitter.on('\t').split(line)).toArray(new String[2]);
weights.put(pair[0], Double.parseDouble(pair[1]));
weights.put(prefix + pair[0], Double.parseDouble(pair[1]));
}
in.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
LogInfo.logs("Read %s weights", weights.size());
LogInfo.end_track();
}
示例13: getGroupSearchFilter
import com.google.common.base.Splitter; //导入依赖的package包/类
public Filter getGroupSearchFilter(String query)
{
SingleFilter groupClass = new SingleFilter(OBJECTCLASS, groupObject);
groupClass.setLimit(config.getSearchLimit());
query = checkQuery(query);
if( isSearchAllQuery(query) )
{
return groupClass;
}
AndFilter and = new AndFilter(groupClass);
for( String token : Splitter.onPattern("\\s").omitEmptyStrings().trimResults(CharMatcher.is('*')).split(query) )
{
token = (config.isWildcards() ? "*" : "") + token + '*';
OrFilter or = new OrFilter();
or.addFilter(new SingleFilter(groupNameField, token, false));
or.addFilter(new SingleFilter(groupIdField, token, false));
and.addFilter(or);
}
return and;
}
示例14: process
import com.google.common.base.Splitter; //导入依赖的package包/类
private PropertyTree process(PropertyTree meta, SiteConfig siteConfig, ImmutableList<Category> categories) {
Builder builder = FixedPropertyTree.builder()
.copyOf(meta);
for (PostProcessing.Category cat : categories) {
Optional<Tree> tree = siteConfig.tree(cat.tree());
tree.ifPresent(t -> {
ImmutableList<String> sourceVal = meta.findList(String.class, Splitter.on(".").split(cat.source()));
ImmutableSet<String> allParents = t.allParentsOf(sourceVal);
ImmutableSet<String> allCategories = Sets.union(allParents, Sets.newHashSet(sourceVal)).immutableCopy();
allCategories.forEach(c -> {
builder.put(cat.name(), c);
});
});
}
return builder.build();
}
示例15: parseEnchantments
import com.google.common.base.Splitter; //导入依赖的package包/类
public Map<Enchantment, Integer> parseEnchantments(Element el, String name) throws InvalidXMLException {
Map<Enchantment, Integer> enchantments = Maps.newHashMap();
Node attr = Node.fromAttr(el, name, StringUtils.pluralize(name));
if(attr != null) {
Iterable<String> enchantmentTexts = Splitter.on(";").split(attr.getValue());
for(String enchantmentText : enchantmentTexts) {
int level = 1;
List<String> parts = Lists.newArrayList(Splitter.on(":").limit(2).split(enchantmentText));
Enchantment enchant = XMLUtils.parseEnchantment(attr, parts.get(0));
if(parts.size() > 1) {
level = XMLUtils.parseNumber(attr, parts.get(1), Integer.class);
}
enchantments.put(enchant, level);
}
}
for(Element elEnchantment : el.getChildren(name)) {
Pair<Enchantment, Integer> entry = parseEnchantment(elEnchantment);
enchantments.put(entry.first, entry.second);
}
return enchantments;
}