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:br.usp.poli.lta.cereda.spa2run.Utils.java

public static void printException(Exception exception) {
    System.out.println(StringUtils.repeat("-", 70));
    System.out.println(StringUtils.center("An exception was thrown".toUpperCase(), 70));
    System.out.println(StringUtils.repeat("-", 70));
    System.out.println(WordUtils.wrap(exception.getMessage(), 70, "\n", true));
    System.out.println(StringUtils.repeat("-", 70));
    System.exit(0);/*from   ww  w . j  a  v a2  s  .c  o m*/
}

From source file:com.conversantmedia.mapreduce.tool.RunJob.java

/**
 * Outputs the driver's list//w  w  w  . j  a v  a  2  s  . c om
 * 
 * @param driversMap   map of driver metadata to output to console
 */
protected static void outputDriversTable(Map<String, DriverMeta> driversMap) {

    String[] colNames = new String[] { "Name", "Description", "Ver", "Class" };
    String[] aligns = new String[] { "-", "-", "-", "-" };
    int maxDescriptionWidth = 48;
    int widths[] = new int[colNames.length];
    for (int i = 0; i < colNames.length; i++) {
        widths[i] = colNames[i].length();
    }
    int padding = 2;
    for (Entry<String, DriverMeta> e : driversMap.entrySet()) {
        if (!e.getValue().hidden) {
            int i = 0;
            widths[i] = Math.max(e.getKey().length(), widths[i]);
            widths[i + 1] = Math.min(Math.max(e.getValue().description.length(), widths[i + 1]),
                    maxDescriptionWidth);
            widths[i + 2] = Math.max(e.getValue().version.length(), widths[i + 2]);
            widths[i + 3] = Math.max(e.getValue().driverClass.getName().length(), widths[i + 3]);
        }
    }

    // sum widths
    int width = padding * widths.length - 1;
    for (int w : widths) {
        width += w;
    }

    String sep = StringUtils.repeat("=", width);
    System.out.println(sep);
    System.out.println(StringUtils.center("A V A I L A B L E    D R I V E R S", width));
    System.out.println(sep);
    String[] underscores = new String[colNames.length];
    StringBuilder headersFormatSb = new StringBuilder();
    StringBuilder valuesFormatSb = new StringBuilder();
    for (int i = 0; i < widths.length; i++) {
        headersFormatSb.append("%-").append(widths[i] + padding).append("s");
        valuesFormatSb.append("%").append(aligns[i]).append(widths[i] + padding).append("s");
        underscores[i] = StringUtils.repeat("-", widths[i]);
    }
    String format = headersFormatSb.toString();
    System.out.format(format, (Object[]) colNames);
    System.out.println();
    System.out.format(format, (Object[]) underscores);
    System.out.println();

    format = valuesFormatSb.toString();
    List<String> descriptionLines = new ArrayList<>();
    for (Entry<String, DriverMeta> e : driversMap.entrySet()) {
        if (!e.getValue().hidden) {
            descriptionLines.clear();
            String description = e.getValue().description;
            if (description.length() > maxDescriptionWidth) {
                splitLine(descriptionLines, description, maxDescriptionWidth);
                description = descriptionLines.remove(0);
            }
            System.out.format(format, e.getKey(), description,
                    StringUtils.center(e.getValue().version, widths[2]), e.getValue().driverClass.getName());
            System.out.println();
            while (!descriptionLines.isEmpty()) {
                System.out.format(format, "", descriptionLines.remove(0), "", "");
                System.out.println();
            }
        }
    }
}

From source file:org.apache.batchee.cli.command.StepExecutions.java

@Override
public void doRun() {
    final JobOperator operator = operator();
    final List<StepExecution> executions = operator.getStepExecutions(id);
    if (executions == null || executions.isEmpty()) {
        info("Executions of " + id + " not found");
        return;//from www.j  a v a 2s. c  o m
    }

    info("Step executions of " + id);

    final List<Metric.MetricType> metricsOrder = new ArrayList<Metric.MetricType>();
    final StringBuilder metrics = new StringBuilder();
    for (final Metric.MetricType type : Metric.MetricType.values()) {
        metrics.append("\t|\t").append(type.name());
        metricsOrder.add(type);
    }

    final DateFormat format = new SimpleDateFormat("YYYYMMdd hh:mm:ss");
    info("   step id\t|\t step name\t|\t    start time   \t|\t     end time    \t|\texit status\t|\tbatch status"
            + metrics.toString());
    for (final StepExecution exec : executions) {
        final StringBuilder builder = new StringBuilder(
                String.format("%10d\t|\t%s\t|\t%s\t|\t%s\t|\t%s\t|\t%s", exec.getStepExecutionId(),
                        StringUtils.center(exec.getStepName(), 10), format.format(exec.getStartTime()),
                        exec.getEndTime() != null ? format.format(exec.getEndTime()) : "-",
                        StringUtils.center(exec.getExitStatus() == null ? "-" : exec.getExitStatus(), 11),
                        StringUtils.center(String.valueOf(exec.getBatchStatus()), 12)));
        final Map<Metric.MetricType, Long> stepMetrics = new HashMap<Metric.MetricType, Long>();
        if (exec.getMetrics() != null) {
            for (final Metric m : exec.getMetrics()) {
                stepMetrics.put(m.getType(), m.getValue());
            }
        }
        for (final Metric.MetricType type : metricsOrder) {
            final Long value = stepMetrics.get(type);
            builder.append("\t|\t");
            if (value != null) {
                builder.append(StringUtils.center(Long.toString(value), type.name().length()));
            } else {
                builder.append("-");
            }
        }
        info(builder.toString());
    }
}

From source file:org.apache.syncope.client.cli.view.Table.java

private void printTitle() {
    System.out.format(TABLE_TITLE_FORMAT, StringUtils.center(" ", tableWidth - 6));
    System.out.format(TABLE_TITLE_FORMAT, StringUtils.center(title.toUpperCase(), tableWidth - 6));
    System.out.format(TABLE_TITLE_FORMAT, StringUtils.center(" ", tableWidth - 6));
}

From source file:org.apache.syncope.client.cli.view.Table.java

private void printHeaders() {
    printColumnSpace();//from   w w w.  j  a  v a  2s. co m

    for (int h = 0; h < columnsNumber; h++) {
        tmpValuesArray[h] = StringUtils.center(headers.get(h).toUpperCase(), columnsSize[h]);
    }

    System.out.format(tableContentFormat, tmpValuesArray);

    printColumnSpace();
}

From source file:org.apache.syncope.client.cli.view.Table.java

private void printeContent() {
    printColumnSpace();//from ww  w  .  j  ava 2s . c  om

    values.forEach(value -> {
        for (int j = 0; j < columnsNumber; j++) {
            if (value.get(j) == null) {
                tmpValuesArray[j] = StringUtils.center("null", columnsSize[j]);
            } else {
                tmpValuesArray[j] = StringUtils.center(value.get(j), columnsSize[j]);
            }
        }
        System.out.format(tableContentFormat, tmpValuesArray);
    });

    printColumnSpace();
}

From source file:org.apache.syncope.client.cli.view.Table.java

private void printColumnSpace() {
    for (int h = 0; h < columnsNumber; h++) {
        tmpValuesArray[h] = StringUtils.center(" ", columnsSize[h]);
    }//from   w w  w  . ja v  a2 s. c o  m

    System.out.format(tableContentFormat, tmpValuesArray);
}

From source file:org.opencb.opencga.app.cli.analysis.executors.VariantCommandExecutor.java

private void samples() throws Exception {

    VariantCommandOptions.VariantSamplesFilterCommandOptions cliOptions = variantCommandOptions.samplesFilterCommandOptions;

    //        Map<Long, String> studyIds = getStudyIds(sessionId);
    Query query = VariantQueryCommandUtils.parseBasicVariantQuery(cliOptions.variantQueryOptions, new Query());

    VariantStorageManager variantManager = new VariantStorageManager(catalogManager, storageEngineFactory);

    VariantSampleFilter variantSampleFilter = new VariantSampleFilter(variantManager.iterable(sessionId));

    if (StringUtils.isNotEmpty(cliOptions.samples)) {
        query.append(VariantDBAdaptor.VariantQueryParams.RETURNED_SAMPLES.key(),
                Arrays.asList(cliOptions.samples.split(",")));
    }//from  w  ww. j a  va2 s  .c o  m
    if (StringUtils.isNotEmpty(cliOptions.study)) {
        query.append(VariantDBAdaptor.VariantQueryParams.STUDIES.key(), cliOptions.study);
    }

    List<String> genotypes = Arrays.asList(cliOptions.genotypes.split(","));
    if (cliOptions.all) {
        Collection<String> samplesInAllVariants = variantSampleFilter.getSamplesInAllVariants(query, genotypes);
        System.out.println("##Samples in ALL variants with genotypes " + genotypes);
        for (String sample : samplesInAllVariants) {
            System.out.println(sample);
        }
    } else {
        Map<String, Set<Variant>> samplesInAnyVariants = variantSampleFilter.getSamplesInAnyVariants(query,
                genotypes);
        System.out.println("##Samples in ANY variants with genotypes " + genotypes);
        Set<Variant> variants = new TreeSet<>((v1, o2) -> v1.getStart().compareTo(o2.getStart()));
        samplesInAnyVariants.forEach((sample, v) -> variants.addAll(v));

        System.out.print(StringUtils.rightPad("#SAMPLE", 10));
        //            System.out.print("|");
        for (Variant variant : variants) {
            System.out.print(StringUtils.center(variant.toString(), 15));
            //                System.out.print("|");
        }
        System.out.println();
        samplesInAnyVariants.forEach((sample, v) -> {
            System.out.print(StringUtils.rightPad(sample, 10));
            //                System.out.print("|");
            for (Variant variant : variants) {
                if (v.contains(variant)) {
                    System.out.print(StringUtils.center("X", 15));
                } else {
                    System.out.print(StringUtils.center("-", 15));
                }
                //                    System.out.print("|");
            }
            System.out.println();
        });

    }
}

From source file:org.pdfgal.pdfgal.utils.impl.WatermarkUtilsImpl.java

@Override
public void addWatermark(final PDDocument doc, final PDPage page, final Color color, final String text,
        final WatermarkPosition watermarkPosition) throws IOException, WatermarkOutOfLengthException {

    if (doc != null && page != null && color != null && StringUtils.isNotBlank(text)
            && watermarkPosition != null) {

        // Attributes are extrated from the watermarkPosition argument.
        Double rotationAngle = 0D;
        Double rotationTX = 0D;/* www . j a va 2s.co  m*/
        Double rotationTY = 0D;
        Integer maxLength = 0;

        if (page.getMediaBox().getHeight() > page.getMediaBox().getWidth()) {
            // Page is portrait
            rotationAngle = watermarkPosition.getRotationAnglePortrait();
            rotationTX = watermarkPosition.getRotationTXPortrait();
            rotationTY = watermarkPosition.getRotationTYPortrait();
            maxLength = watermarkPosition.getMaxLengthPortrait();
        } else {
            // Page is landscape
            rotationAngle = watermarkPosition.getRotationAngleLandscape();
            rotationTX = watermarkPosition.getRotationTXLandscape();
            rotationTY = watermarkPosition.getRotationTYLandscape();
            maxLength = watermarkPosition.getMaxLengthLandscape();
        }

        // In case text is too large, an exception is thrown.
        if (text.length() > maxLength) {
            throw new WatermarkOutOfLengthException(Constants.WATERMARK_OUT_OF_LENGTH_EXCEPTION_MESSAGE);
        }

        final PDPageContentStream contentStream = new PDPageContentStream(doc, page, true, true);
        contentStream.appendRawCommands("/TransparentState gs\n");
        contentStream.setNonStrokingColor(color);
        contentStream.beginText();
        contentStream.setFont(PDType1Font.HELVETICA, 70);
        contentStream.setTextRotation(rotationAngle, rotationTX, rotationTY);
        // Text is centered
        final Integer size = (maxLength * 2) - text.length();
        final String centeredText = StringUtils.center(text, size);
        contentStream.drawString(centeredText);
        contentStream.endText();
        contentStream.close();
    }
}

From source file:org.pf4j.demo.Boot.java

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