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.dates.DateMapFunctions.java

/**
 * Returns a StringColumn with the year and day-of-year derived from this column concatenated into a String
 * that will sort lexicographically in temporal order.
 * <p>//  www .  ja v  a2 s.c o  m
 * This simplifies the production of plots and tables that aggregate values into standard temporal units (e.g.,
 * you want monthly data but your source data is more than a year long and you don't want months from different
 * years aggregated together).
 */
default StringColumn yearDay() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & month");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (DateColumn.valueIsMissing(c1)) {
            newColumn.appendMissing();
        } else {
            String ym = String.valueOf(PackedLocalDate.getYear(c1));
            ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getDayOfYear(c1)), 3, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}

From source file:com.eucalyptus.auth.login.Hmacv4LoginModule.java

private String digestUTF8(final String text) {
    return Strings.padStart(
            new BigInteger(1, Digest.SHA256.get().digest(text.getBytes(Charsets.UTF_8))).toString(16), 64, '0');
}

From source file:tech.tablesaw.columns.datetimes.DateTimeMapFunctions.java

/**
 * Returns a StringColumn with the year and month from this column concatenated into a String that will sort
 * lexicographically in temporal order.//from  w  ww .j  a v a  2 s .  c  o m
 * <p>
 * This simplifies the production of plots and tables that aggregate values into standard temporal units (e.g.,
 * you want monthly data but your source data is more than a year long and you don't want months from different
 * years aggregated together).
 */
default StringColumn yearMonth() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & month");
    for (int r = 0; r < this.size(); r++) {
        long c1 = this.getLongInternal(r);
        if (DateTimeColumn.valueIsMissing(c1)) {
            newColumn.append(StringColumnType.missingValueIndicator());
        } else {
            String ym = String.valueOf(getYear(c1));
            ym = ym + "-" + Strings.padStart(String.valueOf(getMonthValue(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}

From source file:org.fenixedu.treasury.domain.document.FinantialDocument.java

public String getUiDocumentNumber() {
    return String.format("%s %s/%s",
            this.getDocumentNumberSeries().getFinantialDocumentType().getDocumentNumberSeriesPrefix(),
            this.getDocumentNumberSeries().getSeries().getCode(),
            Strings.padStart(this.getDocumentNumber(), 7, '0'));
}

From source file:org.exoplatform.acceptance.ui.model.CurrentUser.java

/**
 * Computes the gravatar URL associated to the user email
 *
 * @param size  The size (width) of the image to generate
 * @param https If the URL must be in HTTPs or no
 * @return The URL of the gravatar/*from w  w w  .j a  v a 2  s  . c om*/
 * @throws java.security.NoSuchAlgorithmException If MD5 Algorithm isn't available
 */
public String getGravatarUrl(int size, boolean https) throws NoSuchAlgorithmException {
    MessageDigest digest = MessageDigest.getInstance("MD5");
    digest.update(getCurrentUser().getEmail().trim().toLowerCase().getBytes(Charset.defaultCharset()));
    String hash = Strings.padStart(new BigInteger(1, digest.digest()).toString(16), 32, '0');
    if (https) {
        return "https://secure.gravatar.com/avatar/" + hash + "?s=" + size + "&d=mm";
    } else {
        return "http://www.gravatar.com/avatar/" + hash + "?s=" + size + "&d=mm";
    }
}

From source file:org.kegbot.core.hardware.KegboardController.java

synchronized void setSerialNumber(final String serialNumber) {
    if (mSerialNumber.equals(serialNumber)) {
        return;//from  w w  w  .  j  a v a  2 s . co m
    }
    if (!mSerialNumber.isEmpty()) {
        Log.w(TAG, String.format("Ignoring serial number change from=%s to=%s.", mSerialNumber, serialNumber));
        return;
    }

    final Matcher matcher = SERIAL_RE.matcher(serialNumber);
    if (matcher.matches()) {
        final String g1 = matcher.group(1);
        final String g2 = matcher.group(2);
        final String g3 = Strings.padStart(matcher.group(3), 8, '0');

        Log.d(TAG, "setSerialNumber: " + mSerialNumber);
        mSerialNumber = String.format("KB-%s-%s-%s", g1, g2, g3);
        mName = getShortNameFromSerialNumber(mSerialNumber);
    } else {
        Log.w(TAG, "Unknown serial number, ignoring: " + serialNumber);
    }
}

From source file:com.tarvon.fractala.util.ColorHelper.java

private void chooseColor(JTextField f) {
    // pick existing field color
    Color prev;/*from   ww  w. j  av a 2 s. c  o m*/
    try {
        prev = Color.decode(f.getText());
    } catch (Exception ex) {
        prev = Color.BLACK;
    }

    // let the user pick a color
    colorChooser.setColor(prev);
    colorChooserOk = false;
    colorChooserDialog.setVisible(true);
    Color picked = colorChooser.getColor();

    // then assign
    if (colorChooserOk) {
        String c = Integer.toHexString(picked.getRGB());
        if (c.length() == 7) {
            c = c.substring(1, 7);
        } else if (c.length() > 7) {
            c = c.substring(2, 8);
        } else if (c.length() < 6) {
            c = Strings.padStart(c, 6, '0');
        }
        f.setText("#" + c);

        // update gui post return
        update();
    }
}

From source file:org.apache.hadoop.mapred.JobTrackerHAServiceProtocol.java

/**
 * @return zero padded counter with sys dir prefix
 *///from  w  w  w.  j av a2s  .c o m
private String createSysDirName(long counter) {
    String paddedCounter = Strings.padStart("" + counter, 12, '0');
    return SYSTEM_DIR_SEQUENCE_PREFIX + paddedCounter;
}

From source file:org.apache.drill.exec.store.parquet.ParquetResultListener.java

public void printColumnMajor(ValueVector vv) {
    if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
        System.out.println("\n" + vv.getField().getAsSchemaPath().getRootSegment().getPath());
    }/* w ww.ja va  2 s .co  m*/
    for (int j = 0; j < vv.getAccessor().getValueCount(); j++) {
        if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
            Object o = vv.getAccessor().getObject(j);
            if (o instanceof byte[]) {
                try {
                    o = new String((byte[]) o, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.print(Strings.padStart(o + "", 20, ' ') + " ");
            System.out.print(", " + (j % 25 == 0 ? "\n batch:" + batchCounter + " v:" + j + " - " : ""));
        }
    }
    if (ParquetRecordReaderTest.VERBOSE_DEBUG) {
        System.out.println("\n" + vv.getAccessor().getValueCount());
    }
}

From source file:tech.tablesaw.columns.dates.DateMapFunctions.java

/**
 * Returns a StringColumn with the year and week-of-year derived from this column concatenated into a String
 * that will sort lexicographically in temporal order.
 * <p>//from w  ww  .j  av a2  s  .co m
 * This simplifies the production of plots and tables that aggregate values into standard temporal units (e.g.,
 * you want monthly data but your source data is more than a year long and you don't want months from different
 * years aggregated together).
 */
default StringColumn yearWeek() {
    StringColumn newColumn = StringColumn.create(this.name() + " year & month");
    for (int r = 0; r < this.size(); r++) {
        int c1 = this.getIntInternal(r);
        if (DateColumn.valueIsMissing(c1)) {
            newColumn.appendMissing();
        } else {
            String ym = String.valueOf(PackedLocalDate.getYear(c1));
            ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getWeekOfYear(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}