List of usage examples for com.google.common.base Strings padEnd
public static String padEnd(String string, int minLength, char padChar)
From source file:harp.HarpMain.java
public static void main(String[] args) throws Exception { if (args.length == 0 || !OPERATIONS.containsKey(args[0])) { System.err.println("Harp usage:"); System.err.println("java -jar <path to harp jar> OPERATION arg..."); System.err.println();/*from w w w .jav a2 s . com*/ System.err.println("Where operation is one of these commands:"); for (Entry<String, String> opEntry : OPERATIONS.entrySet()) { System.err.println(Strings.padEnd(opEntry.getKey(), 8, ' ') + " " + opEntry.getValue()); } System.exit(1); } String op = args[0]; switch (op) { case "run": run(args); break; case "node": node(args); break; case "test": test(args); break; } }
From source file:pro.foundev.GzipCompressionOfColumnExample.java
public static void main(String[] args) { Cluster cluster = Cluster.builder().addContactPoint("127.0.0.1").build(); try {/* ww w. j a va 2s . co m*/ String inputText = ""; Random random = new Random(); for (int i = 0; i < 1000; i++) { String randomString = String.valueOf(random.nextFloat()); String paddedRandomString = Strings.padEnd(randomString, 10, 'a'); inputText += paddedRandomString + "\n"; } Session session = cluster.newSession(); session.execute("create keyspace if not exists test with replication =" + " { 'class':'SimpleStrategy', 'replication_factor':1 } "); session.execute("create table if not exists test.blobs (id int, value blob, primary key(id))"); ByteBuffer zippedBlob = toByteBuffer(inputText); session.execute("insert into test.blobs (id, value) values (1, ?)", zippedBlob); Row row = session.execute("select * from test.blobs where id = 1 ").one(); ByteBuffer fromCassandra = row.getBytes("value"); String outputText = fromByteBuffer(fromCassandra); if (outputText.length() > 0) { System.out.println("output text is as follows"); System.out.println(outputText); } else { System.out.println("no data in value from database FAILURE!!!"); } if (inputText.equals(outputText)) { System.out.println("input text matches output text"); } else { System.exit(188); System.out.println("critical error text does not match FAILURE!!!"); } } finally { cluster.close(); } }
From source file:com.facebook.buck.cxx.platform.DebugPathSanitizer.java
/** * @return the given path as a string, expanded using {@code separator} to fulfill the required * {@code pathSize}./*from w w w .j a v a2 s . com*/ */ public static String getPaddedDir(String path, int size, char pad) { Preconditions.checkArgument(path.length() <= size, String.format("Path is too long to sanitize:\n'%s' is %d characters long, limit is %d.", path, path.length(), size)); return Strings.padEnd(path, size, pad); }
From source file:eu.itesla_project.eurostag.network.EsgName.java
public EsgName(String name, int maxLength) { if (name.length() > maxLength) { throw new RuntimeException( "Invalid id '" + name + "', expected to be less or equal to " + maxLength + " characters"); }/* w w w . ja va 2 s . c o m*/ this.name = Strings.padEnd(name, maxLength, ' '); }
From source file:net.awairo.mcmod.common.LogFormatter.java
@VisibleForTesting static String getLevelString(String levelName) { return "[" + Strings.padEnd(levelName.toUpperCase(), 7, ' ') + "]"; }
From source file:eu.itesla_project.iidm.eurostag.export.CutEurostagNamingStrategy.java
protected String getEsgId(EurostagDictionary dictionary, NameType nameType, String iidmId) { String esgId = iidmId.length() > nameType.getLength() ? iidmId.substring(0, nameType.getLength()) : Strings.padEnd(iidmId, nameType.getLength(), ' '); int counter = 0; while (dictionary.esgIdExists(esgId)) { String counterStr = Integer.toString(counter++); if (counterStr.length() > nameType.getLength()) { throw new RuntimeException("Renaming fatal error " + iidmId + " -> " + esgId); }/*from www . ja v a 2 s. c o m*/ esgId = esgId.substring(0, nameType.getLength() - counterStr.length()) + counterStr; } return esgId; }
From source file:exec.plm12.DistributedWorker.java
public void run(String serverIp, String rootFolder, String version) throws Exception { Asserts.assertNotNull(serverIp);// w w w .j av a2 s . c o m RmiUtils.setRmiDefaults(); while (true) { Logger.log(Strings.padEnd("#### restarting worker ", 80, '#')); runGarbageCollection(); try { Config config = RmiUtils.request(Config.class, serverIp); assertVersion(version, config.getVersion()); Logger.log("# version: %s", version); Logger.log("# root: %s", rootFolder); Logger.log("# dataset: %s", config.getDatasetName()); Injector injector = Guice.createInjector(new Module(rootFolder, config.getDatasetName())); ITaskScheduler<?> tp = RmiUtils.request(ITaskScheduler.class, serverIp); Logger.log("# requesting task..."); Runnable task = tp.getNextNullableTask(); if (task != null) { if (task instanceof InjectableRunnable) { ((InjectableRunnable) task).injectionForMembers(injector); } Logger.log(Strings.repeat("#", 80)); task.run(); } else { Logger.log("# no tasks available. waiting..."); Logger.log(Strings.repeat("#", 80)); Thread.sleep(5000); } } catch (Exception e) { Logger.log("# communication error:\n%s", e.getMessage()); Logger.log("# waiting..."); Logger.log(Strings.repeat("#", 80)); Thread.sleep(5000); } Logger.log(""); } }
From source file:eu.itesla_project.eurostag.EurostagScenario.java
private static String format(double f, int width) { String s = new DecimalFormat(Strings.padEnd("#.0", width + 1, '#'), SYMBOLS).format(f); if (s.length() > width) { throw new RuntimeException("Impossible to format " + f + " to " + width + " characters"); }/*from w ww. j a v a 2 s . c o m*/ return String.format("%" + width + "s", s); }
From source file:exec.plm12.LocalRunner.java
public void run(String selector, int numIterations, Injector injector) throws Exception { Asserts.assertNotNull(selector);//from www.j a va 2s . c o m Asserts.assertGreaterThan(numIterations, 0); for (int itNum = 0; itNum < numIterations; itNum++) { String itHeader = String.format("##### iteration %d/%d ", (itNum + 1), numIterations); log(Strings.repeat("#", 80)); log(Strings.padEnd(itHeader, 80, '#')); log(Strings.repeat("#", 80)); log(""); TaskScheduler<?> scheduler = createScheduler(selector, injector); Runnable task = scheduler.getNextNullableTask(); while (task != null) { String taskHeader = String.format("##### next task (in iteration %d/%d) ", (itNum + 1), numIterations); log(Strings.padEnd(taskHeader, 80, '#')); log(""); if (task instanceof InjectableRunnable) { ((InjectableRunnable) task).injectionForMembers(injector); } task.run(); task = scheduler.getNextNullableTask(); } } String itHeader = String.format("##### %d iterations finished ", numIterations); log(Strings.repeat("#", 80)); log(Strings.padEnd(itHeader, 80, '#')); log(Strings.repeat("#", 80)); }
From source file:org.aicer.grok.util.Grok.java
private static final void displayResults(final Map<String, String> results) { if (results != null) { for (Map.Entry<String, String> entry : results.entrySet()) { System.out.println(Strings.padEnd(entry.getKey(), 11, ' ') + " = " + entry.getValue()); }/*w w w. jav a 2s .c o m*/ } }