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:org.matsim.contrib.taxi.benchmark.TaxiBenchmarkPostProcessor.java

private void writeValues(String file, int column) {
    String field = statsColumns[column];
    PrintWriter pw = new PrintWriter(IOUtils.getBufferedWriter(file + "_" + field + ".txt"));
    StringBuffer lineId = new StringBuffer(StringUtils.leftPad(field, 20));
    StringBuffer lineN = new StringBuffer(StringUtils.leftPad("n", 20));
    StringBuffer lineM = new StringBuffer(StringUtils.leftPad("m", 20));
    StringBuffer lineRatio = new StringBuffer(StringUtils.leftPad("ratio", 20));

    for (Experiment e : experiments) {
        if (e == EMPTY_COLUMN) {
            lineId.append('\t');
            lineN.append('\t');
            lineM.append('\t');
            lineRatio.append('\t');
        } else {/*from w w w .j  a  v  a 2  s. co  m*/
            Stats s = e.stats.get(0);
            double ratio = (double) s.n / s.m;
            lineId.append('\t').append(e.id);
            lineN.append('\t').append(s.n);
            lineM.append('\t').append(s.m);
            lineRatio.append('\t').append(String.format("%.2f", ratio));
        }
    }

    pw.println(lineId.toString());
    pw.println(lineN.toString());
    pw.println(lineM.toString());
    pw.println(lineRatio.toString());

    int statsCount = experiments[0].stats.size();
    DecimalFormat format = new DecimalFormat("#.###");

    for (int i = 0; i < statsCount; i++) {
        // String cfg0 = experiments[0].stats.get(i).cfg;
        // pw.printf("%20s", cfg0);

        for (Experiment e : experiments) {
            if (e == EMPTY_COLUMN) {
                pw.print('\t');// insert one empty column
            } else {
                Stats s = e.stats.get(i);

                // if (!cfg0.equals(s.cfg)) {
                // throw new RuntimeException();
                // }

                pw.print("\t" + format.format(s.values[column]));
            }
        }

        pw.println();
    }

    pw.close();
}

From source file:org.nchadoop.ui.listbox.Displayable.java

public String formatDisplayText(final int width, final long maximumSize) {
    final String readableSize = StringUtils.leftPad(Utils.readableFileSize(this.size), 10);
    final String guage = createGuage(this.size, maximumSize);

    return StringUtils.rightPad(MessageFormat.format("{0} {1} {2}", readableSize, guage, this.name), width);
}

From source file:org.openiot.ui.request.definition.web.sparql.nodes.base.AbstractSparqlNode.java

public String generatePad(int padDepth) {
    return StringUtils.leftPad("", DEPTH_SPACES * padDepth);
}

From source file:org.skfiy.typhon.spi.war.WarProvider.java

/**
 *
 * @param fightObjects//from  w w w  . jav a 2s  .  c om
 * @param holdPoints
 * @return
 */
public Collection<WarCombo> calculateCombo(List<FightObject> fightObjects, int[] holdPoints) {
    Shot[][] table = toShotTable(fightObjects, holdPoints);
    Map<Shot, WarCombo> combos = new HashMap<>();

    Shot shot, temp;
    int x1, y1, x2, y2, x3, y3;
    for (int i = 0; i < table.length; i++) {
        Shot[] shots = table[i];
        for (int j = 0; j < 3; j++) { // ?
            shot = shots[j];
            x1 = i;
            y1 = j;

            if (i == 0) {
                x2 = x1 + 1;
                y2 = y1 + 1;

                x3 = x2 + 1;
                y3 = y2 + 1;
                temp = isCombo(shot, table[x2][y2], table[x3][y3]);
                if (temp != null) {
                    plusComboPoint(combos, temp, x1, y1, fightObjects.get(y1));
                    plusComboPoint(combos, temp, x2, y2, fightObjects.get(y2));
                    plusComboPoint(combos, temp, x3, y3, fightObjects.get(y3));
                }
            } else if (i == 2) { // ?
                x2 = x1 - 1;
                y2 = y1 + 1;

                x3 = x2 - 1;
                y3 = y2 + 1;
                temp = isCombo(shot, table[x2][y2], table[x3][y3]);
                if (temp != null) {
                    plusComboPoint(combos, temp, x1, y1, fightObjects.get(y1));
                    plusComboPoint(combos, temp, x2, y2, fightObjects.get(y2));
                    plusComboPoint(combos, temp, x3, y3, fightObjects.get(y3));
                }
            }

            // 
            x3 = x2 = x1;
            y2 = y1 + 1;
            y3 = y2 + 1;

            temp = isCombo(shot, table[x2][y2], table[x3][y3]);
            if (temp != null) {
                plusComboPoint(combos, temp, x1, y1, fightObjects.get(y1));
                plusComboPoint(combos, temp, x2, y2, fightObjects.get(y2));
                plusComboPoint(combos, temp, x3, y3, fightObjects.get(y3));

                if (temp == Shot.Q7) {
                    if (j == 0) {
                        temp = table[i][3];
                        if (temp != Shot.Miss && temp != Shot.Q7) {
                            plusComboPoint(combos, temp, x1, y1, fightObjects.get(y1));
                            plusComboPoint(combos, temp, x2, y2, fightObjects.get(y2));
                            plusComboPoint(combos, temp, x3, y3, fightObjects.get(y3));
                        } else if (temp == Shot.Q7) {
                            temp = table[i][4];
                            if (temp != Shot.Miss && temp != Shot.Q7) {
                                // 1combo
                                plusComboPoint(combos, temp, x1, y1, fightObjects.get(y1));
                                plusComboPoint(combos, temp, x2, y2, fightObjects.get(y2));
                                plusComboPoint(combos, temp, x3, y3, fightObjects.get(y3));
                            }
                        }
                    } else if (j == 1) {
                        // First
                        temp = table[i][0];
                        if (temp != Shot.Miss && temp != Shot.Q7) {
                            plusComboPoint(combos, temp, i, j, fightObjects.get(j));
                            plusComboPoint(combos, temp, i, j + 1, fightObjects.get(j + 1));
                            plusComboPoint(combos, temp, i, j + 2, fightObjects.get(j + 2));
                        }

                        // Last
                        temp = table[i][4];
                        if (temp != Shot.Miss && temp != Shot.Q7) {
                            plusComboPoint(combos, temp, i, j + 1, fightObjects.get(y1));
                            plusComboPoint(combos, temp, i, j + 2, fightObjects.get(y2));
                            plusComboPoint(combos, temp, i, j + 3, fightObjects.get(y3));
                        }
                        //====================================================//
                    } else if (j == 2 && table[i][1] != Shot.Miss) {
                        temp = table[i][1];
                        if (temp == Shot.Q7) {
                            temp = table[i][0];
                        }

                        if (temp != Shot.Miss && temp != Shot.Q7) {
                            plusComboPoint(combos, temp, i, 2, fightObjects.get(2));
                            plusComboPoint(combos, temp, i, 3, fightObjects.get(3));
                            plusComboPoint(combos, temp, i, 4, fightObjects.get(4));
                        }
                    }
                }
            } // 7?

        }
    }

    if (LOG.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder();
        for (WarCombo combo : combos.values()) {
            sb.append("\n").append(StringUtils.leftPad(combo.getShot().name(), 4));
            sb.append("(").append(StringUtils.leftPad(String.valueOf(combo.getComboCount()), 2)).append(")");
            sb.append(": {");
            for (Point point : combo.getPoints()) {
                sb.append(StringUtils.leftPad(table[point.getX()][point.getY()].name(), 4));
                sb.append("[").append(point.getX()).append(", ").append(point.getY()).append("] ");
            }
            sb.deleteCharAt(sb.length() - 1);
            sb.append("}");
        }
        LOG.debug(sb.toString());
    }

    // ??
    List<WarCombo> warCombos = new ArrayList<>(combos.values());
    Collections.sort(warCombos);
    return warCombos;
}

From source file:org.structr.common.CaseHelper.java

/**
 * Test method.//w ww  .  j a  va2s  .  com
 */
public static void main(String[] args) {

    String[] input = { "check_ins", "CheckIns", "blog_entry", "BlogEntry", "blog_entries", "BlogEntries",
            "blogentry", "blogentries" };

    for (int i = 0; i < input.length; i++) {

        System.out.println(
                StringUtils.rightPad(input[i], 20) + StringUtils.leftPad(toUpperCamelCase(input[i]), 20)
                        + StringUtils.leftPad(toUnderscore(input[i], true), 20)
                        + StringUtils.leftPad(toUnderscore(input[i], false), 20));

    }
}

From source file:playground.jbischoff.taxi.berlin.supply.TaxiStatusDataAnalyser.java

public static Matrices calculateAveragesByHour(Matrices statusMatrices, int days) {
    //convert 5-minute-vehicles ==> 1-hour-vehicles 5 / 60
    //and then average over days 
    final double normalizeFactor = 5. / 60 / days;

    return calculateAverages(statusMatrices, normalizeFactor, new Function<String, String>() {
        public String apply(String from) {
            try {
                return StringUtils.leftPad(STATUS_DATE_FORMAT.parse(from).getHours() + "", 2);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }/*from  w w w .  ja  v  a 2s  . c  om*/
        }
    });
}

From source file:playground.michalm.poznan.demand.taxi.ServedRequestsAggregator.java

public static void main(String[] args) {
    Scenario scenario = ScenarioUtils.createScenario(VrpConfigUtils.createConfig());

    //Map<Id, Zone> zones = PoznanZones.readTaxiZones(scenario);
    Map<Id<Zone>, Zone> zones = PoznanZones.readVisumZones(scenario);

    Iterable<ServedRequest> requests = PoznanServedRequests.readRequests(2, 3, 4);
    requests = PoznanServedRequests.filterNormalPeriods(requests);
    requests = PoznanServedRequests.filterWorkDaysPeriods(requests);
    requests = PoznanServedRequests.filterRequestsWithinAgglomeration(requests);

    //aggregateRequests
    ZoneFinder zoneFinder = new ZoneFinder(zones, 200);
    final FormatBasedDateDiscretizer hourlyDateDiscretizer = new FormatBasedDateDiscretizer(
            FormatBasedDateDiscretizer.YMDH);
    DemandAggregator demandAggregator = new DemandAggregator(zoneFinder, hourlyDateDiscretizer);

    for (ServedRequest r : requests) {
        demandAggregator.addTrip(r.assigned, r.from, r.to);
    }/*from   ww  w .java2s . c  o m*/

    demandAggregator.printCounters();

    //write ODs to file
    String matricesFile = "d:/PP-rad/taxi/poznan-supply/zlecenia_obsluzone/matrices_workdays.txt";
    String header = "year\tmonth\tm_day\tw_day\thour";
    final DateFormat tabDateFormat = new SimpleDateFormat("yy\tMM\tdd\tu\tHH");

    MatricesTxtWriter w1 = new MatricesTxtWriter(demandAggregator.getMatrices().getMatrices());
    w1.setKeyHeader(header);
    w1.setKeyFormatter(new Function<String, String>() {
        @Override
        public String apply(String key) {
            Date date = hourlyDateDiscretizer.parseDiscretizedDate(key);
            return tabDateFormat.format(date);
        }
    });
    w1.write(matricesFile);

    Matrices aggregatedMatrices = MatrixUtils.aggregateMatrices(demandAggregator.getMatrices(),
            new Function<String, String>() {
                @Override
                public String apply(String key) {
                    return StringUtils.leftPad(hourlyDateDiscretizer.parseDiscretizedDate(key).getHours() + "",
                            2);
                };
            });

    String aggregatedMatricesFile = "d:/PP-rad/taxi/poznan-supply/zlecenia_obsluzone/matrices_workdays_aggregated.txt";
    MatricesTxtWriter w2 = new MatricesTxtWriter(aggregatedMatrices.getMatrices());
    w2.setKeyHeader("hour");
    w2.write(aggregatedMatricesFile);
}

From source file:se.trixon.mapollage.Operation.java

private void saveToFile() {
    mListener.onOperationLog("");
    List keys = new ArrayList(mRootFolders.keySet());
    Collections.sort(keys);/*from  w w w.  j  a v a 2 s .  c  o m*/

    keys.stream().forEach((key) -> {
        mRootFolder.getFeature().add(mRootFolders.get((String) key));
    });

    if (mPathFolder != null && !mPathFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathFolder);
    }

    if (mPathGapFolder != null && !mPathGapFolder.getFeature().isEmpty()) {
        mRootFolder.getFeature().add(mPathGapFolder);
    }

    if (isUsingThumbnails()) {
        mListener.onOperationLog(
                "\n" + String.format(mBundle.getString("stored_thumbnails"), mThumbsDir.getAbsolutePath()));
    }

    try {
        StringWriter stringWriter = new StringWriter();
        mKml.marshal(stringWriter);
        String kmlString = stringWriter.toString();

        if (mOptions.isCleanNs2()) {
            mListener.onOperationLog(mBundle.getString("clean_ns2"));
            kmlString = StringUtils.replace(kmlString, "xmlns:ns2=", "xmlns=");
            kmlString = StringUtils.replace(kmlString, "<ns2:", "<");
            kmlString = StringUtils.replace(kmlString, "</ns2:", "</");
        }

        if (mOptions.isCleanSpace()) {
            mListener.onOperationLog(mBundle.getString("clean_space"));
            kmlString = StringUtils.replace(kmlString, "        ", "\t");
            kmlString = StringUtils.replace(kmlString, "    ", "\t");
        }

        kmlString = StringUtils.replaceEach(kmlString, new String[] { "&lt;", "&gt;", "&amp;" },
                new String[] { "<", ">", "" });

        if (mOptions.isLogKml()) {
            mListener.onOperationLog("\n");
            mListener.onOperationLog(kmlString);
            mListener.onOperationLog("\n");
        }

        mListener.onOperationLog(String.format(Dict.SAVING.toString(), mDestinationFile.getAbsolutePath()));
        FileUtils.writeStringToFile(mDestinationFile, kmlString, "utf-8");

        String files = mBundle.getString("status_files");
        String exif = mBundle.getString("status_exif");
        String coordinate = mBundle.getString("status_coordinate");
        String time = mBundle.getString("status_time");
        String error = " " + Dict.Dialog.ERRORS.toString().toLowerCase();
        String placemarks = mBundle.getString("status_placemarks");

        int rightPad = files.length();
        rightPad = Math.max(rightPad, exif.length());
        rightPad = Math.max(rightPad, coordinate.length());
        rightPad = Math.max(rightPad, time.length());
        rightPad = Math.max(rightPad, error.length());
        rightPad = Math.max(rightPad, placemarks.length());
        rightPad++;

        int leftPad = 8;
        StringBuilder summaryBuilder = new StringBuilder("\n");

        String filesValue = String.valueOf(mFiles.size());
        summaryBuilder.append(StringUtils.rightPad(files, rightPad)).append(":")
                .append(StringUtils.leftPad(filesValue, leftPad)).append("\n");

        String exifValue = String.valueOf(mNumOfExif);
        summaryBuilder.append(StringUtils.rightPad(exif, rightPad)).append(":")
                .append(StringUtils.leftPad(exifValue, leftPad)).append("\n");

        String coordinateValue = String.valueOf(mNumOfGps);
        summaryBuilder.append(StringUtils.rightPad(coordinate, rightPad)).append(":")
                .append(StringUtils.leftPad(coordinateValue, leftPad)).append("\n");

        String placemarksValue = String.valueOf(mNumOfPlacemarks);
        summaryBuilder.append(StringUtils.rightPad(placemarks, rightPad)).append(":")
                .append(StringUtils.leftPad(placemarksValue, leftPad)).append("\n");

        String errorValue = String.valueOf(mNumOfErrors);
        summaryBuilder.append(StringUtils.rightPad(error, rightPad)).append(":")
                .append(StringUtils.leftPad(errorValue, leftPad)).append("\n");

        String timeValue = String.valueOf(Math.round((System.currentTimeMillis() - mStartTime) / 1000.0));
        summaryBuilder.append(StringUtils.rightPad(time, rightPad)).append(":")
                .append(StringUtils.leftPad(timeValue, leftPad)).append(" s").append("\n");

        mListener.onOperationFinished(summaryBuilder.toString(), mFiles.size());
    } catch (IOException ex) {
        mListener.onOperationFailed(ex.getLocalizedMessage());
    }
}

From source file:se.trixon.mapollage.profile.Profile.java

@Override
public String toDebugString() {
    ArrayList<ProfileInfo> profileInfos = new ArrayList<>();
    profileInfos.add(mSource.getProfileInfo());
    profileInfos.add(mFolder.getProfileInfo());
    profileInfos.add(mPath.getProfileInfo());
    profileInfos.add(mPlacemark.getProfileInfo());
    profileInfos.add(mDescription.getProfileInfo());
    profileInfos.add(mPhoto.getProfileInfo());
    profileInfos.add(getProfileInfo());/*  ww  w  .  j  a v a  2  s  .  com*/

    int maxLength = Integer.MIN_VALUE;
    for (ProfileInfo profileInfo : profileInfos) {
        maxLength = Math.max(maxLength, profileInfo.getMaxLength());
    }
    maxLength = maxLength + 3;

    String separator = " : ";
    StringBuilder builder = new StringBuilder("\n");
    builder.append(StringUtils.leftPad(Dict.PROFILE.toString(), maxLength)).append(separator).append(mName)
            .append("\n");
    builder.append(StringUtils.leftPad("", maxLength)).append(separator).append(mDescriptionString)
            .append("\n");

    for (ProfileInfo profileInfo : profileInfos) {
        builder.append(profileInfo.getTitle()).append("\n");

        for (Map.Entry<String, String> entry : profileInfo.getValues().entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            builder.append(StringUtils.leftPad(key, maxLength)).append(separator).append(value).append("\n");
        }

        builder.append("\n");
    }

    return builder.toString();
}

From source file:se.trixon.mapollage.profile.Profile.java

public String toInfoString() {
    ArrayList<ProfileInfo> profileInfos = new ArrayList<>();
    profileInfos.add(mSource.getProfileInfo());
    profileInfos.add(mFolder.getProfileInfo());
    profileInfos.add(mPath.getProfileInfo());
    profileInfos.add(mPlacemark.getProfileInfo());
    profileInfos.add(mDescription.getProfileInfo());
    profileInfos.add(mPhoto.getProfileInfo());
    profileInfos.add(getProfileInfo());//from   ww  w.ja v  a2s  .  com

    int maxLength = Integer.MIN_VALUE;
    for (ProfileInfo profileInfo : profileInfos) {
        maxLength = Math.max(maxLength, profileInfo.getMaxLength());
    }
    maxLength = maxLength + 3;

    String separator = " : ";
    StringBuilder builder = new StringBuilder();
    for (ProfileInfo profileInfo : profileInfos) {
        builder.append(profileInfo.getTitle()).append("\n");

        for (Map.Entry<String, String> entry : profileInfo.getValues().entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            builder.append(StringUtils.leftPad(key, maxLength)).append(separator).append(value).append("\n");
        }

        builder.append("\n");
    }

    return builder.toString().trim();
}