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:dbs_project.index.performance.IndexTest.java

private /* static */ void outputTime(String testCaseName, int scale, IndexType it, long nanoTime) {
    String timeString = NumberFormat.getInstance(Locale.US).format(nanoTime / 1000d / 1000d / 1000d);
    Utils.getOut().println(testCaseName + "\tTime: " + timeString + " seconds");
    this.scaleResults.add("<measurement><name>" + testCaseName + "</name>" + "<scale>" + scale + "</scale>"
            + "<type>" + it + "</type>" + "<value>" + timeString + "</value></measurement>");
}

From source file:org.openmrs.web.controller.patient.PatientFormController.java

/**
 * Allows for other Objects to be used as values in input tags. Normally, only strings and lists
 * are expected//  w ww .  j  a  va2  s.  com
 *
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
    super.initBinder(request, binder);

    NumberFormat nf = NumberFormat.getInstance(Context.getLocale());
    binder.registerCustomEditor(java.lang.Integer.class,
            new CustomNumberEditor(java.lang.Integer.class, nf, true));
    binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10));
    binder.registerCustomEditor(PatientIdentifierType.class, new PatientIdentifierTypeEditor());
    binder.registerCustomEditor(Location.class, new LocationEditor());
    binder.registerCustomEditor(Concept.class, "civilStatus", new ConceptEditor());
    binder.registerCustomEditor(Concept.class, "causeOfDeath", new ConceptEditor());
}

From source file:au.org.emii.geoserver.wfs.response.RestrictedColumnCsvOutputFormat.java

private NumberFormat getCoordFormatter() {
    NumberFormat coordFormatter = NumberFormat.getInstance(Locale.US);
    coordFormatter.setMaximumFractionDigits(getInfo().getGeoServer().getSettings().getNumDecimals());
    coordFormatter.setGroupingUsed(false);

    return coordFormatter;
}

From source file:org.apache.flex.utilities.converter.flash.FlashConverter.java

/**
 * This method generates those artifacts that resemble the runtime part of the Flash SDK.
 *
 * @throws ConverterException/* www.j  a  va 2s.  co  m*/
 */
protected void generateRuntimeArtifacts() throws ConverterException {
    // Create a list of all libs that should belong to the Flash SDK runtime.
    final File directory = new File(rootSourceDirectory, "runtimes" + File.separator + "player");
    if (!directory.exists() || !directory.isDirectory()) {
        System.out.println("Skipping runtime generation.");
        return;
    }
    final List<File> playerVersions = new ArrayList<File>();
    playerVersions.addAll(Arrays.asList(directory.listFiles(new FlashRuntimeFilter())));

    // In really old SDKs the flash-player was installed in the players directory directly.
    if (new File(directory, "win").exists()) {
        playerVersions.add(directory);
    }

    // Generate artifacts for every jar in the input directories.
    for (final File versionDir : playerVersions) {
        // The flash-player 9 is installed directly in the player directory.
        String playerVersionString;
        if (versionDir == directory) {
            playerVersionString = "9.0";
        } else {
            playerVersionString = 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 MavenArtifact playerArtifact = new MavenArtifact();
        playerArtifact.setGroupId("com.adobe.flash");
        playerArtifact.setArtifactId("runtime");
        playerArtifact.setVersion(version);
        playerArtifact.setPackaging("exe");

        // 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) {
                playerArtifact.addBinaryArtifact("win", flashPlayerBinary);
            }
        }

        // 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) {
                playerArtifact.addBinaryArtifact("mac", flashPlayerBinary);
            }
        }

        // Deploy Linux binaries.
        final File lnxDirectory = new File(versionDir, "lnx");
        if (lnxDirectory.exists()) {
            // Find out if a flash-player binary exists.
            File flashPlayerBinary;
            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");
            } else {
                throw new ConverterException("Couldn't find player archive.");
            }

            // Decompress the archive.
            // First unzip it.
            final FileInputStream fin;
            try {
                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) {
                    playerArtifact.addBinaryArtifact("linux", flashPlayerBinary);
                }
            } catch (FileNotFoundException e) {
                throw new ConverterException("Error processing the linux player tar file", e);
            } catch (IOException e) {
                throw new ConverterException("Error processing the linux player tar file", e);
            }
        }

        // Write this artifact to file.
        writeArtifact(playerArtifact);
    }
}

From source file:forge.util.FileSection.java

/**
 * Gets the double./*w w w .  j  a  v a  2 s . c  o m*/
 *
 * @param fieldName the field name
 * @param defaultValue the default value
 * @return the int
 */
public double getDouble(final String fieldName, final double defaultValue) {
    try {
        if (this.get(fieldName) == null) {
            return defaultValue;
        }

        NumberFormat format = NumberFormat.getInstance(Locale.US);
        Number number = format.parse(this.get(fieldName));

        return number.doubleValue();
    } catch (final NumberFormatException | ParseException ex) {
        return defaultValue;
    }
}

From source file:de.xirp.io.format.FormatParser.java

/**
 * Formats the given data according to this formatting data
 * /*from  www.j  a va2 s  . c  om*/
 * @param parser
 *            the data encapsulated in a parser
 * @return Object with the formatted data<br>
 *         NOTE: Floats are formatted to double for convenience.
 */
public Object formatData(ByteParser parser) {
    ArrayList<Object> parsedData = new ArrayList<Object>(formats.size());
    for (Format format : formats) {
        switch (format.getType()) {
        case CHAR:
            if (format.getLength() == -1) {
                parsedData.add(parser.getNextString());
            } else {
                parsedData.add(parser.getNextString(format.getLength()));
            }
            break;
        case BYTE:
            parsedData.add(parser.getNextByte());
            break;
        case UBYTE:
            parsedData.add(parser.getNextUnsignedByte());
            break;
        case SHORT:
            parsedData.add(parser.getNextShort());
            break;
        case INTEGER:
            parsedData.add(parser.getNextInt());
            break;
        case DOUBLE:
            parsedData.add(parser.getNextDouble());
            break;
        case FLOAT:
            Float f = parser.getNextFloat();
            NumberFormat nf = NumberFormat.getInstance(Locale.ENGLISH);
            nf.setMaximumFractionDigits(format.getLength());
            double d = Double.parseDouble(nf.format(f));
            parsedData.add(d);
            break;
        case LONG:
            parsedData.add(parser.getNextLong());
            break;
        }
    }
    if (parsedData.size() == 1) {
        return parsedData.get(0);
    }
    return parsedData;
}

From source file:userinterface.graph.AxisSettings.java

public AxisSettings(String name, boolean isDomain, Graph graph) {
    this.name = name;
    this.isDomain = isDomain;
    this.graph = graph;
    this.chart = graph.getChart();
    this.plot = chart.getXYPlot();
    this.axis = (isDomain) ? this.plot.getDomainAxis() : this.plot.getRangeAxis();

    this.valuesFormatter = NumberFormat.getInstance(Locale.UK);

    if (this.valuesFormatter instanceof DecimalFormat)
        ((DecimalFormat) this.valuesFormatter)
                .applyPattern("###,###,###,###,###,###,###,###.########################");

    /* Initialise all the settings. */
    heading = new SingleLineStringSetting("heading", name, "The heading for this axis", this, true);
    headingFont = new FontColorSetting("heading font",
            new FontColorPair(new Font("SansSerif", Font.PLAIN, 12), Color.black),
            "The font for this axis' heading.", this, true);
    numberFont = new FontColorSetting("numbering font",
            new FontColorPair(new Font("SansSerif", Font.PLAIN, 12), Color.black),
            "The font used to number the axis.", this, true);

    showGrid = new BooleanSetting("show gridlines", new Boolean(true), "Should the gridlines be visible", this,
            true);// w  w  w . j a  va  2s  .  c  om
    gridColour = new ColorSetting("gridline colour", new Color(204, 204, 204), "The colour of the gridlines",
            this, true);

    String[] logarithmicChoices = { "Normal", "Logarithmic" };
    scaleType = new ChoiceSetting("scale type", logarithmicChoices, logarithmicChoices[0],
            "Should the scale be normal, or logarithmic", this, true);
    autoScale = new BooleanSetting("auto-scale", new Boolean(true),
            "When set to true, all minimum values, maximum values, grid intervals, maximum logarithmic powers and minimum logarithmic powers are automatically set and maintained when the data changes.",
            this, true);
    minValue = new DoubleSetting("minimum value", new Double(0.0), "The minimum value for the axis", this,
            true);
    maxValue = new DoubleSetting("maximum value", new Double(1.0), "The maximum value for the axis", this,
            true);
    gridInterval = new DoubleSetting("gridline interval", new Double(0.2), "The interval between gridlines",
            this, false, new RangeConstraint(0, Double.POSITIVE_INFINITY, false, true));
    logBase = new DoubleSetting("log base", new Double(10), "The base for the logarithmic scale", this, false,
            new RangeConstraint("1,"));

    minimumPower = new DoubleSetting("minimum power", new Double("0.0"),
            "The minimum logarithmic power that should be displayed on the scale", this, true);
    maximumPower = new DoubleSetting("maximum power", new Double("1.0"),
            "The maximum logarithmic power that should be displayed on the scale", this, true);

    String[] logStyleChoices = { "Values", "Base and exponent" };
    logStyle = new ChoiceSetting("logarithmic number style", logStyleChoices, logStyleChoices[1],
            "Should the style of the logarithmic scale show the actual values, or the base with the exponent.",
            this, false);

    /* Add constraints. */
    minValue.addConstraint(new NumericConstraint() {
        public void checkValueDouble(double d) throws SettingException {
            if (activated && d >= maxValue.getDoubleValue())
                throw new SettingException("Minimum value should be < Maximum value");
        }

        public void checkValueInteger(int i) throws SettingException {
            if (activated && i >= maxValue.getDoubleValue())
                throw new SettingException("Minimum value should be < Maximum value");
        }

        public void checkValueLong(long i) throws SettingException {
            if (activated && i >= maxValue.getDoubleValue())
                throw new SettingException("Minimum value should be < Maximum value");
        }
    });
    maxValue.addConstraint(new NumericConstraint() {
        public void checkValueDouble(double d) throws SettingException {
            if (activated && d <= minValue.getDoubleValue())
                throw new SettingException("Maximum value should be > Minimum value");
        }

        public void checkValueInteger(int i) throws SettingException {
            if (activated && i <= minValue.getDoubleValue())
                throw new SettingException("Maximum value should be > Minimum value");
        }

        public void checkValueLong(long i) throws SettingException {
            if (activated && i <= maxValue.getDoubleValue())
                throw new SettingException("Minimum value should be > Maximum value");
        }
    });
    minimumPower.addConstraint(new NumericConstraint() {
        public void checkValueDouble(double d) throws SettingException {
            if (activated && d >= maximumPower.getDoubleValue())
                throw new SettingException("Minimum power should be < Maximum power");
        }

        public void checkValueInteger(int i) throws SettingException {
            if (activated && i >= maximumPower.getDoubleValue())
                throw new SettingException("Minimum power should be < Maximum power");
        }

        public void checkValueLong(long i) throws SettingException {
            if (activated && i >= maximumPower.getDoubleValue())
                throw new SettingException("Minimum power should be < Maximum power");
        }
    });
    maximumPower.addConstraint(new NumericConstraint() {
        public void checkValueDouble(double d) throws SettingException {
            if (activated && d <= minimumPower.getDoubleValue())
                throw new SettingException("Maximum power should be > Minimum power");
        }

        public void checkValueInteger(int i) throws SettingException {
            if (activated && i <= minimumPower.getDoubleValue())
                throw new SettingException("Maximum power should be > Minimum power");
        }

        public void checkValueLong(long i) throws SettingException {
            if (activated && i <= minimumPower.getDoubleValue())
                throw new SettingException("Maximum power should be > Minimum power");
        }
    });

    doEnables();
    display = null;
    activated = true;

    updateAxis();
    setChanged();
    notifyObservers();
}

From source file:logic.Export.java

public boolean convertXls2()
        throws IOException, FileNotFoundException, IllegalArgumentException, ParseException {
    FileInputStream tamplateFile = new FileInputStream(templatePath);
    XSSFWorkbook workbook = new XSSFWorkbook(tamplateFile);

    CellStyle cellStyle = workbook.createCellStyle();
    cellStyle.setDataFormat(workbook.getCreationHelper().createDataFormat().getFormat("#,##"));
    double hours = 0.0;
    NumberFormat format = NumberFormat.getInstance(Locale.FRANCE);
    Number number;//from   w w  w  . j  a  v a  2s.  com
    XSSFSheet sheet;
    XSSFSheet sheet2;
    Cell cell = null;
    ConvertData cd = new ConvertData();
    for (int i = 0; i < cd.getSheetnames().size(); i++) {
        sheet2 = workbook.cloneSheet(0, cd.sheetnames.get(i));
        sheet = workbook.getSheetAt(i + 1);
        cell = sheet.getRow(0).getCell(1);
        cell.setCellValue(cd.sheetnames.get(i));
        ArrayList<String[]> convert = cd.convert(cd.sheetnames.get(i));
        for (int Row = 0; Row < convert.size(); Row++) {
            for (int Cell = 0; Cell < convert.get(Row).length; Cell++) {
                cell = sheet.getRow(9 + Row).getCell(Cell + 1);
                String name;
                switch (Cell) {
                case 3:
                    name = convert.get(Row)[Cell];
                    int parseInt = Integer.parseInt(name);
                    cell.setCellValue(parseInt);
                    cell.setCellType(CellType.NUMERIC);
                    break;
                case 4:
                    number = format.parse(convert.get(Row)[Cell]);
                    cell.setCellValue(number.doubleValue());
                    //  cell.setCellStyle(cellStyle);
                    cell.setCellType(CellType.NUMERIC);

                    break;
                default:
                    cell.setCellValue(convert.get(Row)[Cell]);
                    break;
                }
            }
        }

        for (String[] sa : convert) {
            number = format.parse(sa[4]);
            hours = hours + number.doubleValue();
        }
        cell = sheet.getRow(6).getCell(5);
        cell.setCellValue(hours);
        cell = sheet.getRow(2).getCell(8);
        XSSFCell cellHourlyRate = sheet.getRow(1).getCell(8);
        double numericCellValue = cellHourlyRate.getNumericCellValue();
        cell.setCellValue(hours * numericCellValue);
    }
    workbook.removeSheetAt(0);
    tamplateFile.close();
    File exportFile = newPath.getSelectedFile();
    if (FilenameUtils.getExtension(exportFile.getName()).equalsIgnoreCase("xlsx")) {

    } else {
        exportFile = new File(exportFile.getParentFile(),
                FilenameUtils.getBaseName(exportFile.getName()) + ".xlsx");
    }

    FileOutputStream outFile = new FileOutputStream(exportFile);
    workbook.write(outFile);
    outFile.close();
    tamplateFile.close();
    return true;

}

From source file:com.google.android.apps.santatracker.doodles.pursuit.PursuitFragment.java

@Override
protected void firstPassLoadOnUiThread() {
    wrapper.setOnTouchListener(new View.OnTouchListener() {
        @Override/*  ww w.  ja v  a 2 s  . com*/
        public boolean onTouch(View v, MotionEvent event) {
            return onTouchEvent(event);
        }
    });

    countdownView = new TextView(context);
    countdownView.setGravity(Gravity.CENTER);
    countdownView.setTextColor(context.getResources().getColor(R.color.ui_text_yellow));
    countdownView.setTypeface(Typeface.DEFAULT_BOLD);
    countdownView.setText("0");
    countdownView.setVisibility(View.INVISIBLE);
    Locale locale = context.getResources().getConfiguration().locale;
    countdownView.setText(NumberFormat.getInstance(locale).format(3));
    Point screenDimens = AndroidUtils.getScreenSize();
    UIUtil.fitToBounds(countdownView, screenDimens.x / 10, screenDimens.y / 10);

    final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    gameView = new PursuitView(context);
    wrapper.addView(gameView, 0, lp);

    wrapper.addView(countdownView, 1, lp);
    scoreView = getScoreView();
    wrapper.addView(scoreView, 2, lp);
    pauseView = getPauseView();
    pauseView.hidePauseButton();
    wrapper.addView(pauseView, 3, lp);
}

From source file:org.openmrs.module.personalhr.web.controller.NewPatientFormController.java

/**
 * Allows for other Objects to be used as values in input tags. Normally, only strings and lists
 * are expected/*www .  jav  a  2s  .  c o m*/
 * 
 * @see org.springframework.web.servlet.mvc.BaseCommandController#initBinder(javax.servlet.http.HttpServletRequest,
 *      org.springframework.web.bind.ServletRequestDataBinder)
 */
@Override
protected void initBinder(final HttpServletRequest request, final ServletRequestDataBinder binder)
        throws Exception {
    super.initBinder(request, binder);

    final NumberFormat nf = NumberFormat.getInstance(Context.getLocale());
    binder.registerCustomEditor(java.lang.Integer.class,
            new CustomNumberEditor(java.lang.Integer.class, nf, true));
    binder.registerCustomEditor(java.util.Date.class, new CustomDateEditor(Context.getDateFormat(), true, 10));
    binder.registerCustomEditor(Location.class, new LocationEditor());
    binder.registerCustomEditor(Concept.class, "causeOfDeath", new ConceptEditor());
    request.getSession().setAttribute(WebConstants.OPENMRS_HEADER_USE_MINIMAL, "true");

}