File src/de/openrat/client/util/ParameterMap.java

Last commit: Fri Sep 30 22:45:01 2016 +0200	dankert	first version of the java api.
1 package de.openrat.client.util; 2 3 import java.io.UnsupportedEncodingException; 4 import java.net.URLEncoder; 5 import java.util.Collection; 6 import java.util.HashMap; 7 import java.util.Map; 8 9 public class ParameterMap 10 { 11 private Map<String, String> parameter = new HashMap<String, String>(); 12 13 /** 14 * @return 15 * @see java.util.Map#size() 16 */ 17 public int size() 18 { 19 return parameter.size(); 20 } 21 22 /** 23 * @param key 24 * @return 25 * @see java.util.Map#containsKey(java.lang.Object) 26 */ 27 public boolean containsKey(Object key) 28 { 29 return parameter.containsKey(key); 30 } 31 32 /** 33 * @param key 34 * @return 35 * @see java.util.Map#get(java.lang.Object) 36 */ 37 public String get(Object key) 38 { 39 return parameter.get(key); 40 } 41 42 /** 43 * @param key 44 * @param value 45 * @return 46 * @see java.util.Map#put(java.lang.Object, java.lang.Object) 47 */ 48 public String put(String key, String value) 49 { 50 value = urlEncode(value); 51 return parameter.put(key, value); 52 } 53 54 /** 55 * @return 56 * @see java.util.Map#values() 57 */ 58 public Collection<String> values() 59 { 60 return parameter.values(); 61 } 62 63 public String toQueryString() 64 { 65 66 return new MapConverter(parameter).convertMapToString("=", "&", false); 67 } 68 69 /** 70 * @param m 71 * @see java.util.Map#putAll(java.util.Map) 72 */ 73 public void putAll(ParameterMap other) 74 { 75 parameter.putAll(other.parameter); 76 } 77 78 /** 79 * 80 * @see java.util.Map#clear() 81 */ 82 public void clear() 83 { 84 parameter.clear(); 85 } 86 87 /** 88 * URL-Encoder. 89 * 90 * @param value 91 * @return url-encoded value 92 */ 93 private String urlEncode(String value) 94 { 95 96 String CHARSET_UTF8 = "UTF-8"; 97 98 try 99 { 100 return URLEncoder.encode(value, CHARSET_UTF8); 101 } 102 catch (UnsupportedEncodingException e) 103 { 104 // maybe... this would be strange 105 throw new IllegalStateException(CHARSET_UTF8 + " ist not supported by this VM"); 106 } 107 } 108 109 }
Download src/de/openrat/client/util/ParameterMap.java
History Fri, 30 Sep 2016 22:45:01 +0200 dankert first version of the java api.