Example usage for java.text DecimalFormat DecimalFormat

List of usage examples for java.text DecimalFormat DecimalFormat

Introduction

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

Prototype

public DecimalFormat(String pattern) 

Source Link

Document

Creates a DecimalFormat using the given pattern and the symbols for the default java.util.Locale.Category#FORMAT FORMAT locale.

Usage

From source file:edu.jhu.pha.vospace.node.Node.java

public static String readableFileSize(long size) {
    if (size <= 0)
        return "0 B";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

From source file:com.vmware.qe.framework.datadriven.impl.generator.AbstractDataGenerator.java

@Override
public List<HierarchicalConfiguration> generate(HierarchicalConfiguration data,
        HierarchicalConfiguration context) {
    List<HierarchicalConfiguration> combConfig = new ArrayList<>();
    List<HierarchicalConfiguration> dataCombs = data.configurationsAt("data-combination");
    for (HierarchicalConfiguration dataComb : dataCombs) {
        List<HierarchicalConfiguration> sets = dataComb.configurationsAt("set");
        List<List<HierarchicalConfiguration>> combData = new ArrayList<List<HierarchicalConfiguration>>();
        for (HierarchicalConfiguration set : sets) {
            List<HierarchicalConfiguration> elements = set.configurationsAt("element");
            combData.add(elements);/*from   ww w .  j a va 2  s  .  co m*/
        }
        List<List<Integer>> setIndexData = new ArrayList<>();
        for (List<HierarchicalConfiguration> set : combData) {
            List<Integer> elements = new ArrayList<>();
            for (int i = 0; i < set.size(); i++) {
                elements.add(i);
            }
            setIndexData.add(elements);
        }
        int id = 1;
        List<List<Integer>> combinations = generateCombinations(setIndexData);
        final NumberFormat format = new DecimalFormat("###000");
        for (List<Integer> comb : combinations) {
            HierarchicalConfiguration combination = new HierarchicalConfiguration();
            combination.addProperty("[@test-id]", format.format(id++));
            for (int i = 0; i < comb.size(); i++) {
                HierarchicalConfiguration element = combData.get(i).get(comb.get(i));
                combination.append(element);
            }
            combConfig.add(combination);
        }
    }
    log.debug("Combinations: " + combConfig.size());
    return combConfig;
}

From source file:org.openmeetings.app.data.file.FileUtils.java

public static String getHumanSize(File dir) {
    long size = getSize(dir);

    if (size <= 0)
        return "0";
    final String[] units = new String[] { "B", "KB", "MB", "GB", "TB" };
    int digitGroups = (int) (Math.log10(size) / Math.log10(1024));
    return new DecimalFormat("#,##0.#").format(size / Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}

From source file:com.nkapps.billing.services.NumberServiceImpl.java

@Override
public String convertToText(Double number) {
    if (number == 0) {
        return "00";
    }// ww w.  j a v  a2  s  . c o  m

    String mask = "000000000000";
    DecimalFormat df = new DecimalFormat(mask);
    String snumber = df.format(number.longValue());

    int billions = Integer.parseInt(snumber.substring(0, 3));
    int millions = Integer.parseInt(snumber.substring(3, 6));
    int hundredThousands = Integer.parseInt(snumber.substring(6, 9));
    int thousands = Integer.parseInt(snumber.substring(9, 12));

    String tradBillions;
    switch (billions) {
    case 0:
        tradBillions = "";
        break;
    default:
        tradBillions = convertLessThanOneThousand(billions) + "  ";
    }
    String result = tradBillions;

    String tradMillions;
    switch (millions) {
    case 0:
        tradMillions = "";
        break;
    default:
        tradMillions = convertLessThanOneThousand(millions) + "  ";
    }
    result = result + tradMillions;

    String tradHundredThousands;
    switch (hundredThousands) {
    case 0:
        tradHundredThousands = "";
        break;
    case 1:
        tradHundredThousands = "?? ";
        break;
    default:
        tradHundredThousands = convertLessThanOneThousand(hundredThousands) + " ??";
    }
    result = result + tradHundredThousands;

    String tradThousand;
    tradThousand = convertLessThanOneThousand(thousands);
    result = result + tradThousand;
    Double tiyin = number - number.intValue();
    // remove extra spaces!
    return result.replaceAll("^\\s+", "").replaceAll("\\b\\s{2,}\\b", " ") + " ? "
            + (tiyin.equals(0) ? "00" : Double.valueOf(tiyin * 100).intValue()) + " ";
}

From source file:com.sunchenbin.store.feilong.core.text.NumberFormatUtil.java

/**
 *  {@link Number}  {@link RoundingMode} numberPattern?.
 *
 * @param value/*w  w  w  .  j a  v  a  2  s .  c o  m*/
 *            the value
 * @param numberPattern
 *            the pattern {@link NumberPattern}
 * @param roundingMode
 *            ?{@link RoundingMode}
 * @return  null
 * @see NumberPattern
 * @see DecimalFormat
 * @see <a href="../util/NumberUtil.html#RoundingMode">JAVA 8??</a>
 */
public static String format(Number value, String numberPattern, RoundingMode roundingMode) {
    if (null == value) {
        throw new NullPointerException("the value is null or empty!");
    }

    if (null == numberPattern) {
        throw new NullPointerException("the numberPattern is null or empty!");
    }
    try {
        // applyPattern(pattern, false)
        DecimalFormat decimalFormat = new DecimalFormat(numberPattern);

        // ? RoundingMode.HALF_EVEN
        // ?,?.?,?.??,?,??.???1?,???.
        // 1.15>1.2 1.25>1.2
        if (null != roundingMode) {
            decimalFormat.setRoundingMode(roundingMode);
        }
        String format = decimalFormat.format(value);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("value:[{}], pattern:[{}],return:[{}],decimalFormat.toLocalizedPattern():[{}]", value,
                    numberPattern, format, decimalFormat.toLocalizedPattern()//?? Format ????. 
            );
        }
        return format;
    } catch (Exception e) {
        Object[] objects = { e.getMessage(), value, numberPattern };
        LOGGER.error("{},value:[{}],pattern:[{}]", objects);
        LOGGER.error(e.getClass().getName(), e);
    }
    return StringUtils.EMPTY;
}

From source file:hyperheuristics.main.comparisons.CompareHypervolumes.java

private static void generateTables(String[] problems, String[] heuristicFunctions, int numberOfObjectives,
        String[] algorithms) throws InterruptedException, IOException {
    String outputDirectory = outpath;

    try (FileWriter fileWriter = new FileWriter(outputDirectory + "TABLES_" + numberOfObjectives + ".txt")) {

        StringBuilder tableString = new StringBuilder();
        DecimalFormat decimalFormatter = new DecimalFormat("0.00E0");
        StandardDeviation standardDeviation = new StandardDeviation();

        pfKnown: {/*from ww  w. j  a v a  2s  .  c  om*/
            tableString.append("\\documentclass{paper}\n" + "\n" + "\\usepackage[T1]{fontenc}\n"
                    + "\\usepackage[latin1]{inputenc}\n" + "\\usepackage[hidelinks]{hyperref}\n"
                    + "\\usepackage{tabulary}\n" + "\\usepackage{booktabs}\n" + "\\usepackage{multirow}\n"
                    + "\\usepackage{amsmath}\n" + "\\usepackage{mathtools}\n" + "\\usepackage{graphicx}\n"
                    + "\\usepackage{array}\n" + "\\usepackage[linesnumbered,ruled,inoutnumbered]{algorithm2e}\n"
                    + "\\usepackage{subfigure}\n" + "\\usepackage[hypcap]{caption}\n"
                    + "\\usepackage{pdflscape}\n" + "\n" + "\\begin{document}\n" + "\n" + "\\begin{landscape}\n"
                    + "\n");

            tableString
                    .append("\\begin{table}[!htb]\n" + "\t\\centering\n" + "\t\\def\\arraystretch{1.5}\n"
                            + "\t\\setlength{\\tabcolsep}{10pt}\n" + "\t\\fontsize{8pt}{10pt}\\selectfont"
                            + "\t\\caption{Hypervolume of the $PF_{known}$ fronts for ")
                    .append(numberOfObjectives).append(" objectives}\n" + "\t\\label{tab:Hypervolumes ")
                    .append(numberOfObjectives).append(" objectives}\n" + "\t\\begin{tabulary}{\\textwidth}{c");
            for (String algorithm : algorithms) {
                tableString.append("c");
                for (String heuristicFunction : heuristicFunctions) {
                    tableString.append("c");
                }
            }
            tableString.append("}\n");
            tableString.append("\t\t\\toprule\n");
            tableString.append("\t\t\\textbf{System}");

            for (String algorithm : algorithms) {
                tableString.append(" & \\textbf{").append(algorithm).append("}");
                for (String heuristicFunction : heuristicFunctions) {
                    tableString.append(" & \\textbf{").append(algorithm).append("-").append(heuristicFunction)
                            .append("}");
                }
            }
            tableString.append("\\\\\n");
            tableString.append("\t\t\\midrule\n");

            for (String problem : problems) {
                HypervolumeHandler hypervolumeHandler = new HypervolumeHandler();

                for (String algorithm : algorithms) {
                    String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/"
                            + problem + "_Comb_" + numberOfObjectives + "obj/";

                    //Best PFknown hypervolume
                    //Populate HypervolueHandler
                    hypervolumeHandler.addParetoFront(mecbaDirectory + "All_FUN_"
                            + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem);

                    for (String heuristicFunction : heuristicFunctions) {
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + problem + "/";
                        hypervolumeHandler.addParetoFront(hyperheuristicDirectory + "FUN.txt");
                    }
                }

                double[] mecbaHypervolumes = new double[algorithms.length];
                double[] hyperheuristicHypervolumes = new double[heuristicFunctions.length * algorithms.length];

                Arrays.fill(hyperheuristicHypervolumes, 0D);
                for (int i = 0; i < algorithms.length; i++) {
                    String algorithm = algorithms[i];
                    String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/"
                            + problem + "_Comb_" + numberOfObjectives + "obj/";
                    //Calculate Hypervolume
                    mecbaHypervolumes[i] = hypervolumeHandler.calculateHypervolume(mecbaDirectory + "All_FUN_"
                            + algorithm.toLowerCase().replaceAll("-", "") + "-" + problem, numberOfObjectives);

                    for (int j = 0; j < heuristicFunctions.length; j++) {
                        String heuristicFunction = heuristicFunctions[j];
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + problem + "/";
                        hyperheuristicHypervolumes[i * heuristicFunctions.length + j] = hypervolumeHandler
                                .calculateHypervolume(hyperheuristicDirectory + "FUN.txt", numberOfObjectives);
                    }
                }
                //Write PFknown results
                double maxHypervolume = Double.NEGATIVE_INFINITY;

                for (int i = 0; i < mecbaHypervolumes.length; i++) {
                    double hypervolume = mecbaHypervolumes[i];
                    if (hypervolume > maxHypervolume) {
                        maxHypervolume = hypervolume;
                    }
                }

                for (int i = 0; i < heuristicFunctions.length; i++) {
                    if (hyperheuristicHypervolumes[i] > maxHypervolume) {
                        maxHypervolume = hyperheuristicHypervolumes[i];
                    }
                }

                tableString.append("\t\t" + problem.replaceAll("\\_", "\\\\_"));
                for (int i = 0; i < algorithms.length; i++) {
                    tableString.append(" & ");
                    double mecbaHypervolume = mecbaHypervolumes[i];
                    if (maxHypervolume == mecbaHypervolume) {
                        tableString.append("\\textbf{");
                    }
                    tableString.append(decimalFormatter.format(mecbaHypervolume));
                    if (maxHypervolume == mecbaHypervolume) {
                        tableString.append("}");
                    }

                    for (int j = 0; j < heuristicFunctions.length; j++) {
                        tableString.append(" & ");
                        double hyperheuristicHypervolume = hyperheuristicHypervolumes[i
                                * heuristicFunctions.length + j];
                        if (maxHypervolume == hyperheuristicHypervolume) {
                            tableString.append("\\textbf{");
                        }
                        tableString.append(decimalFormatter.format(hyperheuristicHypervolume));
                        if (maxHypervolume == hyperheuristicHypervolume) {
                            tableString.append("}");
                        }
                    }
                }

                tableString.append("\\\\\n");
            }
            tableString.append("\t\t\\bottomrule\n");
            tableString.append("\t\\end{tabulary}\n");
            tableString.append("\\end{table}\n\n");
        }

        //Best mean hypervolume
        mean: {
            tableString.append("\\begin{table}[!htb]\n" + "\\centering\n" + "\t\\def\\arraystretch{1.5}\n"
                    + "\t\\setlength{\\tabcolsep}{10pt}\n" + "\t\\fontsize{8pt}{10pt}\\selectfont"
                    + "\t\\caption{Hypervolume average found for " + numberOfObjectives + " objectives}\n"
                    + "\t\\label{tab:Hypervolumes average " + numberOfObjectives + " objectives}\n"
                    + "\t\\begin{tabulary}{\\textwidth}{c");
            for (String algorithm : algorithms) {
                tableString.append("c");
                for (String heuristicFunction : heuristicFunctions) {
                    tableString.append("c");
                }
            }
            tableString.append("}\n");
            tableString.append("\t\t\\toprule\n");
            tableString.append("\t\t\\textbf{System}");

            for (String algorithm : algorithms) {
                tableString.append(" & \\textbf{" + algorithm + "}");
                for (String heuristicFunction : heuristicFunctions) {
                    tableString.append(" & \\textbf{" + algorithm + "-" + heuristicFunction + "}");
                }
            }
            tableString.append("\\\\\n");
            tableString.append("\t\t\\midrule\n");

            for (String problem : problems) {
                HypervolumeHandler hypervolumeHandler = new HypervolumeHandler();

                for (String algorithm : algorithms) {
                    String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/"
                            + problem + "_Comb_" + numberOfObjectives + "obj/";

                    for (int i = 0; i < EXECUTIONS; i++) {
                        hypervolumeHandler.addParetoFront(
                                mecbaDirectory + "FUN_" + algorithm.toLowerCase().replaceAll("-", "") + "-"
                                        + problem + "-" + i + ".NaoDominadas");
                    }

                    for (String heuristicFunction : heuristicFunctions) {
                        String path = outpath;
                        path += algorithm + "/" + numberOfObjectives + "objectives/";
                        String hyperheuristicDirectory = path + heuristicFunction + "/" + problem + "/";
                        for (int j = 0; j < EXECUTIONS; j++) {
                            hypervolumeHandler
                                    .addParetoFront(hyperheuristicDirectory + "EXECUTION_" + j + "/FUN.txt");
                        }
                    }
                }

                double[][] mecbaHypervolumes = new double[algorithms.length][EXECUTIONS];
                for (double[] mecbaHypervolume : mecbaHypervolumes) {
                    Arrays.fill(mecbaHypervolume, 0D);
                }

                double mecbaMeanHypervolume[] = new double[algorithms.length];
                Arrays.fill(mecbaMeanHypervolume, 0D);

                double[][] hyperheuristicHypervolumes = new double[algorithms.length
                        * heuristicFunctions.length][EXECUTIONS];
                for (double[] hyperheuristicHypervolume : hyperheuristicHypervolumes) {
                    Arrays.fill(hyperheuristicHypervolume, 0D);
                }

                double[] hyperheuristicMeanHypervolumes = new double[algorithms.length
                        * heuristicFunctions.length];
                Arrays.fill(hyperheuristicMeanHypervolumes, 0D);

                for (int i = 0; i < algorithms.length; i++) {
                    String algorithm = algorithms[i];
                    String mecbaDirectory = "resultado/" + algorithm.toLowerCase().replaceAll("-", "") + "/"
                            + problem + "_Comb_" + numberOfObjectives + "obj/";
                    for (int j = 0; j < EXECUTIONS; j++) {
                        mecbaHypervolumes[i][j] = hypervolumeHandler
                                .calculateHypervolume(
                                        mecbaDirectory + "FUN_" + algorithm.toLowerCase().replaceAll("-", "")
                                                + "-" + problem + "-" + j + ".NaoDominadas",
                                        numberOfObjectives);
                        mecbaMeanHypervolume[i] += mecbaHypervolumes[i][j];
                        for (int k = 0; k < heuristicFunctions.length; k++) {
                            String path = outpath;
                            path += algorithm + "/" + numberOfObjectives + "objectives/";
                            String hyperheuristicDirectory = path + heuristicFunctions[k] + "/" + problem + "/";
                            hyperheuristicHypervolumes[i * heuristicFunctions.length
                                    + k][j] = hypervolumeHandler.calculateHypervolume(
                                            hyperheuristicDirectory + "EXECUTION_" + j + "/FUN.txt",
                                            numberOfObjectives);
                            hyperheuristicMeanHypervolumes[i * heuristicFunctions.length
                                    + k] += hyperheuristicHypervolumes[i * heuristicFunctions.length + k][j];
                        }
                    }
                }

                for (int i = 0; i < mecbaMeanHypervolume.length; i++) {
                    mecbaMeanHypervolume[i] /= (double) EXECUTIONS;
                }
                for (int i = 0; i < hyperheuristicMeanHypervolumes.length; i++) {
                    hyperheuristicMeanHypervolumes[i] /= (double) EXECUTIONS;
                }

                double maxMean = Double.NEGATIVE_INFINITY;
                String maxHeuristic = "NULL";

                for (int i = 0; i < mecbaMeanHypervolume.length; i++) {
                    double mean = mecbaMeanHypervolume[i];
                    if (mean > maxMean) {
                        maxMean = mean;
                        maxHeuristic = algorithms[i];
                    }
                }

                for (int i = 0; i < hyperheuristicMeanHypervolumes.length; i++) {
                    double hyperheuristicMeanHypervolume = hyperheuristicMeanHypervolumes[i];
                    if (hyperheuristicMeanHypervolume > maxMean) {
                        maxMean = hyperheuristicMeanHypervolume;
                        maxHeuristic = algorithms[i / heuristicFunctions.length] + "-"
                                + heuristicFunctions[i % heuristicFunctions.length];
                    }
                }

                HashMap<String, double[]> values = new HashMap<>();

                for (int i = 0; i < algorithms.length; i++) {
                    String algorithm = algorithms[i];
                    values.put(algorithm, mecbaHypervolumes[i]);
                }
                for (int i = 0; i < hyperheuristicHypervolumes.length; i++) {
                    double[] hyperheuristicHypervolume = hyperheuristicHypervolumes[i];
                    String heuristicFunction = heuristicFunctions[i % heuristicFunctions.length];
                    String algorithm = algorithms[i / heuristicFunctions.length];
                    values.put(algorithm + "-" + heuristicFunction, hyperheuristicHypervolume);
                }

                HashMap<String, HashMap<String, Boolean>> result = KruskalWallisTest.test(values);

                tableString.append("\t\t" + problem.replaceAll("\\_", "\\\\_"));
                for (int i = 0; i < algorithms.length; i++) {
                    String algorithm = algorithms[i];
                    tableString.append(" & ");
                    if (algorithm.equals(maxHeuristic) || !result.get(algorithm).get(maxHeuristic)) {
                        tableString.append("\\textbf{");
                    }
                    tableString.append(decimalFormatter.format(mecbaMeanHypervolume[i]));
                    tableString.append(" (")
                            .append(decimalFormatter.format(standardDeviation.evaluate(mecbaHypervolumes[i])))
                            .append(")");
                    if (algorithm.equals(maxHeuristic) || !result.get(algorithm).get(maxHeuristic)) {
                        tableString.append("}");
                    }
                    for (int j = 0; j < heuristicFunctions.length; j++) {
                        String heuristicFunction = algorithm + "-" + heuristicFunctions[j];
                        tableString.append(" & ");
                        if (heuristicFunction.equals(maxHeuristic)
                                || !result.get(heuristicFunction).get(maxHeuristic)) {
                            tableString.append("\\textbf{");
                        }
                        tableString.append(decimalFormatter
                                .format(hyperheuristicMeanHypervolumes[i * heuristicFunctions.length + j]));
                        tableString.append(" (")
                                .append(decimalFormatter.format(standardDeviation.evaluate(
                                        hyperheuristicHypervolumes[i * heuristicFunctions.length + j])))
                                .append(")");
                        if (heuristicFunction.equals(maxHeuristic)
                                || !result.get(heuristicFunction).get(maxHeuristic)) {
                            tableString.append("}");
                        }
                    }
                }
                tableString.append("\\\\\n");
            }
            tableString.append("\t\t\\bottomrule\n");
            tableString.append("\t\\end{tabulary}\n");
            tableString.append("\\end{table}\n");
        }
        tableString.append("\n" + "\\end{landscape}\n" + "\n" + "\\end{document}\n");
        fileWriter.write(tableString.toString().replaceAll("ChoiceFunction", "CF")
                .replaceAll("MultiArmedBandit", "MAB"));
    }
}

From source file:demo.BarChartDemo11.java

/**
 * Creates a sample chart./*www. j a  v  a 2  s .  c o m*/
 *
 * @param dataset  the dataset.
 *
 * @return The chart.
 */
private static JFreeChart createChart(CategoryDataset dataset) {

    // create the chart...
    JFreeChart chart = ChartFactory.createBarChart("Open Source Projects By License", "License", "Percent",
            dataset);
    chart.removeLegend();

    TextTitle source = new TextTitle(
            "Source: http://www.blackducksoftware.com/resources/data/top-20-licenses (as at 30 Aug 2013)",
            new Font("Dialog", Font.PLAIN, 9));
    source.setPosition(RectangleEdge.BOTTOM);
    chart.addSubtitle(source);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setDomainGridlinesVisible(true);

    plot.getDomainAxis().setMaximumCategoryLabelWidthRatio(0.8f);
    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    StandardCategoryToolTipGenerator tt = new StandardCategoryToolTipGenerator("{1}: {2} percent",
            new DecimalFormat("0"));
    renderer.setBaseToolTipGenerator(tt);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.BLUE, 0.0f, 0.0f, new Color(0, 0, 64));
    renderer.setSeriesPaint(0, gp0);

    return chart;

}

From source file:it.cilea.osd.jdyna.widget.WidgetNumero.java

@Override
public PropertyEditor getPropertyEditor(IPersistenceDynaService applicationService) {
    String decimali = "";
    for (int i = 0; i < precisionDef; i++) {
        decimali += "0";
    }// w  w  w  .java  2 s  . c o m
    String pattern = "0" + (precisionDef > 0 ? "." + decimali : "");
    NumberFormat formatter = new DecimalFormat(pattern);

    CustomNumberEditor propertyEditor = new CustomNumberEditor(Double.class, formatter, true);
    return propertyEditor;
}

From source file:matrix.TextUrlMatrix.java

public void textUrlMatrix()
        throws UnsupportedEncodingException, FileNotFoundException, IOException, ParseException {

    double a = 0.7;
    CosSim cossim = new CosSim();
    JSONParser jParser = new JSONParser();
    BufferedReader in = new BufferedReader(new InputStreamReader(
            new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweets.json"), "ISO-8859-9"));
    JSONArray jArray = (JSONArray) jParser.parse(in);
    BufferedReader in2 = new BufferedReader(new InputStreamReader(
            new FileInputStream("/Users/nSabri/Desktop/tweetMatris/userTweetsUrls.json"), "ISO-8859-9"));
    JSONArray jArray2 = (JSONArray) jParser.parse(in2);
    File fout = new File("/Users/nSabri/Desktop/textUrlMatris.csv");
    FileOutputStream fos = new FileOutputStream(fout);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    for (int i = 0; i < 100; i++) {

        for (int j = 0; j < 100; j++) {

            JSONObject tweet1text = (JSONObject) jArray.get(i);
            JSONObject tweet2text = (JSONObject) jArray.get(j);
            JSONObject tweet1url = (JSONObject) jArray2.get(i);
            JSONObject tweet2url = (JSONObject) jArray2.get(j);
            String tweetText1 = tweet1text.get("tweets").toString();
            String tweetText2 = tweet2text.get("tweets").toString();
            String tweetUrl1 = tweet1url.get("title").toString() + tweet1url.get("meta").toString();
            String tweetUrl2 = tweet2url.get("title").toString() + tweet1url.get("meta").toString();

            double CosSimValueText = cossim.Cosine_Similarity_Score(tweetText1, tweetText2);

            double CosSimValueUrl = cossim.Cosine_Similarity_Score(tweetUrl1, tweetUrl2);

            double TextUrlSimValue = (a * CosSimValueText) + ((1 - a) * CosSimValueUrl);

            TextUrlSimValue = Double.parseDouble(new DecimalFormat("##.###").format(TextUrlSimValue));

            bw.write(Double.toString(TextUrlSimValue) + ", ");

        }// ww w  .ja  va 2s  .  c o m
        bw.newLine();
    }
    bw.close();

}

From source file:com.mycompany.flooringmaster.Controllers.Controller.java

private String displayOrder() {
    String strDate = getFileName();
    DecimalFormat df = new DecimalFormat("#.00");
    if (orderDao.getFileOrderList(strDate).isEmpty()) {
        io.println("There are no orders for this day");
        strDate = "invalid";
    } else {/*from  ww  w .jav a 2  s .  c  om*/
        for (Order x : orderDao.getFileOrderList(strDate)) {
            io.println("Order " + x.getOrderNum() + "\t\tName " + x.getName() + " :: Taxes $"
                    + df.format(x.getTaxCost()) + " :: Total Cost $" + df.format(x.getTotalCost()));
            io.println("\t\tArea " + x.getArea() + " :: Product Type " + x.getProductType() + " :: Cost SqFt $"
                    + df.format(x.getCostSqFt()) + " :: Labor Cost SqFt $" + df.format(x.getLaborCostSqFt()));
            io.println("\t\tState " + x.getState() + " :: Tax Rate " + x.getTaxRate() + "% :: Material Cost $"
                    + df.format(x.getMaterialCost()) + " :: Labor Cost $" + df.format(x.getLaborCost()) + "\n");
        }
    }
    return strDate;
}