List of usage examples for org.apache.commons.lang3 StringUtils repeat
public static String repeat(final char ch, final int repeat)
From source file:br.usp.poli.lta.cereda.macro.Application.java
/** * Mtodo principal.// www . ja v a2 s . c o m * @param args Argumentos de linha de comando. */ public static void main(String[] args) { // imprime banner System.out.println(StringUtils.repeat("-", 50)); System.out.println(StringUtils.center("Expansor de macros", 50)); System.out.println(StringUtils.repeat("-", 50)); System.out.println(StringUtils.center("Laboratrio de linguagens e tcnicas adaptativas", 50)); System.out.println(StringUtils.center("Escola Politcnica - Universidade de So Paulo", 50)); System.out.println(); try { // faz o parsing dos argumentos de linha de comando CLIParser parser = new CLIParser(args); Pair<String, File> pair = parser.parse(); // se o par no nulo, possvel prosseguir com a expanso if (pair != null) { // obtm a expanso do texto fornecido na entrada String output = MacroExpander.parse(pair.getFirst()); // se foi definido um arquivo de sada, grava a expanso do // texto nele, ou imprime o resultado no terminal, caso // contrrio if (pair.getSecond() != null) { FileUtils.writeStringToFile(pair.getSecond(), output, Charset.forName("UTF-8")); System.out.println("Arquivo gerado com sucesso."); } else { System.out.println(output); } } else { // verifica se a execuo corresponde a uma chamada ao editor // embutido de macros if (parser.isEditor()) { // cria o editor e exibe SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DisplayUtils.init(); Editor editor = new Editor(); editor.setVisible(true); } }); } } } catch (Exception exception) { // ocorreu uma exceo, imprime a mensagem de erro System.out.println(StringUtils.rightPad("ERRO: ", 50, "-")); System.out.println(WordUtils.wrap(exception.getMessage(), 50)); System.out.println(StringUtils.repeat(".", 50)); } }
From source file:net.socket.bio.TimeClient.java
/** * @param args/* w w w. ja v a 2 s. c o m*/ */ public static void main(String[] args) { int port = 8089; if (args != null && args.length > 0) { try { port = Integer.valueOf(args[0]); } catch (NumberFormatException e) { // } } Socket socket = null; BufferedReader in = null; PrintWriter out = null; try { socket = new Socket("127.0.0.1", port); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out = new PrintWriter(socket.getOutputStream(), true); out.println("QUERY TIME ORDER"); out.println("QUERY TIME ORDER"); String test = StringUtils.repeat("hello tcp", 1000); out.println(test); System.out.println("Send order 2 server succeed."); String resp = in.readLine(); System.out.println("Now is : " + resp); } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(socket); } }
From source file:br.usp.poli.lta.cereda.spa2run.Main.java
public static void main(String[] args) { Utils.printBanner();/*from w w w . j a v a 2 s .c o m*/ CommandLineParser parser = new DefaultParser(); try { CommandLine line = parser.parse(Utils.getOptions(), args); List<Spec> specs = Utils.fromFilesToSpecs(line.getArgs()); List<Metric> metrics = Utils.fromFilesToMetrics(line); Utils.setMetrics(metrics); Utils.resetCalculations(); AdaptiveAutomaton automaton = Utils.getAutomatonFromSpecs(specs); System.out.println("SPA generated successfully:"); System.out.println("- " + specs.size() + " submachine(s) found."); if (!Utils.detectEpsilon(automaton)) { System.out.println("- No empty transitions."); } if (!metrics.isEmpty()) { System.out.println("- " + metrics.size() + " metric(s) found."); } System.out.println("\nStarting shell, please wait...\n" + "(press CTRL+C or type `:quit'\n" + "to exit the application)\n"); String query = ""; Scanner scanner = new Scanner(System.in); String prompt = "[%d] query> "; String result = "[%d] result> "; int counter = 1; do { try { String term = String.format(prompt, counter); System.out.print(term); query = scanner.nextLine().trim(); if (!query.equals(":quit")) { boolean accept = automaton.recognize(Utils.toSymbols(query)); String type = automaton.getRecognitionPaths().size() == 1 ? " (deterministic)" : " (nondeterministic)"; System.out.println(String.format(result, counter) + accept + type); if (!metrics.isEmpty()) { System.out.println(StringUtils.repeat(" ", String.format("[%d] ", counter).length()) + Utils.prettyPrintMetrics()); } System.out.println(); } } catch (Exception exception) { System.out.println(); Utils.printException(exception); System.out.println(); } counter++; Utils.resetCalculations(); } while (!query.equals(":quit")); System.out.println("That's all folks!"); } catch (ParseException nothandled) { Utils.printHelp(); } catch (Exception exception) { Utils.printException(exception); } }
From source file:de.uniwue.info6.database.SQLParserTest.java
public static void main(String[] args) throws Exception { String test = "Dies ist ein einfacher Test"; System.out.println(StringTools.forgetOneWord(test)); System.exit(0);/* w w w . j av a2 s. co m*/ // SimpleTupel<String, Integer> test1 = new SimpleTupel<String, Integer>("test1", 1); // SimpleTupel<String, Integer> test2 = new SimpleTupel<String, Integer>("test1", 12); // ArrayList<SimpleTupel<String, Integer>> test = new ArrayList<SimpleTupel<String, Integer>>(); // test.add(test1); // System.out.println(test1.equals(test2)); // System.exit(0); final boolean resetDb = true; // Falls nur nach einer bestimmten Aufgabe gesucht wird final Integer exerciseID = 39; final Integer scenarioID = null; final int threadSize = 1; final EquivalenceLock<Long[]> equivalenceLock = new EquivalenceLock<Long[]>(); final Long[] performance = new Long[] { 0L, 0L }; // ------------------------------------------------ // final ScenarioDao scenarioDao = new ScenarioDao(); final ExerciseDao exerciseDao = new ExerciseDao(); final ExerciseGroupDao groupDao = new ExerciseGroupDao(); final UserDao userDao = new UserDao(); final ArrayList<Thread> threads = new ArrayList<Thread>(); // ------------------------------------------------ // try { ConnectionManager.offline_instance(); if (resetDb) { Cfg.inst().setProp(MAIN_CONFIG, IMPORT_EXAMPLE_SCENARIO, true); Cfg.inst().setProp(MAIN_CONFIG, FORCE_RESET_DATABASE, true); new GenerateData().resetDB(); ConnectionTools.inst().addSomeTestData(); } } catch (Exception e) { e.printStackTrace(); } // ------------------------------------------------ // final List<Scenario> scenarios = scenarioDao.findAll(); try { // ------------------------------------------------ // String userID; for (int i = 2; i < 100; i++) { userID = "user_" + i; User userToInsert = new User(); userToInsert.setId(userID); userToInsert.setIsAdmin(false); userDao.insertNewInstance(userToInsert); } // ------------------------------------------------ // for (int i = 0; i < threadSize; i++) { Thread thread = new Thread() { public void run() { // ------------------------------------------------ // try { Thread.sleep(new Random().nextInt(30)); } catch (InterruptedException e) { e.printStackTrace(); } // ------------------------------------------------ // User user = userDao.getRandom(); Thread.currentThread().setName(user.getId()); System.err.println( "\n\nINFO (ueps): Thread '" + Thread.currentThread().getName() + "' started\n"); // ------------------------------------------------ // for (Scenario scenario : scenarios) { if (scenarioID != null && !scenario.getId().equals(scenarioID)) { continue; } System.out.println(StringUtils.repeat("#", 90)); System.out.println("SCENARIO: " + scenario.getId()); // ------------------------------------------------ // for (ExerciseGroup group : groupDao.findByScenario(scenario)) { System.out.println(StringUtils.repeat("#", 90)); System.out.println("GROUP: " + group.getId()); System.out.println(StringUtils.repeat("#", 90)); List<Exercise> exercises = exerciseDao.findByExGroup(group); // ------------------------------------------------ // for (Exercise exercise : exercises) { if (exerciseID != null && !exercise.getId().equals(exerciseID)) { continue; } long startTime = System.currentTimeMillis(); for (int i = 0; i < 100; i++) { String userID = "user_" + new Random().nextInt(100000); User userToInsert = new User(); userToInsert.setId(userID); userToInsert.setIsAdmin(false); userDao.insertNewInstance(userToInsert); user = userDao.getById(userID); List<SolutionQuery> solutions = new ExerciseDao().getSolutions(exercise); String solution = solutions.get(0).getQuery(); ExerciseController exc = new ExerciseController().init_debug(scenario, exercise, user); exc.setUserString(solution); String fd = exc.getFeedbackList().get(0).getFeedback(); System.out.println("Used Query: " + solution); if (fd.trim().toLowerCase().equals("bestanden")) { System.out.println(exercise.getId() + ": " + fd); } else { System.err.println(exercise.getId() + ": " + fd + "\n"); } System.out.println(StringUtils.repeat("-", 90)); } long elapsedTime = System.currentTimeMillis() - startTime; // if (i > 5) { // try { // equivalenceLock.lock(performance); // performance[0] += elapsedTime; // performance[1]++; // } catch (Exception e) { // } finally { // equivalenceLock.release(performance); // } // } } } } System.err .println("INFO (ueps): Thread '" + Thread.currentThread().getName() + "' stopped"); } }; thread.start(); threads.add(thread); } for (Thread thread : threads) { thread.join(); } // try { // equivalenceLock.lock(performance); // long elapsedTime = (performance[0] / performance[1]); // System.out.println("\n" + String.format("perf : %d.%03dsec", elapsedTime / 1000, elapsedTime % 1000)); // } catch (Exception e) { // } finally { // equivalenceLock.release(performance); // } } finally { } }
From source file:edu.usc.leqa.Main.java
/** * The main method for LEQA./*ww w .j ava 2 s. c o m*/ * * @param args the command line arguments * @throws IOException */ public static void main(String[] args) throws IOException { long start, actual = 0, estimated = 0; // args = "-f ../sample_inputs/fabric.xml-t ../sample_inputs/tech.xml -i ../sample_inputs/tfc/8bitadder.tfc".split("\\s"); parseInputs(args); // -s 0.001 /* * Parsing inputs: fabric, tech & qasm files * LEQA uses parsers of QSPR */ System.out.println("Parsing technology and fabric files..."); start = System.currentTimeMillis(); layout = LayoutParser.parse(techFileAddr, fabricFileAddr); /* Converting TFC to QASM if TFC is provided. */ String inputExtension = inputFileAddr.substring(inputFileAddr.lastIndexOf('.') + 1); if (inputExtension.compareToIgnoreCase("TFC") == 0) { System.out.println("TFC file is provided. Converting to QASM..."); String qasmFileAddr = inputFileAddr.substring(0, inputFileAddr.lastIndexOf('.')) + ".qasm"; if (TFCParser.parse(inputFileAddr, qasmFileAddr) == false) { System.err.println("Failed to convert " + inputFileAddr + " to QASM format."); System.exit(-1); } inputFileAddr = qasmFileAddr; } else if (inputExtension.compareToIgnoreCase("QASM") != 0) { System.err .println("Extension " + inputExtension + " is not supported! Only qasm and tfc are supported."); System.exit(-1); } /* Parsing the QASM file */ System.out.println("Parsing QASM file..."); qasm = QASMParser.QASMParser(inputFileAddr, layout); if (qasm == null || layout == null) System.exit(-1); parseRuntime = (System.currentTimeMillis() - start) / 1000.0; /* * Invoking LEQA for estimating the latency */ System.out.println("Invoking LEQA..."); start = System.currentTimeMillis(); estimated = LEQA.leqa(qasm, layout, speed); leqaRuntime = (System.currentTimeMillis() - start) / 1000.0; /* * Invoking HL-QSPR for calculating the actual latency * This is for comparison only. It can be commented out */ if (!RuntimeConfig.SKIP) { System.out.println("Invoking QSPR..."); start = System.currentTimeMillis(); actual = QSPR.center(eds, layout, qasm); QSPRRuntime = (System.currentTimeMillis() - start) / 1000.0; } /* * Printing the results */ int separatorLength = 30; System.out.println(); System.out.println(StringUtils.center("Results", separatorLength)); System.out.println(StringUtils.repeat('-', separatorLength)); System.out.println("Estimated value:\t" + estimated); if (!RuntimeConfig.SKIP) { System.out.println("Actual value:\t\t" + actual); System.out.printf("Error:\t\t\t%.2f%%" + lineSeparator, (Math.abs(estimated - actual) * 100.0 / actual)); } System.out.println(StringUtils.repeat('-', separatorLength)); System.out.println("Parsing overhead:\t" + parseRuntime + "s"); System.out.println("LEQA runtime:\t\t" + leqaRuntime + "s"); if (!RuntimeConfig.SKIP) { System.out.println("QSPR time:\t\t" + QSPRRuntime + "s"); System.out.printf("Speed up:\t\t%.2f" + lineSeparator, QSPRRuntime / leqaRuntime); } }
From source file:com.kegare.caveworld.util.Roman.java
public static String toRoman(int num) { if (num <= 0 || num >= 4000) { return ""; }/*from w w w. j av a2s.co m*/ StringBuilder ret = new StringBuilder(); for (int i = 3; i >= 0; i--) { int r = num / values[i]; num %= values[i]; if (r == 4) { ret.append(ones[i]).append(fives[i]); continue; } if (r == 9) { ret.append(ones[i]).append(ones[i + 1]); continue; } if (r >= 5) { ret.append(fives[i]); r -= 5; } ret.append(StringUtils.repeat(ones[i], r)); } return ret.toString(); }
From source file:fr.duminy.jbackup.core.TestUtils.java
public static Path createFile(Path file, long size) throws IOException { return createFile(file, StringUtils.repeat("A", (int) size)); }
From source file:net.gtaun.wl.common.textdraw.TextDrawUtils.java
public static PlayerTextdraw createPlayerTextBG(Player player, float x, float y, float w, float h) { int lines = Math.round((h - 5) / 5.0f); PlayerTextdraw textdraw = PlayerTextdraw.create(player, x + 4, (y - 50) / 1.075f + 50, StringUtils.repeat("~n~", lines)); textdraw.setUseBox(true);/*from w w w.jav a 2 s. co m*/ textdraw.setLetterSize(0.1f, 0.5f); textdraw.setTextSize(x + w - 4, h - 7); return textdraw; }
From source file:fi.hsl.parkandride.config.CoreConfigurationTest.java
@Test public void returns_a_long_enough_tokenSecret_as_is() { String goodSecret = StringUtils.repeat('x', AuthenticationService.SECRET_MIN_LENGTH); CoreConfiguration configuration = new CoreConfiguration(); configuration.tokenSecret = goodSecret; assertThat(configuration.tokenSecret(), is(goodSecret)); }
From source file:info.mikaelsvensson.devtools.common.PathUtils.java
public static String getRelativePath(File source, File target) { source = source.isDirectory() ? source : source.getParentFile(); String sourceFixed = fixPath(source); String targetFixed = fixPath(target); String[] sourceParts = StringUtils.split(sourceFixed, SEP); String[] targetParts = StringUtils.split(targetFixed, SEP); int sharedParts = 0; for (int i = 0; i < sourceParts.length; i++) { String sourcePart = sourceParts[i]; if (targetParts.length == i) { break; }/* w w w. j a va2 s.co m*/ String targetPart = targetParts[i]; if (sourcePart.equals(targetPart)) { sharedParts = i; } } String toSharedRoot = StringUtils.repeat(".." + SEP, sourceParts.length - sharedParts - 1); String fromSharedRoot = StringUtils.join(targetParts, SEP, sharedParts + 1, targetParts.length); if (StringUtils.isEmpty(toSharedRoot) && StringUtils.isEmpty(fromSharedRoot)) { return "." + SEP; } else { return toSharedRoot + fromSharedRoot; } }