List of usage examples for com.google.common.base Strings padStart
public static String padStart(String string, int minLength, char padChar)
From source file:fathom.Services.java
public synchronized void start(Injector injector) { started = true;/*w w w .ja v a 2 s . c o m*/ getServiceClasses().forEach((serviceClass) -> { if (RequireUtil.allowClass(settings, serviceClass)) { Service service = injector.getInstance(serviceClass); instances.add(service); } }); // sort the services into the preferred start order Collections.sort(instances, new Comparator<Service>() { @Override public int compare(Service o1, Service o2) { if (o2.getPreferredStartOrder() < 0) { return -1; } else if (o1.getPreferredStartOrder() < 0) { return 1; } else if (o1.getPreferredStartOrder() < o2.getPreferredStartOrder()) { return -1; } else if (o1.getPreferredStartOrder() > o2.getPreferredStartOrder()) { return 1; } return 0; } }); for (Service service : instances) { log.debug("{} '{}'", Strings.padStart("" + service.getPreferredStartOrder(), 3, '0'), service.getClass().getName()); } for (Service service : instances) { log.info("Starting service '{}'", service.getClass().getName()); try { service.start(); } catch (Exception e) { log.error("Failed to start '{}'", service.getClass().getName(), e); if (e instanceof FatalException) { stop(); System.exit(1); } } } }
From source file:org.apache.fluo.recipes.data.RowHasher.java
private static String genHash(Bytes row) { int hash = Hashing.murmur3_32().hashBytes(row.toArray()).asInt(); hash = hash & 0x7fffffff;//from w ww. java 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:se.toxbee.sleepfighter.utils.string.StringUtils.java
/** * Joins time parts together according to {@link #TIME_JOINER}.<br/> * All the parts are padded with 1 leading zero before joining. * * @param parts the time parts to join together. * @return the time parts joined together. */// w w w. j av a 2 s.c om public static final String joinTime(Integer... parts) { String[] paddedParts = new String[parts.length]; for (int i = 0; i < parts.length; ++i) { paddedParts[i] = Strings.padStart(Integer.toString(parts[i]), 2, '0'); } return TIME_JOINER.join(paddedParts); }
From source file:org.apache.s4.core.moduleloader.ModuleLoaderTestUtils.java
public static Process testModuleLoader(boolean fork) throws Exception { Process forkedS4Node = null; // build custom-modules.jar File gradlewFile = CoreTestUtils.findGradlewInRootDir(); CoreTestUtils.callGradleTask(// w w w. j a v a 2 s . co m new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build.gradle"), "clean", new String[0]); File modulesJarFile = new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build/libs/app/custom-modules.jar"); Assert.assertFalse(modulesJarFile.exists()); CoreTestUtils.callGradleTask( new File(gradlewFile.getParentFile().getAbsolutePath() + "/test-apps/custom-modules/build.gradle"), "jar", new String[0]); // make sure it is created Assert.assertTrue(modulesJarFile.exists()); // pass it as a configuration DeploymentUtils.initAppConfig( new AppConfig.Builder().appClassName(WordCountApp.class.getName()) .customModulesURIs(ImmutableList.of(modulesJarFile.toURI().toString())) .customModulesNames(ImmutableList.of("org.apache.s4.TestListenerModule")).build(), "cluster1", true, "localhost:2181"); if (fork) { forkedS4Node = CoreTestUtils.forkS4Node(new String[] { "-c", "cluster1" }, new ZkClient("localhost:2181"), 10, "cluster1"); } else { S4Node.main(new String[] { "-c", "cluster1" }); } Injector injector = Guice.createInjector( new BaseModule(Resources.getResource("default.s4.base.properties").openStream(), "cluster1"), new DefaultCommModule(Resources.getResource("default.s4.comm.properties").openStream())); Emitter emitter = injector.getInstance(TCPEmitter.class); List<Long> messages = Lists.newArrayList(); for (int i = 0; i < NB_MESSAGES; i++) { messages.add(System.currentTimeMillis()); } ZkClient zkClient = new ZkClient("localhost:2181"); zkClient.create("/test", 0, CreateMode.PERSISTENT); final ZooKeeper zk = CommTestUtils.createZkClient(); final CountDownLatch signalMessagesReceived = new CountDownLatch(1); // watch for last message in test data sequence CoreTestUtils.watchAndSignalCreation( "/test/data" + Strings.padStart(String.valueOf(NB_MESSAGES - 1), 10, '0'), signalMessagesReceived, zk); SerializerDeserializer serDeser = injector.getInstance(SerializerDeserializerFactory.class) .createSerializerDeserializer(Thread.currentThread().getContextClassLoader()); for (Long message : messages) { Event event = new Event(); event.put("message", long.class, message); event.setStreamId("inputStream"); emitter.send(0, serDeser.serialize(event)); } // check sequential nodes in zk with correct data Assert.assertTrue(signalMessagesReceived.await(10, TimeUnit.SECONDS)); List<String> children = zkClient.getChildren("/test"); for (String child : children) { Long data = zkClient.readData("/test/" + child); Assert.assertTrue(messages.contains(data)); } return forkedS4Node; }
From source file:eu.numberfour.n4js.analysis.PositiveAnalyser.java
private String withLineNumbers(String code) { try {//from w w w . ja va2s .c o m return CharStreams.readLines(new StringReader(code), new LineProcessor<String>() { private final StringBuilder lines = new StringBuilder(); private int lineNo = 1; @Override public boolean processLine(String line) throws IOException { lines.append(Strings.padStart(String.valueOf(lineNo++), 3, ' ')).append(": ").append(line) .append("\n"); return true; } @Override public String getResult() { return lines.toString(); } }); } catch (IOException e) { throw new IllegalStateException(e.getMessage()); } }
From source file:tech.tablesaw.columns.datetimes.PackedLocalDateTime.java
public static String toString(long dateTime) { if (dateTime == Long.MIN_VALUE) { return ""; }/*from w w w . j av a 2s.c om*/ 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'); }
From source file:pt.ist.fenix.task.exportData.academic.EnrolmentStatistics.java
private void writeResults() { taskLog("Total -> " + totalEnrolments); taskLog("********************************"); int total = 0; for (Entry<Integer, Integer> entry : enrolmentsNumber.entrySet()) { Integer value = entry.getValue(); taskLog(entry.getKey() + " Inscricao -> " + value); total += value;/*from w w w . java2 s. com*/ } taskLog("Total de alunos inscritos -> " + total); taskLog("********************************"); int totalEnrolments = 0; for (Entry<DegreeCurricularPlan, GenericPair<Integer, Integer>> entry : degreesMap.entrySet()) { String degreeName = Strings.padEnd(entry.getKey().getName(), 12, ' '); //degree name -> students enrolled - number of enrolments taskLog(degreeName + " -> " + Strings.padStart(entry.getValue().getLeft().toString(), 3, ' ') + " " + Strings.padStart(entry.getValue().getRight().toString(), 3, ' ')); totalEnrolments += entry.getValue().getRight(); } taskLog("********************************"); taskLog("Total inscries -> " + totalEnrolments); }
From source file:tech.tablesaw.columns.dates.PackedLocalDate.java
public static String toDateString(int date) { if (date == Integer.MIN_VALUE) { return ""; }//from w w w .j ava 2 s. c o m return getYear(date) + "-" + Strings.padStart(Byte.toString(getMonthValue(date)), 2, '0') + "-" + Strings.padStart(Byte.toString(getDayOfMonth(date)), 2, '0'); }
From source file:pt.ist.fenixedu.contracts.persistenceTierOracle.view.GiafEmployeeAssiduity.java
private static String convertIntoGiafNumber(final String employeeNumber) { return Strings.padStart(employeeNumber, 6, '0'); }
From source file:org.eclipse.xtext.ide.server.contentassist.ContentAssistService.java
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) { try {//from w w w. j av a 2 s. co m final CompletionList result = new CompletionList(); result.setIsIncomplete(true); final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get(); final int caretOffset = document.getOffSet(params.getPosition()); final Position caretPosition = params.getPosition(); final TextRegion position = new TextRegion(caretOffset, 0); try { this.createProposals(document.getContents(), position, caretOffset, resource, acceptor); } catch (final Throwable _t) { if (_t instanceof Throwable) { final Throwable t = (Throwable) _t; boolean _isOperationCanceledException = this.operationCanceledManager .isOperationCanceledException(t); boolean _not = (!_isOperationCanceledException); if (_not) { throw t; } } else { throw Exceptions.sneakyThrow(_t); } } final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> { final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document); item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0')); List<CompletionItem> _items = result.getItems(); _items.add(item); }; IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function); return result; } catch (Throwable _e) { throw Exceptions.sneakyThrow(_e); } }