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

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

Introduction

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

Prototype

public static String rightPad(String str, int size) 

Source Link

Document

Right pad a String with spaces (' ').

Usage

From source file:com.redsqirl.workflow.server.connect.jdbc.JdbcStoreConnection.java

public List<String> displaySelect(ResultSet rs, int maxToRead) throws SQLException {
    int colNb = 0;
    List<Integer> sizes = new LinkedList<Integer>();
    List<List<String>> cells = new LinkedList<List<String>>();
    int sizeCol = 0;
    colNb = rs.getMetaData().getColumnCount();
    {/*from w w  w . ja  v  a2 s.  com*/
        // Set column names
        List<String> row = new LinkedList<String>();
        for (int i = 1; i <= colNb; ++i) {
            row.add(rs.getMetaData().getColumnName(i));
            sizeCol = rs.getMetaData().getColumnName(i).length();
            sizes.add(sizeCol);
        }
        cells.add(row);
    }
    while (rs.next()) {
        List<String> row = new LinkedList<String>();
        for (int i = 1; i <= colNb; ++i) {
            String colVal = rs.getString(i);
            row.add(colVal);

            sizeCol = 0;
            if (colVal != null) {
                sizeCol = colVal.length();
            }
            if (sizes.get(i - 1) < sizeCol) {
                sizes.set(i - 1, sizeCol);
            }
        }
        cells.add(row);
    }
    cleanOldStatement(rs);

    // logger.info("displaySelect list size" + sizes.size() + " " +
    // ans.size());
    List<String> ans = new LinkedList<String>();
    for (int i = 0; i < cells.size(); i++) {
        List<String> row = cells.get(i);
        String rowStr = "|";
        for (int j = 0; j < row.size(); j++) {
            String aux = row.get(j);
            if (aux == null) {
                aux = "null";
            }
            rowStr += StringUtils.rightPad(aux, sizes.get(j)) + "|";
        }
        // logger.info("displaySelect -" + newLine + "-");
        ans.add(rowStr);
    }

    String tableLine = "+";
    for (int j = 0; j < sizes.size(); j++) {
        tableLine += StringUtils.rightPad("", sizes.get(j), "-") + "+";

    }

    if (ans.size() > 0) {
        ans.add(1, tableLine);
    }
    ans.add(0, tableLine);
    if (ans.size() < maxToRead) {
        ans.add(ans.size(), tableLine);
    }

    return ans;
}

From source file:es.emergya.ui.gis.MapViewer.java

public void setTitle(String title) {
    this.title = StringUtils.rightPad(title, 25);
}

From source file:de.codesourcery.eve.skills.ui.components.impl.CharacterSheetComponent.java

protected static String rightPad(String s) {
    return StringUtils.rightPad(s, 20);
}

From source file:msi.gama.util.GAML.java

public static String getDocumentationOn(final String query) {
    final String keyword = StringUtils.removeEnd(StringUtils.removeStart(query.trim(), "#"), ":");
    final Multimap<GamlIdiomsProvider<?>, IGamlDescription> results = GamlIdiomsProvider.forName(keyword);
    if (results.isEmpty()) {
        return "No result found";
    }/*from  ww w . j  a  v a 2 s  . c om*/
    final StringBuilder sb = new StringBuilder();
    final int max = results.keySet().stream().mapToInt(each -> each.name.length()).max().getAsInt();
    final String separator = StringUtils.repeat("", max + 6).concat(Strings.LN);
    results.asMap().forEach((provider, list) -> {
        sb.append("").append(separator).append("|| ");
        sb.append(StringUtils.rightPad(provider.name, max));
        sb.append(" ||").append(Strings.LN).append(separator);
        for (final IGamlDescription d : list) {
            sb.append("== ").append(toText(d.getTitle())).append(Strings.LN)
                    .append(toText(provider.document(d))).append(Strings.LN);
        }
    });

    return sb.toString();

    //
}

From source file:com.alibaba.dubbo.util.KetamaNodeLocatorTest.java

@Test
public void testWeightedDistribution() {
    final int nodeSize = 5;
    final int keySize = 10000;
    final List<String> nodes = generateRandomStrings(nodeSize);
    final List<String> weightedNodes = new ArrayList<String>(nodes);
    weightedNodes.add(nodes.get(3)); // 20%
    for (int ix = 0; ix < 4; ix++) {
        weightedNodes.add(nodes.get(4));
    } // 50%/*ww  w  .ja  va 2s  . c o  m*/
    final long start1 = System.currentTimeMillis();
    final KetamaNodeLocator locator = new KetamaNodeLocator(weightedNodes);

    // Make sure the initialization doesn't take too long.
    assertTrue((System.currentTimeMillis() - start1) < 100);

    final int[] counts = new int[nodeSize];
    for (int ix = 0; ix < nodeSize; ix++) {
        counts[ix] = 0;
    }

    final List<String> keys = generateRandomStrings(keySize);

    for (final String key : keys) {
        final String primary = locator.getPrimary(key);
        counts[nodes.indexOf(primary)] += 1;
    }

    // Give about a 30% leeway each way...
    final int min = (keySize * 7) / (nodeSize * 2 * 10);
    final int max = (keySize * 13) / (nodeSize * 2 * 10);
    int total = 0;
    boolean error = false;
    final StringBuilder sb = new StringBuilder("Key distribution error - \n");

    for (int ix = 0; ix < nodeSize; ix++) {
        int expectedMin = min;
        int expectedMax = max;
        if (ix == 3) {
            expectedMin = 2 * min;
            expectedMax = 2 * max;
        }
        if (ix == 4) {
            expectedMin = 5 * min;
            expectedMax = 5 * max;
        }
        if (counts[ix] < expectedMin || counts[ix] > expectedMax) {
            error = true;
            sb.append("  !!  ");
        } else {
            sb.append("      ");
        }
        sb.append(StringUtils.rightPad(nodes.get(ix), 12)).append(": ").append(counts[ix]).append("\n");
        total += counts[ix];
    }
    // Make sure we didn't miss any keys returning values.
    assertEquals(keySize, total);

    //        System.out.println(sb.toString());
    if (error) {
        fail(sb.toString());
    }
}

From source file:de.iteratec.iteraplan.common.util.HashBucketMatrix.java

/**
 * String representation of the HashBucketMatrix. for each entry it shows the key and all of its
 * values. the toString method of each object is used for that.
 * /* www .  ja v  a2 s .c  om*/
 * @return the string representation
 */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder(30);

    // get keys
    HashSet<K2> secondDimensionKeys = new HashSet<K2>();
    for (HashBucketMap<K2, V> bucketMap : this.firstDimension.values()) {
        for (K2 secondKey : bucketMap.keySet()) {
            secondDimensionKeys.add(secondKey);
        }
    }

    sb.append("\n          || ");
    for (K1 key : this.firstDimension.keySet()) {
        if (key == null) {
            sb.append(StringUtils.rightPad("null", 10));
        } else {
            sb.append(StringUtils.rightPad(key.toString(), 10));
        }
        sb.append("| ");
    }
    sb.append('\n');

    for (K2 secondKey : secondDimensionKeys) {
        if (secondKey == null) {
            sb.append(StringUtils.rightPad("null", 10));
        } else {
            sb.append(StringUtils.rightPad(secondKey.toString(), 10));
        }
        sb.append("|| ");
        for (K1 firstKey : this.firstDimension.keySet()) {
            List<V> bucket = this.getBucketNotNull(firstKey, secondKey);
            StringBuffer bucketBuffer = new StringBuffer();
            for (V value : bucket) {
                bucketBuffer.append(value);
                bucketBuffer.append(';');
            }
            if (bucketBuffer.length() > 0) {
                bucketBuffer.deleteCharAt(bucketBuffer.length() - 1);
            }
            sb.append(StringUtils.rightPad(bucketBuffer.toString(), 10));
            sb.append("| ");
        }
        sb.append('\n');
    }

    return sb.toString();
}

From source file:net.bhl.cdt.connector.avl.strategies.AVLProcessGeneratorStrategy.java

private void writeRunCase(AVLProcessGenerator avlProcessGenerator, HashMap<String, BigDecimal> dimensionValues,
        List<String> sweppedDimensions, FileWriter fileWriter) throws IOException {
    if (avlProcessGenerator.getRuncaseCounter() > 1) {
        FileGeneratorHelper.writeLine("", fileWriter);
        FileGeneratorHelper.writeLine("", fileWriter);
    }/*from w w w  .  ja v a2s  .c  om*/

    FileGeneratorHelper.writeLine("---------------------------------------------", fileWriter);
    FileGeneratorHelper.write("Run case  " + avlProcessGenerator.getRuncaseCounter() + ":", fileWriter);
    for (Map.Entry<String, BigDecimal> entry : dimensionValues.entrySet()) {
        if (sweppedDimensions.contains(entry.getKey())) {
            String string = "  " + entry.getKey() + " " + entry.getValue().toString();
            FileGeneratorHelper.write(string, fileWriter);
        }

    }
    FileGeneratorHelper.writeLine("", fileWriter);
    FileGeneratorHelper.writeLine("", fileWriter);
    for (VariableSweep varirableSweep : avlProcessGenerator.getVariableSweeps()) {
        String entryName = varirableSweep.getName();
        BigDecimal entryValue = dimensionValues.get(entryName);
        FileGeneratorHelper.writeLine(" " + StringUtils.rightPad(entryName, 13) + "->  "
                + StringUtils.rightPad(entryName, 13) + "=   " + entryValue, fileWriter);

    }
    avlProcessGenerator.setRuncaseCounter(avlProcessGenerator.getRuncaseCounter() + 1);
    File avlProcessFile = new File(avlProcessGenerator.getCommandFileName());
    int fileSeperatorIndex = avlProcessFile.getName().indexOf(".");
    String processFileName = "avl" + avlProcessFile.getName().subSequence(0, fileSeperatorIndex);
    if (avlProcessGenerator.getRuncaseCounter() > 1) {

        String fullResultFileName = processFileName
                + String.valueOf(avlProcessGenerator.getRuncaseCounter() - 1) + ".out";
        AVLResultImporter avlResultImporter = AvlprocessFactory.eINSTANCE.createAVLResultImporter();
        avlResultImporter.setFileName(fullResultFileName);
        avlResultImporter.setName(fullResultFileName);
        avlProcessGenerator.getAvlResultImporters().add(avlResultImporter);
    }
}

From source file:com.twinsoft.convertigo.engine.util.CarUtils.java

private static Document exportProject(Project project, final List<TestCase> selectedTestCases)
        throws EngineException {
    try {/*from  w w  w . j  a  v a  2 s  .c om*/
        final Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
        //            ProcessingInstruction pi = document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\"");
        //            document.appendChild(pi);
        final Element rootElement = document.createElement("convertigo");

        rootElement.setAttribute("version", com.twinsoft.convertigo.engine.Version.fullProductVersion);
        rootElement.setAttribute("engine", com.twinsoft.convertigo.engine.Version.version);
        rootElement.setAttribute("beans", com.twinsoft.convertigo.beans.Version.version);
        String studioVersion = "";
        try {
            Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.Version");
            studioVersion = (String) c.getDeclaredField("version").get(null);
        } catch (Exception e) {
        } catch (Throwable th) {
        }

        rootElement.setAttribute("studio", studioVersion);
        document.appendChild(rootElement);

        new WalkHelper() {
            protected Element parentElement = rootElement;

            @Override
            protected void walk(DatabaseObject databaseObject) throws Exception {
                Element parentElement = this.parentElement;

                Element element = parentElement;
                element = databaseObject.toXml(document);
                String name = " : " + databaseObject.getName();
                try {
                    name = CachedIntrospector.getBeanInfo(databaseObject.getClass()).getBeanDescriptor()
                            .getDisplayName() + name;
                } catch (IntrospectionException e) {
                    name = databaseObject.getClass().getSimpleName() + name;
                }
                Integer depth = (Integer) document.getUserData("depth");
                if (depth == null) {
                    depth = 0;
                }

                String openpad = StringUtils.repeat("   ", depth);
                String closepad = StringUtils.repeat("   ", depth);
                parentElement.appendChild(document.createTextNode("\n"));
                parentElement.appendChild(
                        document.createComment(StringUtils.rightPad(openpad + "<" + name + ">", 150)));

                if (databaseObject instanceof TestCase && selectedTestCases.size() > 0) {
                    if (selectedTestCases.contains((TestCase) databaseObject)) {
                        parentElement.appendChild(element);
                    }
                } else {
                    parentElement.appendChild(element);
                }

                document.setUserData("depth", depth + 1, null);

                this.parentElement = element;
                super.walk(databaseObject);

                element.appendChild(document.createTextNode("\n"));
                element.appendChild(
                        document.createComment(StringUtils.rightPad(closepad + "</" + name + ">", 150)));
                document.setUserData("depth", depth, null);

                databaseObject.hasChanged = false;
                databaseObject.bNew = false;

                this.parentElement = parentElement;
            }

        }.init(project);

        return document;
    } catch (Exception e) {
        throw new EngineException("Unable to export the project \"" + project.getName() + "\".", e);
    }
}

From source file:com.betfair.cougar.core.impl.ev.ServiceRegisterableExecutionVenue.java

private void dumpProperties() {
    final Map<String, String> props = PropertyConfigurer.getAllLoadedProperties();
    LOGGER.info("Properties loaded from config files and system property overrides");
    int longest = 0;
    for (Map.Entry<String, String> me : props.entrySet()) {
        longest = Math.max(longest, me.getKey().length());
    }/*from   w w w.j a  v a  2  s.  c  om*/
    for (Map.Entry<String, String> me : props.entrySet()) {
        String sysOverride = System.getProperty(me.getKey());
        String value = (sysOverride == null ? me.getValue() : sysOverride);
        if (me.getKey().toLowerCase().contains("password")) {
            value = "*****";
        }
        LOGGER.info("  {} = {}{2}", StringUtils.rightPad(value, longest), me.getKey(), value,
                (sysOverride == null ? "" : " [OVERRIDDEN]"));
    }
}

From source file:com.mosso.client.cloudfiles.sample.FilesCopy.java

public static void getContainerObjects(File localFolder, String containerName) throws IOException,
        HttpException, FilesAuthorizationException, NoSuchAlgorithmException, FilesException {
    FilesClient client = new FilesClient();
    if (client.login()) {
        if (client.containerExists(containerName)) {
            List<FilesObject> objects = client.listObjects(containerName);
            for (FilesObject obj : objects) {
                System.out.println("\t" + StringUtils.rightPad(obj.getName(), 35) + obj.getSizeString());
                File localFile = new File(FilenameUtils.concat(localFolder.getAbsolutePath(), obj.getName()));
                obj.writeObjectToFile(localFile);
            } //for (Object obj: objects)
        } else {/*from  ww  w  .  ja  v a 2  s.co m*/
            logger.fatal("The  container: " + containerName + " does not exist.");
            System.out.println("The  container: " + containerName + " does not exist!");
            System.exit(0);
        }
    } //if ( client.login() )
}