Example usage for java.util Dictionary size

List of usage examples for java.util Dictionary size

Introduction

In this page you can find the example usage for java.util Dictionary size.

Prototype

public abstract int size();

Source Link

Document

Returns the number of entries (distinct keys) in this dictionary.

Usage

From source file:org.codice.ddf.itests.common.SystemStateManager.java

private boolean propertiesMatch(Dictionary<String, Object> dictionary1,
        Dictionary<String, Object> dictionary2) {
    if (dictionary1.size() != dictionary2.size()) {
        return false;
    }/*  w  w w.j  a  v  a2  s.c o  m*/
    Enumeration<String> keys = dictionary1.keys();
    while (keys.hasMoreElements()) {
        String key = keys.nextElement();
        Object o = dictionary1.get(key);
        Object o1 = dictionary2.get(key);
        if (o.getClass().isArray() && o1.getClass().isArray()) {
            if (!ArrayUtils.isEquals(o, o1)) {
                return false;
            }
        } else if (!o.equals(o1)) {
            return false;
        }
    }
    return true;
}

From source file:org.energy_home.jemma.ah.internal.greenathome.GreenathomeAppliance.java

public static Map convertToMap(Dictionary source) {
    Map sink = new HashMap(source.size());
    for (Enumeration keys = source.keys(); keys.hasMoreElements();) {
        Object key = keys.nextElement();
        sink.put(key, source.get(key));/*www . j a  v  a2  s .co  m*/
    }
    return sink;
}

From source file:org.openhab.binding.maxcul.internal.MaxCulBinding.java

private Map<String, Object> convertDictionaryToMap(Dictionary<String, ?> config) {

    Map<String, Object> myMap = new HashMap<String, Object>();

    if (config == null) {
        return null;
    }//w ww.j  a  v a 2s  .  c o m
    if (config.size() == 0) {
        return myMap;
    }

    Enumeration<String> allKeys = config.keys();
    while (allKeys.hasMoreElements()) {
        String key = allKeys.nextElement();
        myMap.put(key, config.get(key));
    }
    return myMap;
}

From source file:org.openhab.binding.mqttitude.internal.MqttitudeBinding.java

/**
 * @{inheritDoc}//from w  w w  .j  a  v a  2  s .c o m
 */
@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {
    // no mandatory binding properties - so fine to get nothing here
    if (properties == null || properties.size() == 0)
        return;

    float homeLat = Float.parseFloat(getOptionalProperty(properties, "home.lat", "0"));
    float homeLon = Float.parseFloat(getOptionalProperty(properties, "home.lon", "0"));

    if (homeLat == 0 || homeLon == 0) {
        homeLocation = null;
        geoFence = 0;
        logger.debug(
                "Mqttitude binding configuration updated, no 'home' location specified. All item bindings must be configured with a <region>.");
    } else {
        homeLocation = new Location(homeLat, homeLon);
        geoFence = Float.parseFloat(getOptionalProperty(properties, "geofence", "100"));
        logger.debug(
                "Mqttitude binding configuration updated, 'home' location specified ({}) with a geofence of {}m.",
                homeLocation.toString(), geoFence);
    }

    // need to re-register all the consumers/topics if the home location has changed
    unregisterAll();
    registerAll();
}

From source file:org.openhab.binding.smarthomatic.internal.SmarthomaticBinding.java

/**
 * @{inheritDoc/* ww  w  . j  a va 2 s .co m*/
 *
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config != null) {

        // to override the default refresh interval one has to add a
        // parameter to openhab.cfg like
        // <bindingName>:refresh=<intervalInMs>
        String refreshIntervalString = (String) config.get("refresh");
        if (StringUtils.isNotBlank(refreshIntervalString)) {
            refreshInterval = Long.parseLong(refreshIntervalString);
        }

        boolean changed = false;

        if (serialPortname != (String) config.get("serialPort")) {
            serialPortname = (String) config.get("serialPort");
            changed = true;
        }
        String dummy = (String) config.get("baud");
        try {
            if (serialBaudrate != Integer.parseInt(dummy)) {
                serialBaudrate = Integer.parseInt(dummy);
                changed = true;
            }
        } catch (NumberFormatException e) {
            logger.info("reading exception");
        }

        if (changed | (baseStation == null)) {
            if (baseStation != null) {
                baseStation.closeSerialPort();
            }

            baseStation = new BaseStation(serialPortname, serialBaudrate, this);
            logger.debug("Smarthomatic Binding:update creates new basestation");
        }

        Enumeration<String> keys = config.keys();
        for (int i = 0; i < config.size(); i++) {
            String key = keys.nextElement();
            StringTokenizer tokens = new StringTokenizer(key, ":");

            if (tokens.nextToken().equals("device")) {
                if (tokens.hasMoreElements()) {
                    dummy = tokens.nextToken();
                    int deviceID = Integer.parseInt(dummy);
                    String name = (String) config.get(key);
                    SmarthomaticGenericBindingProvider.addDevice(name, deviceID);
                    logger.debug("Smarthomatic device {} can be indexed by name {}",
                            new String[] { dummy, name });
                }
            }
            logger.debug("KEY: {}", key);
        }

        setProperlyConfigured(true);
    }
}

From source file:org.openhab.binding.velux.internal.VeluxBinding.java

/***
 *** Reconfiguration methods//from w ww. jav a 2  s  . c  o m
 ***/

@Override
public void updated(final Dictionary<String, ?> config) throws ConfigurationException {
    logger.debug("updated() called with {} dictionary entries.", config.size());
    if (config != null) {
        final String protocol = (String) config.get(VeluxBridgeConfiguration.BRIDGE_PROTOCOL);
        if (isNotBlank(protocol)) {
            this.config.bridgeProtocol = protocol;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_PROTOCOL to {}.", this.config.bridgeProtocol);
        }
        final String ipAddressString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_IPADDRESS);
        if (isNotBlank(ipAddressString)) {
            this.config.bridgeIPAddress = ipAddressString;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_IPADDRESS to {}.", this.config.bridgeIPAddress);
        }
        final String tcpPortString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_TCPPORT);
        if (isNotBlank(tcpPortString)) {
            try {
                this.config.bridgeTCPPort = Integer.parseInt(tcpPortString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_TCPPORT, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_TCPPORT to {}.", this.config.bridgeTCPPort);
        }
        final String passwordString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_PASSWORD);
        if (isNotBlank(passwordString)) {
            this.config.bridgePassword = passwordString;
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_PASSWORD to {}.", this.config.bridgePassword);
        }
        final String timeoutMsecsString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS);
        if (isNotBlank(timeoutMsecsString)) {
            try {
                this.config.timeoutMsecs = Integer.parseInt(timeoutMsecsString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_TIMEOUT_MSECS to {}.", this.config.timeoutMsecs);
        }
        final String retryNoString = (String) config.get(VeluxBridgeConfiguration.BRIDGE_RETRIES);
        if (isNotBlank(retryNoString)) {
            try {
                this.config.retries = Integer.parseInt(retryNoString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_RETRIES, e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_RETRIES to {}.", this.config.retries);
        }
        final String bulkRetrievalString = (String) config
                .get(VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED);
        if (isNotBlank(bulkRetrievalString)) {
            try {
                this.config.isBulkRetrievalEnabled = Boolean.parseBoolean(bulkRetrievalString);
            } catch (NumberFormatException e) {
                throw new ConfigurationException(VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED,
                        e.getMessage());
            }
            this.config.hasChanged = true;
            logger.debug("updated(): adapted BRIDGE_IS_BULK_RETRIEVAL_ENABLED to {}.",
                    this.config.isBulkRetrievalEnabled);
        }
    }

    setProperlyConfigured(true);

    logger.info("{}Config[{}={},{}={},{}={},{}={},{}={},{}={},{}={},{}={}]", VeluxBindingConstants.BINDING_ID,
            VeluxBridgeConfiguration.BRIDGE_PROTOCOL, this.config.bridgeProtocol,
            VeluxBridgeConfiguration.BRIDGE_IPADDRESS, this.config.bridgeIPAddress,
            VeluxBridgeConfiguration.BRIDGE_TCPPORT, this.config.bridgeTCPPort,
            VeluxBridgeConfiguration.BRIDGE_PASSWORD, this.config.bridgePassword.replaceAll(".", "*"),
            VeluxBridgeConfiguration.BRIDGE_TIMEOUT_MSECS, this.config.timeoutMsecs,
            VeluxBridgeConfiguration.BRIDGE_RETRIES, this.config.retries,
            VeluxBridgeConfiguration.BRIDGE_REFRESH_MSECS, this.config.refreshMSecs,
            VeluxBridgeConfiguration.BRIDGE_IS_BULK_RETRIEVAL_ENABLED, this.config.isBulkRetrievalEnabled);

    // Now that we've read ALL the configuration, initialize the binding.
    execute();
}

From source file:org.paxle.tools.ieporter.cm.impl.ConfigurationIEPorterTest.java

public void testExportConfiguration() throws ParserConfigurationException {
    final Dictionary<String, Object> props = new Hashtable<String, Object>();
    props.put("myProperty.Integer", Integer.valueOf(1));
    props.put("myProperty.intArray", new int[] { 1, 2, 3, 4 });
    props.put("myProperty.String", "test");
    props.put("myProperty.StringArray", new String[] { "test1", "test2", "test3" });

    final Configuration config = mock(Configuration.class);
    checking(new Expectations() {
        {//from  w w  w.  j  a va 2s. c  o  m
            atLeast(1).of(config).getPid();
            will(returnValue("testPid"));
            atLeast(1).of(config).getProperties();
            will(returnValue(props));
            never(config);
        }
    });

    Map<String, Document> configs = this.ieporter.exportConfiguration(config);
    assertNotNull(configs);
    assertEquals(1, configs.size());
    assertTrue(configs.containsKey("testPid"));

    Document doc = configs.get("testPid");
    assertNotNull(doc);
    JXPathContext objContext = JXPathContext.newContext(doc);
    assertEquals("testPid", objContext.getValue("//service.pid"));
    assertEquals(props.size(), ((Double) objContext.getValue("count(//property)")).intValue());
    assertEquals(props.get("myProperty.Integer").toString(),
            objContext.getValue("//property[@key='myProperty.Integer']/value"));
    assertEquals(Array.getLength(props.get("myProperty.intArray")),
            ((Double) objContext.getValue("count(//property[@key='myProperty.intArray']/values/value)"))
                    .intValue());
    assertEquals(props.get("myProperty.String").toString(),
            objContext.getValue("//property[@key='myProperty.String']/value"));
    assertEquals(Array.getLength(props.get("myProperty.StringArray")),
            ((Double) objContext.getValue("count(//property[@key='myProperty.StringArray']/values/value)"))
                    .intValue());
}