List of usage examples for org.apache.commons.lang StringUtils rightPad
public static String rightPad(String str, int size)
Right pad a String with spaces (' ').
From source file:org.apache.mahout.classifier.chi_rwcs.mapreduce.TestModel.java
private void writeToFileClassifyTime(String time) throws IOException { FileSystem outFS = outputPath.getFileSystem(getConf()); FSDataOutputStream ofile = null;/*ww w. j a va 2 s . c o m*/ Path filenamePath = new Path(outputPath, dataName + "_classify_time").suffix(".txt"); try { if (ofile == null) { // this is the first value, it contains the name of the input file ofile = outFS.create(filenamePath); // write the Classify Time StringBuilder returnString = new StringBuilder(200); returnString.append("=======================================================").append('\n'); returnString.append("Classify Time\n"); returnString.append("-------------------------------------------------------").append('\n'); returnString.append(StringUtils.rightPad(time, 5)).append('\n'); returnString.append("-------------------------------------------------------").append('\n'); String output = returnString.toString(); ofile.writeUTF(output); ofile.close(); } } finally { Closeables.closeQuietly(ofile); } }
From source file:org.apache.mahout.classifier.df.mapreduce.Resampling.java
private void writeToFilePreprocessingTime(String time) throws IOException { FileSystem outFS = timePath.getFileSystem(getConf()); FSDataOutputStream ofile = null;/*from w w w .j a v a 2 s. co m*/ Path filenamePath = new Path(timePath, dataName + "_resampling_time").suffix(".txt"); try { if (ofile == null) { // this is the first value, it contains the name of the input file ofile = outFS.create(filenamePath); // write the Preprocessing Time StringBuilder returnString = new StringBuilder(200); returnString.append("=======================================================").append('\n'); returnString.append("Preprocessing Time\n"); returnString.append("-------------------------------------------------------").append('\n'); returnString.append(StringUtils.rightPad(time, 5)).append('\n'); returnString.append("-------------------------------------------------------").append('\n'); String output = returnString.toString(); ofile.writeUTF(output); ofile.close(); } } finally { Closeables.closeQuietly(ofile); } }
From source file:org.apache.mahout.utils.vectors.io.AbstractClusterWriter.java
public static String getTopFeatures(Vector vector, String[] dictionary, int numTerms) { List<TermIndexWeight> vectorTerms = Lists.newArrayList(); Iterator<Vector.Element> iter = vector.iterateNonZero(); while (iter.hasNext()) { Vector.Element elt = iter.next(); vectorTerms.add(new TermIndexWeight(elt.index(), elt.get())); }/*from ww w.j av a 2 s . c om*/ // Sort results in reverse order (ie weight in descending order) Collections.sort(vectorTerms, new Comparator<TermIndexWeight>() { @Override public int compare(TermIndexWeight one, TermIndexWeight two) { return Double.compare(two.weight, one.weight); } }); Collection<Pair<String, Double>> topTerms = new LinkedList<Pair<String, Double>>(); for (int i = 0; i < vectorTerms.size() && i < numTerms; i++) { int index = vectorTerms.get(i).index; String dictTerm = dictionary[index]; if (dictTerm == null) { log.error("Dictionary entry missing for {}", index); continue; } topTerms.add(new Pair<String, Double>(dictTerm, vectorTerms.get(i).weight)); } StringBuilder sb = new StringBuilder(100); for (Pair<String, Double> item : topTerms) { String term = item.getFirst(); sb.append("\n\t\t"); sb.append(StringUtils.rightPad(term, 40)); sb.append("=>"); sb.append(StringUtils.leftPad(item.getSecond().toString(), 20)); } return sb.toString(); }
From source file:org.apache.oodt.cas.cli.printer.StdCmdLinePrinter.java
@Override public String printActionsHelp(Set<CmdLineAction> actions) { StringBuilder sb = new StringBuilder(""); sb.append(/*from w w w . j ava2 s. c o m*/ "-----------------------------------------------------------------------------------------------------------------\n"); sb.append("|").append(StringUtils.rightPad(" Action", 35)).append("|").append(" Description\n"); sb.append( "-----------------------------------------------------------------------------------------------------------------\n"); for (CmdLineAction action : sortActions(actions)) { sb.append(" ").append(StringUtils.rightPad(action.getName(), 35)); sb.append(" ").append(action.getDescription()).append("\n\n"); } sb.append( "-----------------------------------------------------------------------------------------------------------------\n"); return sb.toString(); }
From source file:org.apache.oodt.cas.cli.printer.StdCmdLinePrinter.java
protected String getHeader() { return "" + "-----------------------------------------------------------------------------------------------------------------\n" + "|" + StringUtils.rightPad(" Short", 7) + "|" + StringUtils.rightPad(" Long", 50) + "| Description\n" + "-----------------------------------------------------------------------------------------------------------------\n"; }
From source file:org.apache.oodt.cas.cli.printer.StdCmdLinePrinter.java
protected String getOptionHelp(CmdLineOption option, String indent) { String argName = option.hasArgs() ? " <" + option.getArgsDescription() + ">" : ""; String optionUsage = indent + "-" + StringUtils.rightPad(option.getShortOption() + ",", 7) + "--" + StringUtils.rightPad((option.getLongOption() + argName), 49 - indent.length()) + option.getDescription();//from w ww. j a v a 2s . c o m optionUsage = " " + optionUsage; if (!option.getRequirementRules().isEmpty()) { optionUsage += "\n" + getFormattedString("Requirement Rules:", 62, 113) + getFormattedString(option.getRequirementRules().toString(), 63, 113); } if (option instanceof AdvancedCmdLineOption) { if (((AdvancedCmdLineOption) option).hasHandler()) { String handlerHelp = ((AdvancedCmdLineOption) option).getHandler().getHelp(option); if (handlerHelp != null) { optionUsage += "\n" + getFormattedString("Handler:", 62, 113) + getFormattedString(handlerHelp, 63, 113); } } } else if (isGroupOption(option)) { GroupCmdLineOption groupOption = asGroupOption(option); optionUsage += "\n"; optionUsage += " SubOptions:\n"; optionUsage += " > Required:\n"; List<CmdLineOption> optionalOptions = Lists.newArrayList(); for (GroupSubOption subOption : groupOption.getSubOptions()) { if (subOption.isRequired()) { optionUsage += getOptionHelp(subOption.getOption(), " "); } else { optionalOptions.add(subOption.getOption()); } } optionUsage += " > Optional:\n"; for (CmdLineOption optionalOption : optionalOptions) { optionUsage += getOptionHelp(optionalOption, " "); } } return optionUsage; }
From source file:org.apache.sqoop.connector.jdbc.oracle.OracleJdbcCommonInitializer.java
private void showUserTheOraOopWelcomeMessage() { String msg1 = String.format("Using %s", OracleJdbcConnectorConstants.ORACLE_SESSION_MODULE_NAME); int longestMessage = msg1.length(); msg1 = StringUtils.rightPad(msg1, longestMessage); char[] asterisks = new char[longestMessage + 8]; Arrays.fill(asterisks, '*'); String msg = String.format("\n" + "%1$s\n" + "*** %2$s ***\n" + "%1$s", new String(asterisks), msg1); LOG.info(msg);//from w w w. j a v a2 s . c o m }
From source file:org.apache.sqoop.manager.oracle.OraOopUtilities.java
public static String padRight(String s, int n) { return StringUtils.rightPad(s, n); }
From source file:org.apache.sqoop.shell.HelpCommand.java
@SuppressWarnings("unchecked") private void list() { Iterator<Command> iterator; // Figure out the max command name and shortcut length dynamically int maxName = 0; int maxShortcut = 0; iterator = shell.getRegistry().commands().iterator(); while (iterator.hasNext()) { Command command = iterator.next(); if (command.getHidden()) { continue; }/*from w w w. j av a2 s.co m*/ if (command.getName().length() > maxName) { maxName = command.getName().length(); } if (command.getShortcut().length() > maxShortcut) { maxShortcut = command.getShortcut().length(); } } printlnResource(Constants.RES_HELP_INFO); println(); // List the commands we know about printlnResource(Constants.RES_HELP_AVAIL_COMMANDS); iterator = shell.getRegistry().commands().iterator(); while (iterator.hasNext()) { Command command = iterator.next(); if (command.getHidden()) { continue; } String paddedName = StringUtils.rightPad(command.getName(), maxName); String paddedShortcut = StringUtils.rightPad(command.getShortcut(), maxShortcut); String description = command.getDescription(); StringBuilder sb = new StringBuilder(); sb.append(" ").append(MessageFormat.format(resource.getString(Constants.RES_HELP_CMD_DESCRIPTION), paddedName, paddedShortcut, description)); println(sb.toString()); } println(); printlnResource(Constants.RES_HELP_SPECIFIC_CMD_INFO); println(); }
From source file:org.apache.tajo.cli.tools.TajoAdmin.java
private void processList(Writer writer) throws ParseException, IOException, ServiceException, SQLException { List<BriefQueryInfo> queryList = tajoClient.getRunningQueryList(); SimpleDateFormat df = new SimpleDateFormat(DATE_FORMAT); StringBuilder builder = new StringBuilder(); /* print title */ builder.append(StringUtils.rightPad("QueryId", 21)); builder.append(StringUtils.rightPad("State", 20)); builder.append(StringUtils.rightPad("StartTime", 20)); builder.append(StringUtils.rightPad("Query", 30)).append("\n"); builder.append(StringUtils.rightPad(StringUtils.repeat("-", 20), 21)); builder.append(StringUtils.rightPad(StringUtils.repeat("-", 19), 20)); builder.append(StringUtils.rightPad(StringUtils.repeat("-", 19), 20)); builder.append(StringUtils.rightPad(StringUtils.repeat("-", 29), 30)).append("\n"); writer.write(builder.toString());/*from w w w . j ava 2s . com*/ builder = new StringBuilder(); for (BriefQueryInfo queryInfo : queryList) { builder.append(StringUtils.rightPad(new QueryId(queryInfo.getQueryId()).toString(), 21)); builder.append(StringUtils.rightPad(queryInfo.getState().name(), 20)); builder.append(StringUtils.rightPad(df.format(queryInfo.getStartTime()), 20)); builder.append(StringUtils.abbreviate(queryInfo.getQuery(), 30)).append("\n"); } writer.write(builder.toString()); }