Exemplo n.º 1
0
 protected void setSodaTestOn(STClass[] classes) {
   for (int i = 0; i < classes.length; i++) {
     try {
       Field field = classes[i].getClass().getDeclaredField("st");
       try {
         Platform4.setAccessible(field);
       } catch (Throwable t) {
         // JDK 1.x has no setAccessible
       }
       field.set(classes[i], this);
     } catch (Exception e) {
       System.err.println("Add the following line to Class " + classes[i].getClass().getName());
       System.err.println("public static transient SodaTest st;");
     }
   }
 }
Exemplo n.º 2
0
  public boolean isEqual(Object a_compare, Object a_with, String a_path, Stack a_stack) {
    if (a_path == null || a_path.length() < 1) {
      if (a_compare != null) {
        a_path = a_compare.getClass().getName() + ":";
      } else {
        if (a_with != null) {
          a_path = a_with.getClass().getName() + ":";
        }
      }
    }

    String path = a_path;

    if (a_compare == null) {
      return a_with == null;
    }
    if (a_with == null) {
      return false;
    }
    Class clazz = a_compare.getClass();
    if (clazz != a_with.getClass()) {
      return false;
    }

    if (isSimple(clazz)) {
      return a_compare.equals(a_with);
    }

    if (a_stack == null) {
      a_stack = new Stack();
    }

    // takes care of repeating calls to the same object
    if (a_stack.contains(a_compare)) {
      return true;
    }
    a_stack.push(a_compare);

    Field fields[] = clazz.getDeclaredFields();
    for (int i = 0; i < fields.length; i++) {
      if (storeableField(clazz, fields[i])) {
        Platform4.setAccessible(fields[i]);
        try {
          path = a_path + fields[i].getName() + ":";
          Object compare = fields[i].get(a_compare);
          Object with = fields[i].get(a_with);
          if (compare == null) {
            if (with != null) {
              return false;
            }
          } else if (with == null) {
            return false;
          } else {
            if (compare.getClass().isArray()) {
              if (!with.getClass().isArray()) {
                return false;
              } else {
                compare = normalizeNArray(compare);
                with = normalizeNArray(with);
                int len = Array.getLength(compare);
                if (len != Array.getLength(with)) {
                  return false;
                } else {
                  for (int j = 0; j < len; j++) {
                    Object elementCompare = Array.get(compare, j);
                    Object elementWith = Array.get(with, j);
                    //										if (l_persistentArray)
                    if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                      return false;
                    } else if (elementCompare == null) {
                      if (elementWith != null) {
                        return false;
                      }
                    } else if (elementWith == null) {
                      return false;
                    } else {
                      Class elementCompareClass = elementCompare.getClass();
                      if (elementCompareClass != elementWith.getClass()) {
                        return false;
                      }
                      if (hasPublicConstructor(elementCompareClass)) {
                        if (!isEqual(elementCompare, elementWith, path, a_stack)) {
                          return false;
                        }
                      } else if (!elementCompare.equals(elementWith)) {
                        return false;
                      }
                    }
                  }
                }
              }
            } else if (hasPublicConstructor(fields[i].getType())) {
              if (!isEqual(compare, with, path, a_stack)) {
                return false;
              }
            } else {
              if (!compare.equals(with)) {
                return false;
              }
            }
          }
        } catch (IllegalAccessException ex) {
          // probably JDK 1
          // never mind this field
          return true;
        } catch (Exception e) {
          System.err.println("STCompare failure executing path:" + path);
          e.printStackTrace();
          return false;
        }
      }
    }
    return true;
  }
Exemplo n.º 3
0
 protected static boolean jdkOK(Object obj) {
   return Platform4.jdk().ver() >= 2 || STClass1.class.isAssignableFrom(obj.getClass());
 }