Example usage for java.text DecimalFormatSymbols DecimalFormatSymbols

List of usage examples for java.text DecimalFormatSymbols DecimalFormatSymbols

Introduction

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

Prototype

public DecimalFormatSymbols(Locale locale) 

Source Link

Document

Create a DecimalFormatSymbols object for the given locale.

Usage

From source file:bigtweet.model.StudyingBeacons.java

@Override
public void updateMetricsForParametersValues(JSONArray parametersValues, int parametersValuesIndex) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    DecimalFormat df = new DecimalFormat("0.000", otherSymbols);

    //get infected array for each seed

    double infected[] = new double[seedAndStates.values().size()];

    for (int i = 0; i < infected.length; i++) {
        //number of infected for each seed            
        //System.out.println(  ((Map<String,Integer>) (seedAndStates.values().toArray()[i])).get("INFECTED"));
        infected[i] = (new Double(
                ((Map<String, Integer>) (seedAndStates.values().toArray()[i])).get("ENDORSER")));
    }// w ww  .  j a  v  a  2 s  .  com

    //get metrics for this experiment and this dataset
    double minInfected = (new Min()).evaluate(infected);
    double mean = (new Mean()).evaluate(infected);
    double sd = (new StandardDeviation()).evaluate(infected);

    //put in metricsForLastExperiment, JSON object
    metricsForLastExperiment = new JSONObject();//create new object for the last experiment    
    metricsForLastExperiment.put("minEndorsers", df.format(minInfected));
    metricsForLastExperiment.put("mean", df.format(mean));
    metricsForLastExperiment.put("sd", df.format(sd));

    JSONObject statesJSON = new JSONObject();
    for (Map.Entry<Long, Map<String, Integer>> entry : seedAndStates.entrySet()) {
        statesJSON.put(entry.getKey().toString(), entry.getValue());
    }

    metricsForLastExperiment.put("randomSeedsAndStates", statesJSON);

    //update metrics for all experiments

    if (mean < this.bestMean) {
        //System.out.println(name + " bestmean " + df.format(bestMean).toString() + " mean " + df.format(mean).toString());
        bestMean = mean;
        experimentWithBestMean = parametersValuesIndex;
        metricsForAllExperiments.put("bestMean", df.format(bestMean));
        metricsForAllExperiments.put("experimentWithBestMean", parametersValuesIndex);
    }
    if (minInfected < this.bestEndorser) {

        bestEndorser = minInfected;
        experimentWithBestEndorser = parametersValuesIndex;
        metricsForAllExperiments.put("bestEndorsers", df.format(minInfected));
        metricsForAllExperiments.put("experimentWithBestEndorsers", parametersValuesIndex);
    }

    generateBatchOuputForChart(parametersValues, parametersValuesIndex, mean);

}

From source file:org.techytax.helper.AmountHelper.java

public static String format(int amount) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
    return df.format(amount);
}

From source file:bigtweet.model.ComparingToRealData.java

/**
 * Update the min distnce , mean and sd in all experiments and the min
 * distance mean and sd for one experiments with several seeds in this
 * dataset//  ww  w. ja  v  a2 s  .c  om
 * The experiment id is passed
 */
@Override
public void updateMetricsForParametersValues(JSONArray parametersValues, int parametersValuesIndex) {
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.US);
    DecimalFormat df = new DecimalFormat("0.000", otherSymbols);

    //get distances array for each seed
    Object obDist[] = seedAndDistances.values().toArray();
    double distances[] = new double[obDist.length];
    for (int i = 0; i < obDist.length; i++) {
        distances[i] = (double) obDist[i];
    }

    //get metrics for this experiment and this dataset
    double minDistance = (new Min()).evaluate(distances);
    double mean = (new Mean()).evaluate(distances);
    double sd = (new StandardDeviation()).evaluate(distances);

    //put in metricsForLastExperiment, JSON object
    metricsForLastExperiment = new JSONObject();//create new object for the last experiment    
    metricsForLastExperiment.put("minDistance", df.format(minDistance));
    metricsForLastExperiment.put("mean", df.format(mean));
    metricsForLastExperiment.put("sd", df.format(sd));

    JSONObject distancesJSON = new JSONObject();
    for (Map.Entry<Long, Double> entry : seedAndDistances.entrySet()) {
        distancesJSON.put(entry.getKey().toString(), df.format(entry.getValue()));

    }

    metricsForLastExperiment.put("randomSeedsAndDistances", distancesJSON);

    //update metrics for all experiments

    if (mean < this.bestMean) {
        //System.out.println(name + " bestmean " + df.format(bestMean).toString() + " mean " + df.format(mean).toString());
        bestMean = mean;
        experimentWithBestMean = parametersValuesIndex;
        metricsForAllExperiments.put("bestMean", df.format(bestMean));
        metricsForAllExperiments.put("experimentWithBestMean", parametersValuesIndex);
    }
    if (minDistance < this.bestDistance) {

        //System.out.println(name + " bestdos " + df.format(bestDistance).toString() + " dis " + df.format(minDistance).toString());
        bestDistance = minDistance;
        experimentWithBestDistance = parametersValuesIndex;
        metricsForAllExperiments.put("bestDistance", df.format(minDistance));
        metricsForAllExperiments.put("experimentWithBestDistance", parametersValuesIndex);
    }

}

From source file:org.techytax.helper.AmountHelper.java

public static String format(BigInteger amount) {
    if (amount == null) {
        return null;
    }/*  ww w. j  a va 2s .  co m*/
    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.GERMAN);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');
    DecimalFormat df = new DecimalFormat("###,###,###,##0", otherSymbols);
    return df.format(amount);
}

From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java

public static String format(String type, String value, JspContext jspContext) {

    if (StringUtils.isEmpty(value)) {
        return value;
    } else if ("date".equals(type) || "timestamp".equals(type) || "hour".equals(type)) {

        DateFormat dateFormat = DateFormat.getDateTimeInstance();
        if ("timestamp".equals(type)) {
            dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM,
                    locale(jspContext));
        } else if ("date".equals(type)) {
            dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM, locale(jspContext));
        } else if ("hour".equals(type)) {
            dateFormat = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale(jspContext));
        }//from   ww  w .j  a  v  a  2 s.co m
        List<String> patterns = new ArrayList<>();
        patterns.add("yyyy-MM-dd HH:mm:ss");
        patterns.add("yyyy-MM-dd");
        patterns.add("E MMM dd HH:mm:ss zzz yyyy");
        for (String pattern : patterns) {
            try {
                return dateFormat.format(new SimpleDateFormat(pattern, Locale.ENGLISH).parse(value));
            } catch (ParseException pe) {
                //Try another format
            }
        }
        return value;
    } else if ("currency".equals(type)) {
        DecimalFormat nf = new DecimalFormat("#,##0.00", new DecimalFormatSymbols(locale(jspContext)));
        return nf.format(new Double(value));
    } else if ("cep".equals(type)) {
        return String.format("%08d", Long.valueOf(value)).replaceAll("^([0-9]{5})([0-9]{3})$", "$1-$2");
    } else if ("cpf".equals(type)) {
        return String.format("%011d", Long.valueOf(value))
                .replaceAll("^([0-9]{3})([0-9]{3})([0-9]{3})([0-9]{2})$", "$1.$2.$3-$4");
    } else if ("cnpj".equals(type)) {
        return String.format("%014d", Long.valueOf(value))
                .replaceAll("^([0-9]{2})([0-9]{3})([0-9]{3})([0-9]{4})([0-9]{2})$", "$1.$2.$3/$4-$5");
    } else if ("tel".equals(type)) {
        return String.format("%010d", Long.valueOf(value)).replaceAll("^([0-9]{2})([0-9]{4,5})([0-9]{4})$",
                "($1) $2-$3");
    }
    return value;
}

From source file:org.apache.archiva.rest.services.utils.ArtifactBuilder.java

public Artifact build() {
    ArtifactReference ref = new ArtifactReference();
    ref.setArtifactId(artifactMetadata.getProject());
    ref.setGroupId(artifactMetadata.getNamespace());
    ref.setVersion(artifactMetadata.getVersion());

    String type = null, classifier = null;

    MavenArtifactFacet facet = (MavenArtifactFacet) artifactMetadata.getFacet(MavenArtifactFacet.FACET_ID);
    if (facet != null) {
        type = facet.getType();//w w  w .j av  a 2 s. com
        classifier = facet.getClassifier();
    }

    ref.setClassifier(classifier);
    ref.setType(type);
    File file = managedRepositoryContent.toFile(ref);

    String extension = getExtensionFromFile(file);

    Artifact artifact = new Artifact(ref.getGroupId(), ref.getArtifactId(), ref.getVersion());
    artifact.setRepositoryId(artifactMetadata.getRepositoryId());
    artifact.setClassifier(classifier);
    artifact.setPackaging(type);
    artifact.setType(type);
    artifact.setFileExtension(extension);
    artifact.setPath(managedRepositoryContent.toPath(ref));
    // TODO: find a reusable formatter for this
    double s = this.artifactMetadata.getSize();
    String symbol = "b";
    if (s > 1024) {
        symbol = "K";
        s /= 1024;

        if (s > 1024) {
            symbol = "M";
            s /= 1024;

            if (s > 1024) {
                symbol = "G";
                s /= 1024;
            }
        }
    }
    artifact.setContext(managedRepositoryContent.getId());
    DecimalFormat df = new DecimalFormat("#,###.##", new DecimalFormatSymbols(Locale.US));
    artifact.setSize(df.format(s) + " " + symbol);

    artifact.setId(ref.getArtifactId() + "-" + ref.getVersion() + "." + ref.getType());

    return artifact;

}

From source file:com.nextgis.maplibui.formcontrol.Coordinates.java

public String getFormattedValue() {
    DecimalFormat format = new DecimalFormat("#.######", new DecimalFormatSymbols(Locale.US));
    return format.format(mValue);
}

From source file:org.matsim.contrib.drt.analysis.DynModeTripsAnalyser.java

public static String summarizeTrips(List<DynModeTrip> trips, String delimiter) {
    DescriptiveStatistics waitStats = new DescriptiveStatistics();
    DescriptiveStatistics rideStats = new DescriptiveStatistics();
    DescriptiveStatistics distanceStats = new DescriptiveStatistics();
    DescriptiveStatistics directDistanceStats = new DescriptiveStatistics();

    DescriptiveStatistics traveltimes = new DescriptiveStatistics();

    DecimalFormat format = new DecimalFormat();
    format.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));
    format.setMinimumIntegerDigits(1);/*from   www . j  a  va2 s . com*/
    format.setMaximumFractionDigits(2);
    format.setGroupingUsed(false);

    for (DynModeTrip trip : trips) {
        if (trip.getToLinkId() == null) {
            continue;
        }
        waitStats.addValue(trip.getWaitTime());
        rideStats.addValue(trip.getInVehicleTravelTime());
        distanceStats.addValue(trip.getTravelDistance());
        directDistanceStats.addValue(trip.getUnsharedDistanceEstimate_m());
        traveltimes.addValue(trip.getInVehicleTravelTime() + trip.getWaitTime());
    }
    String value = format.format(waitStats.getValues().length) + delimiter + format.format(waitStats.getMean())
            + delimiter + format.format(waitStats.getMax()) + delimiter
            + format.format(waitStats.getPercentile(95)) + delimiter
            + format.format(waitStats.getPercentile(75)) + delimiter
            + format.format(waitStats.getPercentile(50)) + delimiter + format.format(rideStats.getMean())
            + delimiter + format.format(distanceStats.getMean()) + delimiter
            + format.format(directDistanceStats.getMean()) + delimiter + format.format(traveltimes.getMean());
    return value;
}

From source file:com.cognitivabrasil.repositorio.data.entities.Files.java

@Transient
public String getSizeFormatted() {
    String[] powerOfByte = { "Bytes", "KB", "MB", "GB", "TB" };
    if (this.sizeInBytes == null || this.sizeInBytes <= 0) {
        return "Tamanho no definido";
    }/*from  www  .ja va  2  s  .c  o m*/
    int potencia = 0;
    int proxima;
    boolean testaPotenciaActual;
    boolean testaPotenciaSeguinte;
    do {
        proxima = potencia + 1;
        testaPotenciaActual = (Math.pow(2L, potencia * 10) <= this.sizeInBytes);
        testaPotenciaSeguinte = (this.sizeInBytes < Math.pow(2L, proxima * 10));
        potencia++;

    } while (!(testaPotenciaActual && testaPotenciaSeguinte));

    potencia--;

    DecimalFormatSymbols otherSymbols = new DecimalFormatSymbols(Locale.ENGLISH);
    otherSymbols.setDecimalSeparator(',');
    otherSymbols.setGroupingSeparator('.');

    DecimalFormat myFormatter = new DecimalFormat("##.#", otherSymbols);

    return myFormatter.format(this.sizeInBytes / Math.pow(2L, potencia * 10)) + " " + powerOfByte[potencia];
}

From source file:edu.ku.brc.util.GeoRefConverter.java

/**
 * 
 */
public GeoRefConverter() {
    decimalSep = Character.toString(new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator());
}