下面列出了java.util.Dictionary#keys ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
static public void printDictionary(PrintWriter out, Dictionary<?, ?> d)
throws IOException
{
out.println("<table border=0>");
for (final Enumeration<?> e = d.keys(); e.hasMoreElements();) {
final Object key = e.nextElement();
final Object val = d.get(key);
out.println("<tr>");
out.println("<td valign=top>");
printObject(out, key);
out.println("</td>");
out.println("<td valign=top>");
printObject(out, val);
out.println("</td>");
out.println("</tr>");
}
out.println("</table>");
}
/**
* Returns the smallest value that has an entry in the label table.
*
* @return smallest value that has an entry in the label table, or
* null.
* @since 1.6
*/
protected Integer getLowestValue() {
Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
Enumeration keys = dictionary.keys();
Integer min = null;
while (keys.hasMoreElements()) {
Integer i = (Integer) keys.nextElement();
if (min == null || i < min) {
min = i;
}
}
return min;
}
/**
* Returns the biggest value that has an entry in the label table.
*
* @return biggest value that has an entry in the label table, or
* null.
* @since 1.6
*/
protected Integer getHighestValue() {
Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
Enumeration keys = dictionary.keys();
Integer max = null;
while (keys.hasMoreElements()) {
Integer i = (Integer) keys.nextElement();
if (max == null || i > max) {
max = i;
}
}
return max;
}
/**
* Returns the biggest value that has an entry in the label table.
*
* @return biggest value that has an entry in the label table, or
* null.
* @since 1.6
*/
protected Integer getHighestValue() {
Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
Enumeration keys = dictionary.keys();
Integer max = null;
while (keys.hasMoreElements()) {
Integer i = (Integer) keys.nextElement();
if (max == null || i > max) {
max = i;
}
}
return max;
}
public void paintInfo(Graphics g, double x, double y) {
StringBuffer sb = new StringBuffer();
sb.append(b.getLocation() + ", id=" + b.getBundleId() + "\n");
Dictionary<String, String> headers = b.getHeaders();
for(Enumeration<String> e = headers.keys(); e.hasMoreElements(); ) {
final String key = e.nextElement();
final String val = (String)headers.get(key);
sb.append(key + ": " + val + "\n");
}
spin.paintBox(sb.toString(), g, Color.white, Color.black, (int)x, (int)y,
.8, 300, 300);
}
/**
* Returns the smallest value that has an entry in the label table.
*
* @return smallest value that has an entry in the label table, or
* null.
* @since 1.6
*/
protected Integer getLowestValue() {
Dictionary dictionary = slider.getLabelTable();
if (dictionary == null) {
return null;
}
Enumeration keys = dictionary.keys();
Integer min = null;
while (keys.hasMoreElements()) {
Integer i = (Integer) keys.nextElement();
if (min == null || i < min) {
min = i;
}
}
return min;
}
/**
* Returns the biggest value that has an entry in the label table.
*
* @return biggest value that has an entry in the label table, or
* null.
*/
protected Integer getHighestValue ()
{
final Dictionary dictionary = component.getLabelTable ();
if ( dictionary == null )
{
return null;
}
final Enumeration keys = dictionary.keys ();
Integer max = null;
while ( keys.hasMoreElements () )
{
final Integer i = ( Integer ) keys.nextElement ();
if ( max == null || i > max )
{
max = i;
}
}
return max;
}
private void configure(UndertowHTTPServerEngine e, Dictionary<String, ?> properties) {
ThreadingParameters threading = createThreadingParameters(properties);
if (threading != null) {
e.setThreadingParameters(threading);
}
Enumeration<String> keys = properties.keys();
while (keys.hasMoreElements()) {
String k = keys.nextElement();
if ("continuationsEnabled".equals(k)) {
e.setContinuationsEnabled(Boolean.parseBoolean((String)properties.get(k)));
} else if ("maxIdleTime".equals(k)) {
e.setMaxIdleTime(Integer.parseInt((String)properties.get(k)));
}
}
}
protected int getHeightOfTallestLabel() {
Dictionary dictionary = slider.getLabelTable();
int tallest = 0;
if ( dictionary != null ) {
Enumeration keys = dictionary.keys();
while ( keys.hasMoreElements() ) {
JComponent label = (JComponent) dictionary.get(keys.nextElement());
tallest = Math.max( label.getPreferredSize().height, tallest );
}
}
return tallest;
}
<K, V> Map<K, V> toMap(Dictionary<K, V> properties, Map<K, V> map) {
if (properties != null) {
for (Enumeration<K> e = properties.keys(); e.hasMoreElements();) {
K key = e.nextElement();
map.put(key, properties.get(key));
}
}
return map;
}
/**
* Invoked by iPojo when one or several properties were updated from Config Admin.
* @param properties
*/
@Override
public void updateProperties( Dictionary<?,?> properties ) {
// Ignore iPojo properties
final List<String> propertiesToSkip = Arrays.asList(
"component",
"felix.fileinstall.filename" );
Map<String,String> map = new HashMap<> ();
for( Enumeration<?> en = properties.keys(); en.hasMoreElements(); ) {
Object key = en.nextElement();
String keyAsString = String.valueOf( key );
if( propertiesToSkip.contains( keyAsString ))
continue;
// "null" are not acceptable values in dictionaries
// (OSGi often use Hash tables)
Object value = properties.get( key );
map.put( keyAsString, String.valueOf( value ));
}
this.cache.clear();
this.cache.putAll( map );
this.logger.fine( "Preferences were updated in bulk mode." );
}
@SuppressWarnings("rawtypes")
private static String explode(Dictionary dictionary) {
Enumeration keys = dictionary.keys();
StringBuffer result = new StringBuffer();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
result.append(String.format("%s=%s", key, dictionary.get(key)));
if (keys.hasMoreElements()) {
result.append(", ");
}
}
return result.toString();
}
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
logger.debug(BINDING_NAME + " updated");
try {
// Process device configuration
if (config != null) {
String refreshIntervalString = (String) config.get("refresh");
if (StringUtils.isNotBlank(refreshIntervalString)) {
refreshInterval = Long.parseLong(refreshIntervalString);
}
// parse all configured receivers
// ( yamahareceiver:<uid>.host=10.0.0.2 )
Enumeration<String> keys = config.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
if (key.endsWith(CONFIG_KEY_HOST)) {
// parse host
String host = (String) config.get(key);
int separatorIdx = key.indexOf('.');
// no uid => one device => use default UID
String uid = separatorIdx == -1 ? DEFAULT_DEVICE_UID : key.substring(0, separatorIdx);
// proxy is stateless. keep them in a map in the
// binding.
proxies.put(uid, new YamahaReceiverProxy(host));
}
}
setProperlyConfigured(true);
}
} catch (Throwable t) {
logger.error("Error configuring " + getName(), t);
}
}
private static Integer getMaxSliderValue(JSlider slider) {
Dictionary dictionary = slider.getLabelTable();
if (dictionary != null) {
Enumeration keys = dictionary.keys();
int max = slider.getMinimum() - 1;
while (keys.hasMoreElements()) {
max = Math.max(max, ((Integer) keys.nextElement()).intValue());
}
if (max == slider.getMinimum() - 1) {
return null;
}
return new Integer(max);
}
return null;
}
protected int getWidthOfWidestLabel() {
Dictionary dictionary = slider.getLabelTable();
int widest = 0;
if ( dictionary != null ) {
Enumeration keys = dictionary.keys();
while ( keys.hasMoreElements() ) {
JComponent label = (JComponent) dictionary.get(keys.nextElement());
widest = Math.max( label.getPreferredSize().width, widest );
}
}
return widest;
}
protected int getWidthOfWidestLabel() {
Dictionary dictionary = slider.getLabelTable();
int widest = 0;
if ( dictionary != null ) {
Enumeration keys = dictionary.keys();
while ( keys.hasMoreElements() ) {
JComponent label = (JComponent) dictionary.get(keys.nextElement());
widest = Math.max( label.getPreferredSize().width, widest );
}
}
return widest;
}
/**
* @{inheritDoc
*/
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
if (config != null) {
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 matcher = EXTRACT_TV_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
logger.debug(
"given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
continue;
}
matcher.reset();
matcher.find();
String deviceId = matcher.group(1);
DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);
if (deviceConfig == null) {
deviceConfig = new DeviceConfig(deviceId);
deviceConfigCache.put(deviceId, deviceConfig);
}
String configKey = matcher.group(2);
String value = (String) config.get(key);
if ("host".equals(configKey)) {
deviceConfig.host = value;
} else if ("port".equals(configKey)) {
deviceConfig.port = Integer.valueOf(value);
} else {
throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
}
}
}
}
/**
* Paints the labels.
* @param g the graphics
*/
public void paintLabels( Graphics g ) {
Rectangle labelBounds = labelRect;
@SuppressWarnings("rawtypes")
Dictionary dictionary = slider.getLabelTable();
if ( dictionary != null ) {
Enumeration<?> keys = dictionary.keys();
int minValue = slider.getMinimum();
int maxValue = slider.getMaximum();
boolean enabled = slider.isEnabled();
while ( keys.hasMoreElements() ) {
Integer key = (Integer)keys.nextElement();
int value = key.intValue();
if (value >= minValue && value <= maxValue) {
JComponent label = (JComponent) dictionary.get(key);
label.setEnabled(enabled);
if (label instanceof JLabel) {
Icon icon = label.isEnabled() ? ((JLabel) label).getIcon() : ((JLabel) label).getDisabledIcon();
if (icon instanceof ImageIcon) {
// Register Slider as an image observer. It allows to catch notifications about
// image changes (e.g. gif animation)
Toolkit.getDefaultToolkit().checkImage(((ImageIcon) icon).getImage(), -1, -1, slider);
}
}
if ( slider.getOrientation() == JSlider.HORIZONTAL ) {
g.translate( 0, labelBounds.y );
paintHorizontalLabel( g, value, label );
g.translate( 0, -labelBounds.y );
}
else {
int offset = 0;
if (!BasicGraphicsUtils.isLeftToRight(slider)) {
offset = labelBounds.width -
label.getPreferredSize().width;
}
g.translate( labelBounds.x + offset, 0 );
paintVerticalLabel( g, value, label );
g.translate( -labelBounds.x - offset, 0 );
}
}
}
}
}
public void mergeConfiguration(Dictionary<String,?> configuration)
throws ConfigurationException
{
if (configuration == null) {
return;
}
final Enumeration<String> e = configuration.keys();
while (e.hasMoreElements()) {
final String key = e.nextElement();
final Object value = configuration.get(key);
try {
if (key.equals(PORT_KEY)) {
if (value instanceof Short) {
port = ((Short) value).intValue();
} else {
port = ((Integer) value).intValue();
}
TelnetConfig.configuration.put(key, value);
} else if (key.equals(HOST_KEY)) {
host = ((String) value);
TelnetConfig.configuration.put(key, value);
} else if (key.equals(UM_KEY)) {
um = ((Boolean) value).booleanValue();
TelnetConfig.configuration.put(key, value);
} else if (key.equals(REQUIRED_GROUP_KEY)) {
requiredGroup = ((String) value).trim();
TelnetConfig.configuration.put(key, value);
} else if (key.equals(FORBIDDEN_GROUP_KEY)) {
forbiddenGroup = ((String) value).trim();
TelnetConfig.configuration.put(key, value);
} else if (key.equals(BUSYWAIT_KEY)) {
busyWait = ((Boolean) value).booleanValue();
TelnetConfig.configuration.put(key, value);
} else if (key.equals(DEFAULT_USER_KEY)) {
defaultUser = ((String) value).trim();
TelnetConfig.configuration.put(key, value);
} else if (key.equals(DEFAULT_PASSWORD_KEY)) {
defaultPassword = ((String) value).trim();
TelnetConfig.configuration.put(key, value);
} else {
TelnetConfig.configuration.put(key, value);
}
} catch (final IndexOutOfBoundsException ioobe) {
throw new ConfigurationException(key, "Wrong type");
} catch (final ClassCastException cce) {
throw new ConfigurationException(key, "Wrong type: "
+ value.getClass().getName());
}
}
}
/**
* {@inheritDoc}
*/
@Override
public void updated(Dictionary<String, ?> config) throws ConfigurationException {
logger.debug("Configuration updated, config {}", config != null ? true : false);
if (config != null) {
if (deviceConfigCache == null) {
deviceConfigCache = new HashMap<String, DeviceConfig>();
}
String granularityString = (String) config.get("granularity");
if (StringUtils.isNotBlank(granularityString)) {
granularity = Integer.parseInt(granularityString);
}
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 matcher = EXTRACT_CONFIG_PATTERN.matcher(key);
if (!matcher.matches()) {
logger.warn(
"given config key '" + key + "' does not follow the expected pattern '<id>.<host|port>'");
continue;
}
matcher.reset();
matcher.find();
String deviceId = matcher.group(1);
DeviceConfig deviceConfig = deviceConfigCache.get(deviceId);
if (deviceConfig == null) {
logger.debug("Added new device {}", deviceId);
deviceConfig = new DeviceConfig(deviceId);
deviceConfigCache.put(deviceId, deviceConfig);
}
String configKey = matcher.group(2);
String value = (String) config.get(key);
if ("serialPort".equals(configKey)) {
deviceConfig.serialPort = value;
} else if ("host".equals(configKey)) {
deviceConfig.host = value;
} else if ("port".equals(configKey)) {
deviceConfig.port = Integer.valueOf(value);
} else {
throw new ConfigurationException(configKey, "the given configKey '" + configKey + "' is unknown");
}
}
setProperlyConfigured(true);
}
}