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:org.onlab.util.Tools.java

/**
 * Converts a long value to hex string; 16 wide and sans 0x.
 *
 * @param value long value//from  w ww. ja v  a 2s .  co m
 * @param width string width; zero padded
 * @return hex string
 */
public static String toHex(long value, int width) {
    return Strings.padStart(UnsignedLongs.toString(value, 16), width, '0');
}

From source file:org.opendaylight.infrautils.utils.mdc.ExecutionOrigin.java

/**
 * The exact internal implementation format of this ID may change over time, and
 * should not be relied upon. It currently is a char '0' padded base-32 encoded
 * atomically incremented 64 bit long./*from  ww  w .j ava 2  s.  c o  m*/
 */
@Override
public String mdcValueString() {
    if (idAsString == null) {
        String nextIdString = Long.toUnsignedString(id, RADIX).toUpperCase(Locale.ENGLISH);
        String paddedNextIdString = Strings.padStart(nextIdString, ID_STRING_MAX_LENGTH, '0');
        this.idAsString = paddedNextIdString;
    }
    return idAsString;
}

From source file:pt.ist.fenixedu.integration.task.exportData.humanResources.ExportEmployeeInfo.java

private void register(final JsonArray result, final User user, final CategoryType type, final String wp,
        final String employer) {
    final JsonObject object = new JsonObject();
    object.addProperty("user", user.getUsername());
    object.addProperty("role", type.name());
    object.addProperty("wp", Strings.padStart(wp, 4, '0'));
    object.addProperty("employer", employer);
    result.add(object);/*from   w ww  .  j  av  a  2s  .  com*/
}

From source file:tech.tablesaw.columns.strings.StringMapFunctions.java

default StringColumn padStart(int minLength, char padChar) {

    StringColumn newColumn = StringColumn.create(name() + "[pad]");

    for (int r = 0; r < size(); r++) {
        String value = getString(r);
        newColumn.append(Strings.padStart(value, minLength, padChar));
    }//  w  ww . j  a  v a2  s .co m
    return newColumn;
}

From source file:pt.ist.fenixedu.libraryattendance.ui.ManageCapacityAndLockersDA.java

private void setLockers(Space library, int lockers, DateTime today) throws IOException {
    int highestLocker = 0;
    for (Space relSpace : library.getChildren()) {
        Space space = relSpace;//from  w w w .j a  va2s  .c o m
        int lockerNumber;
        try {
            lockerNumber = Integer.parseInt(space.getName());
            if (lockerNumber > lockers) {
                final InformationBean bean = space.bean();
                bean.setValidUntil(today);
                space.bean(bean);
            } else {
                setCapacity(space, 1);
            }
            if (lockerNumber > highestLocker) {
                highestLocker = lockerNumber;
            }
        } catch (NumberFormatException e) {
        }
    }
    if (highestLocker < lockers) {
        for (int i = highestLocker + 1; i <= lockers; i++) {
            final InformationBean bean = Information.builder()
                    .name(Strings.padStart(Integer.toString(i), String.valueOf(lockers).length(), '0'))
                    .classification(SpaceClassification.getByName(SpaceUtils.ROOM_SUBDIVISION)).validFrom(today)
                    .allocatableCapacity(1).bean();
            new Space(library, bean);
        }
    }
}

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

/**
 * Returns a StringColumn with the year and month from this column concatenated into a String that will sort
 * lexicographically in temporal order.//w  w w .java 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++) {
        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.getMonthValue(c1)), 2, '0');
            newColumn.append(ym);
        }
    }
    return newColumn;
}

From source file:com.outerspacecat.icalendar.UtcOffsetType.java

@Override
public String toICalendar() {
    return (isNegative() ? "-" : "+") + Strings.padStart(String.valueOf(getHours()), 2, '0')
            + Strings.padStart(String.valueOf(getMinutes()), 2, '0')
            + Strings.padStart(String.valueOf(getSeconds()), 2, '0');
}

From source file:org.apache.rya.indexing.pcj.fluo.app.util.BindingHashShardingFunction.java

private static String genHash(Bytes row) {
    int hash = Hashing.murmur3_32().hashBytes(row.toArray()).asInt();
    hash = hash & 0x7fffffff;/*from w w w . j a  va 2 s .  c o  m*/
    // base 36 gives a lot more bins in 4 bytes than hex, but it is still human readable which is
    // nice for debugging.
    String hashString = Strings.padStart(Integer.toString(hash, Character.MAX_RADIX), HASH_LEN, '0');
    hashString = hashString.substring(hashString.length() - HASH_LEN);
    return hashString;
}

From source file:org.apache.fluo.recipes.core.map.CollisionFreeMap.java

static String genBucketId(int bucket, int maxBucket) {
    Preconditions.checkArgument(bucket >= 0);
    Preconditions.checkArgument(maxBucket > 0);

    int bits = 32 - Integer.numberOfLeadingZeros(maxBucket);
    int bucketLen = bits / 4 + (bits % 4 > 0 ? 1 : 0);

    return Strings.padStart(Integer.toHexString(bucket), bucketLen, '0');
}

From source file:com.facebook.buck.cxx.platform.ObjectFileScrubbers.java

private static void putSpaceLeftPaddedString(ByteBuffer buffer, int len, String value) {
    Preconditions.checkState(value.length() <= len);
    value = Strings.padStart(value, len, ' ');
    buffer.put(value.getBytes(Charsets.US_ASCII));
}