List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:com.cognifide.aet.job.common.comparators.source.diff.DiffParser.java
private ResultDelta buildDelta(String originalChunkHtml, String revisedChunkHtml, Delta delta) { String localOriginalChunkHtml = originalChunkHtml; String localRevisedChunkHtml = revisedChunkHtml; int originalLinesNo = delta.getOriginal().getLines().size(); int revisedLinesNo = delta.getRevised().getLines().size(); int sizeDiff = Math.abs(originalLinesNo - revisedLinesNo); if (sizeDiff > 0) { if (delta.getType().equals(Delta.TYPE.CHANGE)) { // I don't know why, but it have to be like that. sizeDiff++;/*from w ww. j av a2 s. c om*/ } String alignment = StringUtils.repeat(BR_TAG, sizeDiff); if (originalLinesNo > revisedLinesNo) { localRevisedChunkHtml += alignment; } else if (originalLinesNo < revisedLinesNo) { localOriginalChunkHtml += alignment; } } int originalPosition = delta.getOriginal().getPosition(); ResultChunk original = new ResultChunk(originalPosition, localOriginalChunkHtml); int revisedPosition = delta.getRevised().getPosition(); ResultChunk revised = new ResultChunk(revisedPosition, localRevisedChunkHtml); return new ResultDelta(TYPE.valueOf(delta.getType().name()), original, revised); }
From source file:com.baidu.oped.apm.common.buffer.FixedBufferTest.java
@Test public void readPadString() { String testString = StringUtils.repeat('a', 10); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadString(testString, 20); writeBuffer.put(255);/* ww w. j av a 2 s . c o m*/ Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); String readPadString = readBuffer.readPadString(20); Assert.assertEquals(testString, readPadString.substring(0, 10)); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
From source file:com.zilbo.flamingSailor.TE.model.TextLine.java
@Override public void dumpChildren(PrintStream out, int level) { StringBuilder sb = new StringBuilder(); sb.append(StringUtils.repeat("..", level)); sb.append(getClass().getSimpleName()); if (isHeading()) { sb.append(" (H) "); }/*from w w w .j ava 2s .com*/ if (sb.length() < 20) { sb.append(StringUtils.repeat(' ', 20 - sb.length())); } sb.append('\t'); sb.append(getRectangleDebug()).append("\t"); out.print(sb.toString() + " " + normHistoGramToString() + String.format(" H:%5.1f W:%6.1f D:%4.2f P:%4.2f", height(), width(), density(), getLineIsRegularProbability()) + "\t"); String text; text = getText().replace("\n", "\n" + StringUtils.repeat(' ', 43)); if (text.length() > 256) { text = text.substring(0, 256 - 4) + " ..."; } out.println(text); /* for (Component component : getChildren()) { component.dumpChildren(out, level + 1); } */ }
From source file:br.usp.poli.lta.cereda.macro.ui.Editor.java
/** * Construtor./*from w w w . j av a 2 s . co m*/ */ public Editor() { // define as configuraes de exibio super("Expansor de macros"); setPreferredSize(new Dimension(550, 550)); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false); setLayout(new MigLayout()); // cria os botes e suas respectivas aes open = new JButton("Abrir", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/open.png"))); save = new JButton("Salvar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/save.png"))); run = new JButton("Executar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/play.png"))); clear = new JButton("Limpar", new ImageIcon(getClass().getResource("/br/usp/poli/lta/cereda/macro/images/clear.png"))); // cria uma janela de dilogo para abrir e salvar arquivos de texto chooser = new JFileChooser(); chooser.setMultiSelectionEnabled(false); FileNameExtensionFilter filter = new FileNameExtensionFilter("Arquivos de texto", "txt", "text"); chooser.setFileFilter(filter); // ao de abertura de arquivo open.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showOpenDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { String content = FileUtils.readFileToString(file); input.setText(content); output.setText(""); } catch (Exception e) { } } } }); // ao de salvamento de arquivo save.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { int value = chooser.showSaveDialog(Editor.this); if (value == JFileChooser.APPROVE_OPTION) { File file = chooser.getSelectedFile(); try { FileUtils.writeStringToFile(file, input.getText(), Charset.forName("UTF-8")); output.setText(""); } catch (Exception e) { } } } }); // ao de limpeza da janela de sada clear.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { output.setText(""); } }); // ao de execuo do expansor de macros run.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { try { output.setText(MacroExpander.parse(input.getText())); } catch (Exception exception) { String out = StringUtils.rightPad("ERRO: ", 50, "-").concat("\n"); out = out.concat(WordUtils.wrap(exception.getMessage(), 50)).concat("\n"); out = out.concat(StringUtils.repeat(".", 50)).concat("\n"); output.setText(out); } } }); // tela de entrada do texto input = new RSyntaxTextArea(14, 60); input.setCodeFoldingEnabled(true); input.setWrapStyleWord(true); input.setLineWrap(true); RTextScrollPane iinput = new RTextScrollPane(input); add(iinput, "span 4, wrap"); // adiciona os botes add(open); add(save); add(run); add(clear, "wrap"); // tela de sada da expanso output = new RSyntaxTextArea(14, 60); output.setEditable(false); output.setCodeFoldingEnabled(true); output.setWrapStyleWord(true); output.setLineWrap(true); RTextScrollPane ioutput = new RTextScrollPane(output); add(ioutput, "span 4"); // ajustes finais pack(); setLocationRelativeTo(null); }
From source file:com.navercorp.pinpoint.common.buffer.FixedBufferTest.java
@Test public void readPadString() { String testString = StringUtils.repeat('a', 10); Buffer writeBuffer = new FixedBuffer(32); writeBuffer.putPadString(testString, 20); writeBuffer.putInt(255);//from www . j a va2s . co m Buffer readBuffer = new FixedBuffer(writeBuffer.getBuffer()); String readPadString = readBuffer.readPadString(20); Assert.assertEquals(testString, readPadString.substring(0, 10)); int readInt = readBuffer.readInt(); Assert.assertEquals(255, readInt); }
From source file:co.runrightfast.vertx.core.application.RunRightFastVertxApplicationLauncherTest.java
/** * Test of run method, of class RunRightFastVertxApplicationLauncher. *///from ww w. j a v a 2s. c o m @Test public void testHelpOption() { System.out.println(String.format("\n\n%s%s%s%s%s", StringUtils.repeat('*', 10), StringUtils.repeat(' ', 3), "testHelpOption -h", StringUtils.repeat(' ', 3), StringUtils.repeat('*', 10))); RunRightFastVertxApplicationLauncher.run(() -> app, "-h"); System.out.println(String.format("\n\n%s%s%s%s%s", StringUtils.repeat('*', 10), StringUtils.repeat(' ', 3), "testHelpOption --help", StringUtils.repeat(' ', 3), StringUtils.repeat('*', 10))); RunRightFastVertxApplicationLauncher.run(() -> app, "--help"); }
From source file:ftrimble.kingme.device.file.KingMeGPX.java
/** * Quick helper function to ensure that there is the correct * amount of whitespace for the indentation level. *//* w ww. ja va 2 s.c om*/ private String addNewLine() { StringBuilder sb = new StringBuilder(); sb.append("\n"); sb.append(StringUtils.repeat(" ", mIndentLevel)); return sb.toString(); }
From source file:de.uniwue.info6.webapp.admin.SubmissionRow.java
/** * * * @param d//ww w .jav a 2 s . co m * @return */ private static String formatDouble(double d, int places) { DecimalFormat f = new DecimalFormat("#0." + StringUtils.repeat("0", places)); return f.format(d); }
From source file:massbank.admin.Validator2.java
public static Record validate(String recordstring, String contributor) { // test non standard ASCII chars and print warnings for (int i = 0; i < recordstring.length(); i++) { if (recordstring.charAt(i) > 0x7F) { String[] tokens = recordstring.split("\\r?\\n"); System.out.println(//from ww w . j ava2s. c o m "Warning: non standard ASCII charactet found. This might be an error. Please check carefully."); int line = 0, col = 0, offset = 0; for (String token : tokens) { offset = offset + token.length() + 1; if (i < offset) { col = i - (offset - (token.length() + 1)); System.out.println(tokens[line]); StringBuilder error_at = new StringBuilder(StringUtils.repeat(" ", tokens[line].length())); error_at.setCharAt(col, '^'); System.out.println(error_at); break; } line++; } } } Record record = new Record(contributor); Parser recordparser = new RecordParser(record); Result res = recordparser.parse(recordstring); if (res.isFailure()) { System.err.println(); System.err.println(res.getMessage()); int position = res.getPosition(); String[] tokens = recordstring.split("\\n"); int line = 0, col = 0, offset = 0; for (String token : tokens) { offset = offset + token.length() + 1; if (position < offset) { col = position - (offset - (token.length() + 1)); System.err.println(tokens[line]); StringBuilder error_at = new StringBuilder(StringUtils.repeat(" ", col)); error_at.append('^'); System.err.println(error_at); break; } line++; } return null; } else return record; }
From source file:com.gmarciani.gmparser.commons.TestNonDeterministicFunction.java
@Test public void createCompleteAndRemoveAllXY() { System.out.println("#createCompleteAndRemoveAllXY"); GSet<Character> domainX = new GSet<Character>(); domainX.add('a'); domainX.add('b'); domainX.add('c'); GSet<Integer> domainY = new GSet<Integer>(); domainY.add(1);/* w ww . ja va2s .c om*/ domainY.add(2); domainY.add(3); GSet<String> domainZ = new GSet<String>(); for (Character c : domainX) { for (Integer n : domainY) { for (int i = 1; i <= n; i++) domainZ.add(StringUtils.repeat(c, i)); } } Function<Character, Integer, String> function = new NonDeterministicFunction<Character, Integer, String>( domainX, domainY, domainZ); for (Character c : domainX) { for (Integer n : domainY) { for (int i = 1; i <= n; i++) function.add(c, n, StringUtils.repeat(c, i)); } } function.removeAllForXY('b', 2); System.out.println(function); System.out.println(function.toFormattedFunction()); }