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:me.lucko.luckperms.sponge.service.references.SubjectReference.java
public static SubjectReference deserialize(String s) { List<String> parts = Splitter.on('/').limit(2).splitToList(s); return of(parts.get(0), parts.get(1)); }
From source file:com.netflix.metacat.common.partition.util.PartitionUtil.java
/** * Sets the partition key values from the given path. * @param location location path/*from w w w .j a v a 2 s .c o m*/ * @param parts parts */ public static void getPartitionKeyValues(final String location, final Map<String, String> parts) { for (String part : Splitter.on('/').omitEmptyStrings().split(location)) { if (part.contains("=")) { final String[] values = part.split("=", 2); if (values[0].equalsIgnoreCase("null") || values[1].equalsIgnoreCase("null")) { log.debug("Found 'null' string in kvp [{}] skipping.", part); } else { parts.put(values[0], values[1]); } } } }
From source file:com.groupon.mesos.util.UPID.java
public static UPID create(final String master) { checkNotNull(master, "master is null"); final List<String> parts = ImmutableList .copyOf(Splitter.on(CharMatcher.anyOf(":@")).limit(3).split(master)); checkState(parts.size() == 3, "%s is not a valid master definition", master); Integer ip = null;/*from ww w . ja va 2 s . co m*/ try { ip = resolveIp(parts.get(1)); } catch (final IOException e) { LOG.warn("Could not resolve %s: %s", parts.get(1), e.getMessage()); } return new UPID(parts.get(0), HostAndPort.fromParts(parts.get(1), Integer.parseInt(parts.get(2))), ip); }
From source file:org.apache.james.mdn.fields.Text.java
private static String replaceLineBreaksByContinuation(String rawText) { return Joiner.on("\r\n ").join(Splitter.on("\n").trimResults().splitToList(rawText)); }
From source file:com.lithium.flow.util.JsonUtils.java
public static void update(@Nonnull JSONObject json, @Nonnull String path, @Nullable String value) { checkNotNull(json);//www . j av a2 s . c om checkNotNull(path); JSONObject current = json; String prefix = ""; int len = 1; for (String part : Splitter.on('.').split(path)) { if (part.equals("$")) { continue; } len += part.length() + 1; Object object = null; int index = -1; if (part.endsWith("]")) { int index1 = part.indexOf('['); int index2 = part.indexOf(']'); try { index = Integer.parseInt(part.substring(index1 + 1, index2)); String tryPart = part.substring(0, index1); Object array = current.get(tryPart); if (array == null) { tryPart = prefix + tryPart; array = current.get(tryPart); } if (array instanceof JSONArray) { object = ((JSONArray) array).get(index); part = tryPart; prefix = ""; } else { index = -1; } } catch (NumberFormatException e) { index = -1; } } if (prefix.length() == 0) { if (object == null) { String tryPart = part + path.substring(len); if (path.endsWith("." + tryPart)) { object = current.get(tryPart); if (object != null) { part = tryPart; } } } if (object == null) { object = current.get(part); } } if (object instanceof JSONObject) { current = (JSONObject) object; } else if (object != null) { if (index > -1) { JSONArray array = (JSONArray) current.get(part); Class<?> valueType = array.get(index).getClass(); if (value != null && (valueType == Integer.class || valueType == Long.class)) { array.set(index, Long.valueOf(value)); } else { array.set(index, value); } } else { Class<?> valueType = current.get(part).getClass(); if (value != null && (valueType == Integer.class || valueType == Long.class)) { current.put(part, Long.valueOf(value)); } else if (value != null) { current.put(part, value); } else { current.remove(part); } } return; } else { prefix += part + "."; } } throw new RuntimeException("failed to update: " + path); }
From source file:com.google.testing.security.firingrange.utils.Templates.java
/** * Extract a template given an HTTP request. The last path component is the template. * @throws IOException if it cannot find the template. *///from ww w . j ava 2 s .c o m public static String getTemplate(HttpServletRequest request, Class<? extends HttpServlet> clazz) throws IOException { String firstPathPart = Splitter.on('/').splitToList(request.getPathInfo()).get(1); String templateName = firstPathPart + ".tmpl"; return getTemplate(templateName, clazz); }
From source file:org.gradle.launcher.daemon.testing.DaemonContextParser.java
public static DaemonContext parseFrom(String source) { Pattern pattern = Pattern.compile( "^.*DefaultDaemonContext\\[uid=([^\\n]+),javaHome=([^\\n]+),daemonRegistryDir=([^\\n]+),pid=([^\\n]+),idleTimeout=(.+?),daemonOpts=([^\\n]+)].*", Pattern.MULTILINE + Pattern.DOTALL); Matcher matcher = pattern.matcher(source); if (matcher.matches()) { String uid = matcher.group(1); String javaHome = matcher.group(2); String daemonRegistryDir = matcher.group(3); String pidStr = matcher.group(4); Long pid = pidStr.equals("null") ? null : Long.parseLong(pidStr); Integer idleTimeout = Integer.decode(matcher.group(5)); List<String> jvmOpts = Lists.newArrayList(Splitter.on(',').split(matcher.group(6))); return new DefaultDaemonContext(uid, new File(javaHome), new File(daemonRegistryDir), pid, idleTimeout, jvmOpts);/* ww w . ja v a 2 s.c om*/ } else { throw new IllegalStateException("unable to parse DefaultDaemonContext from source: [" + source + "]."); } }
From source file:org.datacleaner.components.machinelearning.impl.VectorNGramFeatureModifier.java
public static Iterable<String> split(Object value) { final String str; if (value == null) { str = ""; } else {/*from www .jav a 2 s . c om*/ str = value.toString().toLowerCase().chars().map(c -> { if (Character.isLetter(c)) { return c; } // replace punctuation and such, leaving only letters and whitespace return ' '; }).collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append).toString(); } return Splitter.on(CharMatcher.whitespace()).omitEmptyStrings().split(str); }
From source file:com.spotify.google.cloud.pubsub.client.integration.Util.java
static String defaultProject() { if (defaultProject != null) { return defaultProject; }//from w w w. j av a 2s .c o m // Try reading $HOME/.config/gcloud/properties final List<String> lines; try { lines = Files.readAllLines(PROPERTIES_PATH.toPath()); } catch (IOException e) { throw new RuntimeException("failed to get default project"); } defaultProject = lines.stream().filter(line -> line.contains("project")).findFirst() .map(line -> Splitter.on(WHITESPACE).splitToList(line)) .map(tokens -> tokens.size() > 2 ? tokens.get(2) : "").orElse(""); if (defaultProject == null) { throw new RuntimeException("failed to get default project"); } return defaultProject; }
From source file:nl.socrates.dom.utils.StringUtils.java
public static String enumDeTitle(final String string) { if (string == null) { return null; }//from w ww.j ava 2 s . com return Joiner.on("_").join(Iterables.transform(Splitter.on(" ").split(string), UPPER_CASE)); }