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

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

Introduction

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

Prototype

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

Source Link

Document

Centers a String in a larger String of size size.

Usage

From source file:StringUtilsExampleV1.java

public static void main(String args[]) {
    System.err.println(StringUtils.center("MTV", 7, '='));
}

From source file:com.rslakra.java.string.TestApacheStringUtils.java

public static void main(String args[]) {

    System.err.println(StringUtils.abbreviate("Take time off working", 0, 10));
    System.err.println(StringUtils.capitalize("vanderLust"));
    System.err.println(StringUtils.center("MTV", 7, '='));
    System.err.println(StringUtils.chomp("temperature", "ure"));
    System.err.println(StringUtils.chop("Dane"));
    System.err.println(StringUtils.contains("Dorothy", "oro"));
    System.err.println(StringUtils.containsNone("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.containsOnly("r u m t", new char[] { 'r', 'o' }));
    System.err.println(StringUtils.countMatches("arthur", "r"));
    System.err.println(StringUtils.deleteWhitespace("f f f f"));
    System.err.println(StringUtils.difference("govern", "government"));
    System.err.println(StringUtils.getLevenshteinDistance("govern", "government"));

}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminEnDecrypt.java

/**
 *   //from ww w.  j  a  v a2s.  com
 * 
 * @param id  ?
 */
public void encrypt(String id) {
    StringBuilder encrypt = new StringBuilder(LINE_SEPERATOR);
    encrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("?")
            .append(LINE_SEPERATOR);
    encrypt.append("").append(StringUtils.center("ID Encryption", PRINT_COLUMN_SIZE, " "));
    encrypt.append("").append(LINE_SEPERATOR);
    encrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    encrypt.append("")
            .append(StringUtils.center(id + " => " + XNDiscCipher.encode(id), PRINT_COLUMN_SIZE, " "));
    encrypt.append("").append(LINE_SEPERATOR);
    encrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    if (printlog) {
        log.info(encrypt.toString());
    } else {
        out.print(encrypt.toString());
    }
}

From source file:com.titankingdoms.dev.titanchat.command.defaults.ListCommand.java

@Override
public void execute(CommandSender sender, String[] args) {
    String header = "&b" + StringUtils.center(" Channel List ", 50, '=');

    StringBuilder list = new StringBuilder();

    for (Channel ch : plugin.getChannelManager().getChannels()) {
        if (!ch.getOperators().contains(sender.getName()))
            if (!Vault.hasPermission(sender, "TitanChat.join." + ch.getName()))
                continue;

        if (ch.getStatus().equals(Status.STAFF) && !Vault.hasPermission(sender, "TitanChat.staff"))
            continue;

        if (ch.getBlacklist().contains(sender.getName()))
            continue;

        if (ch.getConfig().getBoolean("whitelist", false))
            if (!ch.getWhitelist().contains(sender.getName()))
                continue;

        if (list.length() > 0)
            list.append(", ");

        list.append(ch.getName() + " (" + ch.getLinkedPointCountByClass(Participant.class) + ")");
    }/*from w ww  .  j  av a 2s .  co m*/

    sender.sendMessage(header);
    sender.sendMessage(ChatUtils.wordWrap(list.toString(), 50));
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminFile.java

/**
 * ?   Console? //w  w  w  .j  a  v a2s . c  o  m
 * 
 * @param fileList NFile 
 */
private void showFileInfo(ArrayList<NFile> fileList) {
    int size = (fileList == null) ? 0 : fileList.size();
    NFile file = null;
    StringBuilder files = new StringBuilder(LINE_SEPERATOR);
    files.append("").append(StringUtils.center("", 32, "-"));
    files.append("");
    files.append(StringUtils.center("", 65, "-"));
    files.append("");
    files.append(StringUtils.center("", 10, "-"));
    files.append("");
    files.append(StringUtils.center("", 14, "-"));
    files.append("");
    files.append(StringUtils.center("", 14, "-"));
    files.append("");
    files.append(StringUtils.center("", 10, "-"));
    files.append("");
    files.append(StringUtils.center("", 5, "-"));
    files.append("?").append(LINE_SEPERATOR);

    files.append("").append(StringUtils.center("File ID", 32, " "));
    files.append("");
    files.append(StringUtils.center("File Name", 65, " "));
    files.append("");
    files.append(StringUtils.center("Size", 10, " "));
    files.append("");
    files.append(StringUtils.center("Create Date", 14, " "));
    files.append("");
    files.append(StringUtils.center("Modify Date", 14, " "));
    files.append("");
    files.append(StringUtils.center("Status", 10, " "));
    files.append("");
    files.append(StringUtils.center("Media", 5, " "));
    files.append("").append(LINE_SEPERATOR);

    if (size == 0) {
        int colidx = 0;
        files.append("").append(StringUtils.center("", 32, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 65, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        colidx++;
        files.append(StringUtils.center("", 5, "-"));
        files.append("").append(LINE_SEPERATOR);
        files.append("").append(StringUtils.center(" No Data Found.", PRINT_COLUMN_SIZE + colidx, " "))
                .append("").append(LINE_SEPERATOR);
    } else {
        files.append("").append(StringUtils.center("", 32, "-"));
        files.append("");
        files.append(StringUtils.center("", 65, "-"));
        files.append("");
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        files.append(StringUtils.center("", 5, "-"));
        files.append("").append(LINE_SEPERATOR);
    }

    for (int i = 0; i < size; i++) {
        file = (NFile) fileList.get(i);
        files.append("").append(StringUtils.center(file.getId(), 32, " "));
        files.append("");
        files.append(StringUtils.rightPad(getName(file.getName(), 65), 65, " "));
        files.append("");
        files.append(StringUtils.center(Integer.toString(file.getSize()), 10, " "));
        files.append("");
        files.append(StringUtils
                .center((StringUtils.isEmpty(file.getCreatedDate()) ? "N/A" : file.getCreatedDate()), 14, " "));
        files.append("");
        files.append(StringUtils.center(
                (StringUtils.isEmpty(file.getModifiedDate()) ? "N/A" : file.getModifiedDate()), 14, " "));
        files.append("");
        files.append(StringUtils.center(file.getStatType(), 10, " "));
        files.append("");
        files.append(StringUtils.center(Integer.toString(file.getMediaId()), 5, " "));
        files.append("").append(LINE_SEPERATOR);
        if ((i < size - 1) && (i <= MAX_LIST_SIZE)) {
            files.append("").append(StringUtils.center("", 32, "-"));
            files.append("");
            files.append(StringUtils.center("", 65, "-"));
            files.append("");
            files.append(StringUtils.center("", 10, "-"));
            files.append("");
            files.append(StringUtils.center("", 14, "-"));
            files.append("");
            files.append(StringUtils.center("", 14, "-"));
            files.append("");
            files.append(StringUtils.center("", 10, "-"));
            files.append("");
            files.append(StringUtils.center("", 5, "-"));
            files.append("").append(LINE_SEPERATOR);
        }
        if (i > MAX_LIST_SIZE) {
            break;
        }
    }
    if (size == 0) {
        files.append("").append(StringUtils.center("", 32, "-"));
        files.append("-");
        files.append(StringUtils.center("", 65, "-"));
        files.append("-");
        files.append(StringUtils.center("", 10, "-"));
        files.append("-");
        files.append(StringUtils.center("", 14, "-"));
        files.append("-");
        files.append(StringUtils.center("", 14, "-"));
        files.append("-");
        files.append(StringUtils.center("", 10, "-"));
        files.append("-");
        files.append(StringUtils.center("", 5, "-"));
        files.append("").append(LINE_SEPERATOR);
    } else {
        files.append("").append(StringUtils.center("", 32, "-"));
        files.append("");
        files.append(StringUtils.center("", 65, "-"));
        files.append("");
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        files.append(StringUtils.center("", 14, "-"));
        files.append("");
        files.append(StringUtils.center("", 10, "-"));
        files.append("");
        files.append(StringUtils.center("", 5, "-"));
        files.append("").append(LINE_SEPERATOR);
    }
    files.append(size + " row selected.").append(LINE_SEPERATOR).append(LINE_SEPERATOR);
    if (printlog) {
        log.info(files.toString());
    } else {
        out.print(files.toString());
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminVolume.java

/**
 * ? ?  ??   Console? /* w  w  w  .  jav a 2s  .c o  m*/
 * 
 * @param name 
 * @param accessAuth  
 * @param desc  
 */
public void makeVolume(String name, String accessAuth, String desc) {
    try {
        Volume volume = new Volume();
        volume.setName(name);
        volume.setAccessable(accessAuth);
        volume.setDesc(desc);
        volume.setCreatedDate(getCreateDate());
        storage.insertNewVolumeToDB(volume);
        StringBuilder volumes = new StringBuilder(LINE_SEPERATOR);
        volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("?").append(LINE_SEPERATOR);
        volumes.append("").append(StringUtils.center("makeVolue Successfully", 100, " ")).append("")
                .append(LINE_SEPERATOR);
        volumes.append("").append(StringUtils.rightPad("", 100, "-")).append("").append(LINE_SEPERATOR);
        if (printlog) {
            log.info(volumes.toString());
        } else {
            out.print(volumes.toString());
        }
    } catch (Exception ex) {
        logger.log(LoggerIF.LOG_ERROR, "makeVolume() has been failed... " + ex.getMessage());
    }
}

From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java

private static void exerciseRegularInsert(Connection con) throws SQLException {
    logger.info(StringUtils.center("exercise regular insert", 100, "-"));

    Statement stmt = null;/*from w  ww .  jav  a  2s. c  om*/
    try {
        stmt = con.createStatement();
        stmt.executeUpdate("INSERT INTO TEST_TABLE VALUES ( 'value1' )");
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:com.sds.acube.ndisc.xadmin.XNDiscAdminEnDecrypt.java

/**
 *   /*from   ww  w .j  a  va  2 s  .c o m*/
 * 
 * @param id  ?
 */
public void decrypt(String id) {
    StringBuilder decrypt = new StringBuilder(LINE_SEPERATOR);
    decrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("?")
            .append(LINE_SEPERATOR);
    decrypt.append("").append(StringUtils.center("ID Decryption", PRINT_COLUMN_SIZE, " "));
    decrypt.append("").append(LINE_SEPERATOR);
    decrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    decrypt.append("")
            .append(StringUtils.center(id + " => " + XNDiscCipher.decode(id), PRINT_COLUMN_SIZE, " "));
    decrypt.append("").append(LINE_SEPERATOR);
    decrypt.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
            .append(LINE_SEPERATOR);
    if (printlog) {
        log.info(decrypt.toString());
    } else {
        out.print(decrypt.toString());
    }
}

From source file:net.big_oh.common.jdbc.JdbcProxyExerciser.java

private static void exerciseBatchInsert(Connection con) throws SQLException {
    logger.info(StringUtils.center("exercise batch insert", 100, "-"));

    Statement stmt = null;/*from w  w  w.j a v  a  2  s.c om*/
    try {
        stmt = con.createStatement();
        stmt.addBatch("INSERT INTO TEST_TABLE VALUES ( 'value2' )");
        stmt.addBatch("INSERT INTO TEST_TABLE VALUES ( 'value3' )");
        stmt.executeBatch();
    } finally {
        DbUtils.closeQuietly(stmt);
    }
}

From source file:dbutils.ExampleJDBC.java

/**
 * BeanListHandler ResultSet??ListList//w w w.  java  2s.c  om
 */
public static void getBeanListData() {
    Connection conn = getConnection();
    QueryRunner qr = new QueryRunner();
    try {
        ResultSetHandler<Student> rsh = new BeanHandler(Student.class);
        Student usr = qr.query(conn,
                "SELECT id, name, gender, age, team_id as teamId FROM test_student WHERE id=1", rsh);
        System.out.println(StringUtils.center("findById", 50, '*'));
        System.out.println("id=" + usr.getId() + " name=" + usr.getName() + " gender=" + usr.getGender());

        List<Student> results = (List<Student>) qr.query(conn,
                "SELECT id, name, gender, age, team_id as teamId FROM test_student LIMIT 10",
                new BeanListHandler(Student.class));
        System.out.println(StringUtils.center("findAll", 50, '*'));
        for (Student result : results) {
            System.out.println(
                    "id=" + result.getId() + "  name=" + result.getName() + "  gender=" + result.getGender());
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DbUtils.closeQuietly(conn);
    }
}