views:

275

answers:

2

Hello,

I was wondering if there is an easy way to convert the javafx.util.Properties object to a java.util.HashMap.

There is the obvious way of getting each value from the Properties object and putting it in a Map. But with a large number of properties it seems like there should be a way of just getting the Map that backs javafx.util.Properties (if it is a Map).

Thanks in advance for any suggestions.

+1  A: 

I don't really know if javafx.util.Properties are backed by Java Map, but since public API does not mention any way to get this map you probably shouldn't try to do it - even if it was possible (e.g. by extending Properties class) it might change in future versions.

I would stay with copying every element.

pazabo
A: 

+1 for pazabos answer. But I would go the other way around: extend HashMap or java.util.Properties which then could export javafx.util.Properties (or hold an instance) sth. like:

class MyProperties extends HashMap {
    HashSet<String> keys = new HashSet<String>();
    javafx.util.Properties p = new Properties();

    public String get(String str) {
        return p.get(str);
    }

    public Map creatHashMap() {
        Map map = new HashMap();
        for (String k : keys) {
            map.put(k, p.get(k));
        }
        return map;
    }

    public void put() {
        //...
    }
Karussell