MapPropertySet.java
biz/hammurapi/properties/MapPropertySet.java
Violations
Inspector |
Message |
Severity |
Location |
Java Inspector 048 |
Copyrights information should be present in each file. |
1 |
|
Java Inspector 049 |
Use a Collection instead of arrays Object[] |
2 |
40:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
42:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
48:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
55:9
|
Java Inspector 089 |
Undocumented constructor |
2 |
59:9
|
Java Inspector 089 |
Undocumented method |
2 |
65:9
|
Java Inspector 089 |
Undocumented method |
2 |
73:9
|
Java Inspector 089 |
Undocumented method |
2 |
77:9
|
Java Inspector 089 |
Undocumented method |
2 |
81:9
|
Java Inspector 089 |
Undocumented method |
2 |
85:9
|
Java Inspector 089 |
Undocumented method |
2 |
112:9
|
Java Inspector 089 |
Undocumented method |
2 |
118:9
|
Java Inspector 089 |
Undocumented method |
2 |
122:9
|
Java Inspector 089 |
Method is not properly documented |
2 |
134:9
|
Java Inspector 089 |
Undocumented parameter otherSet |
2 |
134:9
|
Java Inspector 089 |
Undocumented method |
2 |
158:9
|
Java Inspector 089 |
Undocumented method |
2 |
182:9
|
Java Inspector 051 |
It is good practice to call in any case super() in a constructor. |
3 |
42:9
|
Java Inspector 051 |
It is good practice to call in any case super() in a constructor. |
3 |
48:9
|
Java Inspector 051 |
It is good practice to call in any case super() in a constructor. |
3 |
55:9
|
Java Inspector 051 |
It is good practice to call in any case super() in a constructor. |
3 |
59:9
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23package biz.hammurapi.properties;
24
25import java.util.HashMap;
26import java.util.HashSet;
27import java.util.Iterator;
28import java.util.Map;
29import java.util.Set;
30import java.util.Map.Entry;
31
32
33
34
35
36
37
38public class MapPropertySet implements PropertySet {
39 private Map map = new HashMap();
40 private PropertySet[] chain = {};
41
42 public MapPropertySet(PropertySet[] chain) {
43 if (chain!=null) {
44 this.chain = chain;
45 }
46 }
47
48 public MapPropertySet(Map source, PropertySet[] chain) {
49 this(chain);
50 if (source!=null) {
51 map.putAll(source);
52 }
53 }
54
55 public MapPropertySet() {
56
57 }
58
59 public MapPropertySet(Map source) {
60 if (source!=null) {
61 map.putAll(source);
62 }
63 }
64
65 public Set getPropertyNames() {
66 HashSet ret = new HashSet(map.keySet());
67 for (int i=0; i<chain.length; ++i) {
68 ret.addAll(chain[i].getPropertyNames());
69 }
70 return ret;
71 }
72
73 public PropertySet getSubset(String prefix) {
74 return new PropertySubSet(this, prefix);
75 }
76
77 public boolean remove(String name) {
78 return map.remove(name)!=null;
79 }
80
81 public void set(String name, Object value) {
82 map.put(name, value);
83 }
84
85 public Object get(String name) {
86 Object ret = map.get(name);
87 if (ret!=null) {
88 return ret;
89 }
90
91 Iterator mit = mounts.entrySet().iterator();
92 while (mit.hasNext()) {
93 Map.Entry mount= (Entry) mit.next();
94 if (name.startsWith((String) mount.getKey())) {
95 ret = ((PropertySet) mount.getValue()).get(name.substring(((String) mount.getKey()).length()));
96 if (ret!=null) {
97 return ret;
98 }
99 }
100 }
101
102 for (int i=0; i<chain.length; ++i) {
103 ret = chain[i].get(name);
104 if (ret!=null) {
105 return ret;
106 }
107 }
108
109 return ret;
110 }
111
112 public void clear() {
113 map.clear();
114 }
115
116 private Map mounts = new HashMap();
117
118 public void mount(String prefix, PropertySet source) {
119 mounts.put(prefix, source);
120 }
121
122 public void setAll(PropertySet source) {
123 Iterator nit = source.getPropertyNames().iterator();
124 while (nit.hasNext()) {
125 String pName = (String) nit.next();
126 set(pName, source.get(pName));
127 }
128 }
129
130
131
132
133
134 public boolean compareProperties(PropertySet otherSet) {
135 Set myNames = new HashSet(getPropertyNames());
136 Set otherNames = new HashSet(otherSet.getPropertyNames());
137 if (!myNames.equals(otherNames)) {
138 return false;
139 }
140
141 Iterator mnit = myNames.iterator();
142 while (mnit.hasNext()) {
143 String pName = (String) mnit.next();
144 Object myValue = get(pName);
145 Object otherValue = otherSet.get(pName);
146 if (myValue==null) {
147 if (otherValue!=null) {
148 return false;
149 }
150 } else if (!myValue.equals(otherValue)) {
151 return false;
152 }
153 }
154
155 return true;
156 }
157
158 public boolean containsAll(PropertySet subSet) {
159 Set myNames = new HashSet(getPropertyNames());
160 Set subsetNames = new HashSet(subSet.getPropertyNames());
161 if (!myNames.containsAll(subsetNames)) {
162 return false;
163 }
164
165 Iterator snit = subsetNames.iterator();
166 while (snit.hasNext()) {
167 String pName = (String) snit.next();
168 Object myValue = get(pName);
169 Object subsetValue = subSet.get(pName);
170 if (myValue==null) {
171 if (subsetValue!=null) {
172 return false;
173 }
174 } else if (!myValue.equals(subsetValue)) {
175 return false;
176 }
177 }
178
179 return true;
180 }
181
182 public Object get(String name, Object defaultValue) {
183 Object ret = get(name);
184 return ret == null ? defaultValue : ret;
185 }
186}
187
188