1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.configuration;
18
19 import java.util.Iterator;
20
21 /***
22 * Strict comparator for configurations.
23 *
24 * @since 1.0
25 *
26 * @author <a href="mailto:herve.quiroz@esil.univ-mrs.fr">Herve Quiroz</a>
27 * @author <a href="mailto:shapira@mpi.com">Yoav Shapira</a>
28 * @version $Revision$, $Date: 2005-02-26 13:56:39 +0100 (Sat, 26 Feb 2005) $
29 */
30 public class StrictConfigurationComparator implements ConfigurationComparator
31 {
32 /***
33 * Create a new strict comparator.
34 */
35 public StrictConfigurationComparator()
36 {
37 }
38
39 /***
40 * Compare two configuration objects.
41 *
42 * @param a the first configuration
43 * @param b the second configuration
44 * @return true if keys from a are found in b and keys from b are
45 * found in a and for each key in a, the corresponding value
46 * is the sale in for the same key in b
47 */
48 public boolean compare(Configuration a, Configuration b)
49 {
50 if (a == null && b == null)
51 {
52 return true;
53 }
54 else if (a == null || b == null)
55 {
56 return false;
57 }
58
59 for (Iterator keys = a.getKeys(); keys.hasNext();)
60 {
61 String key = (String) keys.next();
62 Object value = a.getProperty(key);
63 if (!value.equals(b.getProperty(key)))
64 {
65 return false;
66 }
67 }
68
69 for (Iterator keys = b.getKeys(); keys.hasNext();)
70 {
71 String key = (String) keys.next();
72 Object value = b.getProperty(key);
73 if (!value.equals(a.getProperty(key)))
74 {
75 return false;
76 }
77 }
78
79 return true;
80 }
81 }