Example usage for org.apache.commons.lang3 StringUtils center

List of usage examples for org.apache.commons.lang3 StringUtils center

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils center.

Prototype

public static String center(final String str, final int size) 

Source Link

Document

Centers a String in a larger String of size size using the space character (' ').

If the size is less than the String length, the String is returned.

Usage

From source file:ro.fortsoft.pf4j.demo.Boot.java

private static void printLogo() {
    System.out.println(StringUtils.repeat("#", 40));
    System.out.println(StringUtils.center("PF4J-DEMO", 40));
    System.out.println(StringUtils.repeat("#", 40));
}

From source file:sawtooth.examples.xo.XoHandler.java

/**
 * Helper function to print game data to the logger.
 *//*from  w  w w . ja v  a  2 s  . c o  m*/
private void display(String msg) {
    String displayMsg = "";
    int length = 0;
    String[] msgLines = msg.split("\n");
    if (msg.contains("\n")) {
        for (String line : msgLines) {
            if (line.length() > length) {
                length = line.length();
            }
        }
    } else {
        length = msg.length();
    }

    displayMsg = displayMsg.concat("\n+" + printDashes(length + 2) + "+\n");
    for (String line : msgLines) {
        displayMsg = displayMsg.concat("+" + StringUtils.center(line, length + 2) + "+\n");
    }
    displayMsg = displayMsg.concat("+" + printDashes(length + 2) + "+");
    logger.info(displayMsg);
}

From source file:us.parr.animl.data.DataTable.java

public String toString(VariableFormat[] colFormats) {
    StringBuilder buf = new StringBuilder();
    List<Integer> colWidths = map(colNames, n -> n.length());
    // compute column widths as max of col name or widest value in column
    for (int j = 0; j < colWidths.size(); j++) {
        int w = Math.max(colWidths.get(j), getColumnMaxWidth(j));
        colWidths.set(j, w);/* w ww . j a  v a2  s. co m*/
        String name = StringUtils.center(colNames[j], w);
        if (j > 0) {
            buf.append(" ");
        }
        buf.append(name);
    }
    buf.append("\n");
    for (int i = 0; i < rows.size(); i++) {
        Object[] values = getValues(i);
        for (int j = 0; j < colWidths.size(); j++) {
            int colWidth = colWidths.get(j);
            String colValue = values[j].toString();
            switch (colFormats[colTypes[j].ordinal()]) {
            case LEFT:
                colValue = String.format("%-" + colWidth + "s", colValue);
                break;
            case CENTER:
                colValue = StringUtils.center(colValue, colWidth);
                break;
            case RIGHT:
                colValue = String.format("%" + colWidth + "s", colValue);
                break;
            }
            if (j > 0) {
                buf.append(" ");
            }
            buf.append(colValue);
        }
        buf.append("\n");
    }
    return buf.toString();
}

From source file:zombiesia.Messages.java

/**
 * Mthode affichant le message dynamiquement, en fonction de la longueur du message.
 * @param messages Un tableau de messages  afficher  la suite
 *///from w w w. ja  v  a  2s . c  o m
public static void introArray(String[] messages) {
    try {
        for (String mess : messages) {
            String[] lines = WordUtils.wrap(mess, longueur, "\n", true).split("\n");
            System.out.println("--" + StringUtils.repeat(' ', longueur) + "--");
            for (String l : lines)
                System.out.println("--" + StringUtils.center(l, longueur) + "--");

            System.out.println(StringUtils.repeat('-', longueur + 4));

            Thread.sleep(mess.length() * 45);
        }
    } catch (Exception e) {
        System.err.print("Erreur : Opration interrompue.");
    }
}