Example usage for org.apache.commons.configuration2 PropertiesConfiguration size

List of usage examples for org.apache.commons.configuration2 PropertiesConfiguration size

Introduction

In this page you can find the example usage for org.apache.commons.configuration2 PropertiesConfiguration size.

Prototype

@Override
public final int size() 

Source Link

Document

This implementation handles synchronization and delegates to sizeInternal() .

Usage

From source file:com.sikulix.core.SX.java

private static void setOptions(PropertiesConfiguration someOptions) {
    if (isNull(someOptions) || someOptions.size() == 0) {
        return;//from w  w  w. j  a v a 2 s  .  co m
    }
    Iterator<String> allKeys = someOptions.getKeys();
    List<String> sxSettings = new ArrayList<>();
    while (allKeys.hasNext()) {
        String key = allKeys.next();
        if (key.startsWith("Settings.")) {
            sxSettings.add(key);
            continue;
        }
        trace("!setOptions: %s = %s", key, someOptions.getProperty(key));
    }
    if (sxSettings.size() > 0) {
        Class cClass = null;
        try {
            cClass = Class.forName("org.sikuli.basics.Settings");
        } catch (ClassNotFoundException e) {
            error("!setOptions: %s", cClass);
        }
        if (!isNull(cClass)) {
            for (String sKey : sxSettings) {
                String sAttr = sKey.substring("Settings.".length());
                Field cField = null;
                Class ccField = null;
                try {
                    cField = cClass.getField(sAttr);
                    ccField = cField.getType();
                    if (ccField.getName() == "boolean") {
                        cField.setBoolean(null, someOptions.getBoolean(sKey));
                    } else if (ccField.getName() == "int") {
                        cField.setInt(null, someOptions.getInt(sKey));
                    } else if (ccField.getName() == "float") {
                        cField.setFloat(null, someOptions.getFloat(sKey));
                    } else if (ccField.getName() == "double") {
                        cField.setDouble(null, someOptions.getDouble(sKey));
                    } else if (ccField.getName() == "String") {
                        cField.set(null, someOptions.getString(sKey));
                    }
                    trace("!setOptions: %s = %s", sAttr, someOptions.getProperty(sKey));
                    someOptions.clearProperty(sKey);
                } catch (Exception ex) {
                    error("!setOptions: %s = %s", sKey, sxOptions.getProperty(sKey));
                }
            }
        }
    }
}

From source file:com.sikulix.core.SX.java

private static void mergeExtraOptions(PropertiesConfiguration baseOptions,
        PropertiesConfiguration extraOptions) {
    trace("loadOptions: have to merge extra Options");
    if (isNull(extraOptions) || extraOptions.size() == 0) {
        return;/*from w  ww.j a v a 2s.c  om*/
    }
    Iterator<String> allKeys = extraOptions.getKeys();
    while (allKeys.hasNext()) {
        String key = allKeys.next();
        if (isNull(baseOptions.getProperty(key))) {
            baseOptions.addProperty(key, extraOptions.getProperty(key));
            trace("Option added: %s", key);
        } else {
            baseOptions.addProperty(key, extraOptions.getProperty(key));
            trace("Option changed: %s", key);
        }
    }
}