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:org.locationtech.geogig.repository.LocalRemoteRefSpec.java
static LocalRemoteRefSpec parseSingle(final String remoteName, final String refspec) { List<String> refs = Splitter.on(':').omitEmptyStrings().trimResults().splitToList(refspec); Preconditions.checkArgument(refs.size() > 0 && refs.size() < 3, "Invalid refspec, please use [+]<remoteref>[:<localref>]. Got %s", refspec); String remoteref = refs.get(0); boolean force = remoteref.charAt(0) == '+'; if (force) {/*from w w w. j a v a 2 s .c o m*/ remoteref = remoteref.substring(1); } String localref = refs.size() == 1 ? "" : refs.get(1); Preconditions.checkState(!Strings.isNullOrEmpty(remoteref)); boolean isAllChildren = remoteref.endsWith("/*"); if (isAllChildren) { remoteref = remoteref.substring(0, remoteref.length() - 2); if (localref.isEmpty()) { localref = String.format("refs/remotes/%s", remoteName); } else { Preconditions.checkArgument(localref.endsWith("/*"), "If remote ref is a catch-all (ends in /*), local ref should also be"); localref = localref.substring(0, localref.length() - 2); } } else { Preconditions.checkArgument(!localref.endsWith("/*"), "If remote ref is not a catch-all (does not ends in /*), local ref should not be"); if (-1 == remoteref.indexOf('/') && !Ref.HEAD.equals(remoteref)) { remoteref = Ref.append(Ref.HEADS_PREFIX, remoteref); } String remoteRefSimpleName = Ref.stripCommonPrefix(remoteref); if (localref.isEmpty()) { localref = remoteRefSimpleName; } if (localref.indexOf('/') == -1) { localref = String.format("refs/remotes/%s/%s", remoteName, localref); } } return new LocalRemoteRefSpec(remoteref, localref, force, isAllChildren); }
From source file:ch.ethz.system.mt.tpch.DistributionLoader.java
private static Distribution loadDistribution(Iterator<String> lines, String name) { int count = -1; ImmutableMap.Builder<String, Integer> members = ImmutableMap.builder(); while (lines.hasNext()) { // advance to "begin" String line = lines.next(); if (isEnd(name, line)) { Map<String, Integer> weights = members.build(); checkState(count == weights.size(), "Expected %d entries in distribution %s, but only %d entries were found", count, weights.size());//ww w . ja va 2 s .c om return new Distribution(name, weights); } List<String> parts = ImmutableList .copyOf(Splitter.on('|').trimResults().omitEmptyStrings().split(line)); checkState(parts.size() == 2, "Expected line to contain two parts, but it contains %d parts: %s", parts.size(), line); String value = parts.get(0); int weight; try { weight = Integer.parseInt(parts.get(1)); } catch (NumberFormatException e) { throw new IllegalStateException( String.format("Invalid distribution %s: invalid weight on line %s", name, line)); } if (value.equalsIgnoreCase("count")) { count = weight; } else { members.put(value, weight); } } throw new IllegalStateException(String.format("Invalid distribution %s: no end statement", name)); }
From source file:springfox.documentation.swagger.schema.ApiModelProperties.java
public static AllowableValues allowableValueFromString(String allowableValueString) { AllowableValues allowableValues = new AllowableListValues(Lists.<String>newArrayList(), "LIST"); String trimmed = allowableValueString.trim(); if (trimmed.startsWith("range[")) { trimmed = trimmed.replaceAll("range\\[", "").replaceAll("]", ""); Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(trimmed); List<String> ranges = newArrayList(split); allowableValues = new AllowableRangeValues(ranges.get(0), ranges.get(1)); } else if (trimmed.contains(",")) { Iterable<String> split = Splitter.on(',').trimResults().omitEmptyStrings().split(trimmed); allowableValues = new AllowableListValues(newArrayList(split), "LIST"); } else if (hasText(trimmed)) { List<String> singleVal = Collections.singletonList(trimmed); allowableValues = new AllowableListValues(singleVal, "LIST"); }/* w w w . j av a2s .c o m*/ return allowableValues; }
From source file:org.graylog2.configuration.converters.URIListConverter.java
@Override public List<URI> convertFrom(String value) { if (value == null) { throw new ParameterException("URI List must not be null."); }/*www. java 2 s .c o m*/ final Iterable<String> splittedUris = Splitter.on(SEPARATOR).omitEmptyStrings().trimResults().split(value); return StreamSupport.stream(splittedUris.spliterator(), false).map(this::constructURIFromString) .collect(Collectors.toList()); }
From source file:yrun.YarnRunnerUtil.java
private static Path buildJar(URL url, String resourceName) throws IOException { String classPath = System.getProperty(JAVA_CLASS_PATH); String pathSeparator = System.getProperty(PATH_SEPARATOR); Splitter splitter = Splitter.on(pathSeparator); for (String path : splitter.split(classPath)) { File file = new File(new File(path), resourceName); if (file.exists()) { return buildJarFromClassFile(file, resourceName); }/*from w w w .ja v a 2 s . c om*/ } throw new IOException("Resource [" + resourceName + "] not found in classpath."); }
From source file:com.facebook.buck.versions.VersionBuckConfig.java
private VersionUniverse getVersionUniverse(String name) { VersionUniverse.Builder universe = VersionUniverse.builder(); ImmutableList<String> vals = delegate.getListWithoutComments(UNIVERSES_SECTION, name); for (String val : vals) { List<String> parts = Splitter.on('=').limit(2).trimResults().splitToList(val); if (parts.size() != 2) { throw new HumanReadableException( "`%s:%s`: must specify version selections as a comma-separated list of " + "`//build:target=<version>` pairs: \"%s\"", UNIVERSES_SECTION, name, val); }/*from w ww.j a v a 2 s . co m*/ universe.putVersions(delegate.getBuildTargetForFullyQualifiedTarget(parts.get(0)), Version.of(parts.get(1))); } return universe.build(); }
From source file:org.graylog.plugins.metrics.core.jadconfig.StringMapConverter.java
@Override public Map<String, String> convertFrom(String value) { if (value == null) { throw new ParameterException("Couldn't convert value \"null\" to a map of strings."); }// w ww . j av a 2 s . c om try { return Splitter.on(SEPARATOR).omitEmptyStrings().trimResults() .withKeyValueSeparator(KEY_VALUE_SEPARATOR).split(value); } catch (Exception e) { throw new ParameterException(e.getMessage(), e); } }
From source file:io.mapzone.controller.ui.project.KeywordsValidator.java
@Override public Collection<String> transform2Model(String fieldValue) throws Exception { return fieldValue != null ? Splitter.on(',').omitEmptyStrings().trimResults().splitToList(fieldValue) : null;//from w ww. j a v a 2s . c o m }
From source file:com.googlecode.blaisemath.util.xml.PointAdapter.java
@Override public Point unmarshal(String v) { if (v == null) { return null; }//from ww w.j ava2 s. co m Matcher m = Pattern.compile("point\\[(.*)\\]").matcher(v.toLowerCase().trim()); if (m.find()) { String inner = m.group(1); Iterable<String> kv = Splitter.on(",").trimResults().split(inner); try { int x = Integer.valueOf(Iterables.get(kv, 0)); int y = Integer.valueOf(Iterables.get(kv, 1)); return new Point(x, y); } catch (NumberFormatException x) { Logger.getLogger(PointAdapter.class.getName()).log(Level.FINEST, "Not an integer", x); return null; } } else { Logger.getLogger(PointAdapter.class.getName()).log(Level.FINEST, "Not a valid point", v); return null; } }
From source file:org.apache.isis.core.commons.configbuilder.PrimerForEnvironmentVariableISIS_OPTS.java
private static Map<String, String> fromEnv(final String env, final String separator) { final LinkedHashMap<String, String> map = Maps.newLinkedHashMap(); if (env != null) { final List<String> keyAndValues = Splitter.on(separator).splitToList(env); for (String keyAndValue : keyAndValues) { final List<String> parts = Lists.newArrayList(Splitter.on("=").splitToList(keyAndValue)); if (parts.size() >= 2) { String key = parts.get(0); parts.remove(0);/* w w w. jav a 2 s . co m*/ final String value = Joiner.on("=").join(parts); map.put(key, value); } } } return map; }