List of usage examples for com.google.common.base Strings padStart
public static String padStart(String string, int minLength, char padChar)
From source file:tech.tablesaw.columns.instant.PackedInstant.java
public static String toString(long dateTime) { if (dateTime == Long.MIN_VALUE) { return ""; }/*from ww w. j av a2s .co m*/ int date = date(dateTime); int time = time(dateTime); return "" + PackedLocalDate.getYear(date) + "-" + Strings.padStart(Byte.toString(PackedLocalDate.getMonthValue(date)), 2, '0') + "-" + Strings.padStart(Byte.toString(PackedLocalDate.getDayOfMonth(date)), 2, '0') + "T" + Strings.padStart(Byte.toString(PackedLocalTime.getHour(time)), 2, '0') + ":" + Strings.padStart(Byte.toString(PackedLocalTime.getMinute(time)), 2, '0') + ":" + Strings.padStart(Byte.toString(PackedLocalTime.getSecond(time)), 2, '0') + "." + Strings.padStart(String.valueOf(PackedLocalTime.getMilliseconds(time)), 3, '0') + "Z"; }
From source file:io.fluo.stress.trie.Split.java
private static TreeSet<Text> genSplits(int level, int numTablets) { TreeSet<Text> splits = new TreeSet<>(); String ls = String.format("%02d:", level); int numSplits = numTablets - 1; int distance = (((int) Math.pow(Character.MAX_RADIX, Node.HASH_LEN) - 1) / numTablets) + 1; int split = distance; for (int i = 0; i < numSplits; i++) { splits.add(new Text( ls + Strings.padStart(Integer.toString(split, Character.MAX_RADIX), Node.HASH_LEN, '0'))); split += distance;//w w w. j av a 2 s .c o m } splits.add(new Text(ls + "~")); return splits; }
From source file:org.cinchapi.concourse.util.Versions.java
/** * Convert a numerical version in decimal form (i.e. 0.4.1) to a long * that respects natural version number ordering. For example, the long * conversion for 0.5.0 is guaranteed to be greater than the long * conversion for 0.4.1./*from www . j a v a 2 s .c om*/ * <p> * The {@code maxComponentLength} parameter is used to ensure that each * component of the version has the necessary padding. You should specify * this value to be the largest possible length of a version number * component in your scheme (i.e. for version A.B.C if component C may * possible go up as high as 999, then you should specify 3 for the * maxComponentLength value). * </p> * <p> * <strong>Warning:</strong>If one or more of the component lengths is * greater than {@code maxComponentLength} then this method will use the * larger component length in its calculation. This may potentially lead to * unexpected results, so its best to specify the {@code maxComponentLength} * to be sufficiently large. * </p> * * @param version * @param maxComponentLength * @return the long representation of the version */ public static long toLongRepresentation(String version, int maxComponentLength) { String[] toks = version.split("\\."); int n = maxComponentLength; List<Integer> parts = Lists.newArrayList(); // figure out max component length for (String tok : toks) { n = Math.max(n, tok.length()); } // do any padding and parse to int for (String tok : toks) { parts.add(Integer.parseInt(Strings.padStart(tok, n, Character.forDigit(0, 10)))); } long sum = 0; for (int i = 0; i < parts.size(); i++) { sum += parts.get(i) * Math.pow(10, (n * parts.size() - (i + 1))); } return sum; }
From source file:com.surgeplay.visage.VisageFormatter.java
@Override public String format(LogRecord record) { if (record.getThrown() != null) { record.getThrown().printStackTrace(); }/*from ww w. ja v a 2 s .c o m*/ Ansi ansi = Ansi.ansi(); if (Visage.ansi) { ansi.fgBright(Color.BLACK); } Date date = new Date(record.getMillis()); ansi.a("@"); ansi.a(format.format(date)); if (Visage.ansi) { ansi.reset(); } ansi.a(Strings.padStart(Thread.currentThread().getName(), 22, ' ')); ansi.a(" "); if (Visage.ansi && colors.containsKey(record.getLevel())) { ansi.fgBright(colors.get(record.getLevel())); } ansi.a(names.get(record.getLevel())); if (Visage.ansi) { ansi.reset(); } ansi.a(": "); if (Visage.ansi && colors.containsKey(record.getLevel()) && record.getLevel().intValue() >= Level.SEVERE.intValue()) { ansi.bold(); ansi.fgBright(colors.get(record.getLevel())); } ansi.a(record.getMessage()); if (Visage.ansi) { ansi.reset(); } ansi.a("\n"); return ansi.toString(); }
From source file:com.spotify.metrics.ffwd.Percentile.java
private double toQuantile(int whole, int decimal) { return Double.parseDouble("0." + Strings.padStart("" + whole, 2, '0') + decimal); }
From source file:com.opengamma.strata.report.framework.format.AsciiTable.java
private static String formatValue(StringBuilder buf, int colLength, AsciiTableAlignment alignment, String value) {/* w w w .j a va2 s . co m*/ if (alignment == AsciiTableAlignment.RIGHT) { return Strings.padStart(value, colLength, ' '); } else { return Strings.padEnd(value, colLength, ' '); } }
From source file:de.brands4friends.daleq.core.internal.formatting.MarkdownTableFormatter.java
private void appendBody(final TableData table, final Appendable appendable, final List<Column> columns) throws IOException { for (RowData row : table.getRows()) { appendSeparator(appendable);//from w w w .j av a2 s . c o m for (Column column : columns) { appendWhitespace(appendable); final FieldData field = row.getFieldBy(column.name); final String value = field.getValue().or(""); if (column.alignment == Alignment.LEFT) { appendable.append(Strings.padEnd(value, column.width, PAD_CHAR)); } else { appendable.append(Strings.padStart(value, column.width, PAD_CHAR)); } appendWhitespace(appendable); appendSeparator(appendable); } appendNewline(appendable); } }
From source file:org.jclouds.kinetic.util.Utils.java
private static String padStringValue(String value, int length) { return Strings.padStart(value, length, '\0'); }
From source file:appeng.parts.automation.PlaneConnections.java
public String getFilenameSuffix() { String suffix = Integer.toBinaryString(getIndex()); return Strings.padStart(suffix, 4, '0'); }
From source file:eu.thebluemountain.customers.dctm.brownbag.badcontentslister.Content.java
/** * The method appends the path representation * @param sb is the string builder to append to * @param ticket is the actual ticket to represent as path * @param sep is the path separator to use * @return the supplied buffer/*from w w w . j a v a2s . co m*/ */ public static StringBuilder pathOf(StringBuilder sb, int ticket, char sep) { String path = Strings.padStart(UnsignedInteger.fromIntBits(ticket).toString(16), 8, '0'); return sb.append(path.charAt(0)).append(path.charAt(1)).append(sep).append(path.charAt(2)) .append(path.charAt(3)).append(sep).append(path.charAt(4)).append(path.charAt(5)).append(sep) .append(path.charAt(6)).append(path.charAt(7)); }