Example usage for com.google.common.base Splitter on

List of usage examples for com.google.common.base Splitter on

Introduction

In this page you can find the example usage for com.google.common.base Splitter on.

Prototype

@CheckReturnValue
@GwtIncompatible("java.util.regex")
public static Splitter on(final Pattern separatorPattern) 

Source Link

Document

Returns a splitter that considers any subsequence matching pattern to be a separator.

Usage

From source file:com.google.devtools.build.android.resources.IntArrayFieldInitializer.java

public static FieldInitializer of(String name, String value) {
    Preconditions.checkArgument(value.startsWith("{ "), "Expected list starting with { ");
    Preconditions.checkArgument(value.endsWith(" }"), "Expected list ending with } ");
    // Check for an empty list, which is "{ }".
    if (value.length() < 4) {
        return new IntArrayFieldInitializer(name, ImmutableList.<Integer>of());
    }/*from   www.  j  a v  a2  s .c o m*/
    ImmutableList.Builder<Integer> intValues = ImmutableList.builder();
    String trimmedValue = value.substring(2, value.length() - 2);
    Iterable<String> valueStrings = Splitter.on(',').trimResults().split(trimmedValue);
    for (String valueString : valueStrings) {
        intValues.add(Integer.decode(valueString));
    }
    return new IntArrayFieldInitializer(name, intValues.build());
}

From source file:com.google.code.jgntp.internal.message.read.GntpMessageResponseParser.java

public GntpMessageResponseParser() {
    separatorSplitter = Splitter.on(GntpMessage.SEPARATOR).omitEmptyStrings();
    statusLineSplitter = Splitter.on(' ').omitEmptyStrings().trimResults();
}

From source file:org.trimou.engine.interpolation.DotKeySplitter.java

public DotKeySplitter() {
    splitter = Splitter.on(Strings.DOT).omitEmptyStrings();
}

From source file:org.apache.aurora.common.args.parsers.RangeParser.java

@Override
public Range<Integer> doParse(String raw) throws IllegalArgumentException {
    ImmutableList<String> numbers = ImmutableList.copyOf(Splitter.on('-').omitEmptyStrings().split(raw));
    try {/*ww  w. ja v  a2s. c om*/
        int from = Integer.parseInt(numbers.get(0));
        int to = Integer.parseInt(numbers.get(1));
        if (numbers.size() != 2) {
            throw new IllegalArgumentException("Failed to parse the range:" + raw);
        }
        if (to < from) {
            return Range.closed(to, from);
        } else {
            return Range.closed(from, to);
        }
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Failed to parse the range:" + raw, e);
    }
}

From source file:org.jboss.hal.core.finder.FinderPath.java

public static FinderPath from(String path) {
    List<FinderSegment> segments = new ArrayList<>();

    if (nullToEmpty(path).trim().length() != 0) {
        Map<String, String> parts = Splitter.on(FinderPath.SEPARATOR)
                .withKeyValueSeparator(FinderSegment.SEPARATOR).split(path);
        for (Map.Entry<String, String> entry : parts.entrySet()) {
            segments.add(new FinderSegment(entry.getKey(), entry.getValue()));
        }/*from w  w w .  j  a  v a 2  s  .c  o  m*/
    }

    return new FinderPath(segments);
}

From source file:org.incode.module.commchannel.dom.impl.type.CommunicationChannelType.java

private static String enumTitle(final Enum<?> anEnum) {
    if (anEnum == null) {
        return null;
    }// w ww.  j ava2 s . c o  m
    return Joiner.on(" ")
            .join(Iterables.transform(Splitter.on("_").split(anEnum.toString()), LOWER_CASE_THEN_CAPITALIZE));
}

From source file:org.locationtech.geogig.storage.postgresql.config.EnvironmentBuilder.java

private static Map<String, String> extractShortKeys(String rawQuery) {
    Map<String, String> shortKeys = new HashMap<>();
    for (String pair : Splitter.on('&').split(rawQuery)) {
        List<String> p = Splitter.on('=').splitToList(pair);
        // it should be the raw query, URL decode the values
        try {/*from  w  ww.  ja  v a  2s . c om*/
            shortKeys.put(p.get(0), URLDecoder.decode(p.get(1), StandardCharsets.UTF_8.name()));
        } catch (UnsupportedEncodingException uee) {
            throw new RuntimeException(uee);
        }
    }
    return shortKeys;
}

From source file:com.xebialabs.overcast.command.Command.java

public static Command fromString(String s) {
    Command c = new Command();

    for (String o : Splitter.on(" ").split(s)) {
        c.getCommand().add(o);//w  w  w .  j a v  a 2  s  .  co  m
    }

    return c;
}

From source file:net.freifunk.autodeploy.firmware.Firmware.java

public static Device fromString(final String deviceString) {
    final Iterable<String> parts = Splitter.on('-').split(deviceString);
    Preconditions.checkArgument(Iterables.size(parts) == 2);
    final String model = Iterables.get(parts, 0);
    final String version = Iterables.get(parts, 1);
    return new Device(model, version);
}

From source file:org.apache.gobblin.metrics.Tag.java

/**
 * Reverse of Tag.toString(). Parses a string of the form "key:value" into a {@link Tag}.
 *
 * <p>//  ww  w. j  av  a  2s.c  om
 *   If there are multiple ":" in the input string, the key will be the substring up to the first ":", and the
 *   value will be the substring after the first ":".
 * </p>
 *
 * @param tagKeyValue String of the form "key:value".
 * @return {@link org.apache.gobblin.metrics.Tag} parsed from input.
 */
public static Tag<String> fromString(String tagKeyValue) {
    List<String> splitKeyValue = Splitter.on(KEY_VALUE_SEPARATOR).limit(2).omitEmptyStrings()
            .splitToList(tagKeyValue);
    if (splitKeyValue.size() == 2) {
        return new Tag<>(splitKeyValue.get(0), splitKeyValue.get(1));
    } else {
        return null;
    }
}