Example usage for java.util Dictionary isEmpty

List of usage examples for java.util Dictionary isEmpty

Introduction

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

Prototype

public abstract boolean isEmpty();

Source Link

Document

Tests if this dictionary maps no keys to value.

Usage

From source file:Main.java

public static void main(String[] args) {

    Dictionary d = new Hashtable();

    // add elements in the hashtable
    d.put("1", "from java2s.com");
    d.put("2", "Cocoa");
    d.put("5", "Coffee");

    // return true if this dictionary maps no keys to value.
    boolean b = d.isEmpty();
    System.out.println("Dictionary is empty:" + b);
}

From source file:Main.java

public static boolean isNullOrNothing(final Dictionary dict) {
    return dict == null || dict.isEmpty();
}

From source file:org.apache.cxf.dosgi.dsw.OsgiUtils.java

public static Filter createFilterFromProperties(BundleContext bc, Dictionary properties) {

    if (properties == null || properties.isEmpty()) {
        return null;
    }/*  w w w.ja v  a  2  s.  c o  m*/

    StringBuilder sb = new StringBuilder();
    sb.append("(&");
    for (Enumeration keys = properties.keys(); keys.hasMoreElements();) {
        String key = keys.nextElement().toString();
        String value = properties.get(key).toString();
        sb.append('(').append(key).append('=').append(value).append(')');
    }
    sb.append(')');
    return createFilter(bc, sb.toString());
}

From source file:org.eclipse.smarthome.io.transport.mqtt.MqttService.java

@Override
public void updated(Dictionary<String, ?> properties) throws ConfigurationException {

    // load broker configurations from configuration file
    if (properties == null || properties.isEmpty()) {
        return;//from w w w .j  a v  a  2s  .co m
    }

    Enumeration<String> keys = properties.keys();
    while (keys.hasMoreElements()) {

        String key = keys.nextElement();

        if (key.equals("service.pid")) {
            // ignore the only non-broker property..
            continue;
        }

        String[] subkeys = key.split("\\.");
        if (subkeys.length != 2) {
            logger.debug("MQTT Broker property '{}' should have the format 'broker.propertykey'", key);
            continue;
        }

        String value = (String) properties.get(key);
        String name = subkeys[0].toLowerCase();
        String property = subkeys[1];

        if (StringUtils.isBlank(value)) {
            logger.trace("Property is empty: {}", key);
            continue;
        } else {
            logger.trace("Processing property: {} = {}", key, value);
        }

        MqttBrokerConnection conn = brokerConnections.get(name);
        if (conn == null) {
            conn = new MqttBrokerConnection(name);
            brokerConnections.put(name, conn);
        }

        if (property.equals("url")) {
            conn.setUrl(value);
        } else if (property.equals("user")) {
            conn.setUser(value);
        } else if (property.equals("pwd")) {
            conn.setPassword(value);
        } else if (property.equals("qos")) {
            conn.setQos(Integer.parseInt(value));
        } else if (property.equals("retain")) {
            conn.setRetain(Boolean.parseBoolean(value));
        } else if (property.equals("async")) {
            conn.setAsync(Boolean.parseBoolean(value));
        } else if (property.equals("clientId")) {
            conn.setClientId(value);
        } else {
            logger.warn("Unrecognized property: {}", key);
        }
    }
    logger.info("MQTT Service initialization completed.");

    for (MqttBrokerConnection con : brokerConnections.values()) {
        try {
            con.start();
        } catch (Exception e) {
            logger.error("Error starting broker connection {} : {}", con.getName(), e.getMessage());
        }
    }
}

From source file:org.eclipse.vtp.framework.engine.http.HttpConnector.java

/**
 * The MIME type for the specified resource.
 * //from w  w  w  .  j a  v a  2 s.c o  m
 * @param resourcePath The resource to determine the MIME type of.
 * @return The MIME type for the specified resource.
 */
public String getMimeType(String resourcePath) {
    @SuppressWarnings("rawtypes")
    Dictionary properties = this.properties;
    if (properties == null)
        return null;
    if (resourcePath == null || properties.isEmpty())
        return null;
    int lastSlash = resourcePath.lastIndexOf('/');
    if (lastSlash >= 0)
        resourcePath = resourcePath.substring(lastSlash + 1);
    if (resourcePath.length() == 0)
        return null;
    Object mimeType = properties.get(MIME_TYPE_PREFIX + resourcePath);
    while (!(mimeType instanceof String)) {
        int firstDot = resourcePath.indexOf('.');
        if (firstDot < 0)
            return null;
        resourcePath = resourcePath.substring(firstDot + 1);
        mimeType = properties.get(MIME_TYPE_PREFIX + resourcePath);
    }
    return (String) mimeType;
}

From source file:org.opendaylight.controller.cluster.datastore.DatastoreContextIntrospector.java

/**
 * Applies the given properties to the cached DatastoreContext and yields a new DatastoreContext
 * instance which can be obtained via {@link getContext}.
 *
 * @param properties the properties to apply
 * @return true if the cached DatastoreContext was updated, false otherwise.
 *///w  w w .  j a v a 2s  .c  o  m
public synchronized boolean update(Dictionary<String, Object> properties) {
    currentProperties = null;
    if (properties == null || properties.isEmpty()) {
        return false;
    }

    LOG.debug("In update: properties: {}", properties);

    ImmutableMap.Builder<String, Object> mapBuilder = ImmutableMap.<String, Object>builder();

    Builder builder = DatastoreContext.newBuilderFrom(context);

    final String dataStoreTypePrefix = context.getDataStoreName() + '.';

    List<String> keys = getSortedKeysByDatastoreType(Collections.list(properties.keys()), dataStoreTypePrefix);

    boolean updated = false;
    for (String key : keys) {
        Object value = properties.get(key);
        mapBuilder.put(key, value);

        // If the key is prefixed with the data store type, strip it off.
        if (key.startsWith(dataStoreTypePrefix)) {
            key = key.replaceFirst(dataStoreTypePrefix, "");
        }

        if (convertValueAndInvokeSetter(key, value, builder)) {
            updated = true;
        }
    }

    currentProperties = mapBuilder.build();

    if (updated) {
        context = builder.build();
    }

    return updated;
}

From source file:org.openhab.binding.ddwrt.internal.DDWRTBinding.java

/**
 * {@inheritDoc}/*from w ww  .j  a  v a  2s  .  c  o m*/
 */
@Override
@SuppressWarnings("rawtypes")
public void updated(Dictionary config) throws ConfigurationException {

    logger.info("Update DD-WRT Binding configuration ...");

    if (config == null) {
        return;
    } else {
        if (config.isEmpty()) {
            throw new RuntimeException("No properties in openhab.cfg set!");
        }
        String ip = (String) config.get("ip");
        if (StringUtils.isNotBlank(ip)) {
            if (!ip.equals(DDWRTBinding.ip)) {
                // only do something if the ip has changed
                DDWRTBinding.ip = ip;
                String port = (String) config.get("port");
                if (!StringUtils.isNotBlank(port)) {
                    port = "23";
                }
                DDWRTBinding.port = port;
                conditionalDeActivate();

            }
        }
        String username = (String) config.get("username");
        if (StringUtils.isNotBlank(username)) {
            DDWRTBinding.username = username;
        }

        String password = (String) config.get("password");
        if (StringUtils.isNotBlank(password)) {
            DDWRTBinding.password = password;
        }

        String interface_24 = (String) config.get("interface_24");
        if (StringUtils.isNotBlank(interface_24)) {
            DDWRTBinding.interface_24 = interface_24;
        }

        String interface_50 = (String) config.get("interface_50");
        if (StringUtils.isNotBlank(interface_50)) {
            DDWRTBinding.interface_50 = interface_50;
        }

        String interface_guest = (String) config.get("interface_guest");
        if (StringUtils.isNotBlank(interface_guest)) {
            DDWRTBinding.interface_guest = interface_guest;
        }

    }
}

From source file:org.openhab.binding.dmlsmeter.internal.DmlsMeterBinding.java

/**
 * @{inheritDoc//from   w w  w . j av a 2  s.  c o  m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config == null || config.isEmpty()) {
        logger.warn("Empty or null configuration. Ignoring.");
        return;
    }

    Set<String> names = getNames(config);

    for (String name : names) {

        String value = (String) config.get(name + ".serialPort");
        String serialPort = value != null ? value : DmlsMeterDeviceConfig.DEFAULT_SERIAL_PORT;

        value = (String) config.get(name + ".baudRateChangeDelay");
        int baudRateChangeDelay = value != null ? Integer.valueOf(value)
                : DmlsMeterDeviceConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY;

        value = (String) config.get(name + ".echoHandling");
        boolean echoHandling = value != null ? Boolean.valueOf(value)
                : DmlsMeterDeviceConfig.DEFAULT_ECHO_HANDLING;

        DmlsMeterReader reader = createDmlsMeterReader(name,
                new DmlsMeterDeviceConfig(serialPort, baudRateChangeDelay, echoHandling));

        if (meterDevices.put(reader.getName(), reader) != null) {
            logger.info("Recreated reader {} with  {}!", reader.getName(), reader.getConfig());
        } else {
            logger.info("Created reader {} with  {}!", reader.getName(), reader.getConfig());
        }
    }

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

From source file:org.openhab.binding.echonetlite.internal.ECHONETLiteBinding.java

@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
    if (config == null || config.isEmpty())
        throw new IllegalArgumentException("config is empty");
    else {// w  w w .ja  v  a  2 s  .co m
        for (final Enumeration<String> e = config.keys(); e.hasMoreElements();) {
            final String key = e.nextElement();
            final String value = StringUtils.trim((String) config.get(key));

            // skip empty values
            if (StringUtils.isBlank(value)) {
                continue;
            }
            final Matcher matcher = CONFIG_PATTERN.matcher(key);
            if (matcher.matches()) {
                final String device = matcher.group(1);
                final String property = matcher.group(2);
                if (!deviceMap.containsKey(device)) {
                    deviceMap.put(device, new DeviceInfo());
                }
                DeviceInfo deviceInfo = deviceMap.get(device);

                // dispatch individual properties
                if (("host").equalsIgnoreCase(property)) {
                    deviceInfo.setHost(value);
                } else if (("port").equalsIgnoreCase(property)) {
                    deviceInfo.setPort(Integer.parseInt(value));
                } else if (("ehd").equalsIgnoreCase(property)) {
                    deviceInfo.setEhd(CommonUtils.hexStringToByteArray(value));
                } else if (("edata_head").equalsIgnoreCase(property)) {
                    deviceInfo.setEdataHead(CommonUtils.hexStringToByteArray(value));
                }
            }
        }
    }
}

From source file:org.openhab.binding.iec6205621meter.internal.Iec6205621MeterBinding.java

/**
 * @{inheritDoc//from   w w  w  . j  a  v  a2 s .  co  m
 */
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {

    if (config == null || config.isEmpty()) {
        logger.warn("Empty or null configuration. Ignoring.");
        return;
    }

    Set<String> names = getNames(config);

    for (String name : names) {

        String value = (String) config.get(name + ".serialPort");
        String serialPort = value != null ? value : MeterConfig.DEFAULT_SERIAL_PORT;

        value = (String) config.get(name + ".baudRateChangeDelay");
        int baudRateChangeDelay = value != null ? Integer.valueOf(value)
                : MeterConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY;

        value = (String) config.get(name + ".echoHandling");
        boolean echoHandling = value != null ? Boolean.valueOf(value) : MeterConfig.DEFAULT_ECHO_HANDLING;

        Meter meterConfig = createIec6205621MeterConfig(name,
                new MeterConfig(serialPort, baudRateChangeDelay, echoHandling));

        if (meterDeviceConfigurtions.put(meterConfig.getName(), meterConfig) != null) {
            logger.info("Recreated reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
        } else {
            logger.info("Created reader {} with  {}!", meterConfig.getName(), meterConfig.getConfig());
        }
    }

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