List of usage examples for org.apache.commons.lang StringUtils repeat
public static String repeat(String str, int repeat)
Repeat a String repeat
times to form a new String.
From source file:net.sourceforge.seqware.common.util.TabExpansionUtil.java
/** * Produce output resembling Postgres with one "table" per record * * @param tabSeparated//from w w w.jav a 2 s .c om * @return */ public static String expansion(String tabSeparated) { String[] lines = tabSeparated.split("\n"); // get headers String[] header = lines[0].split("\t"); // determine maximum header length and other formatting int maxHeader = 0; int maxContent = 0; for (String h : header) { maxHeader = Math.max(maxHeader, h.length()); } List<String[]> records = new ArrayList<String[]>(); for (int i = 1; i < lines.length; i++) { String[] record = lines[i].split("\t"); for (String col : record) { maxContent = Math.max(col.length(), maxContent); } records.add(record); } maxContent++; // do output StringBuilder buff = new StringBuilder(); for (int i = 0; i < records.size(); i++) { String head = "-[ RECORD " + i + " ]"; buff.append(head); buff.append(StringUtils.repeat("-", maxHeader - head.length())); buff.append("+"); buff.append(StringUtils.repeat("-", maxContent)); buff.append("\n"); int j = 0; for (String col : records.get(i)) { buff.append(header[j]); buff.append(StringUtils.repeat(" ", maxHeader - header[j].length())); buff.append("| "); buff.append(col); buff.append(StringUtils.repeat(" ", maxContent - col.length())); buff.append("\n"); j++; } } return buff.toString(); }
From source file:net.sourceforge.seqware.common.util.TabExpansionUtil.java
/** * Produce aligned output that lines up properly in the terminal * * @param tabSeparated// ww w . j a v a2s . c om * @return */ public static String aligned(String tabSeparated) { String[] lines = tabSeparated.split("\n"); // get headers String[] header = lines[0].split("\t"); // determine maximum header length and other formatting int[] maxContent = new int[header.length]; List<String[]> records = new ArrayList<String[]>(); for (int i = 0; i < lines.length; i++) { String[] record = lines[i].split("\t"); int j = 0; for (String col : record) { maxContent[j] = Math.max(col.length(), maxContent[j]); j++; } records.add(record); } // do output StringBuilder buff = new StringBuilder(); for (int i = 0; i < records.size(); i++) { int j = 0; for (String col : records.get(i)) { buff.append(col); buff.append(StringUtils.repeat(" ", Math.max(0, (maxContent[j] - col.length())))); buff.append("|"); j++; } if (i == 0) { buff.append("\n"); for (int c : maxContent) { buff.append(StringUtils.repeat("-", c)); buff.append("+"); } } buff.append("\n"); } return buff.toString(); }
From source file:net.sourceforge.vulcan.spring.jdbc.JdbcBuildOutcomeStoreTest.java
public void testTruncateMessageArg() throws Exception { outcome.setMessageArgs(new Object[] { StringUtils.repeat("abcd", 65) }); JdbcBuildOutcomeDto result = storeOutcome(); outcome.getMessageArgs()[0] = StringUtils.repeat("abcd", 63) + "a..."; assertPersistence(result);//from ww w .j a v a 2 s . c o m }
From source file:net.sourceforge.vulcan.spring.jdbc.JdbcBuildOutcomeStoreTest.java
public void testSaveTestFailuresTruncatesLongMessageAndDetails() throws Exception { final List<TestFailureDto> list = new ArrayList<TestFailureDto>(); final TestFailureDto tf = new TestFailureDto(); tf.setName("a name of a test"); tf.setBuildNumber(outcome.getBuildNumber()); tf.setMessage(StringUtils.repeat("blegh ", JdbcBuildOutcomeStore.MAX_TEST_FAILURE_MESSAGE_LENGTH * 2)); tf.setDetails(StringUtils.repeat("blah ", JdbcBuildOutcomeStore.MAX_TEST_FAILURE_DETAILS_LENGTH * 2)); list.add(tf);/*from w w w . j a v a2s . c o m*/ outcome.setTestFailures(list); final JdbcBuildOutcomeDto loadedOutcome = storeOutcome(); final TestFailureDto loadedFailure = loadedOutcome.getTestFailures().get(0); assertEquals(JdbcBuildOutcomeStore.MAX_TEST_FAILURE_MESSAGE_LENGTH, loadedFailure.getMessage().length()); assertEquals(JdbcBuildOutcomeStore.MAX_TEST_FAILURE_DETAILS_LENGTH, loadedFailure.getDetails().length()); }
From source file:net.sourceforge.vulcan.spring.jdbc.JdbcBuildOutcomeStoreTest.java
public void testSaveCommitLogTruncatesLongMessage() throws Exception { final ChangeLogDto log = new ChangeLogDto(); final ChangeSetDto a = new ChangeSetDto(); a.setMessage(StringUtils.repeat("did some stuff", JdbcBuildOutcomeStore.MAX_COMMIT_MESSAGE_LENGTH)); a.setRevisionLabel("1.42"); log.setChangeSets(Arrays.asList(a)); outcome.setChangeLog(log);/* w w w . j av a 2 s .c o m*/ final JdbcBuildOutcomeDto loadedOutcome = storeOutcome(); final ChangeSetDto change = loadedOutcome.getChangeLog().getChangeSets().get(0); assertEquals(JdbcBuildOutcomeStore.MAX_COMMIT_MESSAGE_LENGTH, change.getMessage().length()); }
From source file:net.tbnr.gearz.game.GearzGame.java
@SafeVarargs protected final void displayWinners(PlayerType... players) { List<String> strings = new ArrayList<>(); String line = ChatColor.GOLD.toString() + ChatColor.STRIKETHROUGH + StringUtils.repeat(" ", 64); strings.add(line);//from ww w . j a v a 2s. co m for (int x = 0, l = progressiveWinColors.length; x < players.length; x++) { int place = x + 1; float percentage = x == 0 ? 0f : (float) x / players.length; int index = Double.valueOf(Math.floor(l * percentage)).intValue(); ChatColor color = progressiveWinColors[index]; strings.add( " " + color + players[x].getUsername() + ChatColor.GRAY + " - " + color + String.valueOf(place) + NumberSuffixes.getForString(String.valueOf(place)).getSuffix() + " place."); } strings.add(line); for (PlayerType player : allPlayers()) { TPlayer tPlayer = player.getTPlayer(); for (String s : strings) { tPlayer.sendMessage(s); } } }
From source file:net.tbnr.manager.command.ClearChat.java
@TCommand(name = "clearchat", description = "Clears chat globally", usage = "/clearchat", permission = "gearz.clearchat.all", senders = { TCommandSender.Player, TCommandSender.Console }, aliases = { "cc", "cchat", "clearc" }) @SuppressWarnings("unused") public TCommandStatus clearchat(CommandSender sender, TCommandSender type, TCommand meta, Command command, String[] args) {//from w w w . j a v a 2s . c o m for (int i = 0; i <= 200; i++) { silentBroadcast("", true); } silentBroadcast(ChatColor.DARK_AQUA + "+" + ChatColor.STRIKETHROUGH + StringUtils.repeat(" ", 60) + "+", false); silentBroadcast(ChatColor.DARK_AQUA + "\u25BA" + ChatColor.RESET + "" + ChatColor.BOLD + " The chat has been cleared by a staff member", false); silentBroadcast(ChatColor.DARK_AQUA + "+" + ChatColor.STRIKETHROUGH + StringUtils.repeat(" ", 60) + "+", false); sender.sendMessage(ChatColor.GREEN + "Chat cleared!"); return TCommandStatus.SUCCESSFUL; }
From source file:net.tbnr.util.render.ImageToChatBukkitUtil.java
public static String centerText(String text) { int maxWidth = 55; int spaces = (int) Math.round((maxWidth - 1.4 * ChatColor.stripColor(text).length()) / 2); return StringUtils.repeat(" ", spaces) + text; }
From source file:ninja.text.TextImpl.java
@Override public Text repeat(int times) { return Text.of(StringUtils.repeat(data.toString(), times)); }
From source file:nl.cyso.vcloud.client.docs.Readme.java
private String getNameSection() { StringBuilder section = new StringBuilder(); String header = String.format("%s - a tool to manage vCloud datacenter objects\n", Version.PROJECT_NAME); section.append(header);/*from www . j a v a 2 s .c o m*/ section.append(StringUtils.repeat("-", header.length()) + "\n\n"); return section.toString(); }