I've been updating some old code that uses Enumerations, to use an EntrySet instead. However, I get different results and I'm not sure why.
Several properties return different values when using the EntrySet. I choose the "Button.font" property as a simple example.
So the question is why is the value different when using an EntrySet?
import java.util.*;
import javax.swing.*;
import javax.swing.plaf.*;
public class UIManagerTest
{
public static void main(String[] args)
{
UIDefaults defaults = UIManager.getLookAndFeelDefaults();
String property = "Button.font";
// This works the way I want it to
useEnumeration(defaults, property);
// This doesn't work the way I want it to
useEntrySet(defaults, property);
}
public static void useEnumeration(UIDefaults defaults, String property)
{
for ( Enumeration enumm = defaults.keys(); enumm.hasMoreElements(); )
{
Object key = enumm.nextElement();
Object value = defaults.get( key );
if (key.toString().equals(property))
{
System.out.println("Enumeration: " + property + " : " + value);
}
}
}
public static void useEntrySet(UIDefaults defaults, String property)
{
for (Map.Entry e: defaults.entrySet())
{
Object key = e.getKey();
Object value = e.getValue();
if (key.toString().equals(property))
{
System.out.println("EntrySet : " + property + " : " + value);
}
}
}
}