/**
 * @license
 * Copyright 2017 The FOAM Authors. All Rights Reserved.
 * http://www.apache.org/licenses/LICENSE-2.0
 */

package foam.util;

public class SafetyUtil {
  public static int compare(Object o1 , Object o2) {
    if ( o1 == null && o2 == null ) return 0;
    if ( o2 == null ) return 1;
    if ( o1 == null ) return -1;

    if ( o1 instanceof Number && o2 instanceof Number ) {
      double d1 = ( (Number) o1 ).doubleValue();
      double d2 = ( (Number) o2 ).doubleValue();

      if ( d1 == d2 ) return  0;
      if ( d1  > d2 ) return  1;
      if ( d1  < d2 ) return -1;
    }

    return ((Comparable) o1).compareTo(o2);
  }

  public static Object deepClone(Object o) {
    if ( o == null ) return null;
    if ( o instanceof foam.core.FObject ) return ((foam.core.FObject)o).deepClone();
    if ( o.getClass().isArray() ) return foam.util.Arrays.deepClone(o);

    // TODO: Non FObjects arn't cloneable, should we throw?
    // Certainly not for immutable boxed types Int, String, Double, etc,
    // but maybe we should for types we don't know about.
    return o;
  }

  public static boolean isEmpty(String s) {
    return s == null || s.isEmpty();
  }
}

@@ -875,16 +875,191 @@
 lone(o);
+%0A    if ( o instanceof java.util.Map ) return deepCloneMap((java.util.Map)o);%0A    if ( o instanceof java.util.Collection ) return deepCloneCollection((java.util.Collection)o);
 %0A%0A    //
@@ -1258,24 +1258,988 @@
 urn o;%0A  %7D%0A%0A
+  public static java.util.Map deepCloneMap(java.util.Map o) %7B%0A    try %7B%0A      java.util.Map result = (java.util.Map)o.getClass().newInstance();%0A%0A      java.util.Iterator%3Cjava.util.Map.Entry%3E entries = o.entrySet().iterator();%0A%0A      while ( entries.hasNext() ) %7B%0A        java.util.Map.Entry entry = entries.next();%0A        Object value = deepClone(entry.getValue());%0A        result.put(entry.getKey(), value);%0A      %7D%0A%0A      return result;%0A    %7D catch(InstantiationException %7C IllegalAccessException e) %7B%0A      return null;%0A    %7D%0A  %7D%0A%0A  public static java.util.Collection deepCloneCollection(java.util.Collection o) %7B%0A    try %7B%0A      java.util.Collection result = (java.util.Collection)o.getClass().newInstance();%0A%0A      java.util.Iterator iter = o.iterator();%0A%0A      while ( iter.hasNext() ) %7B%0A        result.add(deepClone(iter.next()));%0A      %7D%0A%0A      return result;%0A    %7D catch(InstantiationException %7C IllegalAccessException e) %7B%0A      return null;%0A    %7D%0A  %7D%0A%0A
   public sta

Add deep cloning of java Maps and Collections.