Java Code Examples for java.util.Dictionary#isEmpty()
The following examples show how to use
java.util.Dictionary#isEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DarkSliderUI.java From darklaf with MIT License | 6 votes |
public Dimension getPreferredHorizontalSize() { Dimension dim = super.getPreferredHorizontalSize(); Rectangle rect = new Rectangle(0, 0, 0, 0); rect.setSize(dim); adjustRect(rect, true); Dictionary<?, ?> dict = slider.getLabelTable(); if (dict != null && !dict.isEmpty()) { int totalLabelWidth = 0; Enumeration<?> labels = dict.elements(); while (labels.hasMoreElements()) { Object obj = labels.nextElement(); if (obj instanceof Component) { totalLabelWidth += ((Component) obj).getPreferredSize().width; } } totalLabelWidth += getThumbWidth(); rect.width = Math.max(rect.width, totalLabelWidth); } return rect.getSize(); }
Example 2
Source File: MqttEventBusBinding.java From openhab1-addons with Eclipse Public License 2.0 | 6 votes |
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { // load event bus pubish/subscribe configuration from configuration file if (properties == null || properties.isEmpty()) { logger.trace("No mqtt-eventbus properties configured."); return; } logger.debug("Initializing MQTT Event Bus Binding"); // stop existing publishers/subscribers deactivate(); brokerName = (String) properties.get("broker"); if (StringUtils.isEmpty(brokerName)) { logger.debug("No broker name configured for MQTT EventBusBinding"); return; } setupEventBusStatePublisher((String) properties.get("statePublishTopic")); setupEventBusStateSubscriber((String) properties.get("stateSubscribeTopic")); setupEventBusCommandPublisher((String) properties.get("commandPublishTopic")); setupEventBusCommandSubscriber((String) properties.get("commandSubscribeTopic")); logger.debug("MQTT Event Bus Binding initialization completed."); }
Example 3
Source File: DarkSliderUI.java From darklaf with MIT License | 5 votes |
protected void adjustRect(final Rectangle rectangle, final boolean outwards) { boolean horizontal = slider.getOrientation() == JSlider.HORIZONTAL; Dictionary<?, ?> dict = slider.getLabelTable(); if (!slider.getPaintLabels() || dict == null || dict.isEmpty() || !horizontal) { return; } int extra = getLowerHorizontalExtend(); int extend = getUpperHorizontalExtend(); int factor = outwards ? 1 : -1; rectangle.x -= factor * extra; rectangle.width += factor * (extra + extend); }
Example 4
Source File: ObjectPoolImpl.java From neoscada with Eclipse Public License 1.0 | 5 votes |
@Override @SuppressWarnings ( "unchecked" ) public synchronized void addService ( final String id, final S service, Dictionary<?, ?> properties ) { if ( this.disposed ) { return; } if ( properties == null || properties.isEmpty () ) { properties = emptyHashtable; } else { properties = new UnmodifyableDictionary<Object, Object> ( (Dictionary<Object, Object>)properties ); } logger.debug ( "Adding service: {} -> {} -> {}", new Object[] { id, service, properties } ); Map<S, Dictionary<?, ?>> serviceMap = this.services.get ( id ); if ( serviceMap == null ) { serviceMap = new HashMap<S, Dictionary<?, ?>> ( 1 ); this.services.put ( id, serviceMap ); } final Dictionary<?, ?> oldService = serviceMap.put ( service, properties ); if ( oldService != null ) { logger.warn ( "Replaced service: {}", new Object[] { id } ); } fireAddedService ( id, service, properties ); }
Example 5
Source File: Args.java From xipki with Apache License 2.0 | 5 votes |
public static <K,V> Dictionary<K,V> notEmpty(Dictionary<K,V> argument, String name) { Objects.requireNonNull(argument, name + " may not be null"); if (argument.isEmpty()) { throw new IllegalArgumentException(name + " may not be empty"); } return argument; }
Example 6
Source File: Ipx800Config.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * Read and parse the config creating the Ipx800Config object * * @param config * @return the configuration * @throws ConfigurationException when configuration is invalid */ static Ipx800Config readConfig(Dictionary<String, ?> config) throws ConfigurationException { Ipx800Config ipx800config = Ipx800Config.INSTANCE; if (config == null || config.isEmpty()) { return null; } for (final Enumeration<String> e = config.keys(); e.hasMoreElements();) { final String key = e.nextElement(); final String value = (String) config.get(key); // skip empty values if (value == null || value.trim().isEmpty()) { continue; } // skip keys that we don't want to process here ... if ("service.pid".equals(key)) { continue; } try { // check for config keys final Matcher matcher = CONFIG_PATTERN.matcher(key); if (matcher.matches()) { final String device = matcher.group(1); final String property = matcher.group(2); // device config Ipx800DeviceConfig deviceConfig = ipx800config.retrieveDevice(device); // dispatch individual properties if ("host".equalsIgnoreCase(property)) { deviceConfig.host = value.trim(); } else if ("port".equalsIgnoreCase(property)) { deviceConfig.port = value.trim(); } else { final String ext = matcher.group(3); final String number = matcher.group(4); if ("x880".equalsIgnoreCase(ext)) { deviceConfig.x880extensions[Integer.parseInt(number) - 1] = value.trim(); } else { deviceConfig.x400extensions[Integer.parseInt(number) - 1] = value.trim(); } } } else { throw new ConfigurationException(key, "Invalid config key"); } } catch (NumberFormatException ex) { throw new ConfigurationException(key, "Invalid value: '" + value + "'"); } } return ipx800config; }
Example 7
Source File: DDWRTBinding.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @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; } } }
Example 8
Source File: Iec6205621MeterBinding.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { if (config == null || config.isEmpty()) { return; } Set<String> names = getNames(config); for (String name : names) { String value = Objects.toString(config.get(name + ".serialPort"), null); String serialPort = value != null ? value : MeterConfig.DEFAULT_SERIAL_PORT; value = Objects.toString(config.get(name + ".initMessage"), null); byte[] initMessage = value != null ? DatatypeConverter.parseHexBinary(value) : null; value = Objects.toString(config.get(name + ".baudRateChangeDelay"), null); int baudRateChangeDelay = value != null ? Integer.valueOf(value) : MeterConfig.DEFAULT_BAUD_RATE_CHANGE_DELAY; value = Objects.toString(config.get(name + ".echoHandling"), null); boolean echoHandling = value != null ? Boolean.valueOf(value) : MeterConfig.DEFAULT_ECHO_HANDLING; Meter meterConfig = createIec6205621MeterConfig(name, new MeterConfig(serialPort, initMessage, 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()); } } // to override the default refresh interval one has to add a // parameter to openhab.cfg like // <bindingName>:refresh=<intervalInMs> String refreshStr = Objects.toString(config.get("refresh"), null); if (StringUtils.isNotBlank(refreshStr)) { refreshInterval = Long.parseLong(refreshStr); } setProperlyConfigured(true); }
Example 9
Source File: StiebelHeatPumpBinding.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
/** * {@inheritDoc} */ @Override public void updated(Dictionary<String, ?> config) throws ConfigurationException { String serialPort = null; int baudRate = DEFAULT_BAUD_RATE; serialTimeout = DEFAULT_SERIAL_TIMEOUT; String host = null; int port = 0; logger.debug("Loading stiebelheatpump binding configuration."); if (config == null || config.isEmpty()) { logger.warn("Empty or null configuration. Ignoring."); return; } 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")); } if (StringUtils.isNotBlank((String) config.get("serialPort"))) { serialPort = (String) config.get("serialPort"); } if (StringUtils.isNotBlank((String) config.get("baudRate"))) { baudRate = Integer.parseInt((String) config.get("baudRate")); } if (StringUtils.isNotBlank((String) config.get("host"))) { host = (String) config.get("host"); } if (StringUtils.isNotBlank((String) config.get("port"))) { port = Integer.parseInt((String) config.get("port")); } if (StringUtils.isNotBlank((String) config.get("serialTimeout"))) { serialTimeout = Integer.parseInt((String) config.get("serialTimeout")); } if (StringUtils.isNotBlank((String) config.get("version"))) { version = (String) config.get("version"); } try { if (host != null) { this.connector = new TcpConnector(host, port); } else { this.connector = new SerialPortConnector(serialPort, baudRate); } boolean isInitialized = getInitialHeatPumpSettings(); setTime(); if (host != null) { logger.info("Created heatpump configuration with tcp {}:{}, version:{} ", host, port, version); } else { logger.info("Created heatpump configuration with serialport:{}, baudrate:{}, version:{} ", serialPort, baudRate, version); } setProperlyConfigured(isInitialized); } catch (RuntimeException e) { logger.warn(e.getMessage(), e); throw e; } } }
Example 10
Source File: SqueezeServer.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
@Override public synchronized void updated(Dictionary<String, ?> config) throws ConfigurationException { // disconnect first in case the config has changed for an existing // instance disconnect(); host = null; cliPort = DEFAULT_CLI_PORT; webPort = DEFAULT_WEB_PORT; retries = DEFAULT_RETRIES; retryTimeout = DEFAULT_RETRY_TIMEOUT; ttsUrl = DEFAULT_TTS_URL; ttsMaxSentenceLength = DEFAULT_TTS_MAX_SENTENCE_LENGTH; playersById.clear(); playersByMacAddress.clear(); if (config == null || config.isEmpty()) { logger.warn("Empty or null configuration. Ignoring."); return; } Enumeration<String> keys = config.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); // the config-key enumeration contains additional keys that we // don't want to process here ... if ("service.pid".equals(key)) { continue; } Matcher serverMatcher = SERVER_CONFIG_PATTERN.matcher(key); Matcher playerMatcher = PLAYER_CONFIG_PATTERN.matcher(key); Matcher ttsUrlMatcher = TTS_URL_CONFIG_PATTERN.matcher(key); Matcher ttsMaxSentenceLengthMatcher = TTS_MAX_SENTENCE_LENGTH_CONFIG_PATTERN.matcher(key); String value = (String) config.get(key); if (serverMatcher.matches()) { String serverConfig = serverMatcher.group(2); if (serverConfig.equals("host") && StringUtils.isNotBlank(value)) { host = value; } else if (serverConfig.equals("cliport") && StringUtils.isNotBlank(value)) { cliPort = Integer.valueOf(value); } else if (serverConfig.equals("webport") && StringUtils.isNotBlank(value)) { webPort = Integer.valueOf(value); } else if (serverConfig.equals("retries") && StringUtils.isNotBlank(value)) { retries = Integer.valueOf(value); } else if (serverConfig.equals("retryTimeout") && StringUtils.isNotBlank(value)) { retryTimeout = Integer.valueOf(value); } } else if (playerMatcher.matches()) { String playerId = playerMatcher.group(1); String macAddress = value; SqueezePlayer player = new SqueezePlayer(this, playerId, macAddress); playersById.put(playerId.toLowerCase(), player); playersByMacAddress.put(macAddress.toLowerCase(), player); } else if (ttsUrlMatcher.matches() && StringUtils.isNotBlank(value)) { ttsUrl = value; } else if (ttsMaxSentenceLengthMatcher.matches() && StringUtils.isNotBlank(value)) { ttsMaxSentenceLength = Integer.valueOf(value); } else { logger.warn("Ignored unexpected or unsupported configuration: {}", key); } } if (StringUtils.isEmpty(host)) { throw new ConfigurationException("host", "No Squeeze Server host specified - this property is mandatory"); } if (playersById.size() == 0) { throw new ConfigurationException("host", "No Squeezebox players specified - there must be at least one player"); } // attempt to connect using our new config if (!connect()) { retryConnect(); } }
Example 11
Source File: MqttService.java From openhab1-addons with Eclipse Public License 2.0 | 4 votes |
@Override public void updated(Dictionary<String, ?> properties) throws ConfigurationException { // load broker configurations from configuration file if (properties == null || properties.isEmpty()) { return; } 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")) { int parsedQos = safeParseInt(property, value); if (parsedQos > -1) { conn.setQos(parsedQos); } } else if (property.equals("retain")) { if (validateBooleanSetting(property, value)) { conn.setRetain(Boolean.parseBoolean(value)); } } else if (property.equals("async")) { if (validateBooleanSetting(property, value)) { conn.setAsync(Boolean.parseBoolean(value)); } } else if (property.equals("clientId")) { if (value.length() > 65535) { logger.warn("clientId must be less than 65536 characters long"); throw new ConfigurationException("clientId", "clientId must be less than 65536 characters long"); } conn.setClientId(value); } else if (property.equals("allowLongerClientIds")) { if (validateBooleanSetting(property, value)) { conn.setAllowLongerClientIds(Boolean.parseBoolean(value)); } } else if (property.equals("lwt")) { MqttWillAndTestament will = MqttWillAndTestament.fromString(value); logger.debug("Setting last will: {}", will); conn.setLastWill(will); } else if (property.equals("keepAlive")) { int parsedKeepAlive = safeParseInt(property, value); if (parsedKeepAlive > -1) { conn.setKeepAliveInterval(parsedKeepAlive); } } 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", e); } } }