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.facebook.buck.core.parser.buildtargetparser.FlavorParser.java
/** * Given a comma-separated string of flavors, returns an iterable containing the separated names * of the flavors inside./*from w w w . j a v a 2s .c om*/ * * <p>Also maps deprecated flavor names to their supported names. */ public Iterable<String> parseFlavorString(String flavorString) { return Iterables.transform(Splitter.on(",").omitEmptyStrings().trimResults().split(flavorString), flavor -> { String mapped = DEPRECATED_FLAVORS.get(flavor); if (mapped != null) { // Show a warning the first time a deprecated flavor is used. if (deprecatedFlavorWarningShown.add(flavor)) { LOG.warn("Flavor %s is deprecated; use %s instead.", flavor, mapped); } return mapped; } else { return flavor; } }); }
From source file:org.graylog.collector.outputs.OutputConfiguration.java
public OutputConfiguration(String id, Config config) { this.id = id; if (config.hasPath("inputs")) { this.inputs = Sets.newHashSet( Splitter.on(",").omitEmptyStrings().trimResults().split(config.getString("inputs"))); }//w w w . j a v a 2 s . c o m }
From source file:co.cask.cdap.security.server.MTLSUserIdentity.java
/** * Extract the Canonical Name from a {@link X500Principal} name * * @param principal//from w w w . ja v a 2s.c o m * @return */ private String getX509PrincipalCN(String principal) { Map<String, String> principalAttributes = Splitter.on(",").withKeyValueSeparator("=") .split(principal.replaceAll("\\s", "")); if (principalAttributes.containsKey(PRINCIPAL_CANONICAL_NAME)) { return principalAttributes.get(PRINCIPAL_CANONICAL_NAME); } else { return null; } }
From source file:com.ebay.pulsar.analytics.datasource.PulsarTable.java
public void setTableNameAlias(String tableNameAlias) { this.tableNameAlias = tableNameAlias; super.tableNames.addAll(Sets.newHashSet(Splitter.on(',').trimResults().split(tableNameAlias))); }
From source file:org.zanata.client.util.FileUtil.java
/** * This is taken from guava Files.//www. ja v a2 s .c o m * Returns the lexically cleaned form of the path name, <i>usually</i> (but * not always) equivalent to the original. The following heuristics are used: * * <ul> * <li>empty string becomes . * <li>. stays as . * <li>fold out ./ * <li>fold out ../ when possible * <li>collapse multiple slashes * <li>delete trailing slashes (unless the path is just "/") * </ul> * * <p>These heuristics do not always match the behavior of the filesystem. In * particular, consider the path {@code a/../b}, which {@code simplifyPath} * will change to {@code b}. If {@code a} is a symlink to {@code x}, {@code * a/../b} may refer to a sibling of {@code x}, rather than the sibling of * {@code a} referred to by {@code b}. */ public static String simplifyPath(String pathname) { checkNotNull(pathname); if (pathname.length() == 0) { return "."; } // split the path apart Iterable<String> components = Splitter.on('/').omitEmptyStrings().split(pathname); List<String> path = new ArrayList<String>(); // resolve ., .., and // for (String component : components) { if (component.equals(".")) { continue; } else if (component.equals("..")) { if (path.size() > 0 && !path.get(path.size() - 1).equals("..")) { path.remove(path.size() - 1); } else { path.add(".."); } } else { path.add(component); } } // put it back together String result = Joiner.on('/').join(path); if (pathname.charAt(0) == '/') { result = "/" + result; } while (result.startsWith("/../")) { result = result.substring(3); } if (result.equals("/..")) { result = "/"; } else if ("".equals(result)) { result = "."; } return result; }
From source file:com.eucalyptus.simpleworkflow.stateful.AbstractTaskPolledNotificationChecker.java
@Override public boolean apply(final String channel) { final Iterable<String> channelName = Splitter.on(':').limit(4).split(channel); if (Iterables.size(channelName) == 4) { final String accountNumber = Iterables.get(channelName, 0); final String type = Iterables.get(channelName, 1); final String domain = Iterables.get(channelName, 2); final String taskList = Iterables.get(channelName, 3); if (this.type.equals(type)) try { return hasTasks(accountNumber, domain, taskList); } catch (final Exception e) { logger.error("Error checking for pending tasks", e); }// www . j av a 2 s . c o m } return false; }
From source file:com.microsoftopentechnologies.adinteractiveauth.BrowserLocationListener.java
@Override public void changing(LocationEvent locationEvent) { super.changing(locationEvent); // if the location matches the redirect uri then extract // the auth code and cancel the navigation and invoke the // callback//from w w w .ja v a 2 s . c o m if (locationEvent.location.startsWith(redirectUri)) { locationEvent.doit = false; URI uri = URI.create(locationEvent.location); Map<String, String> response = Splitter.on('&').trimResults().omitEmptyStrings() .withKeyValueSeparator('=').split(uri.getQuery()); if (response.containsKey("code")) { callback.onAuthCodeReceived(response.get("code")); } else { callback.onFailed(uri.getQuery()); } } }
From source file:com.google.api.codegen.nodejs.NodeJSCodePathMapper.java
private String getOutputPath(String elementFullName, ProductConfig config, String methodSample) { boolean haveSample = !Strings.isNullOrEmpty(methodSample); String apiVersion = ""; List<String> packages = Splitter.on(".").splitToList(elementFullName); for (String p : packages) { if (VersionMatcher.isVersion(p)) { apiVersion = p;//from w w w. j av a 2 s .c o m } } ArrayList<String> dirs = new ArrayList<>(); dirs.add("src"); if (haveSample) { dirs.add(SAMPLES_DIRECTORY); } if (!apiVersion.isEmpty()) { dirs.add(apiVersion); } return Joiner.on("/").join(dirs); }
From source file:org.eclipse.che.api.vfs.impl.file.FileMetadataSerializer.java
@Override public void write(DataOutput output, Map<String, String> props) throws IOException { output.writeInt(props.size());//from ww w .ja va 2 s. c om for (Map.Entry<String, String> entry : props.entrySet()) { String value = entry.getValue(); if (value != null) { final String name = entry.getKey(); output.writeUTF(name); final List<String> asList = Splitter.on(',').splitToList(value); output.writeInt(asList.size()); for (String single : asList) { output.writeUTF(single); } } } }
From source file:com.lithium.flow.config.parsers.SubtractConfigParser.java
@Override public boolean parseLine(@Nonnull String line, @Nonnull ConfigBuilder builder) { checkNotNull(line);//from ww w.j a va2 s.c o m checkNotNull(builder); int index = line.indexOf("-="); if (index > -1 && index < line.indexOf("=")) { String key = line.substring(0, index).trim(); final String value = line.substring(index + 2).trim(); String oldValue = builder.getString(key); if (oldValue != null) { builder.setString(key, Joiner.on(" ") .join(Iterables.filter(Splitter.on(" ").split(oldValue), input -> !value.equals(input)))); return true; } } return false; }