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.android.tools.idea.gradle.project.compatibility.BuildFileComponentVersionReader.java

BuildFileComponentVersionReader(@NotNull String keyPath) {
    List<String> segments = Splitter.on('/').splitToList(keyPath);
    myComponentName = segments.get(segments.size() - 1);
    myKey = BuildFileKey.findByPath(keyPath);
}

From source file:brooklyn.entity.container.docker.application.DockerEntitySpecResolver.java

@Override
public EntitySpec<?> resolve(String type, BrooklynClassLoadingContext loader, Set<String> encounteredTypes) {
    String dockerServiceType = getLocalType(type);
    List<String> parts = Splitter.on(":").splitToList(dockerServiceType);
    if (parts.isEmpty() || parts.size() > 2) {
        throw new IllegalArgumentException("Docker serviceType cannot be parsed: " + dockerServiceType);
    }//from  w w w  .  jav a  2s. com
    String imageName = Iterables.get(parts, 0);
    String imageTag = Iterables.get(parts, 1, "latest");
    log.debug("Creating Docker service entity with image {} and tag {}", imageName, imageTag);

    EntitySpec<VanillaDockerApplication> spec = EntitySpec.create(VanillaDockerApplication.class);
    spec.configure(DockerAttributes.DOCKER_IMAGE_NAME, imageName);
    if (parts.size() == 2) {
        spec.configure(DockerAttributes.DOCKER_IMAGE_TAG, imageTag);
    }
    return spec;
}

From source file:org.apache.gobblin.qualitychecker.row.RowLevelPolicyCheckerBuilder.java

@SuppressWarnings("unchecked")
private List<RowLevelPolicy> createPolicyList() throws Exception {
    List<RowLevelPolicy> list = new ArrayList<>();
    Splitter splitter = Splitter.on(",").omitEmptyStrings().trimResults();
    String rowLevelPoliciesKey = ForkOperatorUtils
            .getPropertyNameForBranch(ConfigurationKeys.ROW_LEVEL_POLICY_LIST, this.index);
    String rowLevelPolicyTypesKey = ForkOperatorUtils
            .getPropertyNameForBranch(ConfigurationKeys.ROW_LEVEL_POLICY_LIST_TYPE, this.index);
    if (this.state.contains(rowLevelPoliciesKey) && this.state.contains(rowLevelPolicyTypesKey)) {
        List<String> policies = Lists.newArrayList(splitter.split(this.state.getProp(rowLevelPoliciesKey)));
        List<String> types = Lists.newArrayList(splitter.split(this.state.getProp(rowLevelPolicyTypesKey)));
        if (policies.size() != types.size()) {
            throw new Exception("Row Policies list and Row Policies list type are not the same length");
        }/*from  ww w .j  a  v  a2s.co m*/
        for (int i = 0; i < policies.size(); i++) {
            try {
                Class<? extends RowLevelPolicy> policyClass = (Class<? extends RowLevelPolicy>) Class
                        .forName(policies.get(i));
                Constructor<? extends RowLevelPolicy> policyConstructor = policyClass
                        .getConstructor(State.class, RowLevelPolicy.Type.class);
                RowLevelPolicy policy = policyConstructor.newInstance(this.state,
                        RowLevelPolicy.Type.valueOf(types.get(i)));
                list.add(policy);
            } catch (Exception e) {
                LOG.error(rowLevelPoliciesKey + " contains a class " + policies.get(i)
                        + " which doesn't extend RowLevelPolicy.", e);
                throw e;
            }
        }
    }
    return list;
}

From source file:org.gradle.buildinit.plugins.internal.BuildScriptBuilder.java

/**
 * Adds a comment to the header of the file.
 *//*from  w ww . j av  a2  s . c o m*/
public BuildScriptBuilder fileComment(String comment) {
    headerLines.addAll(Splitter.on("\n").splitToList(comment));
    return this;
}

From source file:annis.gui.EmbeddedVisUI.java

@Override
protected void init(VaadinRequest request) {
    super.init(request);

    String rawPath = request.getPathInfo();
    List<String> splittedPath = new LinkedList<>();
    if (rawPath != null) {
        rawPath = rawPath.substring(PREFIX.length());
        splittedPath = Splitter.on("/").omitEmptyStrings().trimResults().limit(3).splitToList(rawPath);
    }//from www  .j a v  a  2s.co m

    if (splittedPath.size() >= 3) {
        if ("htmldoc".equals(splittedPath.get(0))) {
            showHtmlDoc(splittedPath.get(1), splittedPath.get(2), request.getParameterMap());
        } else {
            setContent(new Label(
                    "unknown visualizer \"" + splittedPath.get(0) + "\", only \"htmldoc\" is supported yet."));
        }
    } else {
        displayGeneralHelp();
    }
    addStyleName("loaded-embedded-vis");
}

From source file:org.ndgf.endit.RemoveTask.java

private String getPnfsId(URI uri) {
    String query = uri.getQuery();
    checkArgument(query != null, "URI lacks query part");
    String id = Splitter.on('&').withKeyValueSeparator('=').split(query).get("bfid");
    checkArgument(id != null, "Query part lacks bfid parameter");
    return id;//ww w .  j  a v  a  2  s. c  om
}

From source file:com.facebook.presto.verifier.source.MySqlSourceQueryConfig.java

@ConfigDescription("The suites of queries in the query database to run")
@Config("suites")
public MySqlSourceQueryConfig setSuites(String suites) {
    if (suites != null) {
        this.suites = Splitter.on(',').trimResults().omitEmptyStrings().splitToList(suites);
    }/*from www.  ja  v  a2  s  .c  o  m*/
    return this;
}

From source file:org.jclouds.elasticstack.functions.MapToDriveInfo.java

@Override
public DriveInfo apply(Map<String, String> from) {
    if (from.size() == 0)
        return null;
    DriveInfo.Builder builder = new DriveInfo.Builder();
    builder.name(from.get("name"));
    if (from.containsKey("tags"))
        builder.tags(Splitter.on(' ').split(from.get("tags")));
    if (from.containsKey("status"))
        builder.status(DriveStatus.fromValue(from.get("status")));
    builder.metrics(buildMetrics(from));
    builder.user(from.get("user"));
    builder.encryptionCipher(from.get("encryption:cipher"));
    builder.uuid(from.get("drive"));
    if (from.containsKey("claim:type"))
        builder.claimType(ClaimType.fromValue(from.get("claim:type")));
    if (from.containsKey("claimed"))
        builder.claimed(Splitter.on(' ').split(from.get("claimed")));
    if (from.containsKey("readers"))
        builder.readers(Splitter.on(' ').split(from.get("readers")));
    if (from.containsKey("size"))
        builder.size(Long.valueOf(from.get("size")));
    Map<String, String> metadata = Maps.newLinkedHashMap();
    for (Entry<String, String> entry : from.entrySet()) {
        if (entry.getKey().startsWith("user:"))
            metadata.put(entry.getKey().substring(entry.getKey().indexOf(':') + 1), entry.getValue());
    }/*from  w  ww  .  j a va  2s  .  c o m*/
    builder.userMetadata(metadata);
    try {
        return builder.build();
    } catch (NullPointerException e) {
        logger.trace("entry missing data: %s; %s", e.getMessage(), from);
        return null;
    }
}

From source file:gobblin.data.management.conversion.hive.query.HiveValidationQueryGenerator.java

/***
 * Generate Hive queries for validating converted Hive table.
 * @param hiveDataset Source {@link HiveDataset}.
 * @param sourcePartition Source {@link Partition} if any.
 * @param conversionConfig {@link ConvertibleHiveDataset.ConversionConfig} for conversion.
 * @return Validation Hive queries.//from   w w  w. j a v a2  s.  c  o  m
 */
public static List<String> generateCountValidationQueries(HiveDataset hiveDataset,
        Optional<Partition> sourcePartition, ConvertibleHiveDataset.ConversionConfig conversionConfig) {

    // Source and converted destination details
    String sourceDatabase = hiveDataset.getDbAndTable().getDb();
    String sourceTable = hiveDataset.getDbAndTable().getTable();
    String destinationDatabase = conversionConfig.getDestinationDbName();
    String destinationTable = conversionConfig.getDestinationTableName();

    // Build query.
    List<String> queries = Lists.newArrayList();

    if (sourcePartition.isPresent()) {
        StringBuilder partitionClause = new StringBuilder();

        boolean isFirst = true;
        String partitionInfo = sourcePartition.get().getName();
        List<String> pInfo = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(partitionInfo);
        for (String aPInfo : pInfo) {
            List<String> pInfoParts = Splitter.on("=").omitEmptyStrings().trimResults().splitToList(aPInfo);
            if (pInfoParts.size() != 2) {
                throw new IllegalArgumentException(String.format("Partition details should be of the format "
                        + "partitionName=partitionValue. Recieved: %s", aPInfo));
            }
            if (isFirst) {
                isFirst = false;
            } else {
                partitionClause.append(" and ");
            }
            partitionClause.append("`").append(pInfoParts.get(0)).append("`='").append(pInfoParts.get(1))
                    .append("'");
        }

        queries.add(String.format("SELECT count(*) FROM `%s`.`%s` WHERE %s ", sourceDatabase, sourceTable,
                partitionClause));
        queries.add(String.format("SELECT count(*) FROM `%s`.`%s` WHERE %s ", destinationDatabase,
                destinationTable, partitionClause));
    } else {
        queries.add(String.format("SELECT count(*) FROM `%s`.`%s` ", sourceDatabase, sourceTable));
        queries.add(String.format("SELECT count(*) FROM `%s`.`%s` ", destinationDatabase, destinationTable));
    }

    return queries;
}

From source file:io.v.impl.google.naming.EndpointImpl.java

private static Endpoint fromV6String(List<String> parts) {
    if (parts.size() < 6) {
        throw new IllegalArgumentException("Invalid format for endpoint, expecting 6 '@'-separated components");
    }//from  ww  w  .  j a  v  a  2s  .  com

    String protocol = parts.get(1);
    String address = unescapeAddress(parts.get(2));
    if (address.isEmpty()) {
        address = ":0";
    }
    List<String> routes = unescapeRoutes(Splitter.on(',').splitToList(parts.get(3)));
    RoutingId routingId = RoutingId.fromString(parts.get(4));
    String mountTableFlag = parts.get(5);
    boolean isMountTable;
    boolean isLeaf;
    if ("".equals(mountTableFlag)) {
        isMountTable = true;
        isLeaf = false;
    } else if ("l".equals(mountTableFlag)) {
        isMountTable = false;
        isLeaf = true;
    } else if ("m".equals(mountTableFlag)) {
        isMountTable = true;
        isLeaf = false;
    } else if ("s".equals(mountTableFlag)) {
        isMountTable = false;
        isLeaf = false;
    } else {
        throw new IllegalArgumentException(
                "Invalid mounttable flag " + mountTableFlag + ", should be one of 'l', 'm' or 's'");
    }

    List<String> blessings;
    if ("".equals(parts.get(6))) {
        blessings = ImmutableList.of();
    } else {
        blessings = Splitter.on(',').splitToList(Joiner.on("@").join(parts.subList(6, parts.size())));
    }
    return new EndpointImpl(protocol, address, routes, routingId, blessings, isMountTable, isLeaf);
}