1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import java.util.HashMap;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Represents the server capabilities
|
---|
8 | *
|
---|
9 | */
|
---|
10 | public class Capabilities {
|
---|
11 | private HashMap<String, HashMap<String,String>> capabilities;
|
---|
12 |
|
---|
13 | public Capabilities() {
|
---|
14 | capabilities = new HashMap<String, HashMap<String,String>>();
|
---|
15 | }
|
---|
16 |
|
---|
17 | public boolean isDefined(String element, String attribute) {
|
---|
18 | if (! capabilities.containsKey(element)) return false;
|
---|
19 | HashMap<String, String> e = capabilities.get(element);
|
---|
20 | if (e == null) return false;
|
---|
21 | return (e.get(attribute) != null);
|
---|
22 | }
|
---|
23 |
|
---|
24 | public String get(String element, String attribute ) {
|
---|
25 | if (! capabilities.containsKey(element)) return null;
|
---|
26 | HashMap<String, String> e = capabilities.get(element);
|
---|
27 | if (e == null) return null;
|
---|
28 | return e.get(attribute);
|
---|
29 | }
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * replies the value of configuration item in the capabilities as
|
---|
33 | * double value
|
---|
34 | *
|
---|
35 | * @param element the name of the element
|
---|
36 | * @param attribute the name of the attribute
|
---|
37 | * @return the value; null, if the respective configuration item doesn't exist
|
---|
38 | * @throws NumberFormatException if the value is not a valid double
|
---|
39 | */
|
---|
40 | public Double getDouble(String element, String attribute) throws NumberFormatException {
|
---|
41 | String s = get(element, attribute);
|
---|
42 | if (s == null) return null;
|
---|
43 | return Double.parseDouble(s);
|
---|
44 | }
|
---|
45 |
|
---|
46 | public Long getLong(String element, String attribute) {
|
---|
47 | String s = get(element, attribute);
|
---|
48 | if (s == null) return null;
|
---|
49 | return Long.parseLong(s);
|
---|
50 | }
|
---|
51 |
|
---|
52 | public void put(String element, String attribute, String value) {
|
---|
53 | if (capabilities == null) {
|
---|
54 | capabilities = new HashMap<String, HashMap<String,String>>();
|
---|
55 | }
|
---|
56 | if (! capabilities.containsKey(element)) {
|
---|
57 | HashMap<String,String> h = new HashMap<String, String>();
|
---|
58 | capabilities.put(element, h);
|
---|
59 | }
|
---|
60 | HashMap<String, String> e = capabilities.get(element);
|
---|
61 | e.put(attribute, value);
|
---|
62 | }
|
---|
63 |
|
---|
64 | public void clear() {
|
---|
65 | capabilities = new HashMap<String, HashMap<String,String>>();
|
---|
66 | }
|
---|
67 |
|
---|
68 | public boolean supportsVersion(String version) {
|
---|
69 | return get("version", "minimum").compareTo(version) <= 0
|
---|
70 | && get("version", "maximum").compareTo(version) >= 0;
|
---|
71 | }
|
---|
72 |
|
---|
73 | }
|
---|