Example usage for com.google.common.base Strings padEnd

List of usage examples for com.google.common.base Strings padEnd

Introduction

In this page you can find the example usage for com.google.common.base Strings padEnd.

Prototype

public static String padEnd(String string, int minLength, char padChar) 

Source Link

Document

Returns a string, of length at least minLength , consisting of string appended with as many copies of padChar as are necessary to reach that length.

Usage

From source file:org.rf.ide.core.executor.ArgumentsFile.java

public String generateContent() {
    if (argNames.isEmpty() || argValues.isEmpty()) {
        return "";
    }/*from   w ww .  j  av a 2  s . c  om*/
    final Optional<String> longestArg = argNames.stream().filter(line -> !line.startsWith("#"))
            .max(Comparator.comparingInt(String::length));

    final BiFunction<String, String, String> joiningFunction = (arg, val) -> arg.startsWith("#") ? arg
            : (Strings.padEnd(arg, longestArg.get().length() + 1, ' ') + val);
    return zip(argNames.stream(), argValues.stream(), joiningFunction).map(String::trim).collect(joining("\n"));
}

From source file:com.google.inject.servlet.PipelineLogger.java

private static String format(String pattern, Object element) {
    return Strings.padEnd(pattern, PADDING, ' ') + ' ' + element;
}

From source file:com.facebook.buck.cxx.DebugPathSanitizer.java

/**
 * @return the given path as a string, expanded using {@code separator} to fulfill the required
 *     {@code pathSize}./*from   www.j av  a  2 s.c o m*/
 */
protected String getExpandedPath(Path path) {
    Preconditions.checkArgument(path.toString().length() <= pathSize,
            String.format("Path is too long to sanitize:\n'%s' is %d characters long, limit is %d.", path,
                    path.toString().length(), pathSize));
    return Strings.padEnd(path.toString(), pathSize, separator);
}

From source file:com.bennavetta.aeneas.cli.Table.java

@Override
public String toString() {
    if (rows.isEmpty())
        return "";

    int numColumns = rows.get(0).size();
    List<Integer> columnWidths = Lists.newArrayList();
    for (int i = 0; i < numColumns; i++) {
        columnWidths.add(extractColumn(i).mapToInt(String::length).max().getAsInt());
    }/*from w  ww .j  a va 2  s . co  m*/

    return rows.stream().map(row -> {
        List<String> paddedRow = Lists.newArrayListWithCapacity(row.size());
        for (int i = 0; i < row.size(); i++) {
            int columnWidth = columnWidths.get(i);
            paddedRow.add(Strings.padEnd(row.get(i), columnWidth, padChar));
        }
        return Joiner.on(Strings.repeat(String.valueOf(padChar), padAmount)).join(paddedRow);
    }).collect(Collectors.joining("\n"));
}

From source file:com.opengamma.strata.report.framework.format.CurrencyParameterSensitivityValueFormatter.java

private String getSensitivityString(CurrencyParameterSensitivity sensitivity, DoubleFunction<String> formatFn,
        boolean pad) {

    StringBuilder sb = new StringBuilder();
    List<ParameterMetadata> parameterMetadata = sensitivity.getParameterMetadata();
    IntFunction<String> labelProvider = i -> Objects
            .toString(Strings.emptyToNull(parameterMetadata.get(i).getLabel()), String.valueOf(i + 1));

    for (int i = 0; i < sensitivity.getSensitivity().size(); i++) {
        String formattedSensitivity = formatFn.apply(sensitivity.getSensitivity().get(i));
        String field = labelProvider.apply(i) + " = " + formattedSensitivity;
        if (pad) {
            field = Strings.padEnd(field, PADDED_FIELD_WIDTH, ' ');
        }/* w  w  w  .  ja  va 2s .  c o  m*/
        sb.append(field);
        if (i < sensitivity.getSensitivity().size() - 1) {
            sb.append(" | ");
        }
    }
    return sb.toString();
}

From source file:com.opengamma.bbg.BloombergContractID.java

public BloombergContractID(String contractCode, String marketSector) {
    ArgumentChecker.notNull(contractCode, "contractCode");
    ArgumentChecker.notNull(marketSector, "marketSector");
    // ticker must be at least 2 characters long - pad with spaces if shorter
    final String paddedCode = Strings.padEnd(contractCode, 2, ' ');
    setContractCode(paddedCode);/*from w ww. j  a va 2s . co  m*/
    setMarketSector(marketSector);
}

From source file:com.opengamma.strata.report.framework.format.CurveCurrencyParameterSensitivityValueFormatter.java

private String getSensitivityString(CurveCurrencyParameterSensitivity sensitivity,
        DoubleFunction<String> formatFn, boolean pad) {

    StringBuilder sb = new StringBuilder();
    Optional<List<CurveParameterMetadata>> parameterMetadata = sensitivity.getMetadata().getParameterMetadata();
    IntFunction<String> labelProvider = parameterMetadata.isPresent()
            ? i -> parameterMetadata.get().get(i).getLabel()
            : i -> String.valueOf(i + 1);

    for (int i = 0; i < sensitivity.getSensitivity().size(); i++) {
        String formattedSensitivity = formatFn.apply(sensitivity.getSensitivity().get(i));
        String field = labelProvider.apply(i) + " = " + formattedSensitivity;
        if (pad) {
            field = Strings.padEnd(field, PADDED_FIELD_WIDTH, ' ');
        }/*www.j a  v  a2 s  .  c  o m*/
        sb.append(field);
        if (i < sensitivity.getSensitivity().size() - 1) {
            sb.append(" | ");
        }
    }
    return sb.toString();
}

From source file:com.cassius.spring.assembly.test.common.toolbox.LogFormatUtil.java

/**
 * Format string./*from   w ww  .  jav  a  2s.c o  m*/
 *
 * @param logs the logs
 * @return the string
 */
public static String format(List<String> logs) {
    String logSep = formatBegLine();

    StringBuilder sb = new StringBuilder(logSep);
    for (String log : logs) {
        String LOG_LINE_BEG = RETURN + SYMBOL_2 + BLANK;
        if (log.length() < LINE_LENGTH - 2) {
            log = LOG_LINE_BEG + Strings.padEnd(log, LINE_LENGTH - 2, ' ');
        } else {

            String LOG_LINE_BREAK = "\n" + SYMBOL_3 + BLANK;
            log = LOG_LINE_BEG
                    + StringUtils.replace(insertBreakLineSymbol(log, LINE_LENGTH - 2), "\n", LOG_LINE_BREAK);
        }
        sb.append(log);
    }
    sb.append(RETURN);
    return sb.toString();
}

From source file:fathom.Core.java

synchronized void startup() {

    Preconditions.checkState(injector == null, "Fathom has already been started!");

    long startTime = System.nanoTime();

    String border = Strings.padEnd("", Constants.MIN_BORDER_LENGTH, '-');
    Optional<String> applicationPackage = Optional.fromNullable(settings.getApplicationPackage());

    log.info(border);//from   ww  w  . j  a v  a2 s. c  o  m
    log.info("Initializing Guice injector");
    log.info(border);
    injector = initializeInjector(applicationPackage);

    Preconditions.checkNotNull(injector, "Failed to initialize Guice injector!");

    log.info(border);
    log.info("Starting services");
    log.info(border);
    services.start(injector);

    Fathom fathom = injector.getInstance(Fathom.class);
    log.info("Starting Fathom '{}'", fathom.getClass().getName());
    initializeMetadata(fathom);
    fathom.onStartup();

    long bootTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
    String name = settings.getApplicationName();
    String version = settings.getApplicationVersion();
    log.info("{} {} initialized in {} ms", name, version, bootTime);
}

From source file:com.google.security.zynamics.binnavi.ZyGraph.Builders.ZyInstructionBuilder.java

/**
 * Builds the mnemonic of an instruction.
 *
 * @param instruction The instruction in question.
 * @param line String buffer where the mnemonic string is added.
 * @param styleRun Style runs list where the formatting information is added.
 *///from w  ww  .j av  a2  s .c  om
private static void buildMnemonic(final IInstruction instruction, final StringBuffer line,
        final List<CStyleRunData> styleRun) {
    final String mnemonic = instruction.getMnemonic();
    styleRun.add(new CStyleRunData(line.length(), mnemonic.length(),
            ConfigManager.instance().getColorSettings().getMnemonicColor()));
    line.append(Strings.padEnd(mnemonic, MINIMUM_MNEMONIC_SIZE, ' '));
}