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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:tech.tablesaw.columns.times.PackedLocalTime.java

public static String toShortTimeString(int time) {
    if (time == TimeColumnType.missingValueIndicator()) {
        return "";
    }//from   ww  w. j  a  va  2s .  co m

    byte hourByte = (byte) (time >> 24);
    byte minuteByte = (byte) (time >> 16);
    byte millisecondByte1 = (byte) (time >> 8);
    byte millisecondByte2 = (byte) time;
    char millis = (char) ((millisecondByte1 << 8) | (millisecondByte2 & 0xFF));
    int second = millis / 1000;

    return String.format("%s:%s:%s", Strings.padStart(Byte.toString(hourByte), 2, '0'),
            Strings.padStart(Byte.toString(minuteByte), 2, '0'),
            Strings.padStart(Integer.toString(second), 2, '0'));
}

From source file:entities.FacDocumentosmaster.java

public String determinarNumFactura() {
    int fin = cfgDocumento.getFinDocumento();
    String aux = String.valueOf(fin);
    String numDocumento = String.valueOf(getFacDocumentosmasterPK().getNumDocumento());
    return cfgDocumento.getPrefijoDoc().concat(Strings.padStart(numDocumento, aux.length(), '0'));
}

From source file:org.jooby.internal.AppPrinter.java

private String configTree(final String[] sources, final int i) {
    if (i < sources.length) {
        return new StringBuilder().append(Strings.padStart("", i, ' ')).append(" ").append(sources[i])
                .append("\n").append(configTree(sources, i + 1)).toString();
    }/*  w w w  . j  a  v a 2 s.c  o  m*/
    return "";
}

From source file:tech.tablesaw.columns.times.TimeMapFunctions.java

/**
 * Returns a StringColumn with the hour and minute-of-hour derived from this column concatenated into a String
 * that will sort lexicographically in temporal order.
 * <p>/*  www  .ja  va2s  .  com*/
 * This simplifies the production of plots and tables that aggregate values into standard temporal units
 */
default StringColumn hourMinute() {
    StringColumn newColumn = StringColumn.create(this.name() + " hour & minute");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (TimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String hm = Strings.padStart(String.valueOf(PackedLocalTime.getHour(c1)), 2, '0');
            hm = hm + "-" + Strings.padStart(String.valueOf(PackedLocalTime.getMinute(c1)), 2, '0');
            newColumn.append(hm);
        }
    }
    return newColumn;
}

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

/**
 * Logic for the pad step//  ww w .  j  ava 2 s.  co  m
 */
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.opensha2.geo.RegionUtils.java

private static String toHex(int i) {
    return Strings.padStart(Integer.toHexString(i), 2, '0');
}

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 {/*from www. ja v  a  2 s  .c om*/
        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:com.google.gerrit.server.mail.send.CommentSender.java

/**
 * @return grouped inline comment data mapped to data structures that are suitable for passing
 *     into Soy./* www.jav a 2 s .  c  o m*/
 */
private List<Map<String, Object>> getCommentGroupsTemplateData(Repository repo) {
    List<Map<String, Object>> commentGroups = new ArrayList<>();

    for (CommentSender.FileCommentGroup group : getGroupedInlineComments(repo)) {
        Map<String, Object> groupData = new HashMap<>();
        groupData.put("link", group.getLink());
        groupData.put("title", group.getTitle());
        groupData.put("patchSetId", group.patchSetId);

        List<Map<String, Object>> commentsList = new ArrayList<>();
        for (Comment comment : group.comments) {
            Map<String, Object> commentData = new HashMap<>();
            commentData.put("lines", getLinesOfComment(comment, group.fileData));
            commentData.put("message", comment.message.trim());
            List<CommentFormatter.Block> blocks = CommentFormatter.parse(comment.message);
            commentData.put("messageBlocks", commentBlocksToSoyData(blocks));

            // Set the prefix.
            String prefix = getCommentLinePrefix(comment);
            commentData.put("linePrefix", prefix);
            commentData.put("linePrefixEmpty", Strings.padStart(": ", prefix.length(), ' '));

            // Set line numbers.
            int startLine;
            if (comment.range == null) {
                startLine = comment.lineNbr;
            } else {
                startLine = comment.range.startLine;
                commentData.put("endLine", comment.range.endLine);
            }
            commentData.put("startLine", startLine);

            // Set the comment link.
            if (comment.lineNbr == 0) {
                commentData.put("link", group.getLink());
            } else if (comment.side == 0) {
                commentData.put("link", group.getLink() + "@a" + startLine);
            } else {
                commentData.put("link", group.getLink() + '@' + startLine);
            }

            // Set robot comment data.
            if (comment instanceof RobotComment) {
                RobotComment robotComment = (RobotComment) comment;
                commentData.put("isRobotComment", true);
                commentData.put("robotId", robotComment.robotId);
                commentData.put("robotRunId", robotComment.robotRunId);
                commentData.put("robotUrl", robotComment.url);
            } else {
                commentData.put("isRobotComment", false);
            }

            // If the comment has a quote, don't bother loading the parent message.
            if (!hasQuote(blocks)) {
                // Set parent comment info.
                Optional<Comment> parent = getParent(comment);
                if (parent.isPresent()) {
                    commentData.put("parentMessage", getShortenedCommentMessage(parent.get()));
                }
            }

            commentsList.add(commentData);
        }
        groupData.put("comments", commentsList);

        commentGroups.add(groupData);
    }
    return commentGroups;
}

From source file:com.facebook.presto.hive.HiveWriterFactory.java

public static String computeBucketedFileName(String filePrefix, int bucket) {
    return filePrefix + "_bucket-" + Strings.padStart(Integer.toString(bucket), BUCKET_NUMBER_PADDING, '0');
}

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

protected void render(final AbstractTraceRegionToString.RegionHandle region, final int idW, final int offsetW,
        final int lengthW, final int indent, final List<String> result) {
    final String id = Strings.padStart(Integer.toString(region.id, this.radix), idW, '0');
    String _xifexpression = null;
    boolean _isUseForDebugging = region.region.isUseForDebugging();
    if (_isUseForDebugging) {
        _xifexpression = "D";
    } else {/*from   w w  w .j  a  v a 2  s . c  om*/
        _xifexpression = " ";
    }
    final String debug = _xifexpression;
    final String offset = Strings.padStart(Integer.toString(region.region.getMyOffset()), offsetW, '0');
    final String length = Strings.padStart(Integer.toString(region.region.getMyLength()), lengthW, '0');
    final String space = Strings.repeat(" ", indent);
    final String name = region.region.getClass().getSimpleName();
    final Function1<AbstractTraceRegionToString.LocationHandle, String> _function = (
            AbstractTraceRegionToString.LocationHandle it) -> {
        return this.render(it);
    };
    final String locations = IterableExtensions.join(
            ListExtensions.<AbstractTraceRegionToString.LocationHandle, String>map(region.locations, _function),
            ", ");
    final String loc = (((((debug + " ") + offset) + "-") + length) + space);
    final String header = (((((id + ": ") + loc) + name) + " -> ") + locations);
    boolean _isEmpty = region.children.isEmpty();
    if (_isEmpty) {
        result.add(header);
    } else {
        result.add((header + " {"));
        for (final AbstractTraceRegionToString.RegionHandle child : region.children) {
            this.render(child, idW, offsetW, lengthW, (indent + 2), result);
        }
        String _repeat = Strings.repeat(" ", loc.length());
        String _plus = ((id + ": ") + _repeat);
        String _plus_1 = (_plus + "}");
        result.add(_plus_1);
    }
}