List of usage examples for com.google.common.base Strings padStart
public static String padStart(String string, int minLength, char padChar)
From source file:AvailableTickets.java
/** * Outputs the available tickets file in memory to file, over-writing * the old available tickets file.//from ww w. ja v a 2 s . c o m * * @throws FatalError Fatal errors occur under the following circumstances: * <br>The Available Tickets File is corrupted. * @throws IOException */ public void write() throws IOException { BufferedWriter writer; String entry; File file = new File(atfFile); writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile())); /* Format each entry and write it to the file */ for (Ticket ticket : tickets) { /* Format the event */ entry = ticket.getEvent().replace(' ', '_'); entry = Strings.padEnd(entry, 20, '_'); /* Format the seller */ entry += Strings.padEnd(ticket.getSeller(), 16, '_'); /* Format the number of tickets */ entry += Strings.padStart(ticket.getVolume().toString(), 3, '0') + "_"; /* Format the price of tickets */ entry += Strings.padStart(String.format("%.2f", ticket.getPrice()), 6, '0') + "\n"; writer.write(entry); } /* Add the END of file identifier and close the file */ writer.write("END_________________________________000_000.00"); writer.close(); }
From source file:org.valkyriercp.application.exceptionhandling.MessagesDialogExceptionHandler.java
protected String formatMessage(String message) { if (message == null) { return ""; }//from ww w. java2 s . com String identString = Strings.padStart("", identLength, ' '); String newLineWithIdentString = "\n" + identString; StringBuilder formattedMessageBuilder = new StringBuilder(identString); StringTokenizer messageTokenizer = new StringTokenizer(message, "\n"); while (messageTokenizer.hasMoreTokens()) { String messageToken = messageTokenizer.nextToken(); formattedMessageBuilder.append(wrap(messageToken, wrapLength)); if (messageTokenizer.hasMoreTokens()) { formattedMessageBuilder.append(newLineWithIdentString); } } return formattedMessageBuilder.toString(); }
From source file:de.faustedition.tei.TeiValidator.java
@Override public void run() { try {/*from ww w .j a v a 2s .c o m*/ final SortedSet<FaustURI> xmlErrors = new TreeSet<FaustURI>(); final SortedMap<FaustURI, String> teiErrors = new TreeMap<FaustURI, String>(); for (FaustURI source : xml.iterate(new FaustURI(FaustAuthority.XML, "/transcript"))) { try { final List<String> errors = validate(source); if (!errors.isEmpty()) { teiErrors.put(source, Joiner.on("\n").join(errors)); } } catch (SAXException e) { logger.debug("XML error while validating transcript: " + source, e); xmlErrors.add(source); } catch (IOException e) { logger.warn("I/O error while validating transcript: " + source, e); } } if (xmlErrors.isEmpty() && teiErrors.isEmpty()) { return; } reporter.send("TEI validation report", new ReportCreator() { public void create(PrintWriter body) { if (!xmlErrors.isEmpty()) { body.println(Strings.padStart(" XML errors", 79, '=')); body.println(); body.println(Joiner.on("\n").join(xmlErrors)); body.println(); } if (!teiErrors.isEmpty()) { body.println(Strings.padStart(" TEI errors", 79, '=')); body.println(); for (Map.Entry<FaustURI, String> teiError : teiErrors.entrySet()) { body.println(Strings.padStart(" " + teiError.getKey(), 79, '-')); body.println(); body.println(teiError.getValue()); body.println(); body.println(); } } } }); } catch (EmailException e) { e.printStackTrace(); } }
From source file:org.jbpm.workbench.cm.server.MockCaseManagementService.java
@Override public String startCaseInstance(final String serverTemplateId, final String containerId, final String caseDefinitionId, final String owner) { final CaseInstanceSummary ci = CaseInstanceSummary.builder() .caseId("CASE-" + Strings.padStart(String.valueOf(caseInstanceList.size() + 1), 5, '0')) .owner(owner).startedAt(new Date()).caseDefinitionId(caseDefinitionId).status(1) .description("New case instance for development").containerId(containerId).stages(caseStageList) .build();/*w w w . j ava2 s . co m*/ caseInstanceList.add(ci); List<CaseActionSummary> actions = new ArrayList<>(caseActionList); caseActionMap.putIfAbsent(ci.getCaseId(), actions.stream().map(s -> { s.setCreatedOn(new Date()); return s; }).collect(toList())); return ci.getCaseId(); }
From source file:com.google.security.zynamics.binnavi.Gui.Debug.StackPanel.CStackMemoryProvider.java
@Override public String getElement(final long address) { if (m_dataLayout == StackDataLayout.Bytes) { if (m_addressMode == AddressMode.BIT32) { final String unpaddedValue = BigInteger.valueOf(ByteHelpers .readDwordBigEndian(m_debugger.getProcessManager().getMemory().getData(address, 4), 0)) .toString(16);/*from w ww. j a v a 2 s . c o m*/ return Strings.padStart(unpaddedValue, 8, '0').toUpperCase(); } else if (m_addressMode == AddressMode.BIT64) { final String unpaddedValue = BigInteger.valueOf(ByteHelpers .readQwordBigEndian(m_debugger.getProcessManager().getMemory().getData(address, 8), 0)) .toString(16); return Strings.padStart(unpaddedValue, 16, '0').toUpperCase(); } else { throw new IllegalStateException("IE01137: Unknown address mode"); } } else if (m_dataLayout == StackDataLayout.Dwords) { if (m_addressMode == AddressMode.BIT32) { final String unpaddedValue = BigInteger.valueOf(ByteHelpers .readDwordLittleEndian(m_debugger.getProcessManager().getMemory().getData(address, 4), 0)) .toString(16); return Strings.padStart(unpaddedValue, 8, '0').toUpperCase(); } else if (m_addressMode == AddressMode.BIT64) { final String unpaddedValue = BigInteger.valueOf(ByteHelpers .readQwordLittleEndian(m_debugger.getProcessManager().getMemory().getData(address, 8), 0)) .toString(16); return Strings.padStart(unpaddedValue, 16, '0').toUpperCase(); } else { throw new IllegalStateException("IE01138: Unknown address mode"); } } else { throw new IllegalStateException("IE01139: Invalid data layout selected"); } }
From source file:com.google.security.zynamics.zylib.disassembly.CAddress.java
@Override public String toHexString() { // Long.toHexString() interprets its argument unsigned return Strings.padStart(Long.toHexString(m_address).toUpperCase(), (m_address & 0x7fffffffffffffffL) < 0x100000000L ? 8 : 16, '0'); }
From source file:org.gradle.model.internal.core.ModelTypeInitializationException.java
private static String pad(int padding) { return Strings.padStart("", padding * 4, ' '); }
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 . j a va2s . co m*/ * @return hex string */ public static String toHex(long value) { return Strings.padStart(UnsignedLongs.toString(value, 16), 16, '0'); }
From source file:CurrentUserAccounts.java
/** * Writes the current user accounts file in memory to file, over-writing * the old current user accounts file.//from ww w.j a v a2 s . c om * * @throws FatalError Fatal errors occur under the following circumstances: * <br>The current user accounts file is corrupted. * @throws IOException */ public void write() throws IOException { BufferedWriter writer; String entry; File file = new File(cuaFile); writer = new BufferedWriter(new FileWriter(file.getAbsoluteFile())); /* Format each entry and write it to the file */ for (User user : users) { /* Format the username */ entry = Strings.padEnd(user.getUsername(), 16, '_'); /* Format the account type */ entry += user.getType() + "_"; /* Format the credit amount */ entry += Strings.padStart(String.format("%.2f", user.getCredit()), 9, '0') + "\n"; writer.write(entry); } /* Add the END of file identifier and close the file */ writer.write("END________________000000.00"); writer.close(); }
From source file:tech.tablesaw.columns.dates.DateMapFunctions.java
/** * Returns a StringColumn with the year and quarter from this column concatenated into a String that will sort * lexicographically in temporal order./*from w ww . j a v a 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 yearQuarter() { StringColumn newColumn = StringColumn.create(this.name() + " year & quarter"); for (int r = 0; r < this.size(); r++) { int c1 = this.getIntInternal(r); if (DateColumn.valueIsMissing(c1)) { newColumn.appendMissing(); } else { String yq = String.valueOf(PackedLocalDate.getYear(c1)); yq = yq + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getQuarter(c1)), 2, '0'); newColumn.append(yq); } } return newColumn; }