List of usage examples for com.google.common.base Splitter on
@CheckReturnValue @GwtIncompatible("java.util.regex") public static Splitter on(final Pattern separatorPattern)
From source file:com.happy_coding.viralo.twitter.FriendDiscoverer.java
/** * retrieve friends by keywords.// w w w. j av a 2 s. c o m * * @param keywords * @param delimiter * @return */ public List<Contact> findFriends(String keywords, String delimiter) { Iterable<String> it = Splitter.on(delimiter).trimResults().omitEmptyStrings().split(keywords); return findFriends(Lists.newArrayList(it)); }
From source file:com.gafactory.core.client.ui.application.security.CurrentUser.java
private void initUserLoad() { String principal = getPrincipal(); String auths = getAuths();/* w w w . j a v a 2 s. c o m*/ List<String> roles = Lists.newArrayList(Splitter.on(", ").split(auths.substring(1, auths.length() - 1))); setUser(principal, roles, true); }
From source file:org.jboss.hal.client.runtime.subsystem.jaxrs.RestResource.java
private Set<String> resourceMethods(String attribute) { List<ModelNode> nodes = failSafeList(this, attribute); return nodes.stream().map(node -> failSafeList(node, RESOURCE_METHODS)).flatMap(Collection::stream) .map(method -> {/*from ww w. j a v a 2 s. c om*/ List<String> methods = Splitter.on(' ').omitEmptyStrings().trimResults() .splitToList(method.asString()); return methods.isEmpty() ? null : methods.get(0); }).filter(Objects::nonNull).collect(toSet()); }
From source file:com.zxy.commons.lang.utils.StringsUtils.java
/** * {@code separator}?List?//www . ja v a2s. c o m * * @param source * @param separator * @return ? */ public static List<String> toList(String source, String separator) { return Splitter.on(separator).trimResults().splitToList(source); // List<String> result = new ArrayList<String>(); // // if (source != null) { // String[] tmps = source.split(separator); // for (String tmp : tmps) { // if (StringUtils.isNotBlank(tmp)) { // result.add(tmp); // } // } // } // return result; }
From source file:com.b2international.commons.Version.java
/** * Parses the specified {@link String} into a {@link Version} object. * The version string must be non-null and conform to the <code>\d+(\.\d+)+</code> format. * //from w w w .j a va 2s.c o m * @param versionString the version string to parse * @return the parsed {@link Version} */ public static Version parseVersion(String versionString) { checkNotNull(versionString, "Version string must not be null."); checkArgument(VERSION_PATTERN.matcher(versionString).matches(), "Version string format is invalid: " + versionString); List<Integer> versionParts = Lists.transform( ImmutableList.copyOf(Splitter.on(VERSION_PART_SEPARATOR).split(versionString)), new StringToIntegerParserFunction()); return new Version(versionParts); }
From source file:org.atteo.dollarbrace.OneOfPropertyResolver.java
@Override public String resolveProperty(String name, PropertyFilter resolver) throws PropertyNotFoundException { if (!name.startsWith(prefix)) { return null; }/* w ww .j a v a 2 s . c o m*/ name = name.substring(prefix.length()); List<Tokenizer.Token> tokens = Tokenizer.splitIntoTokens(name); StringBuilder result = new StringBuilder(); boolean skip = false; for (Tokenizer.Token token : tokens) { if (token.isProperty()) { if (!skip) { try { result.append(resolver.getProperty(token.getValue())); } catch (PropertyNotFoundException e) { skip = true; } } } else { boolean first = true; for (String p : Splitter.on(',').split(token.getValue())) { if (!first) { if (!skip) { return result.toString(); } else { result = new StringBuilder(); skip = false; } } if (!skip) { result.append(p); } first = false; } } } if (skip) { throw new PropertyNotFoundException(name); } return result.toString(); }
From source file:com.intel.rsa.common.types.locations.Location.java
public Location(String text) { if (text == null) { throw new IllegalArgumentException("text must not be null"); }/*w w w . ja v a 2 s . co m*/ Map<String, String> coords = Splitter.on(COORD_SEPARATOR).withKeyValueSeparator(COORD_VALUE_SEPARATOR) .split(text); this.coords = unmodifiableMap(transformValues(coords, Integer::valueOf)); }
From source file:com.mapr.synth.samplers.StringSampler.java
protected void readDistribution(String resourceName) { try {//from w ww . j a v a2 s . c o m if (distribution.compareAndSet(null, new Multinomial<String>())) { Splitter onTab = Splitter.on("\t").trimResults(); for (String line : Resources.readLines(Resources.getResource(resourceName), Charsets.UTF_8)) { if (!line.startsWith("#")) { Iterator<String> parts = onTab.split(line).iterator(); String name = translate(parts.next()); double weight = Double.parseDouble(parts.next()); distribution.get().add(name, weight); } } } } catch (IOException e) { throw new RuntimeException("Couldn't read built-in resource file", e); } }
From source file:com.android.tools.idea.npw.project.DomainToPackageExpression.java
@NotNull @Override/*from w w w .j av a 2 s.c om*/ public String get() { Iterable<String> splitList = Splitter.on('.').split(myCompanyDomain.get()); final List<String> list = Lists.newArrayList(splitList); Collections.reverse(list); list.add(myApplicationName.get()); return list.stream().map(NewProjectModel::toPackagePart).filter(s -> !s.isEmpty()) .collect(Collectors.joining(".")); }
From source file:io.airlift.http.server.HttpRequestEvent.java
public static HttpRequestEvent createHttpRequestEvent(Request request, Response response, TraceTokenManager traceTokenManager, long currentTimeInMillis) { String user = null;/*from www . j a v a2 s. c o m*/ Principal principal = request.getUserPrincipal(); if (principal != null) { user = principal.getName(); } String token = null; if (traceTokenManager != null) { token = traceTokenManager.getCurrentRequestToken(); } long dispatchTime = request.getTimeStamp(); long timeToDispatch = max(dispatchTime - request.getTimeStamp(), 0); Long timeToFirstByte = null; Object firstByteTime = request.getAttribute(TimingFilter.FIRST_BYTE_TIME); if (firstByteTime instanceof Long) { Long time = (Long) firstByteTime; timeToFirstByte = max(time - request.getTimeStamp(), 0); } long timeToLastByte = max(currentTimeInMillis - request.getTimeStamp(), 0); ImmutableList.Builder<String> builder = ImmutableList.builder(); if (request.getRemoteAddr() != null) { builder.add(request.getRemoteAddr()); } for (Enumeration<String> e = request.getHeaders("X-FORWARDED-FOR"); e != null && e.hasMoreElements();) { String forwardedFor = e.nextElement(); builder.addAll(Splitter.on(',').trimResults().omitEmptyStrings().split(forwardedFor)); } String clientAddress = null; ImmutableList<String> clientAddresses = builder.build(); for (String address : Lists.reverse(clientAddresses)) { try { if (!Inet4Networks.isPrivateNetworkAddress(address)) { clientAddress = address; break; } } catch (IllegalArgumentException ignored) { } } if (clientAddress == null) { clientAddress = request.getRemoteAddr(); } String requestUri = null; if (request.getUri() != null) { requestUri = request.getUri().toString(); } String method = request.getMethod(); if (method != null) { method = method.toUpperCase(); } String protocol = request.getHeader("X-FORWARDED-PROTO"); if (protocol == null) { protocol = request.getScheme(); } if (protocol != null) { protocol = protocol.toLowerCase(); } return new HttpRequestEvent(new DateTime(request.getTimeStamp()), token, clientAddress, protocol, method, requestUri, user, request.getHeader("User-Agent"), request.getHeader("Referer"), request.getContentRead(), request.getHeader("Content-Type"), response.getContentCount(), response.getStatus(), response.getHeader("Content-Type"), timeToDispatch, timeToFirstByte, timeToLastByte); }