Example usage for com.google.common.base Joiner join

List of usage examples for com.google.common.base Joiner join

Introduction

In this page you can find the example usage for com.google.common.base Joiner join.

Prototype

@CheckReturnValue
public final String join(@Nullable Object first, @Nullable Object second, Object... rest) 

Source Link

Document

Returns a string containing the string representation of each argument, using the previously configured separator between each.

Usage

From source file:com.salesforce.jprotoc.ProtoTypeMap.java

/**
 * Returns the full Java type name based on the given protobuf type parameters.
 *
 * @param className the protobuf type name
 * @param enclosingClassName the optional enclosing class for the given type
 * @param javaPackage the proto file's configured java package name
 */// w w  w.  j  a v  a  2  s .  co  m
public static String toJavaTypeName(@Nonnull String className, @Nullable String enclosingClassName,
        @Nullable String javaPackage) {

    Preconditions.checkNotNull(className, "className");

    Joiner dotJoiner = Joiner.on('.').skipNulls();
    return dotJoiner.join(javaPackage, enclosingClassName, className);
}

From source file:kungfu.concurrency.threaddump.ThreadUtil.java

public static String writeThreadDump(String prefix) throws IOException {
    DateFormat dateFormat = new SimpleDateFormat("YYYYMMDDHH24MMSS");

    Joiner joiner = Joiner.on(CharPool.UNDERSCORE);

    Date now = new Date();

    File dumpFile = File.createTempFile(joiner.join(prefix, "thread_dump", dateFormat.format(now)), null);

    String threadDump = threadDump();

    Files.write(threadDump, dumpFile, Charset.defaultCharset());

    return dumpFile.getAbsolutePath();
}

From source file:org.apache.impala.analysis.PrivilegeSpec.java

/**
 * Return the table path of a COLUMN level privilege. The table path consists
 * of server name, database name and table name.
 *//*from ww w .  j  ava 2  s .c om*/
public static String getTablePath(TPrivilege privilege) {
    Preconditions.checkState(privilege.getScope() == TPrivilegeScope.COLUMN);
    Joiner joiner = Joiner.on(".");
    return joiner.join(privilege.getServer_name(), privilege.getDb_name(), privilege.getTable_name());
}

From source file:org.eclipse.viatra.cep.vepl.ui.syntaxhighlight.CepDslAntlrTokenToAttributeIdMapper.java

private String getApostrophedKeyword(String keyword) {
    final String APOSTROPHE = "'";
    Joiner joiner = Joiner.on("");
    return joiner.join(APOSTROPHE, keyword, APOSTROPHE);
}

From source file:com.turn.sorcerer.metrics.MetricUnit.java

/**
 * Utility class to generate keys for different monitoring dashboard
 *
 *///from  w  w w.  jav  a2  s. co m
public String getGraphiteKey() {
    if (graphiteOnly) {
        return keyUnits.get(GRAPHITE_KEY);
    }

    String tagName = "";
    if (keyUnits.get(TASK_NAME_KEY) != null) {
        tagName = keyUnits.get(TASK_NAME_KEY);
    } else if (keyUnits.get(PIPELINE_NAME_KEY) != null) {
        tagName = keyUnits.get(PIPELINE_NAME_KEY);
    }
    Joiner joiner = Joiner.on('.');
    return joiner.join(SERVICE_PREFIX, tagName, keyUnits.get(METRIC_NAME_KEY));
}

From source file:com.newlandframework.avatarmq.consumer.AvatarMQConsumer.java

public void init() {
    super.getMessageConnectFactory()
            .setMessageHandle(new MessageConsumerHandler(this, new ConsumerHookMessageEvent(hook)));
    Joiner joiner = Joiner.on(MessageSystemConfig.MessageDelimiter).skipNulls();
    consumerId = joiner.join((clusterId.equals("") ? defaultClusterId : clusterId), topic,
            new MessageIdGenerator().generate());
}

From source file:com.google.appengine.contrib.gaedriver.AppcfgThread.java

@Override
protected List<String> buildArgumentList() {
    List<String> command = new ArrayList<String>();
    Joiner joiner = Joiner.on(File.separator);
    String javaBinary = joiner.join(System.getProperty("java.home"), "bin", "java");
    String toolsJar = joiner.join(config.getSdkDir(), "lib", "appengine-tools-api.jar");
    command.add(javaBinary);/*from   w  w  w.  ja va2 s  . c  o  m*/
    command.add("-cp");
    command.add(toolsJar);
    command.add("com.google.appengine.tools.admin.AppCfg");
    command.add("--application=" + config.getAppId());
    command.add("--sdk_root=" + config.getSdkDir());
    command.add("--server=" + config.getAcHostname());
    command.add("--email=" + config.getUsername());
    command.add("--passin");
    command.addAll(options);
    command.add(this.action);
    command.add(config.getAppDir());
    return command;
}

From source file:com.blackducksoftware.integration.hub.dataservices.notification.items.NotificationContentItem.java

@Override
public int compareTo(final NotificationContentItem o) {
    if (equals(o)) {
        return 0;
    }/*from  w ww . j ava2s. c  o  m*/

    final int createdAtComparison = getCreatedAt().compareTo(o.getCreatedAt());
    if (createdAtComparison != 0) {
        // If createdAt times are different, use createdAt to compare
        return createdAtComparison;
    }

    // Identify same-time non-equal items as non-equal
    final Joiner joiner = Joiner.on(":").skipNulls();
    final String thisProjectVersionString = joiner.join(getProjectVersion().getProjectName(),
            getProjectVersion().getProjectVersionName(), getComponentVersionUrl());
    final String otherProjectVersionString = joiner.join(o.getProjectVersion().getProjectName(),
            o.getProjectVersion().getProjectVersionName(), o.getComponentVersionUrl().toString());

    return thisProjectVersionString.compareTo(otherProjectVersionString);
}

From source file:org.ctoolkit.services.storage.appengine.blob.StorageServiceBean.java

/**
 * Parse bucket name and file name from the full storage name.
 *
 * @param fullName the cloud storage file full name
 * @return the bucket name and file name
 */// w  w  w .  j a v  a  2  s .  c om
private BucketName parseBucketAndName(@Nonnull String fullName) {
    checkNotNull(fullName);

    String[] split = fullName.split("/");
    if (split.length >= 4 && "gs".equals(split[1])) {
        String bucket = split[2];

        if (Strings.isNullOrEmpty(bucket)) {
            throw new IllegalArgumentException("The bucket has no value: '" + fullName + "'");
        }

        Joiner joiner = Joiner.on("/");
        String prefix = joiner.join(split[0], split[1], split[2]);
        String name = fullName.substring(prefix.length() + 1);

        return new BucketName(bucket, name);
    } else {
        String message = "The full storage name does not follow expected pattern '" + STORAGE_NAME_PATTERN
                + "' for given argument: '" + fullName + "' Fill: {0} - bucket name and {1} file name.";

        throw new IllegalArgumentException(message);
    }
}

From source file:com.android.tradefed.result.JsonHttpTestResultReporter.java

/**
 * A util method that converts test metrics and invocation context to json format
 *///from  w  w w  .  ja v a  2s.c  o  m
JSONObject convertMetricsToJson(Collection<TestRunResult> runResults) throws JSONException {
    JSONObject allTestMetrics = new JSONObject();

    StringBuffer resultsName = new StringBuffer();
    // loops over all test runs
    for (TestRunResult runResult : runResults) {

        // Parse run metrics
        if (runResult.getRunMetrics().size() > 0) {
            JSONObject runResultMetrics = new JSONObject(runResult.getRunMetrics());
            String reportingUnit = runResult.getName();
            if (mReportingUnitKeySuffix != null && !mReportingUnitKeySuffix.isEmpty()) {
                reportingUnit += mReportingUnitKeySuffix;
            }
            allTestMetrics.put(reportingUnit, runResultMetrics);
            resultsName.append(String.format("%s%s", reportingUnit, RESULT_SEPARATOR));
        } else {
            CLog.d("Skipping metrics for %s because results are empty.", runResult.getName());
        }

        // Parse test metrics
        Map<TestIdentifier, TestResult> testResultMap = runResult.getTestResults();
        for (Entry<TestIdentifier, TestResult> entry : testResultMap.entrySet()) {
            TestIdentifier testIdentifier = entry.getKey();
            TestResult testResult = entry.getValue();
            Joiner joiner = Joiner.on(SEPARATOR).skipNulls();
            String reportingUnit = joiner.join(mIncludeRunName ? runResult.getName() : null,
                    testIdentifier.getClassName(), testIdentifier.getTestName());
            if (mReportingUnitKeySuffix != null && !mReportingUnitKeySuffix.isEmpty()) {
                reportingUnit += mReportingUnitKeySuffix;
            }
            resultsName.append(String.format("%s%s", reportingUnit, RESULT_SEPARATOR));
            if (testResult.getMetrics().size() > 0) {
                JSONObject testResultMetrics = new JSONObject(testResult.getMetrics());
                allTestMetrics.put(reportingUnit, testResultMetrics);
            } else {
                CLog.d("Skipping metrics for %s because results are empty.", testIdentifier);
            }
        }
    }
    // get build info, and throw an exception if there are multiple (not supporting multi-device
    // result reporting
    List<IBuildInfo> buildInfos = mInvocationContext.getBuildInfos();
    if (buildInfos.size() != 1) {
        throw new IllegalArgumentException(
                String.format("Only expected 1 build info, actual: [%d]", buildInfos.size()));
    }
    IBuildInfo buildInfo = buildInfos.get(0);
    JSONObject result = new JSONObject();
    result.put(KEY_RESULTS_NAME, resultsName);
    result.put(KEY_METRICS, allTestMetrics);
    result.put(KEY_BRANCH, buildInfo.getBuildBranch());
    result.put(KEY_BUILD_FLAVOR, buildInfo.getBuildFlavor());
    result.put(KEY_BUILD_ID, buildInfo.getBuildId());
    return result;
}