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:qa.dep.DependencyTree.java

/**
 * Prints this dependency tree in the CoNLL-X format.
 *
 * @return The CoNLL-X format representation of this dependency tree.
 *///from   w w  w.ja  va  2 s.c  om
public String toString() {
    OptionalInt max_tokensize_optint = values().stream().map(DependencyNode::getForm).mapToInt(String::length)
            .max();
    int max_tokensize = max_tokensize_optint.isPresent() ? max_tokensize_optint.getAsInt() : 0;
    int formwidth = max_tokensize + 2;
    List<String> conllOutput = new ArrayList<>();
    for (int i : navigableKeySet()) {
        if (i == 0) {
            continue;
        }
        DependencyNode node = get(i);
        String form = Strings.padEnd(node.getForm(), formwidth, ' ');
        String lemma = Strings.padEnd(node.getLemma(), 6, ' ');
        String cpos = Strings.padEnd(node.getCpos(), 6, ' ');
        String pos = Strings.padEnd(node.getPos(), 6, ' ');
        String rel = Strings.padEnd(node.getRelationLabel(), 6, ' ');
        conllOutput.add(
                Joiner.on("    ").join(node.getId(), form, lemma, cpos, "_", node.getHeadID(), rel, "_", "_"));
    }
    return Joiner.on('\n').join(conllOutput);
}

From source file:org.dice.solrenhancements.morelikethis.DiceMoreLikeThisHandler.java

private NamedList<String> getMltTermsForDebug(MLTResult mltResult) {
    List<MLTTerm> mltTerms = mltResult.mltTerms;
    Collections.sort(mltTerms);//ww  w . ja  va  2 s  . com
    NamedList<String> it = new NamedList<String>();
    int longestWd = 0;
    int longestFieldName = 0;
    for (MLTTerm mltTerm : mltTerms) {
        longestWd = Math.max(mltTerm.getWord().length(), longestWd);
        longestFieldName = Math.max(mltTerm.getFieldName().length(), longestFieldName);
    }
    for (MLTTerm mltTerm : mltTerms) {
        String paddedfieldName = Strings.padEnd(mltTerm.getFieldName(), longestFieldName, ' ');
        String paddedWd = Strings.padEnd(mltTerm.getWord(), longestWd, ' ');
        it.add(paddedfieldName, paddedWd + " - " + mltTerm.valuesToString());
    }
    return it;
}

From source file:org.openengsb.core.ekb.transformation.wonderland.internal.performer.TransformationPerformer.java

/**
 * Logic for the pad step//from  w w w  .  java  2s  . c  om
 */
private void performPadStep(TransformationStep step) throws Exception {
    String value = getTypedObjectFromSourceField(step.getSourceFields()[0], String.class);
    String lengthString = step.getOperationParamater(TransformationConstants.padLength);
    String characterString = step.getOperationParamater(TransformationConstants.padCharacter);
    String directionString = step.getOperationParamater(TransformationConstants.padDirection);
    Integer length = TransformationPerformUtils.parseIntString(lengthString, true, 0);
    if (characterString == null || characterString.isEmpty()) {
        String message = "The given character string for the pad is empty. Step will be skipped.";
        LOGGER.error(message);
        throw new TransformationStepException(message);
    }
    char character = characterString.charAt(0);
    if (characterString.length() > 0) {
        LOGGER.debug("The given character string is longer than one element. The first character is used.");
    }
    if (directionString == null || !(directionString.equals("Start") || directionString.equals("End"))) {
        LOGGER.debug("Unrecognized direction string. The standard value 'Start' will be used.");
        directionString = "Start";
    }

    if (directionString.equals("Start")) {
        value = Strings.padStart(value, length, character);
    } else {
        value = Strings.padEnd(value, length, character);
    }
    setObjectToTargetField(step.getTargetField(), value);
}

From source file:org.apache.phoenix.jdbc.PhoenixConnection.java

public int executeStatements(Reader reader, List<Object> binds, PrintStream out)
        throws IOException, SQLException {
    int bindsOffset = 0;
    int nStatements = 0;
    PhoenixStatementParser parser = new PhoenixStatementParser(reader);
    try {// w w w.  jav a 2 s .  co m
        while (true) {
            PhoenixPreparedStatement stmt = null;
            try {
                stmt = new PhoenixPreparedStatement(this, parser);
                ParameterMetaData paramMetaData = stmt.getParameterMetaData();
                for (int i = 0; i < paramMetaData.getParameterCount(); i++) {
                    stmt.setObject(i + 1, binds.get(bindsOffset + i));
                }
                long start = System.currentTimeMillis();
                boolean isQuery = stmt.execute();
                if (isQuery) {
                    ResultSet rs = stmt.getResultSet();
                    if (!rs.next()) {
                        if (out != null) {
                            out.println("no rows selected");
                        }
                    } else {
                        int columnCount = 0;
                        if (out != null) {
                            ResultSetMetaData md = rs.getMetaData();
                            columnCount = md.getColumnCount();
                            for (int i = 1; i <= columnCount; i++) {
                                int displayWidth = md.getColumnDisplaySize(i);
                                String label = md.getColumnLabel(i);
                                if (md.isSigned(i)) {
                                    out.print(displayWidth < label.length() ? label.substring(0, displayWidth)
                                            : Strings.padStart(label, displayWidth, ' '));
                                    out.print(' ');
                                } else {
                                    out.print(displayWidth < label.length() ? label.substring(0, displayWidth)
                                            : Strings.padEnd(md.getColumnLabel(i), displayWidth, ' '));
                                    out.print(' ');
                                }
                            }
                            out.println();
                            for (int i = 1; i <= columnCount; i++) {
                                int displayWidth = md.getColumnDisplaySize(i);
                                out.print(Strings.padStart("", displayWidth, '-'));
                                out.print(' ');
                            }
                            out.println();
                        }
                        do {
                            if (out != null) {
                                ResultSetMetaData md = rs.getMetaData();
                                for (int i = 1; i <= columnCount; i++) {
                                    int displayWidth = md.getColumnDisplaySize(i);
                                    String value = rs.getString(i);
                                    String valueString = value == null ? QueryConstants.NULL_DISPLAY_TEXT
                                            : value;
                                    if (md.isSigned(i)) {
                                        out.print(Strings.padStart(valueString, displayWidth, ' '));
                                    } else {
                                        out.print(Strings.padEnd(valueString, displayWidth, ' '));
                                    }
                                    out.print(' ');
                                }
                                out.println();
                            }
                        } while (rs.next());
                    }
                } else if (out != null) {
                    int updateCount = stmt.getUpdateCount();
                    if (updateCount >= 0) {
                        out.println((updateCount == 0 ? "no" : updateCount)
                                + (updateCount == 1 ? " row " : " rows ")
                                + stmt.getUpdateOperation().toString());
                    }
                }
                bindsOffset += paramMetaData.getParameterCount();
                double elapsedDuration = ((System.currentTimeMillis() - start) / 1000.0);
                out.println("Time: " + elapsedDuration + " sec(s)\n");
                nStatements++;
            } finally {
                if (stmt != null) {
                    stmt.close();
                }
            }
        }
    } catch (EOFException e) {
    }
    return nStatements;
}

From source file:org.spf4j.zel.vm.Program.java

public String toAssemblyString() {
    StringBuilder result = new StringBuilder();
    result.append("Program: \n");
    for (int i = 0; i < instructions.length; i++) {
        Object obj = instructions[i];
        result.append(Strings.padEnd(Integer.toString(i), 8, ' '));
        result.append(':');
        result.append(obj);/* w ww .j ava  2s.  c  om*/
        result.append('\n');
    }
    result.append("execType = ").append(this.execType).append("\n");
    result.append("type = ").append(this.type).append("\n");
    return result.toString();
}

From source file:org.geogit.cli.GeogitCLI.java

/**
 * This prints out only porcelain commands
 * /*  w  w w .ja v  a 2 s.c o m*/
 * @param mainCommander
 * 
 * @throws IOException
 */
public void printShortCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        JCommander command = mainCommander.getCommands().get(name);
        Class<? extends Object> clazz = command.getObjects().get(0).getClass();
        String packageName = clazz.getPackage().getName();
        if (!packageName.startsWith("org.geogit.cli.plumbing")) {
            commandNames.add(name);
            longestCommandLenght = Math.max(longestCommandLenght, name.length());
        }
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogit <command> [<args>]");
        console.println();
        console.println("The most commonly used geogit commands are:");
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            console.print("\t");
            console.println(mainCommander.getCommandDescription(cmd));
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.geogit.cli.GeogitCLI.java

/**
 * This prints out all commands, including plumbing ones, without description
 * /*  www  .j a  va 2 s .  c om*/
 * @param mainCommander
 * @throws IOException
 */
public void printCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        commandNames.add(name);
        longestCommandLenght = Math.max(longestCommandLenght, name.length());
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogit <command> [<args>]");
        console.println();
        int i = 0;
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            i++;
            if (i % 3 == 0) {
                console.println();
            } else {
                console.print("\t");
            }
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.locationtech.geogig.cli.GeogigCLI.java

/**
 * This prints out only porcelain commands
 * // ww w.  ja va2  s  . co m
 * @param mainCommander
 * 
 * @throws IOException
 */
public void printShortCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        JCommander command = mainCommander.getCommands().get(name);
        Class<? extends Object> clazz = command.getObjects().get(0).getClass();
        String packageName = clazz.getPackage().getName();
        if (!packageName.startsWith("org.locationtech.geogig.cli.plumbing")) {
            commandNames.add(name);
            longestCommandLenght = Math.max(longestCommandLenght, name.length());
        }
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogig <command> [<args>]");
        console.println();
        console.println("The most commonly used geogig commands are:");
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            console.print("\t");
            console.println(mainCommander.getCommandDescription(cmd));
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.locationtech.geogig.cli.GeogigCLI.java

/**
 * This prints out all commands, including plumbing ones, without description
 * /*from w w  w  . j a  va  2  s.  c  o  m*/
 * @param mainCommander
 * @throws IOException
 */
public void printCommandList(JCommander mainCommander) {
    TreeSet<String> commandNames = Sets.newTreeSet();
    int longestCommandLenght = 0;
    // do this to ignore aliases
    for (String name : mainCommander.getCommands().keySet()) {
        commandNames.add(name);
        longestCommandLenght = Math.max(longestCommandLenght, name.length());
    }
    ConsoleReader console = getConsole();
    try {
        console.println("usage: geogig <command> [<args>]");
        console.println();
        int i = 0;
        for (String cmd : commandNames) {
            console.print(Strings.padEnd(cmd, longestCommandLenght, ' '));
            i++;
            if (i % 3 == 0) {
                console.println();
            } else {
                console.print("\t");
            }
        }
        console.flush();
    } catch (IOException e) {
        throw Throwables.propagate(e);
    }
}

From source file:org.eclipse.xtext.generator.trace.AbstractTraceRegionToString.java

protected String render() {
    final AbstractTraceRegionToString.File localFile = new AbstractTraceRegionToString.File(null);
    final LinkedHashMap<SourceRelativeURI, AbstractTraceRegionToString.File> remoteFiles = CollectionLiterals.<SourceRelativeURI, AbstractTraceRegionToString.File>newLinkedHashMap();
    final List<AbstractTraceRegionToString.RegionHandle> roothandles = CollectionLiterals.<AbstractTraceRegionToString.RegionHandle>newArrayList();
    final int maxid = this.collect(this.getTrace(), 1, localFile, remoteFiles, roothandles);
    final int idwidth = Integer.toString(maxid, this.radix).length();
    List<String> _render = this.render(localFile, idwidth);
    Iterables.<String>addAll(localFile.lines, _render);
    Collection<AbstractTraceRegionToString.File> _values = remoteFiles.values();
    for (final AbstractTraceRegionToString.File file : _values) {
        List<String> _render_1 = this.render(file, idwidth);
        Iterables.<String>addAll(file.lines, _render_1);
    }//from   w  w w .  java 2  s.  com
    final Function1<String, Integer> _function = (String it) -> {
        return Integer.valueOf(it.length());
    };
    Integer _max = IterableExtensions
            .<Integer>max(ListExtensions.<String, Integer>map(localFile.lines, _function));
    int _length = this.getLocalTitle().length();
    int _plus = (_length + 2);
    final int localWidth = Math.max((_max).intValue(), _plus);
    final Function1<AbstractTraceRegionToString.File, Integer> _function_1 = (
            AbstractTraceRegionToString.File it) -> {
        final Function1<String, Integer> _function_2 = (String it_1) -> {
            return Integer.valueOf(it_1.length());
        };
        Integer _max_1 = IterableExtensions
                .<Integer>max(ListExtensions.<String, Integer>map(it.lines, _function_2));
        int _length_1 = this.getRemoteTitle(it.uri).length();
        int _plus_1 = (_length_1 + 2);
        return Integer.valueOf(Math.max((_max_1).intValue(), _plus_1));
    };
    final Integer remoteWidth = IterableExtensions.<Integer>max(
            IterableExtensions.<AbstractTraceRegionToString.File, Integer>map(remoteFiles.values(),
                    _function_1));
    localFile.lines.add(0, this.title(null, localWidth));
    Collection<AbstractTraceRegionToString.File> _values_1 = remoteFiles.values();
    for (final AbstractTraceRegionToString.File file_1 : _values_1) {
        file_1.lines.add(0, this.title(file_1.uri, (remoteWidth).intValue()));
    }
    final List<String> left = localFile.lines;
    final Function1<AbstractTraceRegionToString.File, List<String>> _function_2 = (
            AbstractTraceRegionToString.File it) -> {
        return it.lines;
    };
    final List<String> right = IterableExtensions.<String>toList(
            Iterables.<String>concat(IterableExtensions.<AbstractTraceRegionToString.File, List<String>>map(
                    remoteFiles.values(), _function_2)));
    final ArrayList<String> result = CollectionLiterals.<String>newArrayList();
    if (this.showLegend) {
        result.add(
                "Regions are surrounded by [N[ ... ]N]. Regions on the left and right with the same N are associated.");
    }
    for (int i = 0; ((i < ((Object[]) Conversions.unwrapArray(left, Object.class)).length)
            || (i < ((Object[]) Conversions.unwrapArray(right, Object.class)).length)); i++) {
        {
            String _xifexpression = null;
            int _size = left.size();
            boolean _lessThan = (i < _size);
            if (_lessThan) {
                _xifexpression = left.get(i);
            } else {
                _xifexpression = "";
            }
            final String l = Strings.padEnd(_xifexpression, localWidth, ' ');
            String _xifexpression_1 = null;
            int _size_1 = right.size();
            boolean _lessThan_1 = (i < _size_1);
            if (_lessThan_1) {
                _xifexpression_1 = right.get(i);
            } else {
                _xifexpression_1 = "";
            }
            final String r = _xifexpression_1;
            result.add(((l + " | ") + r));
        }
    }
    if (this.showTree) {
        String _repeat = Strings.repeat("-", ((localWidth + (remoteWidth).intValue()) + 3));
        result.add(_repeat);
        if (this.showLegend) {
            result.add(
                    "<N>: <isDebug> <offset>-<length> <RegionJavaClass> -> <LocationJavaClass>[<offset>,<length>,<uri>]");
        }
        final Function1<AbstractTraceRegionToString.RegionHandle, Set<AbstractTraceRegionToString.RegionHandle>> _function_3 = (
                AbstractTraceRegionToString.RegionHandle it) -> {
            final Function1<AbstractTraceRegionToString.RegionHandle, Iterable<AbstractTraceRegionToString.RegionHandle>> _function_4 = (
                    AbstractTraceRegionToString.RegionHandle it_1) -> {
                return it_1.children;
            };
            return this.<AbstractTraceRegionToString.RegionHandle>collect(it, _function_4);
        };
        final Iterable<AbstractTraceRegionToString.RegionHandle> allhandles = Iterables.<AbstractTraceRegionToString.RegionHandle>concat(
                ListExtensions.<AbstractTraceRegionToString.RegionHandle, Set<AbstractTraceRegionToString.RegionHandle>>map(
                        roothandles, _function_3));
        final Function1<AbstractTraceRegionToString.RegionHandle, Integer> _function_4 = (
                AbstractTraceRegionToString.RegionHandle it) -> {
            return Integer.valueOf(it.region.getMyOffset());
        };
        final int offsetWidth = String.valueOf(IterableExtensions.<Integer>max(
                IterableExtensions.<AbstractTraceRegionToString.RegionHandle, Integer>map(allhandles,
                        _function_4)))
                .length();
        final Function1<AbstractTraceRegionToString.RegionHandle, Integer> _function_5 = (
                AbstractTraceRegionToString.RegionHandle it) -> {
            return Integer.valueOf(it.region.getMyLength());
        };
        final int lengthWidth = String.valueOf(IterableExtensions.<Integer>max(
                IterableExtensions.<AbstractTraceRegionToString.RegionHandle, Integer>map(allhandles,
                        _function_5)))
                .length();
        for (final AbstractTraceRegionToString.RegionHandle handle : roothandles) {
            this.render(handle, idwidth, offsetWidth, lengthWidth, 1, result);
        }
    }
    return IterableExtensions.join(result, org.eclipse.xtext.util.Strings.newLine());
}