Example usage for org.apache.commons.lang StringUtils rightPad

List of usage examples for org.apache.commons.lang StringUtils rightPad

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils rightPad.

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:net.erdfelt.android.sdkfido.console.TablePrinter.java

public void print(PrintStream out) {
    String indent = "  ";

    // Need to calculate widths
    int widths[] = new int[columnCount];

    // Establish baseline values with headers row
    for (int col = 0; col < columnCount; col++) {
        widths[col] = headers[col].length();
    }/*from ww  w . j  av  a  2 s  . co  m*/

    // Now parse all of the rows to grow the column widths to fit.
    for (String[] row : rows) {
        for (int col = 0; col < columnCount; col++) {
            widths[col] = Math.max(row[col].length(), widths[col]);
        }
    }

    // Print Header Row
    out.print(indent);
    boolean delim = false;
    for (int col = 0; col < columnCount; col++) {
        if (delim) {
            out.print(" | ");
        }
        out.print(StringUtils.rightPad(headers[col], widths[col]));
        delim = true;
    }
    out.println();

    // Print Horiz Rule
    out.print("--");
    delim = false;
    for (int col = 0; col < columnCount; col++) {
        if (delim) {
            out.print("-+-");
        }
        out.print(StringUtils.rightPad("", widths[col], '-'));
        delim = true;
    }
    out.println("--");

    // Print Rows
    for (String[] row : rows) {
        out.print(indent);
        delim = false;
        for (int col = 0; col < columnCount; col++) {
            if (delim) {
                out.print(" | ");
            }
            out.print(StringUtils.rightPad(row[col], widths[col]));
            delim = true;
        }
        out.println();
    }
}

From source file:com.actian.services.knime.core.operators.DeriveGroupNodeDialogPane.java

public DeriveGroupNodeDialogPane() {
    initComponents();/*from   w w w  .  jav a 2s  . c o m*/
    // Find out which aggregation functions are loaded.
    Collection<String> list = new ArrayList<>();
    Iterator<FunctionDescription> it = AggregationRegistry.getInstance().getFunctionDescriptions().iterator();
    while (it.hasNext()) {
        FunctionDescription fd = it.next();
        String desc = StringUtils.rightPad(fd.getName(), 20) + fd.getDescription();
        list.add(desc);
    }
    fcomboBox.setModel(new DefaultComboBoxModel<String>(list.toArray(new String[] {})));

}

From source file:edu.msu.cme.rdp.readseq.readers.core.SFFCore.java

public static void main(String[] args) throws Exception {
    SFFCore core = new SFFCore(new File("test/454Reads.sff"));

    System.out.println("Common header:");
    System.out.println(StringUtils.rightPad("  Version:", 20) + core.commonHeader.version);
    System.out.println(StringUtils.rightPad("  Index offset:", 20) + core.commonHeader.indexOffset);
    System.out.println(StringUtils.rightPad("  Index length:", 20) + core.commonHeader.indexLength);
    System.out.println(StringUtils.rightPad("  Num reads:", 20) + core.commonHeader.numReads);
    System.out.println(StringUtils.rightPad("  Header length:", 20) + core.commonHeader.headerLength);
    System.out.println(StringUtils.rightPad("  Key length:", 20) + core.commonHeader.keyLength);
    System.out.println(StringUtils.rightPad("  Num flows:", 20) + core.commonHeader.flowLength);
    System.out.println(StringUtils.rightPad("  Flowgram format:", 20) + core.commonHeader.flowgramFormat);
    System.out.println(StringUtils.rightPad("  Flow:", 20) + core.commonHeader.flow);
    System.out.println(StringUtils.rightPad("  Key:", 20) + core.commonHeader.key);

    System.out.println();//w ww .ja v a  2  s  .  c  o  m
    ReadBlock block = core.readReadBlock();
    System.out.println(">" + block.name);
    System.out.println(StringUtils.rightPad("  Name:", 20) + block.name);
    System.out.println(StringUtils.rightPad("  Name length:", 20) + block.nameLength);
    System.out.println(StringUtils.rightPad("  Number of bases:", 20) + block.numBases);
    System.out.println(StringUtils.rightPad("  Length:", 20) + block.headerLength);
    System.out.println(StringUtils.rightPad("  Clip adapter left:", 20) + block.clipAdapterLeft);
    System.out.println(StringUtils.rightPad("  Clip adapter right:", 20) + block.clipAdapterRight);
    System.out.println(StringUtils.rightPad("  Clip qual left:", 20) + block.clipQualLeft);
    System.out.println(StringUtils.rightPad("  Clip qual right:", 20) + block.clipQualRight);

    System.out.print(StringUtils.rightPad("Flowgrams:", 20));
    for (int index = 0; index < block.flowgrams.length; index++) {
        System.out.print(StringUtils.rightPad(block.flowgrams[index] + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Flow Indices:", 20));
    for (int index = 0; index < block.flowIndex.length; index++) {
        System.out.print(StringUtils.rightPad(block.flowIndex[index] + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Sequence:", 20));
    for (int index = 0; index < block.seq.length(); index++) {
        System.out.print(StringUtils.rightPad(block.seq.charAt(index) + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Quality:", 20));
    for (int index = 0; index < block.qual.length; index++) {
        System.out.print(StringUtils.rightPad(block.qual[index] + "", 10));
    }
    System.out.println();

    System.out.println();
    block = core.readReadBlock();
    System.out.println(">" + block.name);
    System.out.println(StringUtils.rightPad("  Name:", 20) + block.name);
    System.out.println(StringUtils.rightPad("  Name length:", 20) + block.nameLength);
    System.out.println(StringUtils.rightPad("  Number of bases:", 20) + block.numBases);
    System.out.println(StringUtils.rightPad("  Length:", 20) + block.headerLength);
    System.out.println(StringUtils.rightPad("  Clip adapter left:", 20) + block.clipAdapterLeft);
    System.out.println(StringUtils.rightPad("  Clip adapter right:", 20) + block.clipAdapterRight);
    System.out.println(StringUtils.rightPad("  Clip qual left:", 20) + block.clipQualLeft);
    System.out.println(StringUtils.rightPad("  Clip qual right:", 20) + block.clipQualRight);

    System.out.print(StringUtils.rightPad("Flowgrams:", 20));
    for (int index = 0; index < block.flowgrams.length; index++) {
        System.out.print(StringUtils.rightPad(block.flowgrams[index] + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Flow Indices:", 20));
    for (int index = 0; index < block.flowIndex.length; index++) {
        System.out.print(StringUtils.rightPad(block.flowIndex[index] + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Sequence:", 20));
    for (int index = 0; index < block.seq.length(); index++) {
        System.out.print(StringUtils.rightPad(block.seq.charAt(index) + "", 10));
    }
    System.out.println();

    System.out.print(StringUtils.rightPad("Quality:", 20));
    for (int index = 0; index < block.qual.length; index++) {
        System.out.print(StringUtils.rightPad(block.qual[index] + "", 10));
    }
    System.out.println();

    core.close();
}

From source file:de.weltraumschaf.registermachine.vm.RegisterMachine.java

private void debugInit(final StringBuilder debugOutput) {
    if (debug) {/*w  w w. ja  va2  s. c o m*/
        debugOutput.append(StringUtils.rightPad("Init", DEBUG_PAD)).append(" > ").append(config.toString())
                .append(App.NL);
    }
}

From source file:es.emergya.ui.base.plugins.AbstractPlugin.java

protected void loadProperties(String file) {
    Properties p = new Properties();

    try {/*from   ww  w  .ja v a 2s .  c o  m*/
        InputStream is = GoClassLoader.getGoClassLoader().getResourceAsStream(file);
        if (is == null)
            is = LogicConstants.class.getResourceAsStream(file);
        p.load(is);

        this.title = p.getProperty("TITLE");
        this.type = PluginType.getType(p.getProperty("TYPE", "UNKNOWN"));
        this.order = new Integer(p.getProperty("ORDER", "0"));
        this.tip = p.getProperty("TIP", this.title);

    } catch (Throwable e) {
        Logger.getLogger(this.getClass()).error("Couldn't load property file", e);
        this.title = StringUtils.rightPad("Unknown Module", 25);
        this.type = null;
        this.order = new Integer(0);
        this.tip = title;
    }
}

From source file:com.jgui.ttscrape.TextualShowWriter.java

/**
 * Append the show the show file.  Write the title, subtitle
 * rating and date/time./*from  ww  w.j  av  a2s.  c  o  m*/
 * @param writerName name of the writer previously established
 * @param s show to be written. 
 */
@Override
public void writeShow(String writerName, Show s) {
    try {
        Writer w = writers.get(writerName);
        if (w == null) {
            logger.error("writer {} not found", writerName);
        } else {
            StringBuffer sb = new StringBuffer();
            int titlePad = 35;
            String str = s.getTitle();
            if (s.getStars() > 0) {
                str = str + " (" + s.getStars() + ")";
            }
            if (w.includeSubtitle && (s.getSubtitle() != null)) {
                str = str + " " + s.getSubtitle();
                titlePad += 10;
            }
            sb.append(StringUtils.rightPad(str, titlePad));
            sb.append("\t");
            DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm");
            sb.append(StringUtils.rightPad(df.format(s.getStartTime()), 20));
            sb.append("\t");
            sb.append(s.getChannelName() + " " + s.getChannelNumber());
            w.writer.write(sb.toString());
            w.writer.write("\n");
            if (w.includeSubtitle) {
                // write an extra newline to separate
                w.writer.write("\n");
            }
            w.writer.flush();
        }
    } catch (IOException ex) {
        logger.error("failed to write", ex);
    }
}

From source file:com.mosso.client.cloudfiles.sample.FilesList.java

private static void printContainer(String containerName, boolean humanReadable)
        throws IOException, HttpException, FilesException {
    boolean notFound = true;
    FilesClient client = new FilesClient();
    if (client.login()) {
        List<FilesContainer> containers = client.listContainers();
        System.out.println(client.getAccount() + " containers: ");
        for (FilesContainer value : containers) {
            if (value.getName().equalsIgnoreCase(containerName)) {
                notFound = false;/*  w  ww . j a v a 2s  .c om*/

                FilesContainerInfo info = value.getInfo();
                System.out.println("\t" + value.getName() + " - " + info.getObjectCount() + " objects:");

                List<FilesObject> objects = value.getObjects();
                for (FilesObject obj : objects) {
                    if (humanReadable)
                        System.out.println(
                                "\t\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSizeString());
                    else
                        System.out.println(
                                "\t\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSize() + " Bytes");
                }

                if (humanReadable) {
                    System.out.println("\tTotal Size: " + info.getTotalSize() / 1024 + "KB\n");
                } else
                    System.out.println("\tTotal Size: " + info.getTotalSize() + "Bytes\n");
            } //if (value.getName().equalsIgnoreCase(containerName))
            else
                notFound = true;
        } //end for

        if (notFound)
            System.out.println("Container: " + containerName + " was not found !");
    }
}

From source file:de.weltraumschaf.registermachine.vm.RegisterMachine.java

private void debugInstruction(final StringBuilder debugOutput, final Instruction instruction) {
    if (debug) {/*w  w  w  .  j  a v a  2 s. c o m*/
        debugOutput.append(StringUtils.rightPad("Instruction '" + instruction.toString() + "'", DEBUG_PAD))
                .append(" > ").append(config.toString()).append(App.NL);
    }
}

From source file:com.seajas.search.profiler.task.LoggingCleanupTask.java

/**
 * Perform the actual cleaning./*from  w w w  . j a va 2 s  . co m*/
 */
public void cleanup() {
    logger.info("Started log cleaner job");

    // Keep track of the start date for cache clean-up

    Calendar currentDate = Calendar.getInstance();

    currentDate.add(Calendar.HOUR, -loggingRetentionTime);

    List<Logging> entries = profilerService.cleanLogging(currentDate.getTime());

    logger.info("Moving " + entries.size() + " entries from the logging database to on-disk storage");

    // Create a date-formatter

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    SimpleDateFormat fullFormatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");

    // We keep a writer per day

    Map<String, Writer> writerMap = new HashMap<String, Writer>();

    // Write the removed logging entries to their respective files

    for (Logging entry : entries) {
        String date = formatter.format(entry.getCreationDate());

        try {
            Writer writer = writerMap.get(date);

            if (writer == null)
                writerMap.put(date,
                        writer = new FileWriter(loggingPath + File.separator + date + ".log", true));

            writer.write(fullFormatter.format(entry.getCreationDate()) + " "
                    + StringUtils.rightPad(entry.getLevel().toUpperCase(), RIGHT_PAD_SPACES) + " "
                    + entry.getMessage().trim() + "\n");
        } catch (IOException e) {
            logger.error("Could not write the logging entry to the log file for date " + date);
        }
    }

    // Flush and then close the writers

    for (Map.Entry<String, Writer> entry : writerMap.entrySet()) {
        try {
            entry.getValue().flush();
            entry.getValue().close();
        } catch (IOException e) {
            logger.error("Could not flush and close the given log file", e);
        }
    }

    logger.info("Finishing log cleaner job");
}

From source file:com.seajas.search.attender.service.task.LoggingCleanupTask.java

/**
 * Perform the actual cleaning.//  w ww.java2  s  . co  m
 */
public void cleanup() {
    logger.info("Started log cleaner job");

    // Keep track of the start date for cache clean-up

    Calendar currentDate = Calendar.getInstance();

    currentDate.add(Calendar.HOUR, -loggingRetentionTime);

    List<Logging> entries = attenderService.cleanLogging(currentDate.getTime());

    logger.info("Moving " + entries.size() + " entries from the logging database to on-disk storage");

    // Create a date-formatter

    SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
    SimpleDateFormat fullFormatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");

    // We keep a writer per day

    Map<String, Writer> writerMap = new HashMap<String, Writer>();

    // Write the removed logging entries to their respective files

    for (Logging entry : entries) {
        String date = formatter.format(entry.getCreationDate());

        try {
            Writer writer = writerMap.get(date);

            if (writer == null)
                writerMap.put(date,
                        writer = new FileWriter(loggingPath + File.separator + date + ".log", true));

            writer.write(fullFormatter.format(entry.getCreationDate()) + " "
                    + StringUtils.rightPad(entry.getLevel().toUpperCase(), RIGHT_PAD_SPACES) + " "
                    + entry.getMessage().trim() + "\n");
        } catch (IOException e) {
            logger.error("Could not write the logging entry to the log file for date " + date);
        }
    }

    // Flush and then close the writers

    for (Map.Entry<String, Writer> entry : writerMap.entrySet()) {
        try {
            entry.getValue().flush();
            entry.getValue().close();
        } catch (IOException e) {
            logger.error("Could not flush and close the given log file", e);
        }
    }

    logger.info("Finishing log cleaner job");
}