source: josm/trunk/src/org/openstreetmap/josm/io/Capabilities.java@ 2001

Last change on this file since 2001 was 1691, checked in by Gubaer, 15 years ago

#2703: patch (slightly extended) by dmuecke
clean up: few issues in Capabilities and OsmApi

File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import java.util.HashMap;
5
6/**
7 * Represents the server capabilities
8 *
9 */
10public 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}
Note: See TracBrowser for help on using the repository browser.