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 final NumberFormat getInstance() 

Source Link

Document

Returns a general-purpose number format for the current default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:com.archsystemsinc.ipms.sec.webapp.controller.MeetingController.java

@Override
@InitBinder/*www  .ja v a2 s .c  om*/
public void initBinder(final WebDataBinder binder) {
    final SimpleDateFormat dateFormat = new SimpleDateFormat(GenericConstants.DEFAULT_DATE_FORMAT);
    dateFormat.setLenient(false);
    // true passed to CustomDateEditor constructor means convert empty
    // String to null
    binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    final NumberFormat numberFormat = NumberFormat.getInstance();
    binder.registerCustomEditor(Float.class, new CustomNumberEditor(Float.class, numberFormat, true));

}

From source file:edu.cornell.med.icb.goby.modes.SplitFastaMode.java

/**
 * Split a fasta / fastq file by (a) readlength and (b) the maximum number of
 * entries per file. This will output the files that are written to stdout
 * @throws IOException error reading / writing files.
 *//*from   w ww  .  j  a v  a2 s.  c o m*/
@Override
public void execute() throws IOException {
    final FastXReader reader = new FastXReader(inputFile);
    final Int2ObjectMap<PrintStream> outputMap = new Int2ObjectOpenHashMap<PrintStream>();
    final Int2IntMap entriesPerReadLen = new Int2IntOpenHashMap();
    final Int2IntMap filesPerReadLen = new Int2IntOpenHashMap();
    final List<String> removeExt = Arrays.asList("gz", "fa", "mpfa", "fna", "fsa", "fas", "fasta", "fq", "mpfq",
            "fnq", "fsq", "fas", "fastq");
    String inputName = FilenameUtils.getName(inputFile);
    while (true) {
        // Remove the unwanted extensions from the file name
        final String ext = FilenameUtils.getExtension(inputName);
        if (!removeExt.contains(ext)) {
            break;
        }
        inputName = FilenameUtils.getBaseName(inputName);
    }
    final String outputFilenameTemplate = FilenameUtils.getFullPath(inputFile) + inputName
            + "._READLENGTH_._PART_." + reader.getFileType();
    final NumberFormat nf3 = NumberFormat.getInstance();
    nf3.setMinimumIntegerDigits(3);
    final NumberFormat nf2 = NumberFormat.getInstance();
    nf2.setMinimumIntegerDigits(2);
    for (final FastXEntry entry : reader) {
        final int readLen = Math.min(fastxSplitMaxLength, roundReadLen(entry.getReadLength(), splitReadsMod));
        PrintStream out = outputMap.get(readLen);
        if (out == null) {
            filesPerReadLen.put(readLen, 1);
            entriesPerReadLen.put(readLen, 0);
            String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen));
            outputFilename = outputFilename.replaceAll("_PART_", nf2.format(1));
            System.out.println(outputFilename);
            out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename)));
            outputMap.put(readLen, out);
        }
        int numEntries = entriesPerReadLen.get(readLen);
        if (numEntries == maxReadsPerFile) {
            out.close();
            numEntries = 0;
            int numFiles = filesPerReadLen.get(readLen);
            numFiles++;
            filesPerReadLen.put(readLen, numFiles);
            String outputFilename = outputFilenameTemplate.replaceAll("_READLENGTH_", nf3.format(readLen));
            outputFilename = outputFilename.replaceAll("_PART_", nf2.format(numFiles));
            System.out.println(outputFilename);
            out = new PrintStream(new BufferedOutputStream(new FileOutputStream(outputFilename)));
            outputMap.put(readLen, out);
        }
        out.println(entry.getEntry());
        entriesPerReadLen.put(readLen, numEntries + 1);
    }
    for (final PrintStream out : outputMap.values()) {
        out.close();
    }
    outputMap.clear();
    reader.close();
}

From source file:net.luna.common.util.ParseUtils.java

public static String doubleToString(double number, int precision) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMaximumFractionDigits(precision);
    return format.format(number);
}

From source file:com.manpowergroup.cn.icloud.util.Case1.java

private void p0(final DataSource dataSource, String name, int threadCount) throws Exception {

    final CountDownLatch startLatch = new CountDownLatch(1);
    final CountDownLatch endLatch = new CountDownLatch(threadCount);
    for (int i = 0; i < threadCount; ++i) {
        Thread thread = new Thread() {

            public void run() {
                try {
                    startLatch.await();//from   w  ww  . jav a 2s  . c o  m

                    for (int i = 0; i < LOOP_COUNT; ++i) {
                        Connection conn = dataSource.getConnection();
                        conn.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
                endLatch.countDown();
            }
        };
        thread.start();
    }
    long startMillis = System.currentTimeMillis();
    long startYGC = TestUtil.getYoungGC();
    long startFullGC = TestUtil.getFullGC();
    startLatch.countDown();
    endLatch.await();

    long millis = System.currentTimeMillis() - startMillis;
    long ygc = TestUtil.getYoungGC() - startYGC;
    long fullGC = TestUtil.getFullGC() - startFullGC;

    System.out.println("thread " + threadCount + " " + name + " millis : "
            + NumberFormat.getInstance().format(millis) + ", YGC " + ygc + " FGC " + fullGC);

}

From source file:com.skilrock.lms.web.scratchService.orderMgmt.common.BOOrderProcessAction.java

public List<Double> getAgtCreditDetails() throws Exception {
    PrintWriter out = getResponse().getWriter();
    GameDetailsHelper gameHelper = new GameDetailsHelper();
    List<Double> accountList = null;
    try {//  w w  w .  j av  a  2s .c om
        accountList = gameHelper.fetchBOAgentAccDetail(getAgtOrgName());
    } catch (LMSException e) {
        System.out.println("In boOrderProcessAction get Credit details");
        e.printStackTrace();
    }
    HttpSession session = getRequest().getSession();
    double creditrLimit = 0.0;
    double currentCrLimit = 0.0;
    double availableLimit = 0.0;
    if (accountList != null) {
        System.out.println("acountlist not null");
        creditrLimit = accountList.get(0);
        currentCrLimit = accountList.get(1);
        availableLimit = accountList.get(2);
        session.setAttribute("CRLIMIT", currentCrLimit);
        session.setAttribute("CURRBAL", availableLimit);
        // session.setAttribute("CURRBAL",currentBalance);
    }
    // changed by yogesh to display available limit on jsp page(without E
    // type value)
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(2);
    String availableCreditTodisplay = nf.format(availableLimit).replace(",", "");
    System.out.println("available credit as string#######################3  " + availableCreditTodisplay);
    String html = "<tr><td><font color='red'>  Order Cannot be Dispatched !   Available Credit Amount of '"
            + getAgtOrgName()
            + "' is Insufficient </font> </td><td><br><font color='red'>Available Credit Amount is :</font><input type='text' readonly='true' name='crBal' id='crBal' value='"
            + availableCreditTodisplay + "'/></td></tr>";
    System.out.println(html + "99999999999");
    response.setContentType("text/html");

    out.print(html);
    System.out.println("crredit amount" + currentCrLimit + "avalaible credit" + availableLimit);
    return null;

}

From source file:LabelXYToolTipGenerator.java

private String format(double num, int minDecimalPlaces, int maxDecimalPlaces) {
    NumberFormat format = NumberFormat.getInstance();
    format.setMinimumFractionDigits(minDecimalPlaces);
    format.setMaximumFractionDigits(maxDecimalPlaces);
    return (format.format(num));
}

From source file:com.datasalt.pangool.solr.SolrRecordWriter.java

private String getOutFileName(TaskAttemptContext context, String prefix) {
    TaskID taskId = context.getTaskAttemptID().getTaskID();
    int partition = taskId.getId();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumIntegerDigits(5);/*from w  ww  .  j ava 2s.  c om*/
    nf.setGroupingUsed(false);
    StringBuilder result = new StringBuilder();
    result.append(prefix);
    result.append("-");
    result.append(nf.format(partition));
    return result.toString();
}

From source file:fr.ign.cogit.geoxygene.appli.layer.LayerViewAwtPanel.java

private void saveImage() {
    LayerViewAwtPanel.logger.debug("record"); //$NON-NLS-1$
    Color bg = this.getBackground();
    BufferedImage image = new BufferedImage(this.getWidth(), this.getHeight(), BufferedImage.TYPE_INT_ARGB);
    Graphics2D graphics = image.createGraphics();
    graphics.setColor(bg);//from  w  ww.j  a  v a  2s  .c  o  m
    graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
    this.getRenderingManager().copyTo(graphics);
    this.recording = false;
    // this.paintOverlays(graphics);
    graphics.dispose();
    try {
        NumberFormat format = NumberFormat.getInstance();
        format.setMinimumIntegerDigits(3);
        ImgUtil.saveImage(image, this.recordFileName + format.format(this.recordIndex) + ".png"); //$NON-NLS-1$
        this.recordIndex++;
    } catch (IOException e1) {
        e1.printStackTrace();
    }
}

From source file:com.unicornlabs.kabouter.gui.power.PowerPanel.java

/**
 * Sets the chart data and title//from w w  w.j  av  a 2s.co  m
 *
 * @param logs the list of power logs
 * @param title the title of the chart
 */
public void setupChart(ArrayList<Powerlog> logs, String title) {

    myDataSeriesMap.clear();

    //Create a collection to store the series
    dataset = new XYSeriesCollection();

    //Add each of the logs to the series
    for (Powerlog p : logs) {
        XYSeries deviceSeries = myDataSeriesMap.get(p.getId().getDeviceid());

        if (deviceSeries == null) {
            deviceSeries = new XYSeries(p.getId().getDeviceid());
            myDataSeriesMap.put(p.getId().getDeviceid(), deviceSeries);
            dataset.addSeries(deviceSeries);
        }

        deviceSeries.add(p.getId().getLogtime().getTime(), p.getPower());
    }

    //Create a custom date axis to display dates on the X axis
    DateAxis dateAxis = new DateAxis("Date");
    //Make the labels vertical
    dateAxis.setVerticalTickLabels(true);

    //Create the power axis
    NumberAxis powerAxis = new NumberAxis("Power");

    //Set both axes to auto range for their values
    powerAxis.setAutoRange(true);
    dateAxis.setAutoRange(true);

    //Create the tooltip generator
    StandardXYToolTipGenerator ttg = new StandardXYToolTipGenerator("{0}: {2}",
            new SimpleDateFormat("yyyy/MM/dd HH:mm"), NumberFormat.getInstance());

    //Set the renderer
    StandardXYItemRenderer renderer = new StandardXYItemRenderer(StandardXYItemRenderer.LINES, ttg, null);

    //Create the plot
    XYPlot plot = new XYPlot(dataset, dateAxis, powerAxis, renderer);

    //Create the chart
    myChart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //Attach the chart to the panel
    ((ChartPanel) chartPanel).setChart(myChart);
    //Set max draw size to 2560x1440
    ((ChartPanel) chartPanel).setMaximumDrawHeight(1440);
    ((ChartPanel) chartPanel).setMaximumDrawWidth(2560);
}

From source file:br.com.OCTur.view.ContigenteController.java

@FXML
private void eCarregarGraficosActionEvent(ActionEvent actionEvent) {
    DefaultCategoryDataset dcdDados = new DefaultCategoryDataset();
    if (rbAeroporto.isSelected()) {
        if (inicio >= aeroportos.size() && !aeroportos.isEmpty()) {
            inicio = aeroportos.size() - 10;
        }//from  w ww. ja v  a 2s  . c  o  m
        for (EntidadeGrafico<Aeroporto> entidadegrafico : aeroportos.subList(inicio,
                inicio + 10 > aeroportos.size() ? aeroportos.size() : inicio + 10)) {
            if (entidadegrafico.getValue() >= MAX) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString());
            } else if (entidadegrafico.getValue() <= MIN) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString());
            } else {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString());
            }
        }
    } else if (rbCompanhia.isSelected()) {
        if (inicio >= companhias.size() && !companhias.isEmpty()) {
            inicio = companhias.size() - 10;
        }
        for (EntidadeGrafico<Companhia> entidadegrafico : companhias.subList(inicio,
                inicio + 10 > companhias.size() ? companhias.size() : inicio + 10)) {
            if (entidadegrafico.getValue() >= MAX) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString());
            } else if (entidadegrafico.getValue() <= MIN) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString());
            } else {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString());
            }
        }
    } else {
        if (inicio >= aviaos.size() && !aviaos.isEmpty()) {
            inicio = aviaos.size() - 10;
        }
        for (EntidadeGrafico<Aviao> entidadegrafico : aviaos.subList(inicio,
                inicio + 10 > aviaos.size() ? aviaos.size() : inicio + 10)) {
            if (entidadegrafico.getValue() >= MAX) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Maior", entidadegrafico.toString());
            } else if (entidadegrafico.getValue() <= MIN) {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas/Menor", entidadegrafico.toString());
            } else {
                dcdDados.setValue(entidadegrafico.getValue(), "Pessoas", entidadegrafico.toString());
            }
        }
    }
    JFreeChart jFreeChart = ChartFactory.createBarChart("", "", "", dcdDados, PlotOrientation.VERTICAL, false,
            false, false);
    if (rbAviao.isSelected()) {
        jFreeChart.getCategoryPlot().getRangeAxis().setRange(new Range(0, 100));
        jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}%", NumberFormat.getInstance()));
        jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(true);
    } else {
        jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelGenerator(
                new StandardCategoryItemLabelGenerator("{2}", NumberFormat.getInstance()));
        jFreeChart.getCategoryPlot().getRenderer().setBaseItemLabelsVisible(true);
    }
    ChartPanel chartPanel = new ChartPanel(jFreeChart);
    snGraficos.setContent(chartPanel);
    snGraficos.getContent().repaint();
}