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:adalid.util.doclet.MetaDoclet.java
private static void println(String key, int value) { if (key != null && value > 0) { System.out.println(StringUtils.repeat(TAB, margin) + key + " = " + value); }//from w w w . ja v a 2 s. co m }
From source file:adalid.core.View.java
@Override protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) { String tab = verbose ? StringUtils.repeat(" ", 4) : ""; String fee = verbose ? StringUtils.repeat(tab, n) : ""; String faa = " = "; String foo = verbose ? EOL : ", "; String string = super.fieldsToString(n, key, verbose, fields, maps); if (fields || verbose) { string += fee + tab + "fields" + faa + _viewFields.size() + foo; }// www . java 2 s. com return string; }
From source file:com.egt.ejb.toolkit.JasperQuery.java
private String joins(SystemTable table, int depth, Set joined) { String suffix = ""; if (depth == 0) { depthCount = 0;/* w w w . jav a 2 s. c om*/ tableCount = 0; tableIndexArray = new int[fieldDepth + 1]; } else { if (depth > depthCount) { depthCount = depth; } if (depth == this.fieldDepth) { return ""; } suffix = "_" + depth + "x" + tableIndexArray[depth]; } joined.add(table.getTabname()); String alias = table.getTabname() + suffix; SystemTable reftable; String refalias; String LP = " ("; String RP = ") "; String ij; String nj; String on; String joins = ""; int depthPlus1 = depth + 1; Collection<SystemColumn> tableColumns = depth == 0 ? baseTableColumns : table.getColumns(); for (SystemColumn c : tableColumns) { if (c.getSysForeignKey() != null && tableCount < tableLimit) { reftable = c.getSysForeignKey().getReftabid(); // refalias = reftable.getTabname() + "_" + ++tableCount; tableCount++; tableIndexArray[depthPlus1]++; refalias = reftable.getTabname() + "_" + depthPlus1 + "x" + tableIndexArray[depthPlus1]; nj = joined.contains(reftable.getTabname()) ? "" : this.joins(reftable, depthPlus1, joined); ij = NL + StringUtils.repeat(TAB, depthPlus1); ij += BitUtils.valueOf(c.getIsnullable()) ? "LEFT OUTER JOIN" : "INNER JOIN"; ij += StringUtils.isBlank(nj) ? " " : LP; ij += DQ + reftable.getTabname() + DQ + " " + refalias; on = StringUtils.isBlank(nj) ? " " : NL + StringUtils.repeat(TAB, depthPlus1) + RP; on += "ON "; on += refalias + "." + DQ + c.getSysForeignKey().getRefcolname() + DQ; on += " = "; on += alias + "." + DQ + c.getColname() + DQ; joins += ij + nj + on; } } joined.remove(table.getTabname()); return joins; }
From source file:au.org.ala.delta.translation.PrintFile.java
/** * Output a pair of strings, separated by multiple instances of a supplied * padding character. The padding character is used to ensure that the * content fills the print width exactly. * /* w w w . j ava 2s . c o m*/ * E.g. str1.........................str2 * * @param str1 * The first string * @param str2 * The second string * @param paddingChar * the padding character */ public void outputStringPairWithPaddingCharacter(String str1, String str2, char paddingChar) { indent(); writeJustifiedText(str1, -1); int currentLineLength = _outputBuffer.length(); if (currentLineLength + str2.length() >= _printWidth) { _outputBuffer .append(StringUtils.repeat(Character.toString(paddingChar), _printWidth - currentLineLength)); printBufferLine(_indentOnLineWrap); currentLineLength = _outputBuffer.length(); _outputBuffer.append(StringUtils.repeat(Character.toString(paddingChar), _printWidth - currentLineLength - str2.length())); _outputBuffer.append(str2); printBufferLine(); } else { _outputBuffer.append(StringUtils.repeat(Character.toString(paddingChar), _printWidth - currentLineLength - str2.length())); _outputBuffer.append(str2); printBufferLine(); } }
From source file:adalid.core.Instance.java
@Override protected String fieldsToString(int n, String key, boolean verbose, boolean fields, boolean maps) { String tab = verbose ? StringUtils.repeat(" ", 4) : ""; String fee = verbose ? StringUtils.repeat(tab, n) : ""; String faa = " = "; String foo = verbose ? EOL : ", "; String string = super.fieldsToString(n, key, verbose, fields, maps); if (fields || verbose) { string += fee + tab + "fields" + faa + _instanceFields.size() + foo; }/*from www . j a v a 2 s . c om*/ return string; }
From source file:gobblin.tunnel.TestTunnelWithArbitraryTCPTraffic.java
private void runSimultaneousDataExchange(boolean useTunnel, int nclients) throws IOException, InterruptedException, NoSuchAlgorithmException { long t0 = System.currentTimeMillis(); final int nMsgs = 50; final Map<String, MessageDigest> digestMsgsRecvdAtServer = new HashMap<String, MessageDigest>(); final Map<String, MessageDigest> digestMsgsSentByClients = new HashMap<String, MessageDigest>(); final Map<String, MessageDigest> digestMsgsRecvdAtClients = new HashMap<String, MessageDigest>(); for (int c = 0; c < nclients; c++) { digestMsgsRecvdAtServer.put(Integer.toString(c), MessageDigest.getInstance("MD5")); digestMsgsSentByClients.put(Integer.toString(c), MessageDigest.getInstance("MD5")); digestMsgsRecvdAtClients.put(Integer.toString(c), MessageDigest.getInstance("MD5")); }// ww w .j a va2 s. c om final MessageDigest digestMsgsSentByServer = MessageDigest.getInstance("MD5"); for (int i = 0; i < nMsgs; i++) { digestMsgsSentByServer.update(TalkPastServer.generateMsgFromServer(i).getBytes()); } String hashOfMsgsSentByServer = Hex.encodeHexString(digestMsgsSentByServer.digest()); MockServer talkPastServer = startTalkPastServer(nMsgs, digestMsgsRecvdAtServer); int targetPort = talkPastServer.getServerSocketPort(); Tunnel tunnel = null; MockServer proxyServer = null; if (useTunnel) { proxyServer = startConnectProxyServer(); tunnel = Tunnel.build("localhost", talkPastServer.getServerSocketPort(), "localhost", proxyServer.getServerSocketPort()); targetPort = tunnel.getPort(); } try { List<EasyThread> clientThreads = new ArrayList<EasyThread>(); final int portToUse = targetPort; for (int c = 0; c < nclients; c++) { final int clientId = c; clientThreads.add(new EasyThread() { @Override void runQuietly() throws Exception { long t = System.currentTimeMillis(); LOG.info("\t" + clientId + ": Client starting"); final MessageDigest digestMsgsRecvdAtClient = digestMsgsRecvdAtClients .get(Integer.toString(clientId)); //final SocketChannel client = SocketChannel.open(); // tunnel test hangs for some reason with SocketChannel final Socket client = new Socket(); client.connect(new InetSocketAddress("localhost", portToUse)); EasyThread serverReaderThread = new EasyThread() { @Override public void runQuietly() { try { BufferedReader clientIn = new BufferedReader( new InputStreamReader(client.getInputStream())); String line = clientIn.readLine(); while (line != null && !line.equals("Goodbye")) { //LOG.info("\t" + clientId + ": Server said [" + line.substring(0, 32) + "... ]"); digestMsgsRecvdAtClient.update(line.getBytes()); digestMsgsRecvdAtClient.update("\n".getBytes()); line = clientIn.readLine(); } } catch (IOException e) { e.printStackTrace(); } LOG.info("\t" + clientId + ": Client done reading"); } }.startThread(); MessageDigest hashMsgsFromClient = digestMsgsSentByClients.get(Integer.toString(clientId)); BufferedOutputStream clientOut = new BufferedOutputStream(client.getOutputStream()); for (int i = 0; i < nMsgs; i++) { String msg = clientId + ":" + i + " " + StringUtils.repeat("Blahhh Blahhh ", 10000) + "\n"; //LOG.info(clientId + " sending " + msg.length() + " bytes"); byte[] bytes = msg.getBytes(); hashMsgsFromClient.update(bytes); clientOut.write(bytes); MockServer.sleepQuietly(2); } clientOut.write(("Goodbye\n".getBytes())); clientOut.flush(); LOG.info("\t" + clientId + ": Client done writing in " + (System.currentTimeMillis() - t) + " ms"); serverReaderThread.join(); LOG.info("\t" + clientId + ": Client done in " + (System.currentTimeMillis() - t) + " ms"); client.close(); } }.startThread()); } for (Thread clientThread : clientThreads) { clientThread.join(); } LOG.info("All data transfer done in " + (System.currentTimeMillis() - t0) + " ms"); } finally { talkPastServer.stopServer(); if (tunnel != null) { proxyServer.stopServer(); tunnel.close(); assertFalse(tunnel.isTunnelThreadAlive()); assertEquals(proxyServer.getNumConnects(), nclients); } Map<String, String> hashOfMsgsRecvdAtServer = new HashMap<String, String>(); Map<String, String> hashOfMsgsSentByClients = new HashMap<String, String>(); Map<String, String> hashOfMsgsRecvdAtClients = new HashMap<String, String>(); for (int c = 0; c < nclients; c++) { String client = Integer.toString(c); hashOfMsgsRecvdAtServer.put(client, Hex.encodeHexString(digestMsgsRecvdAtServer.get(client).digest())); hashOfMsgsSentByClients.put(client, Hex.encodeHexString(digestMsgsSentByClients.get(client).digest())); hashOfMsgsRecvdAtClients.put(client, Hex.encodeHexString(digestMsgsRecvdAtClients.get(client).digest())); } LOG.info("\tComparing client sent to server received"); assertEquals(hashOfMsgsSentByClients, hashOfMsgsRecvdAtServer); LOG.info("\tComparing server sent to client received"); for (String hashOfMsgsRecvdAtClient : hashOfMsgsRecvdAtClients.values()) { assertEquals(hashOfMsgsSentByServer, hashOfMsgsRecvdAtClient); } LOG.info("\tDone"); } }
From source file:net.objectlab.kit.util.StringUtil.java
/** * Returns a String which is surrounded by a box made of boxing char. * @param boxing boxing character, eg '+' * @param text//w w w .j a va2 s . com * @return */ public static String boxify(final char boxing, final String text) { if (boxing != 0 && StringUtils.isNotBlank(text)) { final StringBuilder b = new StringBuilder(); b.append(NEW_LINE); final String line = StringUtils.repeat(String.valueOf(boxing), text.length() + 4); b.append(line).append(NEW_LINE); b.append(boxing).append(SPACE).append(text).append(SPACE).append(boxing).append(NEW_LINE); b.append(line).append(NEW_LINE); return b.toString(); } return EMPTY; }
From source file:com.cloudbees.plugins.credentials.CredentialsMatchers.java
/** * Attempts to parse a Credentials Query Language expression and construct the corresponding matcher. * * @param cql the Credentials Query Language expression to parse. * @return a {@link CredentialsMatcher} for this expression. * @throws CQLSyntaxException if the expression could not be parsed. * @since 2.1.0/*from w w w. j a v a2 s . c o m*/ */ @NonNull public static CredentialsMatcher parse(final String cql) { if (StringUtils.isEmpty(cql)) { return always(); } CQLLexer lexer = new CQLLexer(new ANTLRInputStream(cql)); CommonTokenStream tokens = new CommonTokenStream(lexer); CQLParser parser = new CQLParser(tokens); parser.removeErrorListeners(); parser.addErrorListener(new BaseErrorListener() { @Override public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine, String msg, RecognitionException e) { StringBuilder expression = new StringBuilder( cql.length() + msg.length() + charPositionInLine + 256); String[] lines = StringUtils.split(cql, '\n'); for (int i = 0; i < line; i++) { expression.append(" ").append(lines[i]).append('\n'); } expression.append(" ").append(StringUtils.repeat(" ", charPositionInLine)).append("^ ") .append(msg); for (int i = line; i < lines.length; i++) { expression.append("\n ").append(lines[i]); } throw new CQLSyntaxException( String.format("CQL syntax error: line %d:%d%n%s", line, charPositionInLine, expression), charPositionInLine); } }); CQLParser.ExpressionContext expressionContext = parser.expression(); ParseTreeWalker walker = new ParseTreeWalker(); MatcherBuildingListener listener = new MatcherBuildingListener(); try { walker.walk(listener, expressionContext); return listener.getMatcher(); } catch (EmptyStackException e) { throw new IllegalStateException("There should not be an empty stack when starting from an expression", e); } catch (CQLSyntaxError e) { throw new CQLSyntaxException(String.format("CQL syntax error:%n %s%n %s%s unexpected symbol %s", cql, StringUtils.repeat(" ", e.interval.a), StringUtils.repeat("^", e.interval.length()), e.text), e.interval.a); } }
From source file:com.linkedin.harisekhon.Utils.java
public static final void hr() { log.info("# " + StringUtils.repeat("=", 76) + " #"); }
From source file:de.codesourcery.jasm16.utils.Misc.java
public static void printCompilationMarkers(ICompilationUnit unit, String source, boolean printStackTraces, final List<IMarker> errors) { if (errors.isEmpty()) { return;/*from w w w. j av a2s . c o m*/ } Collections.sort(errors, new Comparator<IMarker>() { @Override public int compare(IMarker o1, IMarker o2) { if (o1 instanceof CompilationMarker && o2 instanceof CompilationMarker) { CompilationMarker err1 = (CompilationMarker) o1; CompilationMarker err2 = (CompilationMarker) o2; final ITextRegion loc1 = err1.getLocation(); final ITextRegion loc2 = err2.getLocation(); if (loc1 != null && loc2 != null) { return Integer.valueOf(err1.getLocation().getStartingOffset()) .compareTo(Integer.valueOf(err2.getLocation().getStartingOffset())); } if (loc1 != null) { return -1; } else if (loc2 != null) { return 1; } return 0; } return 0; } }); for (Iterator<IMarker> it = errors.iterator(); it.hasNext();) { final IMarker tmp = it.next(); if (!(tmp instanceof CompilationMarker)) { continue; } final CompilationMarker error = (CompilationMarker) tmp; final int errorOffset; ITextRegion range; if (error.getLocation() != null) { range = error.getLocation(); errorOffset = range.getStartingOffset(); } else { errorOffset = error.getErrorOffset(); if (errorOffset != -1) { range = new TextRegion(errorOffset, 1); } else { range = null; } } int line = error.getLineNumber(); int column = error.getColumnNumber(); if (column == -1 && (error.getErrorOffset() != -1 && error.getLineStartOffset() != -1)) { column = error.getErrorOffset() - error.getLineStartOffset() + 1; } if ((line == -1 || column == -1) & errorOffset != -1) { try { SourceLocation location = unit.getSourceLocation(range); line = location.getLineNumber(); column = errorOffset - location.getLineStartOffset() + 1; if (column < 1) { column = -1; } } catch (Exception e) { // can't help it } } final boolean hasLocation = line != -1 && column != -1; final String severity = error.getSeverity() != null ? error.getSeverity().getLabel() + ": " : ""; final String locationString; if (hasLocation) { locationString = severity + "line " + line + ", column " + column + ": "; } else if (errorOffset != -1) { locationString = severity + "offset " + errorOffset + ": "; } else { locationString = severity + "< unknown location >: "; } boolean hasSource = false; String sourceLine = null; if (line != -1 || range != null) { Line thisLine = null; Line nextLine = null; if (line != -1) { try { thisLine = error.getCompilationUnit().getLineByNumber(line); IScanner scanner = new Scanner(source); scanner.setCurrentParseIndex(thisLine.getLineStartingOffset()); while (!scanner.eof() && scanner.peek() != '\n') { scanner.read(); } nextLine = new Line(line + 1, scanner.currentParseIndex()); } catch (Exception e) { // can't help it } if (thisLine != null && nextLine != null) { sourceLine = new TextRegion(thisLine.getLineStartingOffset(), nextLine.getLineStartingOffset() - thisLine.getLineStartingOffset()).apply(source); } else { sourceLine = range.apply(source); column = 1; } hasSource = true; } else { // range != null sourceLine = range.apply(source); column = 1; hasSource = true; } } if (hasSource) { sourceLine = sourceLine.replaceAll(Pattern.quote("\r\n"), "").replaceAll(Pattern.quote("\n"), "") .replaceAll("\t", " "); final String trimmedSourceLine = removeLeadingWhitespace(sourceLine); if (column != -1 && trimmedSourceLine.length() != sourceLine.length()) { column -= (sourceLine.length() - trimmedSourceLine.length()); } sourceLine = trimmedSourceLine; } String firstLine; String secondLine = null; if (hasLocation) { if (hasSource) { firstLine = locationString + sourceLine + "\n"; secondLine = StringUtils.repeat(" ", locationString.length()) + StringUtils.repeat(" ", (column - 1)) + "^ " + error.getMessage() + "\n"; } else { firstLine = locationString + error.getMessage(); } } else { firstLine = "Unknown error: " + error.getMessage(); } System.err.print(firstLine); if (secondLine != null) { System.err.print(secondLine); } System.out.println(); if (printStackTraces && error.getCause() != null) { error.getCause().printStackTrace(); } } }