JAL-3246 JAL-3247 Reworked JVL files as getdown.txt config with limitations
[jalview.git] / getdown / src / getdown / core / src / main / java / com / threerings / getdown / util / Config.java
index 4fc5e16..6f99fa6 100644 (file)
@@ -373,6 +373,72 @@ public class Config
         String os = bits[0], arch = (bits.length > 1) ? bits[1] : "";
         return (osname.indexOf(os) != -1) && (osarch.indexOf(arch) != -1);
     }
+    
+    public void mergeConfig(Config newValues, boolean merge) {
+      
+      for (Map.Entry<String, Object> entry : newValues.getData().entrySet()) {
+        
+        String key = entry.getKey();
+        Object nvalue = entry.getValue();
+
+        if (!merge || key.equals("appbase")) {
+          _data.put(key, nvalue);
+        } else {
+          
+          // merge
+          
+          Object value = _data.get(key);
+          
+          if (value == null) {
+            _data.put(key, nvalue);
+          } else if (value instanceof String) {
+            if (nvalue instanceof String) {
+              
+              // value is String, nvalue is String
+              _data.put(key, new String[] { (String)value, (String)nvalue });
+              
+            } else if (nvalue instanceof String[]) {
+              
+              // value is String, nvalue is String[]
+              String[] nvalues = (String[])nvalue;
+              String[] newvalues = new String[nvalues.length+1];
+              newvalues[0] = (String)value;
+              System.arraycopy(nvalues, 0, newvalues, 1, nvalues.length);
+              _data.put(key, newvalues);
+              
+            }
+          } else if (value instanceof String[]) {
+            if (nvalue instanceof String) {
+              
+              // value is String[], nvalue is String
+              String[] values = (String[])value;
+              String[] newvalues = new String[values.length+1];
+              System.arraycopy(values, 0, newvalues, 0, values.length);
+              newvalues[values.length] = (String)nvalue;
+              _data.put(key, newvalues);
+              
+            } else if (nvalue instanceof String[]) {
+              
+              // value is String[], nvalue is String[]
+              String[] values = (String[])value;
+              String[] nvalues = (String[])nvalue;
+              String[] newvalues = new String[values.length + nvalues.length];
+              System.arraycopy(values, 0, newvalues, 0, values.length);
+              System.arraycopy(nvalues, 0, newvalues, values.length, newvalues.length);
+              _data.put(key, newvalues);
+              
+            }
+          }
+          
+        }
+
+      }
+      
+    }
+    
+    public Map<String, Object> getData() {
+      return _data;
+    }
 
     private final Map<String, Object> _data;
 }