diff options
author | Pacien TRAN-GIRARD | 2014-05-04 17:37:41 +0200 |
---|---|---|
committer | Pacien TRAN-GIRARD | 2014-05-04 17:37:41 +0200 |
commit | 688634ae5a5aaf663159032e67d2132ea61c5d5f (patch) | |
tree | e0642498c904e8a9373df479239fbfc603a957d3 /src/net | |
parent | 780bae6cd1a4d2a81b8c3ed72ee5d73cee9b5ccb (diff) | |
download | esieequest-688634ae5a5aaf663159032e67d2132ea61c5d5f.tar.gz |
Implement "save" and "load"
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/pacien/util/CleanJSONObject.java | 48 | ||||
-rw-r--r-- | src/net/pacien/util/IntrinsicMap.java | 23 |
2 files changed, 63 insertions, 8 deletions
diff --git a/src/net/pacien/util/CleanJSONObject.java b/src/net/pacien/util/CleanJSONObject.java new file mode 100644 index 0000000..0982ca8 --- /dev/null +++ b/src/net/pacien/util/CleanJSONObject.java | |||
@@ -0,0 +1,48 @@ | |||
1 | package net.pacien.util; | ||
2 | |||
3 | import java.util.Collection; | ||
4 | import java.util.Map; | ||
5 | |||
6 | import org.json.simple.JSONObject; | ||
7 | |||
8 | public class CleanJSONObject extends JSONObject { | ||
9 | |||
10 | /** | ||
11 | * | ||
12 | */ | ||
13 | private static final long serialVersionUID = 6700060746446264070L; | ||
14 | |||
15 | public CleanJSONObject() { | ||
16 | super(); | ||
17 | } | ||
18 | |||
19 | @Override | ||
20 | public Object put(final String key, final Object value) { | ||
21 | if (value == null) { | ||
22 | return null; | ||
23 | } | ||
24 | return super.put(key, value); | ||
25 | } | ||
26 | |||
27 | public Object put(final String key, final Map<?, ?> map) { | ||
28 | if (map.isEmpty()) { | ||
29 | return null; | ||
30 | } | ||
31 | return super.put(key, map); | ||
32 | } | ||
33 | |||
34 | public Object put(final String key, final Collection<?> collection) { | ||
35 | if (collection.isEmpty()) { | ||
36 | return null; | ||
37 | } | ||
38 | return super.put(key, collection); | ||
39 | } | ||
40 | |||
41 | public Object put(final String key, final Object[] array) { | ||
42 | if (array.length == 0) { | ||
43 | return null; | ||
44 | } | ||
45 | return super.put(key, array); | ||
46 | } | ||
47 | |||
48 | } | ||
diff --git a/src/net/pacien/util/IntrinsicMap.java b/src/net/pacien/util/IntrinsicMap.java index a68dcbe..fe59ac2 100644 --- a/src/net/pacien/util/IntrinsicMap.java +++ b/src/net/pacien/util/IntrinsicMap.java | |||
@@ -3,12 +3,13 @@ | |||
3 | */ | 3 | */ |
4 | package net.pacien.util; | 4 | package net.pacien.util; |
5 | 5 | ||
6 | import java.util.Collection; | ||
6 | import java.util.HashMap; | 7 | import java.util.HashMap; |
7 | import java.util.Map; | 8 | import java.util.Map; |
8 | 9 | ||
9 | /** | 10 | /** |
10 | * @author pacien | 11 | * @author pacien |
11 | * | 12 | * |
12 | */ | 13 | */ |
13 | public class IntrinsicMap<K, V extends Mappable> extends HashMap<K, V> { | 14 | public class IntrinsicMap<K, V extends Mappable> extends HashMap<K, V> { |
14 | 15 | ||
@@ -27,14 +28,14 @@ public class IntrinsicMap<K, V extends Mappable> extends HashMap<K, V> { | |||
27 | /** | 28 | /** |
28 | * @param initialCapacity | 29 | * @param initialCapacity |
29 | */ | 30 | */ |
30 | public IntrinsicMap(int initialCapacity) { | 31 | public IntrinsicMap(final int initialCapacity) { |
31 | super(initialCapacity); | 32 | super(initialCapacity); |
32 | } | 33 | } |
33 | 34 | ||
34 | /** | 35 | /** |
35 | * @param m | 36 | * @param m |
36 | */ | 37 | */ |
37 | public IntrinsicMap(Map<? extends K, ? extends V> m) { | 38 | public IntrinsicMap(final Map<? extends K, ? extends V> m) { |
38 | super(m); | 39 | super(m); |
39 | } | 40 | } |
40 | 41 | ||
@@ -42,18 +43,24 @@ public class IntrinsicMap<K, V extends Mappable> extends HashMap<K, V> { | |||
42 | * @param initialCapacity | 43 | * @param initialCapacity |
43 | * @param loadFactor | 44 | * @param loadFactor |
44 | */ | 45 | */ |
45 | public IntrinsicMap(int initialCapacity, float loadFactor) { | 46 | public IntrinsicMap(final int initialCapacity, final float loadFactor) { |
46 | super(initialCapacity, loadFactor); | 47 | super(initialCapacity, loadFactor); |
47 | } | 48 | } |
48 | 49 | ||
49 | @SuppressWarnings("unchecked") | 50 | @SuppressWarnings("unchecked") |
50 | public V put(V value) { | 51 | public V put(final V value) { |
51 | return super.put((K) value.getKey(), value); | 52 | return super.put((K) value.getKey(), value); |
52 | } | 53 | } |
53 | 54 | ||
54 | @Override | 55 | @Override |
55 | public V put(K key, V value) { | 56 | public V put(final K key, final V value) { |
56 | return this.put(value); | 57 | return this.put(value); |
57 | } | 58 | } |
58 | 59 | ||
60 | public void putAll(final Collection<V> collection) { | ||
61 | for (final V value : collection) { | ||
62 | this.put(value); | ||
63 | } | ||
64 | } | ||
65 | |||
59 | } | 66 | } |