示例#1
1
 @Override
 public int hashCode() {
   return System.identityHashCode(type)
       + Arrays.deepHashCode(elements)
       + (enumConstant != null ? enumConstant.hashCode() : 0)
       + (values != null ? values.hashCode() : 0)
       + (superObject != null ? superObject.hashCode() : 0);
 }
 static void setElements(RawObject collection, Object[] elements) {
   RawObject value = null;
   while (value == null && collection != null) {
     Map<String, Object> values = collection.getValues();
     if (values != null) {
       value = (RawObject) values.get("elements");
       if (value != null) {
         values.put("elements", new RawObject(value.getType(), elements));
       } else {
         collection = collection.getSuper();
       }
     }
   }
   if (value == null) {
     throw new IllegalStateException();
   }
 }
示例#3
0
  private void formatRawObject(StringBuilder buf, String indent, String id, boolean isSuper) {
    if (type.isEnum()) {
      buf.append(indent);
      buf.append("<Enum");
      formatId(buf, id);
      buf.append(" class=\"");
      buf.append(type.getClassName());
      buf.append("\" typeId=\"");
      buf.append(type.getId());
      buf.append("\">");
      buf.append(enumConstant);
      buf.append("</Enum>\n");
    } else {
      String indent2 = indent + INDENT;
      String endTag;
      buf.append(indent);
      if (type.isArray()) {
        buf.append("<Array");
        endTag = "</Array>";
      } else if (isSuper) {
        buf.append("<Super");
        endTag = "</Super>";
      } else {
        buf.append("<Object");
        endTag = "</Object>";
      }
      formatId(buf, id);
      if (type.isArray()) {
        buf.append(" length=\"");
        buf.append(elements.length);
        buf.append('"');
      }
      buf.append(" class=\"");
      buf.append(type.getClassName());
      buf.append("\" typeId=\"");
      buf.append(type.getId());
      buf.append("\">\n");

      if (superObject != null) {
        superObject.formatRawObject(buf, indent2, null, true);
      }
      if (type.isArray()) {
        for (int i = 0; i < elements.length; i += 1) {
          formatValue(buf, indent2, String.valueOf(i), elements[i]);
        }
      } else {
        TreeSet<String> keys = new TreeSet<String>(values.keySet());
        for (String name : keys) {
          formatValue(buf, indent2, name, values.get(name));
        }
      }
      buf.append(indent);
      buf.append(endTag);
      buf.append("\n");
    }
  }
 static Object[] getElements(RawObject collection) {
   Object value = null;
   while (value == null && collection != null) {
     Map<String, Object> values = collection.getValues();
     if (values != null) {
       value = values.get("elements");
       if (value == null) {
         collection = collection.getSuper();
       }
     }
   }
   if (value == null || !(value instanceof RawObject)) {
     throw new IllegalStateException(
         "Collection proxy for a secondary key field must " + "contain a field named 'elements'");
   }
   RawObject rawObj = (RawObject) value;
   Format format = (Format) rawObj.getType();
   if (!format.isArray() || format.getComponentType().getId() != Format.ID_OBJECT) {
     throw new IllegalStateException("Collection proxy 'elements' field must by an Object array");
   }
   return rawObj.getElements();
 }
示例#5
0
 @Override
 public boolean equals(Object other) {
   if (other == this) {
     return true;
   }
   if (!(other instanceof RawObject)) {
     return false;
   }
   RawObject o = (RawObject) other;
   if (type != o.type) {
     return false;
   }
   if (!Arrays.deepEquals(elements, o.elements)) {
     return false;
   }
   if (enumConstant != null) {
     if (!enumConstant.equals(o.enumConstant)) {
       return false;
     }
   } else {
     if (o.enumConstant != null) {
       return false;
     }
   }
   if (values != null) {
     if (!values.equals(o.values)) {
       return false;
     }
   } else {
     if (o.values != null) {
       return false;
     }
   }
   if (superObject != null) {
     if (!superObject.equals(o.superObject)) {
       return false;
     }
   } else {
     if (o.superObject != null) {
       return false;
     }
   }
   return true;
 }
示例#6
0
 private static void formatValue(StringBuilder buf, String indent, String id, Object val) {
   if (val == null) {
     buf.append(indent);
     buf.append("<Null");
     formatId(buf, id);
     buf.append("/>\n");
   } else if (val instanceof RawObject) {
     ((RawObject) val).formatRawObject(buf, indent, id, false);
   } else {
     buf.append(indent);
     buf.append("<Value");
     formatId(buf, id);
     buf.append(" class=\"");
     buf.append(val.getClass().getName());
     buf.append("\">");
     buf.append(val.toString());
     buf.append("</Value>\n");
   }
 }
 public int getKey(RawObject o) {
   Object val = o.getValues().get("key");
   return ((Integer) val).intValue();
 }