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.github.tomakehurst.wiremock.common.Urls.java

public static Map<String, QueryParameter> splitQuery(String query) {
    if (query == null) {
        return Collections.emptyMap();
    }/*w ww .j  a  v  a2s  . com*/

    Iterable<String> pairs = Splitter.on('&').split(query);
    ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
    for (String queryElement : pairs) {
        int firstEqualsIndex = queryElement.indexOf('=');
        if (firstEqualsIndex == -1) {
            builder.putAll(queryElement, "");
        } else {
            String key = queryElement.substring(0, firstEqualsIndex);
            String value = decode(queryElement.substring(firstEqualsIndex + 1));
            builder.putAll(key, value);
        }
    }

    return Maps.transformEntries(builder.build().asMap(),
            new Maps.EntryTransformer<String, Collection<String>, QueryParameter>() {
                public QueryParameter transformEntry(String key, Collection<String> values) {
                    return new QueryParameter(key, ImmutableList.copyOf(values));
                }
            });
}

From source file:gobblin.data.management.copy.replication.WatermarkMetadataUtil.java

public static Watermark deserialize(String content) throws WatermarkMetadataMulFormatException {
    List<String> tmp = Splitter.on(DELIMITER).trimResults().omitEmptyStrings().splitToList(content);
    if (tmp.size() < 2) {
        throw new WatermarkMetadataMulFormatException("wrong format " + content);
    }/*from   w w  w.  ja  va  2 s .  co m*/

    String classname = tmp.get(0);
    String jsonStr = tmp.get(1);

    try {
        Class<? extends Watermark> watermarkClass = (Class<? extends Watermark>) Class.forName(classname);

        return WatermarkSerializerHelper.convertJsonToWatermark(new JsonParser().parse(jsonStr),
                watermarkClass);
    } catch (ClassNotFoundException e) {
        throw new WatermarkMetadataMulFormatException("wrong format " + e.getMessage());
    }
}

From source file:fr.inria.atlanmod.neoemf.data.hbase.util.HBaseEncoderUtil.java

public static String[] toStringsReferences(byte[] value) {
    if (nonNull(value)) {
        checkArgument(value.length % (UUID_LENGTH + 1) == UUID_LENGTH);
        int length = (value.length + 1) / (UUID_LENGTH + 1);

        Iterator<String> iterator = Splitter.on(VALUE_SEPERATOR_DEFAULT).split(Bytes.toString(value))
                .iterator();/*from w  w w  .  j a va 2 s.  c  o  m*/
        //            List<String>  strings = new LinkedList<String>();
        String[] strings = new String[length];
        int index = 0;
        while (iterator.hasNext()) {
            //                strings.add(iterator.next());
            strings[index++] = iterator.next();
        }
        //            return strings.toArray(new String[strings.size()]);
        return strings;
    }
    return null;
}

From source file:org.jclouds.openstack.nova.v2_0.domain.zonescoped.RegionAndId.java

public static RegionAndId fromSlashEncoded(String id) {
    Iterable<String> parts = Splitter.on('/').split(checkNotNull(id, "id"));
    checkArgument(Iterables.size(parts) == 2, "id must be in format regionId/id");
    return new RegionAndId(Iterables.get(parts, 0), Iterables.get(parts, 1));
}

From source file:com.teradata.benchto.driver.utils.YamlUtils.java

public static List<String> asStringList(Object object) {
    if (!(object instanceof Iterable<?>)) {
        return ImmutableList.copyOf(Splitter.on(",").trimResults().omitEmptyStrings().split(object.toString()));
    } else {//w  w  w .j a  v a  2  s  .c  o  m
        Iterable<?> iterable = (Iterable<?>) object;
        return StreamSupport.stream(iterable.spliterator(), false).map(Object::toString).collect(toList());
    }
}

From source file:com.facebook.buck.jvm.java.intellij.IjProjectBuckConfig.java

public static IjProjectConfig create(BuckConfig buckConfig) {
    Optional<String> excludedResourcePathsOption = buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION,
            "excluded_resource_paths");

    Iterable<String> excludedResourcePaths;
    if (excludedResourcePathsOption.isPresent()) {
        excludedResourcePaths = Sets.newHashSet(
                Splitter.on(',').omitEmptyStrings().trimResults().split(excludedResourcePathsOption.get()));
    } else {// w  w w  . j a va2 s .  c  o  m
        excludedResourcePaths = Collections.emptyList();
    }

    Optional<String> generatedSourcesMap = buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION,
            "generated_srcs_map");

    Map<String, String> depToGeneratedSourcesMap = generatedSourcesMap
            .map(value -> Splitter.on(',').omitEmptyStrings().trimResults()
                    .withKeyValueSeparator(Splitter.on("=>").trimResults()).split(value))
            .orElse(Collections.emptyMap());

    return IjProjectConfig.builder()
            .setAutogenerateAndroidFacetSourcesEnabled(!buckConfig.getBooleanValue(PROJECT_BUCK_CONFIG_SECTION,
                    "disable_r_java_idea_generator", false))
            .setJavaBuckConfig(buckConfig.getView(JavaBuckConfig.class)).setBuckConfig(buckConfig)
            .setProjectJdkName(buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "jdk_name"))
            .setProjectJdkType(buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "jdk_type"))
            .setAndroidModuleSdkName(
                    buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "android_module_sdk_name"))
            .setAndroidModuleSdkType(
                    buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "android_module_sdk_type"))
            .setJavaModuleSdkName(buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "java_module_sdk_name"))
            .setJavaModuleSdkType(buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "java_module_sdk_type"))
            .setProjectLanguageLevel(buckConfig.getValue(INTELLIJ_BUCK_CONFIG_SECTION, "language_level"))
            .setExcludedResourcePaths(excludedResourcePaths)
            .setDepToGeneratedSourcesMap(depToGeneratedSourcesMap).build();
}

From source file:am.ik.categolj2.domain.model.Categories.java

public static Categories fromCategory(String categoryString) {
    Iterable<String> names = Splitter.on(Categories.SEPARATOR).omitEmptyStrings().split(categoryString);
    int i = 1;// ww  w  .  j a v a 2  s. c  o m
    List<Category> categories = new ArrayList<>();
    for (String name : names) {
        categories.add(new Category(null, i++, name));
    }
    return new Categories(categories);
}

From source file:com.google.api.codegen.ruby.RDocCommentFixer.java

private static String protoToRubyDoc(String comment) {
    boolean messageFound = false;
    boolean isFirstSegment = true;
    String result = "";
    for (String name : Splitter.on(".").splitToList(comment)) {
        char firstChar = name.charAt(0);
        if (Character.isUpperCase(firstChar)) {
            messageFound = true;/* w w w .ja  va2 s .co m*/
            result += (isFirstSegment ? "" : "::") + name;
        } else if (messageFound) {
            // Lowercase segment after message is found is field.
            // In Ruby, it is referred as "Message#field" format.
            result += "#" + name;
        } else {
            result += (isFirstSegment ? "" : "::") + Character.toUpperCase(firstChar) + name.substring(1);
        }
        isFirstSegment = false;
    }
    return result;
}

From source file:com.torodb.mongodb.commands.impl.general.AttrRefHelper.java

public static KvValue<?> calculateValueAndAttRef(BsonDocument doc, AttributeReference.Builder refBuilder)
        throws CommandFailed {
    if (doc.size() != 1) {
        throw new CommandFailed("find", "The given query is not supported right now");
    }//ww w  .jav  a 2 s  . c o m
    Entry<?> entry = doc.getFirstEntry();

    for (String subKey : Splitter.on('.').split(entry.getKey())) {
        refBuilder.addObjectKey(subKey);
    }

    BsonValue<?> value = entry.getValue();
    if (value.isArray()) {
        throw new CommandFailed("find", "Filters with arrays are not supported right now");
    }
    if (value.isDocument()) {
        return calculateValueAndAttRef(value.asDocument(), refBuilder);
    } else {
        return MongoWpConverter.translate(value);
    }
}

From source file:ext.deployit.community.cli.plainarchive.base.UriQueryStrings.java

public static @Nonnull Map<String, String> toMap(@Nonnull String queryString) {
    final Builder<String, String> inProgress = ImmutableMap.builder();
    for (String keyValue : Splitter.on(ATTRIBUTES_SEPARATOR).split(queryString)) {
        String[] keyAndValue = keyValue.split(ATTRIBUTE_KEY_VALUE_SEPARATOR);
        checkArgument(keyAndValue.length == 2,
                "Invalid query string format. Expected 'key=value&key2=value&...' but found section '%s'",
                keyValue);/*from   w  w w . ja  v  a2 s . c  om*/
        inProgress.put(keyAndValue[0], keyAndValue[1]);
    }
    return inProgress.build();
}