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:com.sds.acube.ndisc.mts.xserver.XNDiscServer.java

/**
 * FixedThreadPool ?  Console?   Notice 
 *///w  w w.ja v  a 2 s  .  c  om
private void getXNDiscNotice() {
    if (WORKER_POOL_TYPE.equals("F")
            && XNDiscConfig.getBoolean(XNDiscConfig.MULTIPLICATION_THREAD_AVAILABLE_PROCESSORS)) {
        int worker_thread_pool = XNDiscConfig.getInt(XNDiscConfig.WORKER_POOL_THREAD_COUNT, 15);
        StringBuilder msg = new StringBuilder(LINE_SEPERATOR);
        msg.append("").append(StringUtils.center(" XNDisc Server Notice !!! ", 90, "-")).append("?")
                .append(LINE_SEPERATOR);
        msg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
        msg.append("")
                .append(StringUtils.rightPad("Readjust the number of the Worker Thread Pool,", 90, " "))
                .append("").append(LINE_SEPERATOR);
        msg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
        msg.append("")
                .append(StringUtils.rightPad("Original Thread Pool Size : " + worker_thread_pool
                        + " => Changed Thread Pool Size : " + WORKER_THREAD_POOL, 90, " "))
                .append("").append(LINE_SEPERATOR);
        msg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
        msg.append("").append(StringUtils.rightPad("", 90, "-")).append("").append(LINE_SEPERATOR);
        logger.log(LoggerIF.LOG_INFO, msg.toString());
    }
}

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

/**
 * ?   ? Console? /*from w w  w .j a  v a  2  s  . c  om*/
 * 
 * @param host HOST 
 * @param port PORT 
 * @param fileId ? ?
 */
public void removeFile(String host, int port, String fileId) {
    NFile[] nFile = null;
    int numOfFiles = 1;
    try {
        if (fileId.indexOf(",") >= 0) {
            String fileIds[] = StringUtils.split(fileId, ",");
            if (fileIds != null && fileIds.length > 0) {
                nFile = new NFile[fileIds.length];
                for (int i = 0; i < fileIds.length; i++) {
                    nFile[i] = new NFile();
                    nFile[i].setId(fileIds[i]);
                }
            }
        } else {
            nFile = new NFile[numOfFiles];
            nFile[0] = new NFile();
            nFile[0].setId(fileId);
        }
        xnapi.XNDisc_Connect(host, port);
        boolean ret = xnapi.XNDISC_FileDel(nFile);
        if (ret) {
            StringBuilder files = new StringBuilder(LINE_SEPERATOR);
            files.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("?")
                    .append(LINE_SEPERATOR);
            if (fileId.indexOf(",") >= 0) {
                String fileIds[] = StringUtils.split(fileId, ",");
                if (fileIds != null && fileIds.length > 0) {
                    for (int i = 0; i < fileIds.length; i++) {
                        files.append("").append(StringUtils.center("removeFile[" + i + "] : " + fileIds[i],
                                PRINT_COLUMN_SIZE, " ")).append("").append(LINE_SEPERATOR);
                    }
                }
            } else {
                files.append("").append(StringUtils.center("removeFile : " + fileId, PRINT_COLUMN_SIZE, " "))
                        .append("").append(LINE_SEPERATOR);
            }
            files.append("").append(StringUtils.rightPad("", PRINT_COLUMN_SIZE, "-")).append("")
                    .append(LINE_SEPERATOR);
            if (printlog) {
                log.info(files.toString());
            } else {
                out.print(files.toString());
            }
        } else {
            logger.log(LoggerIF.LOG_ERROR, "Remove File ID : " + fileId + " failed !!!!");
        }
    } catch (FileException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NetworkException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } catch (NDiscException e) {
        logger.log(LoggerIF.LOG_ERROR, e.getMessage());
    } finally {
        try {
            xnapi.XNDisc_Disconnect();
        } catch (NetworkException ne) {
            logger.log(LoggerIF.LOG_ERROR, ne.getMessage());
        } catch (IOException e) {
            logger.log(LoggerIF.LOG_ERROR, e.getMessage());
        }
    }
}

From source file:com.sds.acube.ndisc.mts.xserver.XNDiscServer.java

/**
 * XNDisc Server ?  /* www  .  j a  v a  2 s. com*/
 * 
 * @return ? 
 */
private String getXNDiscServerStartMessage() {
    StringBuilder smsg = new StringBuilder(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.rightPad("", 90, "-")).append("?").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.center("XNDisc Server (Version : " + XNDISC_SERVER_VERSION + ")", 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.center("Listening on " + this.server.getLocalAddress().getHostName() + "("
                    + this.server.getLocalAddress().getHostAddress() + "):" + this.server.getLocalPort(), 90,
                    " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("Start on " + XNDiscUtils.getStartDate(), 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center(" XNDisc Server Options ", 90, "-")).append("")
            .append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.rightPad("       Use SSL : " + Boolean.toString(USE_SSL), 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       Dispatcher Initial Size : " + DISPATCHER_INIT_COUNT, 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(
            StringUtils.rightPad("       Dispatcher maximum Handle Size : " + DISPATCHER_MAX_HANDLES, 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       Read Buffer Use Direct : " + READ_BUFFER_USEDIRECT, 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       Worker Pool Thread Priority : "
                    + XNDiscConfig.getString(XNDiscConfig.WORKER_POOL_PRIORITY, "NORM"), 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       Worker Pool minimun Size : " + MIN_SIZE_WORKER_POOL, 90, " "))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       Worker Pool maximum Size : " + SIZE_WORKER_POOL, 90, " "))
            .append("").append(LINE_SEPERATOR);
    if (WORKER_POOL_TYPE.equals("F")) {
        smsg.append("").append(StringUtils.rightPad("       Thread Pool Type : Fixed", 90, " "))
                .append("").append(LINE_SEPERATOR);
        smsg.append("")
                .append(StringUtils.rightPad("       Thread Pool Size : " + WORKER_THREAD_POOL, 90, " "))
                .append("").append(LINE_SEPERATOR);
    } else if (WORKER_POOL_TYPE.equals("C")) {
        smsg.append("").append(StringUtils.rightPad("       Thread Pool Type : Cached", 90, " "))
                .append("").append(LINE_SEPERATOR);
    }
    smsg.append("").append(StringUtils.center("", 90, " ")).append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.rightPad("", 90, "-")).append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       OS Architecture   : " + System.getProperty("os.arch"), 90, ""))
            .append("").append(LINE_SEPERATOR);
    smsg.append("")
            .append(StringUtils.rightPad("       OS Name           : " + System.getProperty("os.name"), 90, ""))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(
            StringUtils.rightPad("       OS Version        : " + System.getProperty("os.version"), 90, ""))
            .append("").append(LINE_SEPERATOR);
    Runtime runtime = Runtime.getRuntime();
    smsg.append("").append(
            StringUtils.rightPad("       Processors        : " + runtime.availableProcessors() + "(s)", 90, ""))
            .append("").append(LINE_SEPERATOR);
    smsg.append("").append(StringUtils.rightPad("", 90, "-")).append("").append(LINE_SEPERATOR);
    return smsg.toString();
}

From source file:edu.utah.further.core.api.text.StringUtil.java

/**
 * <p>/*  www  .j  ava2s .  c  om*/
 * Centers a String in a larger String of size <code>size</code>. Uses a supplied
 * String as the value to pad the String with.
 * </p>
 * 
 * <p>
 * If the size is less than the String length, the String is returned. A
 * <code>null</code> String returns <code>null</code>. A negative size is treated as
 * zero.
 * </p>
 * 
 * <pre>
 * StringUtil.centerWithSpace(null, *, *)     = null
 * StringUtil.centerWithSpace("header", 12, '=')    = "== Header =="
 * </pre>
 */
public static String centerWithSpace(final String str, final int size, final String padStr) {
    return StringUtils.center(SPACE_STRING + str + SPACE_STRING, size, padStr);
}

From source file:edu.utah.further.core.api.text.StringUtil.java

/**
 * The same as {@link #centerWithSpace(String, int, String)}, only that the size is
 * the size of the padding on each side of <code>str</code> rather than the total
 * output string length.//from w  ww . j a va2 s .  c om
 * 
 * @param str
 * @param padSize
 * @param padStr
 * @return
 */
public static String centerWithSpacePadSize(final String str, final int padSize, final String padStr) {
    return StringUtils.center(SPACE_STRING + str + SPACE_STRING, str.length() + 2 + padSize, padStr);
}

From source file:org.apache.sqoop.shell.utils.TableDisplayer.java

/**
 * Display given columns in nice table structure to given IO object.
 *
 * @param headers List of headers/*from   www.  ja  va  2s.  co m*/
 * @param columns Array of columns
 */
public static void display(List<String> headers, List<String>... columns) {
    assert headers != null;
    assert columns != null;
    assert headers.size() == columns.length;

    // Count of columns
    int columnCount = headers.size();

    // List of all maximal widths of each column
    List<Integer> widths = new LinkedList<Integer>();
    for (int i = 0; i < columnCount; i++) {
        widths.add(getMaximalWidth(headers.get(i), columns[i]));
    }

    // First line is border
    drawLine(widths);

    // Print out header (text is centralised)
    print("| ");
    for (int i = 0; i < columnCount; i++) {
        print(StringUtils.center(headers.get(i), widths.get(i), ' '));
        print((i == columnCount - 1) ? " |" : " | ");
    }
    println();

    // End up header by border
    drawLine(widths);

    // Number of rows in the table
    int rows = getMaximalRows(columns);

    // Print out each row
    for (int row = 0; row < rows; row++) {
        print("| ");
        for (int i = 0; i < columnCount; i++) {
            print(StringUtils.rightPad(columns[i].get(row), widths.get(i), ' '));
            print((i == columnCount - 1) ? " |" : " | ");
        }
        println();
    }

    // End table by final border
    drawLine(widths);
}

From source file:org.isatools.isatab.export.isatab.pipeline.GraphLayersTest.java

@Test
public void testBasics() {
    out.println("\n\n" + StringUtils.center(" Testing GraphLayers, basics ", 120, "-") + "\n");

    GraphLayers gls = new GraphLayers();

    DataNode dn1 = new DataNode(null);
    dn1.setAcc("dn1");

    DataNode dn2 = new DataNode(null);
    dn2.setAcc("dn2");

    DataNode dn3 = new DataNode(null);
    dn3.setAcc("dn3");

    gls.setLayer(dn1, 0);/*from  w  ww . j a v  a2 s  .  com*/
    gls.setLayer(dn2, 2);
    gls.setLayer(dn1, 1);
    gls.setLayer(dn3, -1);

    assertEquals("Rats! Wrong layer for dn1!", 1, gls.getLayer(dn1));
    assertEquals("Rats! Wrong layer for dn2!", 2, gls.getLayer(dn2));
    assertTrue("Rats! Layer 2 should contain dn2!", gls.containsGraphEl(2, dn2));
    assertTrue("Rats! Layer 1 should contain dn1!", gls.getGraphEls(1).contains(dn1));
    assertEquals("Rats! dn3 should not be in!", -1, gls.getLayer(dn3));

    out.println("\n" + StringUtils.center(" /end: Testing GraphLayers, basics ", 120, "-") + "\n");

}

From source file:org.isatools.isatab.export.isatab.pipeline.GraphLayersTest.java

@SuppressWarnings("unchecked")
@Test/*from   ww w .  j  av a2 s .  co  m*/
public void testInserLayer() {
    out.println("\n\n" + StringUtils.center(" Testing GraphLayers, insertLayer() ", 120, "-") + "\n");

    GraphLayers gls = new GraphLayers();

    DataNode dn1 = new DataNode(null);
    dn1.setAcc("dn1");

    DataNode dn2 = new DataNode(null);
    dn2.setAcc("dn2");

    DataNode dn3 = new DataNode(null);
    dn3.setAcc("dn3");

    Processing proc1 = new MaterialProcessing(null);
    proc1.setAcc("proc1");

    Processing proc2 = new MaterialProcessing(null);
    proc2.setAcc("proc2");

    gls.setLayer(dn1, 0);
    gls.setLayer(dn2, 2);
    gls.setLayer(dn1, 1);
    gls.setLayer(dn3, -1);
    gls.setLayer(proc1, 2);
    gls.setLayer(proc2, 3);
    gls.insertLayer(2);

    // Should be 1:dn1 3:dn2,proc1, 4:proc2

    assertEquals("Rats! Wrong layer for dn1!", 1, gls.getLayer(dn1));
    assertEquals("Rats! Wrong layer for dn2!", 3, gls.getLayer(dn2));
    assertTrue("Rats! Layer 2 should contain dn2!", gls.containsGraphEl(3, dn2));
    assertTrue("Rats! Layer 1 should contain dn1!", gls.getGraphEls(1).contains(dn1));
    assertEquals("Rats! dn3 should not be in!", -1, gls.getLayer(dn3));
    assertEquals("Rats! proc1 should be in 3!", 3, gls.getLayer(proc1));
    assertEquals("Rats! proc2 should be in 4!", 4, gls.getLayer(proc2));
    assertTrue("Rats! Layer 3 should contain dn2!", gls.getGraphEls(3).contains(dn2));

    out.println("\n" + StringUtils.center(" /end: Testing GraphLayers, insertLayer() ", 120, "-") + "\n");

}

From source file:org.isatools.isatab.export.isatab.pipeline.IsaTabTableBuilderTest.java

@Test
public void testBasics() {
    out.println("\n\n" + StringUtils.center(" Testing ISATAB exporter, IsaTabTableBuilder, basiscs ", 120, "-")
            + "\n");

    FullStudyPipelineModel pip = new FullStudyPipelineModel();

    pip.src1.addAnnotation(new Annotation(SMP_ANN_TYPE, "sample.txt"));
    pip.src2.addAnnotation(new Annotation(SMP_ANN_TYPE, "sample.txt"));
    pip.as1.addAnnotation(new Annotation(SMP_ANN_TYPE, "sample.txt"));

    BIIObjectStore store = new BIIObjectStore();
    IsaTabTableBuilder tbld = new IsaTabTableBuilder(store, pip.study);

    out.println(tbld.report());/* w  ww. ja va  2s  . co m*/

    // TODO: assertions!

    out.println(
            "\n" + StringUtils.center(" /end: Testing ISATAB exporter, IsaTabTableBuilder, basiscs ", 120, "-")
                    + "\n");
}

From source file:org.isatools.isatab.export.isatab.pipeline.IsaTabTableBuilderTest.java

@Test
public void testSeparatedAssayFile() {
    out.println("\n\n"
            + StringUtils.center(" Testing ISATAB exporter, IsaTabTableBuilder, assay file export ", 120, "-")
            + "\n");

    SeparatedFilesModel pip = new SeparatedFilesModel();

    BIIObjectStore store = new BIIObjectStore();

    IsaTabTableBuilder tbld = new IsaTabTableBuilder(store, pip.study, "assay.txt");

    out.println(tbld.report());//from  w w w  .j a v a 2 s . c o m

    // TODO: assertions!

    out.println("\n" + StringUtils
            .center(" /end: Testing ISATAB exporter, IsaTabTableBuilder, assay file export ", 120, "-") + "\n");
}