Esempio n. 1
0
  @Override
  public boolean equals(Object obj) {
    //		if (!(obj instanceof StackValue)) {
    //			return false;
    //		}
    if (this == obj) {
      return true;
    }

    if (obj instanceof StackValue) {
      StackValue stackValue = (StackValue) obj;

      boolean match = stackValue.getType() == type;
      if (!match) {
        return false;
      }

      switch (type) {
        case TYPE_STRING:
          match = string.equals(stackValue.getString());
          break;
        case TYPE_FLOAT:
          match = (floatValue == stackValue.getFloat());
          break;
        case TYPE_REGISTER:
          match = (registerNumber == stackValue.getRegisterNumber());
          break;
        case TYPE_BOOLEAN:
          match = (booleanValue == stackValue.getBoolean());
          break;
        case TYPE_DOUBLE:
          match = (doubleValue == stackValue.getDouble());
          break;
        case TYPE_INTEGER:
          match = (integerValue == stackValue.getInteger());
          break;
        case TYPE_CONSTANT_8:
          match = (constant8 == stackValue.getConstant8());
          break;
        case TYPE_CONSTANT_16:
          match = (constant16 == stackValue.getConstant16());
          break;
      }
      return match;
    } else if (obj instanceof NotOperation) {
      return obj.equals(this);
    } else {
      return false;
    }
  }
Esempio n. 2
0
 private static Element writePush(Element parentElement, Push push) {
   Element element = parentElement.addElement("push");
   List values = push.getValues();
   for (Iterator it = values.iterator(); it.hasNext(); ) {
     StackValue value = (StackValue) it.next();
     switch (value.getType()) {
       case StackValue.TYPE_BOOLEAN:
         element.addElement("boolean").addAttribute("value", Boolean.toString(value.getBoolean()));
         break;
       case StackValue.TYPE_CONSTANT_16:
         element
             .addElement("constant16")
             .addAttribute("id", Integer.toString(value.getConstant16()));
         break;
       case StackValue.TYPE_CONSTANT_8:
         element
             .addElement("constant8")
             .addAttribute("id", Integer.toString(value.getConstant8()));
         break;
       case StackValue.TYPE_DOUBLE:
         element.addElement("double").addAttribute("value", Double.toString(value.getDouble()));
         break;
       case StackValue.TYPE_FLOAT:
         element.addElement("float").addAttribute("value", Float.toString(value.getFloat()));
         break;
       case StackValue.TYPE_INTEGER:
         element.addElement("integer").addAttribute("value", Long.toString(value.getInteger()));
         break;
       case StackValue.TYPE_NULL:
         element.addElement("null");
         break;
       case StackValue.TYPE_REGISTER:
         element
             .addElement("register")
             .addAttribute("number", Short.toString(value.getRegisterNumber()));
         break;
       case StackValue.TYPE_STRING:
         element.addElement("string").addAttribute("value", value.getString());
         break;
       case StackValue.TYPE_UNDEFINED:
         element.addElement("undefined");
         break;
     }
   }
   return element;
 }