Example usage for java.lang Double parseDouble

List of usage examples for java.lang Double parseDouble

Introduction

In this page you can find the example usage for java.lang Double parseDouble.

Prototype

public static double parseDouble(String s) throws NumberFormatException 

Source Link

Document

Returns a new double initialized to the value represented by the specified String , as performed by the valueOf method of class Double .

Usage

From source file:moacscoper.Parser.java

public int addComponents() throws IOException {
    List<CSVRecord> components = parse("component.dat");
    int componentNumber = 0;
    int performance;
    double reliability;
    for (CSVRecord r : components) {
        performance = Integer.parseInt(r.get(0));
        reliability = Double.parseDouble(r.get(1));
        this.sim.components.add(new SoftwareComponent(componentNumber + 1, "c" + (componentNumber + 1),
                performance, reliability));
        componentNumber++;// ww  w .ja  va2s .  co  m
    }
    return componentNumber; // return total number of components
}

From source file:org.envirocar.wps.util.BasicStats.java

/**
 * calculates acceleration (delta_speed/delta_time in m/s^2) between two single
 * track measurements, represented as Geotools simple features
 * //  w w  w  .  ja  va2s . com
 * 
 * @param feat1
 *            first track measurement (must be temporally before second)
 * @param feat2
 *            second track measurement
 * @return acceleration between first and second measurement
 * @throws ParseException 
 */
public static double calculateAcceleration(SimpleFeature feat1, SimpleFeature feat2) throws ParseException {
    double acceleration = 0;

    //compute delta t in seconds
    ISO8601DateFormat df = new ISO8601DateFormat();
    Date timeStart = df.parse((String) feat1.getAttribute(FeatureProperties.TIME));
    Date timeEnd = df.parse((String) feat2.getAttribute(FeatureProperties.TIME));
    long delta_t = (timeEnd.getTime() - timeStart.getTime()) * 1000;

    //compute delta speed in m/s
    double delta_speed = 0;
    Object spo1 = feat1.getAttribute(FeatureProperties.SPEED);
    Object spo2 = feat2.getAttribute(FeatureProperties.SPEED);

    //compute delta speed in km/h
    if (spo1 != null && spo2 != null) {
        double speed1 = Double.parseDouble((String) spo1);
        double speed2 = Double.parseDouble((String) spo2);
        if (speed2 > speed1) {
            delta_speed = speed2 - speed1;
        }
    }

    //convert to m/s
    delta_speed = delta_speed * 0.278;

    //compute acceleration in m/s^2
    acceleration = delta_speed / delta_t;

    return acceleration;
}

From source file:com.github.andreax79.meca.Main.java

@SuppressWarnings("static-access")
public static void main(String[] args) {
    // create the command line parser
    CommandLineParser parser = new PosixParser();

    // create the Options
    Options options = new Options();
    options.addOption("X", "suppress-output", false, "don't create the output file");

    OptionGroup boundariesOptions = new OptionGroup();
    boundariesOptions.addOption(new Option("P", "periodic", false, "periodic boundaries (default)"));
    boundariesOptions.addOption(new Option("F", "fixed", false, "fixed-value boundaries"));
    boundariesOptions.addOption(new Option("A", "adiabatic", false, "adiabatic boundaries"));
    boundariesOptions.addOption(new Option("R", "reflective", false, "reflective boundaries"));
    options.addOptionGroup(boundariesOptions);

    OptionGroup colorOptions = new OptionGroup();
    colorOptions.addOption(new Option("bn", "black-white", false, "black and white color scheme (default)"));
    colorOptions.addOption(new Option("ca", "activation-color", false, "activation color scheme"));
    colorOptions.addOption(new Option("co", "omega-color", false, "omega color scheme"));
    options.addOptionGroup(colorOptions);

    options.addOption(OptionBuilder.withLongOpt("rule").withDescription("rule number (required)").hasArg()
            .withArgName("rule").create());

    options.addOption(OptionBuilder.withLongOpt("width").withDescription("space width (required)").hasArg()
            .withArgName("width").create());

    options.addOption(OptionBuilder.withLongOpt("steps").withDescription("number of steps (required)").hasArg()
            .withArgName("steps").create());

    options.addOption(OptionBuilder.withLongOpt("alpha").withDescription("memory factor (default 0)").hasArg()
            .withArgName("alpha").create());

    options.addOption(OptionBuilder.withLongOpt("pattern").withDescription("inititial pattern").hasArg()
            .withArgName("pattern").create());

    options.addOption("s", "single-seed", false, "single cell seed");
    options.addOption("si", "single-seed-inverse", false, "all 1 except one cell");

    options.addOption(OptionBuilder.withLongOpt("update-patter")
            .withDescription("update patter (valid values are " + UpdatePattern.validValues() + ")").hasArg()
            .withArgName("updatepatter").create());

    // test//ww  w.  j ava 2s  .c o  m
    // args = new String[]{ "--rule=10", "--steps=500" , "--width=60", "-P" , "-s" };

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (!line.hasOption("rule"))
            throw new ParseException("no rule number (use --rule=XX)");
        int rule;
        try {
            rule = Integer.parseInt(line.getOptionValue("rule"));
            if (rule < 0 || rule > 15)
                throw new ParseException("invalid rule number");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid rule number");
        }

        if (!line.hasOption("width"))
            throw new ParseException("no space width (use --width=XX)");
        int width;
        try {
            width = Integer.parseInt(line.getOptionValue("width"));
            if (width < 1)
                throw new ParseException("invalid width");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid width");
        }

        if (!line.hasOption("steps"))
            throw new ParseException("no number of steps (use --steps=XX)");
        int steps;
        try {
            steps = Integer.parseInt(line.getOptionValue("steps"));
            if (width < 1)
                throw new ParseException("invalid number of steps");
        } catch (NumberFormatException ex) {
            throw new ParseException("invalid number of steps");
        }

        double alpha = 0;
        if (line.hasOption("alpha")) {
            try {
                alpha = Double.parseDouble(line.getOptionValue("alpha"));
                if (alpha < 0 || alpha > 1)
                    throw new ParseException("invalid alpha");
            } catch (NumberFormatException ex) {
                throw new ParseException("invalid alpha");
            }
        }

        String pattern = null;
        if (line.hasOption("pattern")) {
            pattern = line.getOptionValue("pattern");
            if (pattern != null)
                pattern = pattern.trim();
        }

        if (line.hasOption("single-seed"))
            pattern = "S";
        else if (line.hasOption("single-seed-inverse"))
            pattern = "SI";

        UpdatePattern updatePatter = UpdatePattern.synchronous;
        if (line.hasOption("update-patter")) {
            try {
                updatePatter = UpdatePattern.getUpdatePattern(line.getOptionValue("update-patter"));
            } catch (IllegalArgumentException ex) {
                throw new ParseException(ex.getMessage());
            }
        }

        Boundaries boundaries = Boundaries.periodic;
        if (line.hasOption("periodic"))
            boundaries = Boundaries.periodic;
        else if (line.hasOption("fixed"))
            boundaries = Boundaries.fixed;
        else if (line.hasOption("adiabatic"))
            boundaries = Boundaries.adiabatic;
        else if (line.hasOption("reflective"))
            boundaries = Boundaries.reflective;

        ColorScheme colorScheme = ColorScheme.noColor;
        if (line.hasOption("black-white"))
            colorScheme = ColorScheme.noColor;
        else if (line.hasOption("activation-color"))
            colorScheme = ColorScheme.activationColor;
        else if (line.hasOption("omega-color"))
            colorScheme = ColorScheme.omegaColor;

        Output output = Output.all;
        if (line.hasOption("suppress-output"))
            output = Output.noOutput;

        Main.drawRule(rule, width, boundaries, updatePatter, steps, alpha, pattern, output, colorScheme);

    } catch (ParseException ex) {
        System.err.println("Copyright (C) 2009 Andrea Bonomi - <andrea.bonomi@gmail.com>");
        System.err.println();
        System.err.println("https://github.com/andreax79/one-neighbor-binary-cellular-automata");
        System.err.println();
        System.err.println("This program is free software; you can redistribute it and/or modify it");
        System.err.println("under the terms of the GNU General Public License as published by the");
        System.err.println("Free Software Foundation; either version 2 of the License, or (at your");
        System.err.println("option) any later version.");
        System.err.println();
        System.err.println("This program is distributed in the hope that it will be useful, but");
        System.err.println("WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY");
        System.err.println("or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License");
        System.err.println("for more details.");
        System.err.println();
        System.err.println("You should have received a copy of the GNU General Public License along");
        System.err.println("with this program; if not, write to the Free Software Foundation, Inc.,");
        System.err.println("59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.)");
        System.err.println();
        System.err.println(ex.getMessage());
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("main", options);

    } catch (IOException ex) {
        System.err.println("IO exception:" + ex.getMessage());
    }

}

From source file:com.pureinfo.studio.db.cmd2srm.ref.impl.GetAmmountOfOutlayRef.java

/**
 * @see com.pureinfo.importer.ref.IImportorRef#convert(com.pureinfo.dolphin.model.DolphinObject,
 *      com.pureinfo.dolphin.model.DolphinObject, java.lang.String,
 *      java.lang.String, com.pureinfo.dolphin.persister.ISession,
 *      com.pureinfo.dolphin.persister.ISession,
 *      com.pureinfo.dolphin.mapping.EntityMetadata, java.lang.String,
 *      java.lang.String)/*ww w .  jav a 2 s . co  m*/
 */
public Object convert(DolphinObject _old, DolphinObject _new, String _sFromProperty, String _sToProperty,
        ISession _fromSession, ISession _toSession, EntityMetadata _metadata, String _sKey, String _sToTable)
        throws PureException {
    String sValue = _old.getStrProperty(_sFromProperty);
    if (StringUtils.isEmpty(sValue))
        return null;
    double dblValue = Double.parseDouble(sValue);
    return "" + dblValue * 10000;
}

From source file:net.sourceforge.fenixedu.domain.degreeStructure.EctsComparabilityPercentages.java

private double[] extractPercentages(String[] percentages) {
    try {/*from   w w  w  .  j a  va2s  . c o m*/
        double[] perc = new double[11];
        for (int i = 0; i < perc.length; i++) {
            perc[i] = Double.parseDouble(percentages[i]);
        }
        return perc;
    } catch (NumberFormatException e) {
        throw new DomainException("error.ects.invalidTable", StringUtils.join(percentages, "<tab>"));
    }
}

From source file:com.feedzai.fos.api.NumericAttribute.java

@Override
protected double parse(Object original) throws FOSException {
    if (original.getClass() == Double.class) {
        return (Double) original;
    }/*from ww  w .j a  va2  s .  c o  m*/

    try {
        return Double.parseDouble(original.toString());
    } catch (Exception e) {
        throw new FOSException(e.getMessage(), e);
    }
}

From source file:edu.iu.daal_pca.Service.java

public static void readRow(String line, int offset, int nCols, double[] data) throws IOException {
    if (line == null) {
        throw new IOException("Unable to read input dataset");
    }/*from   w w w. j  a v  a 2  s. com*/

    String[] elements = line.split(",");
    for (int j = 0; j < nCols; j++) {
        data[offset + j] = Double.parseDouble(elements[j]);
    }
}

From source file:com.epam.ipodromproject.service.MainService.java

@Transactional
public boolean makeBet(User user, Competition competitionToBet, String money, BetType betType, String horseID) {
    if ((!userService.canMakeBet(user.getUsername(), money, competitionToBet))
            || (!horseService.existsHorseInCompetition(competitionToBet, horseID))) {
        return false;
    }/*w  ww.  j a v a 2s . co m*/
    Date now = new Date();
    Horse horse = horseService.getHorseByID(Long.valueOf(horseID));
    double moneyToBet = Double.parseDouble(money);
    if ((CompetitionState.NOT_REGISTERED.equals(competitionToBet.getState()))
            && (now.compareTo(competitionToBet.getDateOfStart()) <= 0)) {
        Double coefficient = returnCoefficientDueToBetType(
                competitionToBet.getHorses().get(horse).getCoefficient(), betType);
        Bet betInfo = new Bet(moneyToBet, new Date(), betType, horse, user.getPerson(), competitionToBet,
                coefficient);
        betService.update(betInfo);
        userService.makeBet(user, moneyToBet);
        return true;
    } else {
        return false;
    }
}

From source file:edu.cornell.med.icb.util.TestVersionUtils.java

/**
 * Validates functionality of {@link VersionUtils#getImplementationVersion(Class<?> )}.
 */// ww  w.j a v a  2  s .c o m
@Test
public void getObjectImplementationVersion() {
    final String version = VersionUtils.getImplementationVersion(SystemUtils.class);
    assertNotNull("Version number should never be null", version);
    assertTrue("Version number should be at least 2.3", Double.parseDouble(version) >= 2.3);
}

From source file:com.miserablemind.api.consumer.tradeking.api.impl.response_entities.TKWatchlistItemsResponse.java

@JsonSetter("watchlists")
@SuppressWarnings("unchecked")
public void setWatchLists(LinkedHashMap<String, LinkedHashMap> watchListsResponse) {

    //manually deserialize as we need to un-nest some unnecessary stuff
    if (null == watchListsResponse.get("watchlist"))
        return;/*from w ww. jav a2s  .  c o m*/

    ArrayList<LinkedHashMap> items = new ArrayList<>();

    Object itemsContainer = watchListsResponse.get("watchlist").get("watchlistitem");

    //api does not wrap a single result
    if (itemsContainer.getClass() == ArrayList.class) {
        //we know it's ArrayList because of condition
        items = (ArrayList) itemsContainer;
    } else {
        items.add((LinkedHashMap) watchListsResponse.get("watchlist").get("watchlistitem"));
    }

    ArrayList<WatchlistItem> resultList = new ArrayList<>();

    for (Object item : items) {

        LinkedHashMap itemEntries = (LinkedHashMap) item;
        double costBasis = Double.parseDouble((String) itemEntries.get("costbasis"));
        double quantity = Double.parseDouble((String) itemEntries.get("qty"));
        LinkedHashMap instrument = (LinkedHashMap) itemEntries.get("instrument");
        String ticker = (String) instrument.get("sym");

        WatchlistItem itemObject = new WatchlistItem(costBasis, quantity, ticker);
        resultList.add(itemObject);

    }

    this.watchListsItems = new WatchlistItem[resultList.size()];
    this.watchListsItems = resultList.toArray(this.watchListsItems);

}