示例#1
0
  /**
   * Adds an object to this inspector.
   *
   * @param o the object that is to be added
   * @param objID object id of the object that shall be replaced
   */
  public synchronized void replaceObject(Object newObj, int objID)
      throws InterfaceChangedException {

    if (newObj == null) {
      throw new IllegalArgumentException("Argument \"null\" not supported!");
    }

    // objects.getById(objID).setObject(newObj);
    Collection<Object> instances = getObjectsByClassName(newObj.getClass().getName());

    if (instances.size() <= objID) {
      addObject(newObj);
    } else {

      Object oldObj = getObject(objID);

      ObjectDescription oDescOld = getObjectDescription(oldObj);
      ObjectDescription oDescNew = generateObjectDescription(newObj, objID, false);

      if (oDescOld.getSignature().equals(oDescNew.getSignature())) {

        removeObject(objID);
        addObject(newObj, objID);
        objectDescriptions.add(oDescNew);
      } else {
        throw new InterfaceChangedException(
            "Cannot replace object because the interface of the new"
                + " class and the old class are not equal!");
      }
    }
  }
示例#2
0
  /**
   * Removes object with specific ID from the inspector.
   *
   * @param ID the ID of the object that is to be removed
   */
  public void removeObject(int ID) {

    // remove object entry
    ObjectEntry removedElement1 = null;
    for (ObjectEntry oEntry : objects) {
      if (oEntry.getID() == ID) {
        removedElement1 = oEntry;
        break;
      }
    }
    objects.remove(removedElement1);

    // remove object description
    ObjectDescription removedElement2 = null;
    for (ObjectDescription oDesc : objectDescriptions) {
      if (oDesc.getID() == ID) {
        removedElement2 = oDesc;
        break;
      }
    }
    objectDescriptions.remove(removedElement2);
  }