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:de.metas.ui.web.window.datatypes.MediaType.java

public static final Set<MediaType> fromNullableCommaSeparatedString(final String str) {
    if (str == null || str.isEmpty()) {
        return ImmutableSet.of();
    }//from   w ww  .j a  v a 2 s. co m
    final List<String> parts = Splitter.on(",").trimResults().omitEmptyStrings().splitToList(str);
    return parts.stream().map(MediaType::fromJson).collect(ImmutableSet.toImmutableSet());
}

From source file:org.jclouds.googlecomputeengine.compute.predicates.NetworkFirewallPredicates.java

private static boolean inRange(String range, int fromPort, int toPort) {
    List<String> ports = Splitter.on('-').splitToList(range);
    return fromPort >= Integer.valueOf(ports.get(0)) && toPort <= Integer.valueOf(ports.get(1));
}

From source file:uk.ac.ebi.gxa.web.wro4j.tag.ResourcePath.java

private static Splitter splitter() {
    return Splitter.on(PATH_SEPARATOR).omitEmptyStrings();
}

From source file:org.sfs.util.ConfigHelper.java

public static Iterable<String> getArrayFieldOrEnv(JsonObject config, String name,
        Iterable<String> defaultValue) {
    String envVar = formatEnvVariable(name);
    //USED_ENV_VARS.add(envVar);
    if (config.containsKey(name)) {
        JsonArray values = config.getJsonArray(name);
        if (values != null) {
            Iterable<String> iterable = FluentIterable.from(values).filter(Predicates.notNull())
                    .filter(input -> input instanceof String).transform(input -> input.toString());
            log(name, envVar, name, iterable);
            return iterable;
        }//  ww w . jav a2  s .  co m
    } else {
        String value = System.getenv(envVar);
        if (value != null) {
            log(name, envVar, envVar, value);
            return Splitter.on(',').split(value);
        }
    }
    log(name, envVar, null, defaultValue);
    return defaultValue;
}

From source file:com.intel.podm.common.utils.StringRepresentation.java

public static List<String> toList(String stringToSplit, boolean trimResults) {
    Splitter splitter = Splitter.on(ELEMENT_SEPARATOR);

    if (trimResults) {
        splitter = splitter.trimResults();
    }/*from  w  w  w  .j  a  v  a 2s. c o  m*/

    return splitter.splitToList(stringToSplit);
}

From source file:org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToListOfMaps.java

@Override
public List<Map<String, String>> apply(String from) {
    List<Map<String, String>> maps = Lists.newArrayList();
    for (String listOfKeyValues : Splitter.on("\n\n").split(from)) {
        if (!"".equals(listOfKeyValues)) {
            Map<String, String> map = Maps.newLinkedHashMap();
            for (String keyValueLine : Splitter.on('\n').split(listOfKeyValues)) {
                if (!"".equals(keyValueLine)) {
                    int firstIndex = keyValueLine.indexOf(' ');
                    String key = keyValueLine.substring(0, firstIndex);
                    String value = keyValueLine.substring(firstIndex + 1).replace("\\n", "\n");
                    map.put(key, value);
                }/*w ww.  j av a 2 s.  c  o  m*/
            }
            if (map.size() != 0)
                maps.add(map);
        }
    }
    return maps;
}

From source file:com.facebook.buck.features.project.intellij.IjProjectBuckConfig.java

public static IjProjectConfig create(BuckConfig buckConfig, @Nullable AggregationMode aggregationMode,
        @Nullable String generatedFilesListFilename, @Nonnull String projectRoot, String moduleGroupName,
        boolean isCleanerEnabled, boolean removeUnusedLibraries, boolean excludeArtifacts,
        boolean includeTransitiveDependencies, boolean skipBuild, boolean keepModuleFilesInModuleDirsEnabled,
        ImmutableSet<String> includeTestPatterns, ImmutableSet<String> excludeTestPatterns) {
    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 ww. j a va2  s.com
        excludedResourcePaths = Collections.emptyList();
    }

    Map<String, String> labelToGeneratedSourcesMap = buckConfig.getMap(INTELLIJ_BUCK_CONFIG_SECTION,
            "generated_sources_label_map");

    Optional<Path> androidManifest = buckConfig.getPath(INTELLIJ_BUCK_CONFIG_SECTION,
            "default_android_manifest_path", false);

    keepModuleFilesInModuleDirsEnabled = buckConfig.getBooleanValue(INTELLIJ_BUCK_CONFIG_SECTION,
            "keep_module_files_in_module_dirs", false) || keepModuleFilesInModuleDirsEnabled;

    return createBuilder(buckConfig).setExcludedResourcePaths(excludedResourcePaths)
            .setLabelToGeneratedSourcesMap(labelToGeneratedSourcesMap).setAndroidManifest(androidManifest)
            .setCleanerEnabled(isCleanerEnabled)
            .setKeepModuleFilesInModuleDirsEnabled(keepModuleFilesInModuleDirsEnabled)
            .setRemovingUnusedLibrariesEnabled(
                    isRemovingUnusedLibrariesEnabled(removeUnusedLibraries, buckConfig))
            .setExcludeArtifactsEnabled(isExcludingArtifactsEnabled(excludeArtifacts, buckConfig))
            .setSkipBuildEnabled(
                    skipBuild || buckConfig.getBooleanValue(PROJECT_BUCK_CONFIG_SECTION, "skip_build", false))
            .setAggregationMode(getAggregationMode(aggregationMode, buckConfig))
            .setGeneratedFilesListFilename(Optional.ofNullable(generatedFilesListFilename))
            .setProjectRoot(projectRoot)
            .setProjectPaths(new IjProjectPaths(projectRoot, keepModuleFilesInModuleDirsEnabled))
            .setIncludeTransitiveDependency(
                    isIncludingTransitiveDependencyEnabled(includeTransitiveDependencies, buckConfig))
            .setModuleGroupName(getModuleGroupName(moduleGroupName, buckConfig))
            .setIncludeTestPatterns(includeTestPatterns).setExcludeTestPatterns(excludeTestPatterns).build();
}

From source file:org.basepom.mojo.propertyhelper.TransformerRegistry.java

public static List<Function<String, String>> getTransformers(final String transformerNames) {
    if (transformerNames == null) {
        return ImmutableList.<Function<String, String>>of();
    }/*from w ww.  ja va  2s  .  c o  m*/

    ImmutableList.Builder<Function<String, String>> transformers = ImmutableList.builder();
    for (String transformerName : Splitter.on(',').omitEmptyStrings().split(transformerNames)) {
        transformers.add(forName(transformerName));
    }

    return transformers.build();
}

From source file:io.datakernel.datagraph.server.GsonInetSocketAddressAdapter.java

@Override
public InetSocketAddress read(JsonReader reader) throws IOException {
    if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();/*from w w  w . j  av  a 2  s  .c om*/
        return null;
    }
    try {
        Iterator<String> split = Splitter.on(':').split(reader.nextString()).iterator();
        InetAddress hostname = InetAddresses.forString(split.next());
        int port = Integer.parseInt(split.next());
        checkArgument(!split.hasNext());
        return new InetSocketAddress(hostname, port);
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
}

From source file:com.android.tools.idea.gradle.structure.model.PsArtifactDependencySpec.java

@Nullable
public static PsArtifactDependencySpec create(@NotNull String notation) {
    // Example: org.gradle.test.classifiers:service:1.0 where
    //   group: org.gradle.test.classifiers
    //   name: service
    //   version: 1.0
    List<String> segments = Splitter.on(GRADLE_PATH_SEPARATOR).trimResults().omitEmptyStrings()
            .splitToList(notation);/*from w w w  .  ja  v a2  s.  c o  m*/

    // TODO unify notation parsing with ArtifactDependencySpec parsing.
    int segmentCount = segments.size();
    if (segmentCount > 0) {
        segments = Lists.newArrayList(segments);
        String lastSegment = segments.remove(segmentCount - 1);
        int indexOfAt = lastSegment.indexOf('@');
        if (indexOfAt != -1) {
            lastSegment = lastSegment.substring(0, indexOfAt);
        }
        segments.add(lastSegment);
        segmentCount = segments.size();

        String group = null;
        String name = null;
        String version = null;

        if (segmentCount == 1) {
            name = segments.get(0);
        } else if (segmentCount == 2) {
            if (!lastSegment.isEmpty() && Character.isDigit(lastSegment.charAt(0))) {
                name = segments.get(0);
                version = lastSegment;
            } else {
                group = segments.get(0);
                name = segments.get(1);
            }
        } else if (segmentCount == 3 || segmentCount == 4) {
            group = segments.get(0);
            name = segments.get(1);
            version = segments.get(2);
        }
        if (isNotEmpty(name)) {
            return new PsArtifactDependencySpec(name, group, version);
        }
    }
    return null;
}