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.mcmiddleearth.plotbuild.utils.ListUtil.java
public static List<String> messagesFromString(String string) { ArrayList<String> messages = new ArrayList<>(); if (string.length() > 0) { for (String message : Splitter.on(';').split(string)) { messages.add(message);/*from w w w . jav a 2s .c om*/ } } return messages; }
From source file:com.smoketurner.notification.application.core.LongSetParam.java
@Override protected Set<Long> parse(final String input) throws Exception { if (Strings.isNullOrEmpty(input)) { return Collections.emptySet(); }/*from w ww . j a v a2 s . co m*/ final Iterable<String> splitter = Splitter.on(',').omitEmptyStrings().trimResults().split(input); final ImmutableSet.Builder<Long> builder = ImmutableSet.builder(); for (String value : splitter) { try { builder.add(Long.parseLong(value)); } catch (NumberFormatException ignore) { // ignore invalid numbers } } return builder.build(); }
From source file:org.apache.isis.core.commons.configbuilder.PrimerForEnvironmentVariableISIS_OPT.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 = Splitter.on("=").splitToList(keyAndValue); if (parts.size() == 2) { map.put(parts.get(0), parts.get(1)); }// w w w. j a v a 2 s .c om } } return map; }
From source file:org.apache.crunch.impl.mr.run.CrunchInputs.java
public static Map<InputBundle, Map<Integer, List<Path>>> getFormatNodeMap(JobContext job) { Map<InputBundle, Map<Integer, List<Path>>> formatNodeMap = Maps.newHashMap(); Configuration conf = job.getConfiguration(); for (String input : Splitter.on(RECORD_SEP).split(conf.get(RuntimeParameters.MULTI_INPUTS))) { List<String> fields = Lists.newArrayList(SPLITTER.split(input)); InputBundle inputBundle = InputBundle.fromSerialized(fields.get(0)); if (!formatNodeMap.containsKey(inputBundle)) { formatNodeMap.put(inputBundle, Maps.<Integer, List<Path>>newHashMap()); }//from w w w. j a v a 2s . c om Integer nodeIndex = Integer.valueOf(fields.get(1)); if (!formatNodeMap.get(inputBundle).containsKey(nodeIndex)) { formatNodeMap.get(inputBundle).put(nodeIndex, Lists.<Path>newLinkedList()); } formatNodeMap.get(inputBundle).get(nodeIndex).add(new Path(fields.get(2))); } return formatNodeMap; }
From source file:org.anarres.dblx.core.model.ModelLoader.java
@Nonnull public Model load() throws IOException { Model model = new Model(modelName); Splitter splitter = Splitter.on(CharMatcher.BREAKING_WHITESPACE); NODES: {/* w w w. j a v a 2 s . c om*/ URL url = Resources.getResource("models/" + modelName + "/nodes.csv"); CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8); try (Reader in = source.openBufferedStream()) { CSVReader reader = newSVReader(in, '\t', 1); for (String[] line : reader) { String name = line[0]; long x = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[1])); long y = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[2])); long z = (long) LengthUnit.INCH.toMillimetres(Double.parseDouble(line[3])); List<String> tags = splitter.splitToList(line[4]); model.addNode(new Node(name, x, y, z, tags)); } } } BARS: { URL url = Resources.getResource("models/" + modelName + "/bars.csv"); CharSource source = Resources.asCharSource(url, StandardCharsets.UTF_8); try (Reader in = source.openBufferedStream()) { CSVReader reader = newSVReader(in, '\t', 1); for (String[] line : reader) { List<String> tags = splitter.splitToList(line[2]); Bar bar = new Bar(line[0], line[1], tags); model.addEdge(bar); } } } return model; }
From source file:com.facebook.buck.swift.SwiftBuckConfig.java
public Optional<Iterable<String>> getFlags() { Optional<String> value = delegate.getValue(SECTION_NAME, COMPILER_FLAGS_NAME); return value.map(input -> Splitter.on(" ").split(input.trim())); }
From source file:org.apache.james.transport.mailets.remoteDelivery.Delay.java
/** * <p> The optional attempt is the number of tries this delay should be used (default = 1). * The delayTime is parsed by {@link TimeConverter}</p> * * @param initString the string to initialize this Delay object from. It has the form "[attempt\*]delaytime[unit]" *//*from w w w . j a va 2 s. c om*/ public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, TimeConverter.getMilliSeconds(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, TimeConverter.getMilliSeconds(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); }
From source file:org.apache.james.transport.mailets.remote.delivery.Delay.java
/** * <p> The optional attempt is the number of tries this delay should be used (default = 1). * The delayTime is parsed by {@link TimeConverter}</p> * * @param initString the string to initialize this Delay object from. It has the form "[attempt\*]delaytime[unit]" *//*from w w w.j av a 2 s . c o m*/ public static Delay from(String initString) throws MessagingException { if (Strings.isNullOrEmpty(initString)) { throw new NumberFormatException("Null or Empty strings are not permitted"); } List<String> parts = Splitter.on('*').trimResults().splitToList(initString); if (parts.size() == 1) { return new Delay(DEFAULT_ATTEMPTS, TimeConverter.getMilliSeconds(parts.get(0))); } if (parts.size() == 2) { int attempts = Integer.parseInt(parts.get(0)); if (attempts < 0) { throw new MessagingException("Number of attempts negative in " + initString); } return new Delay(attempts, TimeConverter.getMilliSeconds(parts.get(1))); } throw new MessagingException(initString + " contains too much parts"); }
From source file:org.apache.james.transport.mailets.MappingArgument.java
private static Pair<String, String> parseKeyValue(String keyValue) { List<String> pair = Splitter.on(';').trimResults().splitToList(keyValue); if (pair.size() != 2) { throw new IllegalArgumentException(CONFIGURATION_ERROR_MESSAGE); }/*from w ww . j a va 2 s .c o m*/ return Pair.of(pair.get(0), pair.get(1)); }
From source file:org.attribyte.metrics.MetricField.java
/** * Creates set of fields from a comma-separated string. * @param str The string.// ww w . jav a2 s . c o m * @return The set of fields. */ public static final EnumSet<MetricField> setFromString(final String str) { return EnumSet.copyOf(Splitter.on(',').omitEmptyStrings().trimResults().splitToList(str).stream() .map(MetricField::fromString).collect(Collectors.toSet())); }