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

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

Introduction

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

Prototype

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

Source Link

Document

Left pad a String with spaces (' ').

The String is padded to the size of size .

 StringUtils.leftPad(null, *)   = null StringUtils.leftPad("", 3)     = "   " StringUtils.leftPad("bat", 3)  = "bat" StringUtils.leftPad("bat", 5)  = "  bat" StringUtils.leftPad("bat", 1)  = "bat" StringUtils.leftPad("bat", -1) = "bat" 

Usage

From source file:mase.me.MEFinalRepertoireTextStat.java

protected String toString2D(MESubpopulation sub) {
    StringBuilder sb = new StringBuilder();

    // find the bounds of the repertoire
    Collection<int[]> values = new ArrayList<>(sub.inverseHash.values());
    int min0 = Integer.MAX_VALUE, min1 = Integer.MAX_VALUE, max0 = Integer.MIN_VALUE, max1 = Integer.MIN_VALUE;
    for (int[] v : values) {
        min0 = Math.min(min0, v[0]);
        max0 = Math.max(max0, v[0]);
        min1 = Math.min(min1, v[1]);
        max1 = Math.max(max1, v[1]);
    }/*from   w w  w  . j av a 2s . com*/

    // print repertoire
    int pad = Math.max(Integer.toString(min1).length(), Integer.toString(max1).length());
    sb.append(StringUtils.repeat(' ', pad)).append("y\n");
    for (int i1 = max1; i1 >= min1; i1--) {
        sb.append(StringUtils.leftPad(i1 + "", pad)).append("|");
        for (int i0 = min0; i0 <= max0; i0++) {
            int h = sub.hash(new int[] { i0, i1 });
            if (sub.map.containsKey(h)) {
                sb.append("[]");
            } else {
                sb.append("  ");
            }
        }
        sb.append("\n");
    }

    // x-axis lines
    sb.append(StringUtils.repeat(' ', pad)).append('-');
    for (int i0 = min0; i0 <= max0; i0++) {
        sb.append("--");
    }
    sb.append(" x\n");

    // x-axis numbers
    sb.append(StringUtils.repeat(' ', pad + 1));
    int longest = Math.max(Integer.toString(min0).length(), Integer.toString(max0).length());
    int space = (longest + 2) / 2 * 2;
    int order = 0;
    for (int i0 = min0; i0 <= max0; i0++) {
        String s = Integer.toString(i0);
        if (order % (space / 2) == 0) {
            sb.append(StringUtils.rightPad(s, space));
        }
        order++;
    }
    sb.append('\n');
    return sb.toString();
}

From source file:com.callidusrobotics.ui.MessageBox.java

protected List<String> getMessageTokens(final String string, final boolean preformatted) {
    final List<String> tokens = new LinkedList<String>(
            Arrays.asList(string.split(preformatted ? "\n" : "\\s+")));

    if (preformatted) {
        for (int i = 0; i < tokens.size(); i++) {
            String token = tokens.get(i);

            if (!token.isEmpty() && token.charAt(0) == ' ') {
                token = token.trim();// w  w  w. j  a  va 2  s .  c o  m
                token = StringUtils.leftPad(token, token.length() + 1);
                tokens.set(i, token);
            }
        }
    }

    return tokens;
}

From source file:de.openali.odysseus.chart.ext.base.layer.TooltipFormatter.java

private String alignText(final String[] texts, final int i) {
    final String value = texts[i];
    final int alignment = m_alignments[i];

    if (alignment == SWT.LEFT)
        return StringUtils.rightPad(value, m_columnWidths[i]);
    else/*from www .  j a v a2s .c om*/
        return StringUtils.leftPad(value, m_columnWidths[i]);
}

From source file:com.nikonhacker.emu.memory.AutoAllocatingMemory.java

/**
 * Perform a byte store/*from w  w w .  ja  va 2s. co  m*/
 *
 * @param value the value to store
 * @param addr  the address of where to store
 */
public final void store8(int addr, int value) {
    if (logMemoryMessages) {
        System.err.println("Store8 address: 0x" + Integer.toHexString(addr) + " val: 0x"
                + Format.asHex((value & 0xFF), 2) + " - 0b"
                + StringUtils.leftPad(Integer.toBinaryString(value & 0xFF), 8).replace('0', ' '));
    }

    byte[] pageData = writableMemory[getPTE(addr)];
    if (pageData == null) {
        map(truncateToPage(addr), PAGE_SIZE, true, true, true);
        pageData = writableMemory[getPTE(addr)];
    }
    pageData[getOffset(addr)] = (byte) value;
}

From source file:com.sangupta.fileanalysis.db.DBResultViewer.java

private static void format(String value, int size, boolean rightAligned) {
    if (rightAligned) {
        value = StringUtils.leftPad(value, size);
    } else {// w  w w  .ja  va  2s  . c o m
        value = StringUtils.rightPad(value, size);
    }

    System.out.print("| " + value + " ");
}

From source file:com.thinkbiganalytics.spark.validation.HCatDataTypeTest.java

@Test
public void testIsValueConvertibleToChar() throws Exception {

    HCatDataType type = HCatDataType.getDataTypes().get("char");

    assertTrue(type.isValueConvertibleToType("mystring"));
    assertTrue(type.isValueConvertibleToType("99999"));
    assertTrue(type.isValueConvertibleToType("-999"));
    assertTrue(type.isValueConvertibleToType(null));
    assertTrue(type.isValueConvertibleToType(""));
    assertTrue(type.isValueConvertibleToType(StringUtils.leftPad("X", 255)));
    assertFalse(type.isValueConvertibleToType(StringUtils.leftPad("X", 256)));
}

From source file:intelligentWebAlgorithms.algos.taxis.tree.Node.java

public void print(int level) {

    String padding = StringUtils.leftPad("", level * 5);

    String nodeInfo = "Node:" + "attrName=" + this.attributeName + ",isLeaf=" + this.isLeaf + ",concept="
            + this.conceptName;

    System.out.println(padding + nodeInfo);
    for (Map.Entry<String, Node> e : childNodesByBranchName.entrySet()) {
        if (splitValue == null) {
            System.out.println(padding + "-> Branch: [" + attributeName + "=" + e.getKey() + "]");
        } else {/*  w w w. java2 s.c om*/
            String condition;
            if (BranchGroup.BinaryBranchNames.TRUE_BRANCH.equalsIgnoreCase(e.getKey())) {
                condition = "<=";
            } else {
                condition = ">";
            }
            System.out.println(padding + "-> Branch: " + e.getKey() + " [" + attributeName + condition
                    + this.splitValue + "]");

        }
        e.getValue().print(level + 1);
    }
}

From source file:de.egore911.versioning.deployer.Main.java

private static void logPercent(int i, int max) {
    int digits = Integer.toString(max).length();
    String percent = PERCENT_FORMAT.format(100f / max * i);
    LOG.info("{}/{} deployments, {}%", StringUtils.leftPad(Integer.toString(i), digits), max,
            StringUtils.leftPad(percent, 3));
}

From source file:ch.bender.evacuate.Runner.java

/**
 * run//  ww  w. j  ava  2  s .  c  om
 * <p>
 * @throws Exception 
 */
public void run() throws Exception {
    checkDirectories();
    initExcludeMatchers();

    myEvacuateCandidates = new TreeMap<>();
    myFailedChainPreparations = Collections.synchronizedMap(new HashMap<>());
    myFutures = new HashSet<>();
    myExclusionDirCount = 0;
    myEvacuationDirCount = 0;
    myExclusionFileCount = 0;
    myEvacuationFileCount = 0;

    Files.walkFileTree(myBackupDir, new SimpleFileVisitor<Path>() {
        /**
         * @see java.nio.file.SimpleFileVisitor#visitFileFailed(java.lang.Object, java.io.IOException)
         */
        @Override
        public FileVisitResult visitFileFailed(Path aFile, IOException aExc) throws IOException {
            if ("System Volume Information".equals((aFile.getFileName().toString()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            throw aExc;
        }

        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            return Runner.this.visitFile(file, attrs);
        }

        @Override
        public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
            if ("System Volume Information".equals((dir.getFileName()))) {
                return FileVisitResult.SKIP_SUBTREE;
            }

            return Runner.this.preVisitDirectory(dir, attrs);
        }

    });

    if (myEvacuateCandidates.size() == 0) {
        myLog.info("No candidates for evacuation found");
    } else {
        StringBuilder sb = new StringBuilder("\nFound candidates for evacuation:");
        myEvacuateCandidates.keySet().forEach(p -> sb.append("\n    " + p.toString()));
        myLog.info(sb.toString());
    }

    if (myDryRun) {
        myLog.debug("DryRun flag is set. Doing nothing");
        return;
    }

    if (myFutures.size() > 0) {
        myLog.debug("Waiting for all async tasks to complete");
        CompletableFuture.allOf(myFutures.toArray(new CompletableFuture[myFutures.size()])).get();
    }

    if (myFailedChainPreparations.size() > 0) {
        for (Path path : myFailedChainPreparations.keySet()) {
            myLog.error("exception occured", myFailedChainPreparations.get(path));
        }

        throw new Exception("chain preparation failed. See above error messages");
    }

    for (Path src : myEvacuateCandidates.keySet()) {
        Path dst = myEvacuateCandidates.get(src);
        Path dstParent = dst.getParent();

        if (Files.notExists(dstParent)) {
            Files.createDirectories(dstParent); // FUTURE: overtake file attributes from src
        }

        if (myMove) {
            try {
                myLog.debug(
                        "Moving file system object \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                Files.move(src, dst, StandardCopyOption.ATOMIC_MOVE);
            } catch (AtomicMoveNotSupportedException e) {
                myLog.warn("Atomic move not supported. Try copy and then delete");

                if (Files.isDirectory(src)) {
                    myLog.debug("Copying folder \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                    FileUtils.copyDirectory(src.toFile(), dst.toFile());
                    myLog.debug("Delete folder \"" + src.toString() + "\"");
                    FileUtils.deleteDirectory(src.toFile());
                } else {
                    myLog.debug("Copy file \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                    FileUtils.copyFile(src.toFile(), dst.toFile());
                    myLog.debug("Delete file \"" + src.toString() + "\"");
                    Files.delete(src);
                }
            }

        } else {
            if (Files.isDirectory(src)) {
                myLog.debug("Copying folder \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                FileUtils.copyDirectory(src.toFile(), dst.toFile());
            } else {
                myLog.debug("Copy file \"" + src.toString() + "\" to \"" + dst.toString() + "\"");
                FileUtils.copyFile(src.toFile(), dst.toFile());
            }
        }
    }

    myLog.info("\nSuccessfully terminated." + "\n             Evacuated  Skipped" + "\n    Files  : "
            + StringUtils.leftPad("" + myEvacuationDirCount, 9)
            + StringUtils.leftPad("" + myExclusionDirCount, 9) + "\n    Folders: "
            + StringUtils.leftPad("" + myEvacuationFileCount, 9)
            + StringUtils.leftPad("" + myExclusionFileCount, 9));
}

From source file:com.norconex.jef4.status.JobSuiteStatusSnapshot.java

private void toString(StringBuilder b, String jobId, int depth) {
    IJobStatus status = getJobStatus(jobId);
    b.append(StringUtils.repeat(' ', depth * TO_STRING_INDENT));
    b.append(StringUtils.leftPad(new PercentFormatter().format(status.getProgress()), TO_STRING_INDENT));
    b.append("  ").append(status.getJobId());
    b.append(System.lineSeparator());
    for (IJobStatus child : getChildren(jobId)) {
        toString(b, child.getJobId(), depth + 1);
    }//from   w ww .  j  ava2s  .co  m
}