mikewalch commented on a change in pull request #902: fixes #894 merge 
SimpleConfiguration Objects
URL: https://github.com/apache/fluo/pull/902#discussion_r132228853
 
 

 ##########
 File path: 
modules/api/src/main/java/org/apache/fluo/api/config/SimpleConfiguration.java
 ##########
 @@ -250,6 +250,40 @@ public SimpleConfiguration subset(String prefix) {
     return new SimpleConfiguration(internalConfig.subset(prefix));
   }
 
+  /**
+   * @param fallback SimpleConfiguration to join together
+   * @return a new simple configuration that contains all of the current 
properties from this plus
+   *         the properties from fallback that are not present in this.
+   * 
+   * @since 1.2.0
+   */
+  public SimpleConfiguration orElse(SimpleConfiguration fallback) {
+    for (Map.Entry<String, String> entry : fallback.toMap().entrySet()) {
+      if (!this.containsKey(entry.getKey())) {
+        this.setProperty(entry.getKey(), entry.getValue());
+      }
+    }
+    return this;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(this.toString());
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (o == this) {
+      return true;
+    }
+
+    if (o instanceof SimpleConfiguration) {
+      SimpleConfiguration sc = (SimpleConfiguration) o;
+      return this.toString().equals(sc.toString());
 
 Review comment:
   I am not sure about checking for equality by comparing toString().  It 
relies on toString() method to be very consistent. Can properties be printed in 
a different order?  If so, comparing two identical configuration objects could 
return false.  For this comparison, you could convert each simple configuration 
to map, verify that the maps contain same number of entries, and verify that 
all properties & values in on sc matches the other.
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to