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

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

Introduction

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

Prototype

public static String leftPad(String str, int size) 

Source Link

Document

Left pad a String with spaces (' ').

Usage

From source file:de.codesourcery.asm.util.Disassembler.java

/**
 * Disassemble a single {@link AbstractInsnNode} node.
 * //from w  w w . j  a  va  2 s . c o m
 * @param node the node to disassemble
 * @param method the method this node comes from
 * @param includeVirtual whether to 'disassemble' virtual (ASM-generated) nodes that
 * have no equivalent in .class files
 * @param printInsnIndices whether to output the instruction index in front of the mnemonic
 * @return disassembled instruction or <code>null</code> if the node does not map 
 * to a bytecode (=is virtual) and the <code>includeVirtual</code> flag was <code>false</code>
 */
public static String disassemble(AbstractInsnNode node, MethodNode method, boolean includeVirtual,
        boolean printInsnIndices) {
    final int opCode = node.getOpcode();
    final String mnemonic;
    if (opCode < 0 || opCode >= Printer.OPCODES.length) {
        if (!includeVirtual) {
            return null;
        }
        mnemonic = "// " + node.getClass().getSimpleName();
    } else {
        mnemonic = disassemble(node, method);
    }

    if (printInsnIndices) {
        final int indexOf = method.instructions.indexOf(node);
        String index = Integer.toString(indexOf);
        if (index.length() < 4) {
            index = StringUtils.leftPad(index, 4);
        }
        return index + ": " + mnemonic;
    }
    return mnemonic;
}

From source file:aos.lucene.search.advanced.SortingExample.java

public void displayResults(Query query, Sort sort) //
        throws IOException {
    IndexSearcher searcher = new IndexSearcher(directory);

    searcher.setDefaultFieldSortScoring(true, false); //

    TopDocs results = searcher.search(query, null, //
            20, sort); //

    LOGGER.info("\nResults for: " + //
            query.toString() + " sorted by " + sort);

    LOGGER.info(StringUtils.rightPad("Title", 30) + StringUtils.rightPad("pubmonth", 10)
            + StringUtils.center("id", 4) + StringUtils.center("score", 15));

    PrintStream out = new PrintStream(System.out, true, "UTF-8"); //

    DecimalFormat scoreFormatter = new DecimalFormat("0.######");
    for (ScoreDoc sd : results.scoreDocs) {
        int docID = sd.doc;
        float score = sd.score;
        Document doc = searcher.doc(docID);
        out.println(StringUtils.rightPad( //
                StringUtils.abbreviate(doc.get("title"), 29), 30) + //
                StringUtils.rightPad(doc.get("pubmonth"), 10) + //
                StringUtils.center("" + docID, 4) + //
                StringUtils.leftPad( //
                        scoreFormatter.format(score), 12)); //
        out.println("   " + doc.get("category"));
        //out.println(searcher.explain(query, docID));   //
    }//  ww w  .jav a  2s.  co  m

    searcher.close();
}

From source file:com.apporiented.hermesftp.utils.IOUtils.java

/**
 * Returns a line formated directory entry. The permissions are set as follows: The passed read
 * flag is relevant for owner, group and others. The passed write flag is only relevant for the
 * owner.//from   w ww .  j  a  v  a  2 s.  c  o m
 * 
 * @param file The file to be formatted.
 * @param read True if readable.
 * @param write True if writable.
 * @return The formatted line.
 */
public static String formatUnixFtpFileInfo(File file, boolean read, boolean write) {
    long size;
    StringBuffer sb = new StringBuffer();
    String wFlag = write ? "w" : "-";
    String rFlag = read ? "r" : "-";
    String permflags;
    if (file.isDirectory()) {
        permflags = MessageFormat.format("d{0}{1}x{0}-x{0}-x", rFlag, wFlag);
        size = 0;
    } else {
        permflags = MessageFormat.format("-{0}{1}-{0}--{0}--", rFlag, wFlag);
        size = file.length();
    }
    Date date = new Date(file.lastModified());
    sb.append(permflags);
    sb.append(" 1 ftp ftp ");
    sb.append(StringUtils.leftPad("" + size, FILE_SIZE_LENGTH_UNIX));
    sb.append(" ");
    sb.append(DATE_FORMAT_UNIX.format(date));
    sb.append(" ");
    sb.append(file.getName());
    return sb.toString();
}

From source file:de.forsthaus.util.ZkossComponentTreeUtil.java

private StringBuilder getZulTreeImpl(Component component, StringBuilder result, int depth) {
    ++depth;//from   w ww  .  j av  a 2  s .  c  o m
    final CharSequence id = createCompName(component);
    if (CollectionUtils.isEmpty(component.getChildren())) {
        result.append(StringUtils.leftPad("", depth << 2) + "<" + id + " />\n");
        return result;
    }

    result.append(StringUtils.leftPad("", depth << 2) + "<" + id + ">\n");

    ADD_LISTENER.addListener(component, result, depth);

    for (final Iterator<?> iterator = component.getChildren().iterator(); iterator.hasNext();) {
        getZulTreeImpl((Component) iterator.next(), result, depth);
    }

    result.append(StringUtils.leftPad("", depth << 2) + "<" + component.getClass().getSimpleName() + " />\n");
    return result;
}

From source file:io.pcp.parfait.benchmark.CPUThreadTest.java

private String leftPadBoolean(boolean theBoolean) {
    return StringUtils.leftPad(Boolean.toString(theBoolean), 5);
}

From source file:name.milesparker.gerrit.analysis.SimpleFileConverter.java

protected void convert(File file) throws FileNotFoundException, IOException {
    Path path = new Path(file.getAbsolutePath());
    if (!file.isDirectory() && path.getFileExtension() == null) {
        return;/*from  ww w  .  j ava  2 s  . c  o m*/
    }
    for (String ext : ignoreExtension) {
        if (StringUtils.equals(ext, path.getFileExtension())) {
            return;
        }
    }
    if (file.exists()) {
        if (file.isDirectory()) {
            for (File member : file.listFiles()) {
                convert(member);
            }
        } else {
            if (path.getFileExtension() == null) {
                return;
            }
            if (path.getFileExtension().equals(extension)) {
                log("    " + file.getAbsolutePath());
                filesConverted++;
                BufferedReader br = new BufferedReader(new FileReader(file));
                StringBuilder fileContents = new StringBuilder(8000);
                int lineNum = 0;
                while (br.ready()) {
                    String line = br.readLine();
                    String convert = convertLine(line);
                    fileContents.append(convert + "\n");
                    if (!line.equals(convert)) {
                        String lineNumString = StringUtils.leftPad(lineNum + "", 5);
                        log("      " + lineNumString + ":  " + line + "\n              " + convert);
                    }
                    lineNum++;
                }
                br.close();
                BufferedWriter writer = new BufferedWriter(new FileWriter(file));
                String convertString = convertFile(fileContents.toString());
                writer.write(convertString);
                writer.close();
            }
        }
    }
    monitor.worked(1);
}

From source file:de.codesourcery.eve.skills.ui.renderer.SkillTreeRenderer.java

@Override
public Component getTreeCellRendererComponent(final JTree tree, Object n, boolean sel, boolean expanded,
        boolean leaf, int row, boolean hasFocus) {

    final ITreeNode node = (ITreeNode) n;
    final Object value = node.getValue();

    if (value == null) {

        super.getTreeCellRendererComponent(tree, n, sel, expanded, leaf, row, hasFocus);

        setText(null);//from w ww . ja va2  s .  c  om
        return this;
    }

    final ICharacter character = charProvider.getSelectedItem();

    final String label;
    if (value instanceof Prerequisite) {

        super.getTreeCellRendererComponent(tree, n, sel, expanded, leaf, row, hasFocus);

        final Prerequisite r = (Prerequisite) value;

        String sCurrentLvl = "";
        if (character.hasSkill(r.getSkill())) {
            final int currentLvl = character.getSkillLevel(r.getSkill()).getLevel();
            if (currentLvl < r.getRequiredLevel()) {
                sCurrentLvl = " ( current: " + currentLvl + " )";
            }
        }
        label = "req: " + r.getSkill().getName() + " lvl " + r.getRequiredLevel() + sCurrentLvl;

        setForeground(getColorForSkill(r, character));
        setText(label);

        setToolTipText(toToolTip(character, r.getSkill()));

    } else if (value instanceof SkillGroup) {

        super.getTreeCellRendererComponent(tree, n, sel, expanded, leaf, row, hasFocus);

        final SkillGroup cat = (SkillGroup) value;

        if (character != null) {

            final long current = cat.getSkillpoints(character);

            final long maximumSkillpoints = cat.getMaximumSkillpoints();

            final String percent = skillPointDeltaToString(current, maximumSkillpoints);

            label = cat.getName() + "          " + StringUtils.leftPad(percent, 30 - cat.getName().length());
        } else {
            label = cat.getName();
        }
    } else if (value instanceof Skill) {

        final Skill s = (Skill) value;

        final int skillLevel;
        final String skillPoints;
        TrainedSkill trained = null;
        if (character != null) {

            trained = character.getSkillLevel(s);

            final long current = trained.getSkillpoints();
            final long max = s.getMaximumSkillpoints();

            skillLevel = trained.getLevel();
            if (renderCurrentSkillPoints) {
                skillPoints = "        " + skillPointDeltaToString(current, max);
            } else {
                skillPoints = "";
            }
        } else {
            skillLevel = 0;
            skillPoints = "";
        }

        String partiallyTrained = "";
        if (trained != null && skillLevel != Skill.MAX_LEVEL && trained.isPartiallyTrained()) {
            final int nextLevel = skillLevel + 1;
            int percent = Math.round(trained.getFractionOfLevelTrained(nextLevel));
            if (percent == 100) {
                percent = 99;
            }
            partiallyTrained = " [ " + percent + "% of lvl " + nextLevel + " trained ]";
        }

        label = s.getName() + " (Rank " + s.getRank() + ")" + skillPoints + partiallyTrained;

        IRenderCallback callback = new IRenderCallback() {

            @Override
            public Icon getClosedIcon() {
                return (Icon) DefaultLookup.get(tree, tree.getUI(), "Tree.closedIcon");
                //               return DefaultLookup.getIcon(tree, tree.getUI(), "Tree.closedIcon");
            }

            @Override
            public Icon getLeafIcon() {
                return (Icon) DefaultLookup.get(tree, tree.getUI(), "Tree.leafIcon");
                //               return DefaultLookup.getIcon(tree, tree.getUI() , "Tree.leafIcon" );
            }

            @Override
            public Icon getOpenIcon() {
                return (Icon) DefaultLookup.get(tree, tree.getUI(), "Tree.openIcon");
                //               return DefaultLookup.getIcon(tree, tree.getUI() , "Tree.openIcon" );               
            }

            @Override
            public Color getTextNonSelectionColor() {
                return (Color) DefaultLookup.get(tree, tree.getUI(), "Tree.textForeground");
                //               return DefaultLookup.getColor(tree, tree.getUI() , "Tree.textForeground");
            }

            @Override
            public Color getTextSelectionColor() {
                return (Color) DefaultLookup.get(tree, tree.getUI(), "Tree.selectionForeground");
                //               return DefaultLookup.getColor(tree, tree.getUI() , "Tree.selectionForeground");
            }

            @Override
            public Color getBackgroundSelectionColor() {
                return (Color) DefaultLookup.get(tree, tree.getUI(), "Tree.selectionBackground");
                //               return DefaultLookup.getColor(tree, tree.getUI() , "Tree.selectionBackground");
            }

            @Override
            public Color getBackgroundNonSelectionColor() {
                return (Color) DefaultLookup.get(tree, tree.getUI(), "Tree.textBackground");
                //               return DefaultLookup.getColor(tree, tree.getUI() , "Tree.textBackground");
            }
        };

        skillLabel.setText(label);
        skillLabel.setupTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus, callback);
        if (trained != null) {
            skillLabel.setTrainedSkill(trained);
        } else {
            skillLabel.setTrainedSkill(new TrainedSkill(s, 0));
        }
        skillLabel.setForeground(getColorForSkill(s, character));

        skillLabel.setToolTipText(toToolTip(character, s));

        return skillLabel;
    } else {
        label = null;
    }

    if (DEBUG && value != null) {
        final String[] className = value.getClass().getName().split("\\.");
        final String name = "[" + className[className.length - 1] + "]";
        if (label != null) {
            setText(name + " " + label);
        } else {
            setText(name);
        }
    } else {
        setText(label);
    }

    return this;
}

From source file:io.pcp.parfait.benchmark.StandardMetricThroughPutBenchmark.java

private void report(boolean startPcp, List<MonitoredCounter> counters, long timeTaken,
        List<CounterIncrementer> counterIncrementers) {
    long totalBlockedCount = computeTotalBlockedCount(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    long totalBlockedTime = computeTotalBlockedTime(
            transformToListOfBlockedMetricCollectors(counterIncrementers));
    double counterIncrements = computeTotalCounterIncrements(counters);

    double incrementRate = counterIncrements / ((double) timeTaken / 1000);
    NumberFormat numberFormat = NumberFormat.getNumberInstance();
    numberFormat.setGroupingUsed(true);/*w  w w . ja  v  a2s  . c o m*/
    numberFormat.setMaximumFractionDigits(2);
    numberFormat.setMinimumFractionDigits(2);
    String incrementRateString = StringUtils.leftPad(numberFormat.format(incrementRate), 15);

    System.out.printf(
            "pcpStarted: %s\tperMetricLock: %s\tincrementRate(/sec): %s\t blockedCount: %d\t blockedTime: %d\n",
            startPcp, usePerMetricLock, incrementRateString, totalBlockedCount, totalBlockedTime);
}

From source file:com.srikanthps.HbaseBenchmarking.java

private static String format(Long d, int pad) {
    return StringUtils.leftPad(String.format("%10d", d), pad);
}

From source file:com.swtxml.util.proposals.Match.java

public void dump() {
     System.out.println(text);/*from w w  w  .  j a  v  a 2 s  .  c  o m*/
     System.out.println(StringUtils.leftPad("[", start + 1) + StringUtils.leftPad("]", end - start));
     System.out.println(StringUtils.leftPad("C", cursorPos + 1));
 }