List of usage examples for com.google.common.base Strings padStart
public static String padStart(String string, int minLength, char padChar)
From source file:org.ow2.proactive.scheduler.task.context.TaskContextSerializer.java
/** * Serializes a task context to disk.// ww w .j av a2 s . c om * @param context The context object to serialize. * @param directory The directory where to save the context object. * @return A file pointing/holding the serialized context object. * @throws IOException */ public File serializeContext(TaskContext context, File directory) throws IOException { // prefix must be at least 3 characters long String tmpFilePrefix = Strings.padStart(context.getTaskId().value(), 3, '0'); File file = File.createTempFile(tmpFilePrefix, null, directory); try (ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(file))) { objectOutputStream.writeObject(context); } if (context.isRunAsUser()) { ForkerUtils.setSharedPermissions(file); } return file; }
From source file:org.apache.fluo.recipes.data.RowHasher.java
public Pirtos getTableOptimizations(int numTablets) { List<Bytes> splits = new ArrayList<>(numTablets - 1); int numSplits = numTablets - 1; int distance = (((int) Math.pow(Character.MAX_RADIX, HASH_LEN) - 1) / numTablets) + 1; int split = distance; for (int i = 0; i < numSplits; i++) { splits.add(Bytes//from w ww . j a v a2 s . c om .of(prefix + Strings.padStart(Integer.toString(split, Character.MAX_RADIX), HASH_LEN, '0'))); split += distance; } splits.add(Bytes.of(prefix + "~")); Pirtos pirtos = new Pirtos(); pirtos.setSplits(splits); pirtos.setTabletGroupingRegex(Pattern.quote(prefix.toString())); return pirtos; }
From source file:appeng.client.render.model.GlassBakedModel.java
private static ResourceLocation[] generateTexturesFrame() { return IntStream.range(1, 16).mapToObj(Integer::toBinaryString).map(s -> Strings.padStart(s, 4, '0')) .map(s -> new ResourceLocation("appliedenergistics2:blocks/glass/quartz_glass_frame" + s)) .toArray(ResourceLocation[]::new); }
From source file:com.cloudera.oryx.common.servcomp.Namespaces.java
private static String getPaddedGenerationID(int generationID) { return Strings.padStart(Integer.toString(generationID), DIGITS_IN_GENERATION_ID, '0'); }
From source file:com.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 ww w . j av a2s. c o m * <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:edu.cmu.lti.oaqa.baseqa.CasSerializer.java
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { try {/* w w w . j a v a2 s .c om*/ JCas copied = JCasFactory.createJCas(typesystem); CasCopier.copyCas(jcas.getCas(), copied.getCas(), true, true); String id = Strings.padStart(ProcessingStepUtils.getSequenceId(jcas), 4, '0'); CasIOUtil.writeXmi(copied, new File(dir, id + ".xmi")); } catch (IOException | UIMAException e) { e.printStackTrace(); } }
From source file:org.gradle.internal.hash.HashValue.java
public String asZeroPaddedHexString(int expectedLength) { return Strings.padStart(asHexString(), expectedLength, '0'); }
From source file:com.facebook.buck.debug.TraceEvent.java
/** * Converts {@code value} to a string and pads it with up to 4 spaces for improved alignment. * @param value A nonnegative value.//from w w w. jav a 2 s. c o m * @return A padded string. */ static String longToPaddedString(long value) { Preconditions.checkArgument(value >= 0, "value must be positive"); return Strings.padStart(String.valueOf(value), 5, '0'); }
From source file:com.google.javascript.jscomp.FileInstrumentationData.java
/** * Returns a byte-wise hex string representation of the BitField from * MSB (Most Significant Byte) to LSB (Least Significant Byte). * Eg. Single byte: a setting of "0001 1111", returns "1f" * Eg. Multiple bytes: a setting of "0000 0010 0001 1111", returns "1f02" * * @return string representation of bits set *//*from w ww .ja v a2s. c om*/ String getInstrumentedLinesAsHexString() { StringBuilder builder = new StringBuilder(); // Build the hex string. for (byte byteEntry : instrumentedBits.toByteArray()) { // Java bytes are signed, but we want the value as if it were unsigned. int value = UnsignedBytes.toInt(byteEntry); String hexString = Integer.toHexString(value); // Pad string to be two characters (if it isn't already). hexString = Strings.padStart(hexString, 2, '0'); builder.append(hexString); } return builder.toString(); }
From source file:io.fluo.stress.trie.Node.java
private String genHash() { long num = (number == null) ? 0l : number.longValue(); int hash = Hashing.murmur3_32().newHasher().putInt(level).putInt(nodeSize).putLong(num).hash().asInt(); hash = hash & 0x7fffffff;//ww w .j a v a 2 s .com //base 36 gives a lot more bins in 4 bytes than hex, but it still human readable which is nice for debugging. String hashString = Strings.padStart(Integer.toString(hash, Character.MAX_RADIX), HASH_LEN, '0'); return hashString.substring(hashString.length() - HASH_LEN); }