Example usage for org.jdom2 Attribute getDoubleValue

List of usage examples for org.jdom2 Attribute getDoubleValue

Introduction

In this page you can find the example usage for org.jdom2 Attribute getDoubleValue.

Prototype

public double getDoubleValue() throws DataConversionException 

Source Link

Document

This gets the value of the attribute, in double form, and if no conversion can occur, throws a DataConversionException

Usage

From source file:strategies.StatusDataForNinety.java

public void LoadTradingStatus() {

    heldStocks.clear();//from   ww  w. j a  v a2  s  .c om
    try {
        File inputFile = new File(FilePaths.tradingStatusPathFileInput);
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(inputFile);

        Element rootElement = document.getRootElement();

        Element moneyElement = rootElement.getChild("money");

        Attribute attribute = moneyElement.getAttribute("currentCash");
        currentCash = attribute.getDoubleValue();

        attribute = moneyElement.getAttribute("currentFees");
        currentFees = attribute.getDoubleValue();

        List<Element> heldStocksElements = rootElement.getChild("heldPositions").getChildren();

        for (Element heldElement : heldStocksElements) {
            HeldStock held = new HeldStock();
            held.LoadFromXml(heldElement);

            heldStocks.put(held.tickerSymbol, held);
        }
    } catch (JDOMException e) {
        logger.severe("Error in loading from XML: JDOMException.\r\n" + e);
    } catch (IOException ioe) {
        logger.severe("Error in loading from XML: IOException.\r\n" + ioe);
    }
}

From source file:strategies.StockPurchase.java

void LoadFromXml(Element purchaseElement) {
    try {/*w  w  w. j av a2s  .c  o m*/
        Attribute attribute = purchaseElement.getAttribute("priceForOne");
        priceForOne = attribute.getDoubleValue();

        attribute = purchaseElement.getAttribute("position");
        position = attribute.getIntValue();

        attribute = purchaseElement.getAttribute("portions");
        portions = attribute.getIntValue();

        attribute = purchaseElement.getAttribute("date");
        date = LocalDate.parse(attribute.getValue());

    } catch (DataConversionException ex) {
        logger.severe("Error in loading from XML: Failed to convert values in purchases. " + ex.getMessage());
    }
}

From source file:tradingapp.Settings.java

public static void ReadSettings() {
    try {/*from  w  w  w  . java  2s.  c om*/
        File inputFile = new File(FilePaths.settingsPathFile);
        SAXBuilder saxBuilder = new SAXBuilder();
        Document document = saxBuilder.build(inputFile);

        Element rootElement = document.getRootElement();
        Attribute attribute;

        // connection
        Element connectionElement = rootElement.getChild("connection");

        attribute = connectionElement.getAttribute("port");
        port = attribute.getIntValue();

        attribute = connectionElement.getAttribute("clientId");
        clientId = attribute.getIntValue();

        // money
        Element moneyElement = rootElement.getChild("money");

        attribute = moneyElement.getAttribute("investCash");
        investCash = attribute.getDoubleValue();

        attribute = moneyElement.getAttribute("leverage");
        leverage = attribute.getDoubleValue();

        // mail
        Element mailElement = rootElement.getChild("mail");
        mailAddressTradeLog = mailElement.getAttribute("addressTradeLog").getValue();
        mailAddressCheck = mailElement.getAttribute("addressCheck").getValue();
        mailAddressError = mailElement.getAttribute("addressError").getValue();
        mailFrom = mailElement.getAttribute("from").getValue();
        mailPassword = mailElement.getAttribute("password").getValue();

        logger.fine("Updated Settings");
        logger.fine("Loaded Connection - port: " + port + ", clientId: " + clientId);
        logger.fine("Loaded money - investCash: " + investCash + ", leverage: " + leverage);
        logger.fine("Loaded mail - mailAddressTradeLog: " + mailAddressTradeLog + ", mailAddressCheck: "
                + mailAddressCheck + ", mailAddressError: " + mailAddressError + ", mailFrom: " + mailFrom
                + ", mailPassword: " + mailPassword);

    } catch (JDOMException e) {
        logger.severe("Error in loading from XML: JDOMException.\r\n" + e);
    } catch (IOException ioe) {
        logger.severe("Error in loading from XML: IOException.\r\n" + ioe);
    }
}