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.ebay.pulsar.analytics.cache.MemcachedCacheConfig.java

public void setHosts(String hosts) {
    this.hosts = Splitter.on(",").omitEmptyStrings().splitToList(hosts);
    System.out.println("hosts=" + hosts);
}

From source file:com.shopwiki.vaadin.UrlParams.java

public UrlParams(String queryString) {
    if (queryString == null) {
        return;/*ww  w .  j a  v a  2s.  com*/
    }

    Splitter kvSplitter = Splitter.on('=');

    for (String param : Splitter.on('&').split(queryString)) {
        List<String> kv = Lists.newArrayList(kvSplitter.split(param));
        if (kv.size() >= 2) {
            add(kv.get(0), kv.get(1));
        }
    }
}

From source file:com.wealdtech.jackson.modules.InetSocketAddressDeserializer.java

@Override
protected InetSocketAddress _deserialize(String value, DeserializationContext ctxt) throws IOException {
    // TODO check for malformed values
    Iterator<String> vals = Splitter.on(':').split(value).iterator();
    final String host = vals.next();
    final int port = Integer.parseInt(vals.next());
    return new InetSocketAddress(host, port);
}

From source file:org.jclouds.virtualbox.functions.MacAddressToBSD.java

@Override
public String apply(String macAddress) {
    checkArgument(macAddress.length() == 17);
    return Joiner.on(":")
            .join(Iterables.transform(Splitter.on(":").split(macAddress), new Function<String, String>() {
                @Override/*from   w  w w .  jav a  2 s.c o  m*/
                public String apply(String addressPart) {
                    if (addressPart.equals("00"))
                        return "0";
                    if (addressPart.startsWith("0"))
                        return addressPart.substring(1);

                    return addressPart;
                }
            }));
}

From source file:org.sonar.server.util.RubyUtils.java

@CheckForNull
public static <E extends Enum<E>> List<E> toEnums(@Nullable Object o, Class<E> enumClass) {
    if (o == null) {
        return null;
    }//from w  ww  .  j  a v  a2 s.c o  m
    List<E> result = Lists.newArrayList();
    if (o instanceof List) {
        for (String s : (List<String>) o) {
            result.add(Enum.valueOf(enumClass, s));
        }
    } else if (o instanceof CharSequence) {
        for (String s : Splitter.on(',').omitEmptyStrings().split((CharSequence) o)) {
            result.add(Enum.valueOf(enumClass, s));
        }
    } else {
        throw new IllegalArgumentException("Unsupported type: " + o.getClass());
    }
    return result;
}

From source file:com.tek271.reverseProxy.model.Mapping.java

public Mapping(String mapping) {
    checkArgument(isNotBlank(mapping), "mapping must contain a value");
    mapping = trimToEmpty(mapping);//from   w ww .j  a v  a 2  s  .com
    List<String> items = Lists.newArrayList(Splitter.on(',').trimResults().split(mapping));
    checkArgument(items.size() == 3, "mappings must have 3 comma-separated values");

    hiddenDomain = items.get(0);
    proxyDomain = items.get(1);
    proxyResource = items.get(2);
    proxy = proxyDomain + proxyResource;
}

From source file:com.wrmsr.wava.java.lang.JQualifiedName.java

public static JQualifiedName parse(String str) {
    return new JQualifiedName(
            Splitter.on('.').splitToList(str).stream().map(JName::of).collect(toImmutableList()));
}

From source file:org.apache.whirr.service.TagBuilder.java

public static Iterable<String> rolesFromTag(String tag) {
    return Splitter.on('+').split(tag.substring(tag.lastIndexOf('_') + 1));
}

From source file:org.graylog2.utilities.IPSubnetConverter.java

@Override
public Set<IpSubnet> convertFrom(String value) {
    final Set<IpSubnet> converted = new HashSet<>();
    if (value != null) {
        Iterable<String> subnets = Splitter.on(',').trimResults().split(value);
        for (String subnet : subnets) {
            try {
                converted.add(new IpSubnet(subnet));
            } catch (UnknownHostException e) {
                throw new ParameterException("Invalid subnet: " + subnet);
            }//from  w  ww . j a v  a 2  s .  co m
        }
    }
    return converted;
}

From source file:mn.le.farcek.jbw.bundle.beanForm.convertor.ListConvertor.java

@Override
public Object fromString(FormField field, IActionRequest request) throws ConvertorException, IgnoreException {
    BeanProperty beanProperty = field.getBeanProperty();
    String value = request.getParameter(beanProperty.getName());
    if (value == null) {
        return null;
    }/*www.  ja va  2  s .co m*/
    try {
        return Splitter.on(";").trimResults().omitEmptyStrings().splitToList(value);
    } catch (Exception e) {
        throw new ConvertorException(e);
    }
}