Example usage for java.text NumberFormat getInstance

List of usage examples for java.text NumberFormat getInstance

Introduction

In this page you can find the example usage for java.text NumberFormat getInstance.

Prototype

public static NumberFormat getInstance(Locale inLocale) 

Source Link

Document

Returns a general-purpose number format for the specified locale.

Usage

From source file:org.optaplanner.benchmark.impl.statistic.movecountperstep.MoveCountPerStepProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Accepted/selected moves per step");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    DrawingSupplier drawingSupplier = new DefaultDrawingSupplier();
    plot.setOrientation(PlotOrientation.VERTICAL);

    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries acceptedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " accepted");
        XYSeries selectedSeries = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix() + " selected");
        XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
        if (singleBenchmarkResult.isSuccess()) {
            MoveCountPerStepSingleStatistic singleStatistic = (MoveCountPerStepSingleStatistic) singleBenchmarkResult
                    .getSingleStatistic(problemStatisticType);
            for (MoveCountPerStepStatisticPoint point : singleStatistic.getPointList()) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long acceptedMoveCount = point.getMoveCountPerStepMeasurement().getAcceptedMoveCount();
                long selectedMoveCount = point.getMoveCountPerStepMeasurement().getSelectedMoveCount();
                acceptedSeries.add(timeMillisSpent, acceptedMoveCount);
                selectedSeries.add(timeMillisSpent, selectedMoveCount);
            }//  w  w w  . j  av a2s .co m
        }
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        seriesCollection.addSeries(acceptedSeries);
        seriesCollection.addSeries(selectedSeries);
        plot.setDataset(seriesIndex, seriesCollection);

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        } else {
            // Dashed line for selected move count
            renderer.setSeriesStroke(1, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f));
        }
        // Render both lines in the same color
        Paint linePaint = drawingSupplier.getNextPaint();
        renderer.setSeriesPaint(0, linePaint);
        renderer.setSeriesPaint(1, linePaint);
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }

    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " move count per step statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart, problemBenchmarkResult.getName() + "MoveCountPerStepStatistic");
}

From source file:au.com.onegeek.lambda.core.provider.WebDriverBackedSeleniumProvider.java

public void clickAndWait(String id, String seconds) throws ParseException {
    NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
    Number number = format.parse(seconds);
    this.click(id);
    this.waitForPageToLoad(String.valueOf(number.intValue() * 1000));
}

From source file:fr.cph.stock.android.entity.EntityBuilder.java

private void buildUser() throws JSONException {
    user = new User();
    JSONObject jsonUser = json.getJSONObject("user");

    String userIdStr = jsonUser.getString("id");
    user.setUserId(userIdStr);/*from   www  .  j a v  a  2s  .c o  m*/

    String localeStr = jsonUser.getString("locale");
    String language = localeStr.split("_")[0];
    String country = localeStr.split("_")[1];
    Locale locale = new Locale(language, country);
    user.setLocale(locale);

    formatCurrencyZero = NumberFormat.getCurrencyInstance(user.getLocale());
    formatCurrencyZero.setMaximumFractionDigits(0);
    formatCurrencyZero.setMinimumFractionDigits(0);
    formatCurrencyZero.setRoundingMode(RoundingMode.HALF_DOWN);

    formatCurrencyOne = NumberFormat.getCurrencyInstance(user.getLocale());
    formatCurrencyOne.setMaximumFractionDigits(1);
    formatCurrencyOne.setMinimumFractionDigits(0);
    formatCurrencyOne.setRoundingMode(RoundingMode.HALF_DOWN);

    formatCurrencyTwo = NumberFormat.getCurrencyInstance(user.getLocale());
    formatCurrencyTwo.setMaximumFractionDigits(2);
    formatCurrencyTwo.setMinimumFractionDigits(0);
    formatCurrencyTwo.setRoundingMode(RoundingMode.HALF_DOWN);

    formatLocaleZero = NumberFormat.getInstance(user.getLocale());
    formatLocaleZero.setMaximumFractionDigits(0);
    formatLocaleZero.setMinimumFractionDigits(0);
    formatLocaleZero.setRoundingMode(RoundingMode.HALF_DOWN);

    formatLocaleOne = NumberFormat.getInstance(user.getLocale());
    formatLocaleOne.setMaximumFractionDigits(1);
    formatLocaleOne.setMinimumFractionDigits(0);
    formatLocaleOne.setRoundingMode(RoundingMode.HALF_DOWN);

    formatLocaleTwo = NumberFormat.getInstance(user.getLocale());
    formatLocaleTwo.setMaximumFractionDigits(2);
    formatLocaleTwo.setMinimumFractionDigits(0);
    formatLocaleTwo.setRoundingMode(RoundingMode.HALF_DOWN);

    String datePattern = jsonUser.getString("datePattern");
    user.setDatePattern(datePattern);

    String datePatternWithoutHourMin = jsonUser.getString("datePatternWithoutHourMin");
    user.setDatePatternWithoutHourMin(datePatternWithoutHourMin);

    JSONObject lastUpdateJSON = jsonUser.getJSONObject("lastUpdate");
    user.setLastUpdate(extractDate(lastUpdateJSON, user.getDatePattern()));
}

From source file:org.optaplanner.benchmark.impl.statistic.scorecalculationspeed.ScoreCalculationSpeedProblemStatistic.java

@Override
public void writeGraphFiles(BenchmarkReport benchmarkReport) {
    Locale locale = benchmarkReport.getLocale();
    NumberAxis xAxis = new NumberAxis("Time spent");
    xAxis.setNumberFormatOverride(new MillisecondsSpentNumberFormat(locale));
    NumberAxis yAxis = new NumberAxis("Score calculation speed per second");
    yAxis.setNumberFormatOverride(NumberFormat.getInstance(locale));
    yAxis.setAutoRangeIncludesZero(false);
    XYPlot plot = new XYPlot(null, xAxis, yAxis, null);
    plot.setOrientation(PlotOrientation.VERTICAL);
    int seriesIndex = 0;
    for (SingleBenchmarkResult singleBenchmarkResult : problemBenchmarkResult.getSingleBenchmarkResultList()) {
        XYSeries series = new XYSeries(
                singleBenchmarkResult.getSolverBenchmarkResult().getNameWithFavoriteSuffix());
        XYItemRenderer renderer = new XYLineAndShapeRenderer();
        if (singleBenchmarkResult.hasAllSuccess()) {
            ScoreCalculationSpeedSubSingleStatistic subSingleStatistic = (ScoreCalculationSpeedSubSingleStatistic) singleBenchmarkResult
                    .getSubSingleStatistic(problemStatisticType);
            List<ScoreCalculationSpeedStatisticPoint> points = subSingleStatistic.getPointList();
            for (ScoreCalculationSpeedStatisticPoint point : points) {
                long timeMillisSpent = point.getTimeMillisSpent();
                long scoreCalculationSpeed = point.getScoreCalculationSpeed();
                series.add(timeMillisSpent, scoreCalculationSpeed);
            }//from  w  w  w . j a va2s.c o m
        }
        plot.setDataset(seriesIndex, new XYSeriesCollection(series));

        if (singleBenchmarkResult.getSolverBenchmarkResult().isFavorite()) {
            // Make the favorite more obvious
            renderer.setSeriesStroke(0, new BasicStroke(2.0f));
        }
        plot.setRenderer(seriesIndex, renderer);
        seriesIndex++;
    }
    JFreeChart chart = new JFreeChart(problemBenchmarkResult.getName() + " score calculation speed statistic",
            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    graphFile = writeChartToImageFile(chart,
            problemBenchmarkResult.getName() + "ScoreCalculationSpeedStatistic");
}

From source file:de.kopis.glacier.util.VaultInventoryPrinter.java

private String humanReadableSize(final String size) throws IllegalArgumentException {
    final String[] sanitizedSize = sanitize(size);
    double sizeAsDouble = 0;
    try {// w  w w .  j a  va  2 s  .c om
        // parse as US value, because WTF? java default?
        sizeAsDouble = NumberFormat.getInstance(Locale.US).parse(sanitizedSize[0]).doubleValue();
    } catch (final ParseException e) {
        throw new IllegalArgumentException("Can not parse Number", e);
    }
    String humanReadableSize = "";
    String sizeClass = sanitizedSize[1];
    if (sizeAsDouble > 1024) {
        sizeClass = getLargerSizeClass(sanitizedSize[1]);
        humanReadableSize = humanReadableSize(sizeAsDouble / 1024.0 + " " + sizeClass);
    } else {
        humanReadableSize = round(Double.toString(sizeAsDouble), 2, BigDecimal.ROUND_UP) + sizeClass;
    }
    return humanReadableSize;
}

From source file:com.salesmanager.core.module.impl.application.currencies.USDCurrencyModule.java

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;/*w w  w. j a  va  2 s  .c  o m*/

    nf = NumberFormat.getInstance(Locale.US);

    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);

    return nf.format(amount);

}

From source file:air.AirRuntimeGenerator.java

protected void processFlashRuntime(File sdkSourceDirectory, File sdkTargetDirectory) throws Exception {
    final File runtimeDirectory = new File(sdkSourceDirectory, "runtimes");
    final File flashPlayerDirectory = new File(runtimeDirectory, "player");

    File[] versions = flashPlayerDirectory.listFiles(new FileFilter() {
        public boolean accept(File pathname) {
            return pathname.isDirectory() && !"win".equalsIgnoreCase(pathname.getName())
                    && !"lnx".equalsIgnoreCase(pathname.getName())
                    && !"mac".equalsIgnoreCase(pathname.getName());
        }//ww w  .  jav a2 s  .  c  om
    });
    // The flash-player 9 is installed directly in the player directory.
    if (new File(flashPlayerDirectory, "win").exists()) {
        final File[] extendedVersions = new File[versions.length + 1];
        System.arraycopy(versions, 0, extendedVersions, 0, versions.length);
        extendedVersions[versions.length] = flashPlayerDirectory;
        versions = extendedVersions;
    }

    if (versions != null) {
        for (final File versionDir : versions) {
            // If the versionDir is called "player", then this is the home of the flash-player version 9.
            final String playerVersionString = "player".equalsIgnoreCase(versionDir.getName()) ? "9.0"
                    : versionDir.getName();
            final double playerVersion = Double.valueOf(playerVersionString);
            final NumberFormat doubleFormat = NumberFormat.getInstance(Locale.US);
            doubleFormat.setMinimumFractionDigits(1);
            doubleFormat.setMaximumFractionDigits(1);
            final String version = doubleFormat.format(playerVersion);

            final File targetDir = new File(sdkTargetDirectory, "com/adobe/flash/runtime/" + version);

            // Deploy Windows binaries.
            final File windowsDirectory = new File(versionDir, "win");
            if (windowsDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(windowsDirectory, "FlashPlayerDebugger.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayerDebugger.exe");
                } else if (new File(windowsDirectory, "FlashPlayer.exe").exists()) {
                    flashPlayerBinary = new File(windowsDirectory, "FlashPlayer.exe");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-win.exe");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Mac binaries.
            final File macDirectory = new File(versionDir, "mac");
            if (macDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(macDirectory, "Flash Player.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player.app.zip");
                } else if (new File(macDirectory, "Flash Player Debugger.app.zip").exists()) {
                    flashPlayerBinary = new File(macDirectory, "Flash Player Debugger.app.zip");
                }

                // If a binary exists, copy it to the target and create a pom for it.
                if (flashPlayerBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-mac.zip");
                    copyFile(flashPlayerBinary, targetFile);
                }
            }

            // Deploy Linux binaries.
            final File lnxDirectory = new File(versionDir, "lnx");
            if (lnxDirectory.exists()) {
                // Find out if a flash-player binary exists.
                File flashPlayerBinary = null;
                if (new File(lnxDirectory, "flashplayer.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayer.tar.gz");
                } else if (new File(lnxDirectory, "flashplayerdebugger.tar.gz").exists()) {
                    flashPlayerBinary = new File(lnxDirectory, "flashplayerdebugger.tar.gz");
                }

                // Decompress the archive.
                // First unzip it.
                final FileInputStream fin = new FileInputStream(flashPlayerBinary);
                final BufferedInputStream in = new BufferedInputStream(fin);
                final File tempTarFile = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                        ".tar");
                final FileOutputStream out = new FileOutputStream(tempTarFile);
                final GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);
                final byte[] buffer = new byte[1024];
                int n;
                while (-1 != (n = gzIn.read(buffer))) {
                    out.write(buffer, 0, n);
                }
                out.close();
                gzIn.close();

                // Then untar it.
                File uncompressedBinary = null;
                final FileInputStream tarFileInputStream = new FileInputStream(tempTarFile);
                final TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream(
                        tarFileInputStream);
                ArchiveEntry entry;
                while ((entry = tarArchiveInputStream.getNextEntry()) != null) {
                    if ("flashplayer".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    } else if ("flashplayerdebugger".equals(entry.getName())) {
                        uncompressedBinary = File.createTempFile("flex-sdk-linux-flashplayer-binary-" + version,
                                ".uexe");
                        final FileOutputStream uncompressedBinaryOutputStream = new FileOutputStream(
                                uncompressedBinary);
                        while (-1 != (n = tarArchiveInputStream.read(buffer))) {
                            uncompressedBinaryOutputStream.write(buffer, 0, n);
                        }
                        uncompressedBinaryOutputStream.close();
                    }
                }
                tarFileInputStream.close();

                // If a binary exists, copy it to the target and create a pom for it.
                if (uncompressedBinary != null) {
                    if (!targetDir.exists()) {
                        if (!targetDir.mkdirs()) {
                            throw new RuntimeException(
                                    "Could not create directory: " + targetDir.getAbsolutePath());
                        }
                    }
                    final File targetFile = new File(targetDir, "/runtime-" + version + "-linux.uexe");
                    copyFile(uncompressedBinary, targetFile);

                    // Clean up in the temp directory.
                    if (!uncompressedBinary.delete()) {
                        System.out.println("Could not delete: " + uncompressedBinary.getAbsolutePath());
                    }
                }

                // Clean up in the temp directory.
                if (!tempTarFile.delete()) {
                    System.out.println("Could not delete: " + tempTarFile.getAbsolutePath());
                }
            }

            final MavenMetadata playerArtifact = new MavenMetadata();
            playerArtifact.setGroupId("com.adobe.flash");
            playerArtifact.setArtifactId("runtime");
            playerArtifact.setVersion(version);
            playerArtifact.setPackaging("exe");

            writeDocument(createPomDocument(playerArtifact),
                    new File(targetDir, "runtime-" + version + ".pom"));
        }
    }
}

From source file:com.greenpepper.maven.plugin.TestMonitor.java

private String formatElapsedTime(Long runTime) {
    NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
    return numberFormat.format(runTime.doubleValue() / 1000);
}

From source file:de.cosmocode.palava.ipc.legacy.LegacyHttpSessionAdapter.java

@Override
public NumberFormat getNumberFormat() {
    touch();/* w ww  . j a va 2s.c  o m*/
    if (format == null) {
        format = NumberFormat.getInstance(getLocale());
    }
    return format;
}

From source file:com.salesmanager.core.module.impl.application.currencies.EURCurrencyModule.java

public String getFormatedAmount(BigDecimal amount) throws Exception {

    NumberFormat nf = null;//from w w w  .j  av a2s  .  com

    nf = NumberFormat.getInstance(Locale.GERMAN);

    nf.setMaximumFractionDigits(2);
    nf.setMinimumFractionDigits(2);

    return nf.format(amount);

}