Example usage for org.apache.commons.configuration FileConfiguration getDouble

List of usage examples for org.apache.commons.configuration FileConfiguration getDouble

Introduction

In this page you can find the example usage for org.apache.commons.configuration FileConfiguration getDouble.

Prototype

double getDouble(String key);

Source Link

Document

Get a double associated with the given configuration key.

Usage

From source file:gda.device.scannable.TwoJawSlitGap.java

@Override
protected Quantity[] calculateTargets(Object position) throws DeviceException {
    // convert what is supplied to Quantity in user units
    Quantity target = QuantityFactory.createFromObject(position, this.unitsComponent.getUserUnit());
    Quantity[] targets = new Quantity[2];

    if (xmlparametersfilename != null) {
        // perform calculation based on the beam centre in the xml file
        try {/*from   w  ww.j  a v  a2 s .c om*/
            //first check the file exists then load using the New version to ensure any changes outside the VM are picked up
            LocalParameters.getXMLConfiguration(xmlparametersfilename, false);
            FileConfiguration config = LocalParameters.getNewXMLConfiguration(xmlparametersfilename);
            double xmlCentreDbl = config.getDouble(getName());
            Quantity xmlCentre = QuantityFactory.createFromObject(xmlCentreDbl,
                    this.unitsComponent.getUserUnit());
            targets[0] = xmlCentre.plus(target.divide(2.0));
            targets[1] = xmlCentre.minus(target.divide(2.0));
        } catch (Exception e) {
            throw new DeviceException(e.getMessage(), e);
        }
        // 
    } else {
        // perform the calculation based on the current beam centre i.e. current motor positions
        Quantity currentGap = getCurrentGap();
        Quantity delta = target.minus(currentGap).divide(2);
        Quantity firstJawPosition = QuantityFactory.createFromObject(firstJaw.getPosition(),
                QuantityFactory.createUnitFromString(this.firstJaw.getUserUnits()));
        Quantity secondJawPosition = QuantityFactory.createFromObject(secondJaw.getPosition(),
                QuantityFactory.createUnitFromString(this.firstJaw.getUserUnits()));

        targets[0] = firstJawPosition.plus(delta);
        targets[1] = secondJawPosition.minus(delta);
    }
    return targets;
}

From source file:gda.util.userOptions.UserOptions.java

public static UserOptions createFromTemplate(String configDir, String configName)
        throws ConfigurationException, IOException, Exception {
    FileConfiguration config = LocalParameters.getXMLConfiguration(configDir, configName, false, true);
    UserOptions options = new UserOptions();
    options.title = config.getString(propTitle);
    options.containsDefault = true;//from   w w  w.  j  a v  a 2  s .  c  o  m
    Integer index = 0;
    while (true) {
        String tag = "options.option(" + index + ").";
        Object description = null;
        try {
            String keyName = config.getString(tag + propKeyName);
            /*
             * stop on last key
             */
            if (keyName == null)
                break;
            description = config.getProperty(tag + propDesc);
            Object type = config.getProperty(tag + propType);
            UserOption<? extends Object, ? extends Object> option;
            if (type != null && type.equals(typeBoolean)) {
                option = new UserOption<Object, Boolean>(description, config.getBoolean(tag + propDefValue));
            } else if (type != null && type.equals(typeString)) {
                option = new UserOption<Object, String>(description, config.getString(tag + propDefValue));
            } else if (type != null && type.equals(typeDouble)) {
                option = new UserOption<Object, Double>(description, config.getDouble(tag + propDefValue));
            } else if (type != null && type.equals(typeInteger)) {
                option = new UserOption<Object, Integer>(description, config.getInt(tag + propDefValue));
            } else {
                option = new UserOption<Object, Object>(description, config.getProperty(tag + propDefValue));
            }
            options.put(keyName, option);
            index++;
        } catch (Exception ex) {
            throw new Exception("Error reading option " + index, ex);
        }
    }
    return options;
}