示例#1
0
 /**
  * Returns object with specific ID.
  *
  * @param ID Id of the object that is to be returned.
  * @return the object with specified ID
  */
 public Object getObject(int ID) {
   ObjectEntry obj = objects.getById(ID);
   Object result = null;
   if (obj != null) {
     result = obj.getObject();
   }
   return result;
 }
示例#2
0
  /**
   * Returns a collection containing all instances of a given class object.
   *
   * @param name the name of the class object
   * @return a collection containing all instances of a given class object
   */
  public Collection<Object> getObjectsByClassName(String name) {
    ArrayList<Object> result = new ArrayList<Object>();

    for (ObjectEntry o : objects) {
      if (o.getObject() != null && o.getObject().getClass().getName().equals(name)) {
        result.add(o.getObject());
        //                System.out.println("TRUE: O1: " + o.getObject()
        //                        + ", " + o.getObject().getClass().getName()
        //                        + " O2: " + name);
      } else {
        //                System.out.println("FALSE: O1: " + o.getObject()
        //                        + ", " + o.getObject().getClass().getName()
        //                        + " O2: " + name);
      }
    }

    return result;
  }
示例#3
0
  /**
   * Returns a collection containing all instances controlled by this inspector.
   *
   * @return a collection containing all instances controlled by this inspector
   */
  public Collection<Object> getObjects() {
    ArrayList<Object> result = new ArrayList<Object>();

    for (ObjectEntry o : objects) {
      result.add(o.getObject());
    }

    return result;
  }
示例#4
0
  /**
   * Returns the ID of an object.
   *
   * @param o the object thats ID is to be returned
   * @return the ID of the object if the object could be found; <code>null</code> otherwise
   */
  public Integer getObjectID(Object o) {
    // search for an already existing reference to object o
    for (ObjectEntry oE : objects) {
      if (oE.getObject() == o) {
        //                System.out.println(">> Object found!");
        return oE.getID();
      }
    }

    return null;
  }
示例#5
0
  /**
   * Adds an object to the inspector.
   *
   * @param o the object that is to be added
   * @param objID the ID of the object (only used when loading from file or if replacing instance,
   *     because then we need to restore the ID) if <code>null</code> the id will be generated
   *     (usual case)
   * @return <code>true</code>, if successfully added, i.e. is not already atached to the inspector;
   *     <code>false</code> otherwise
   */
  public boolean addObject(Object o, Integer objID) {

    System.out.println(">> Add Object: " + o);

    boolean alreadyAdded = false;

    // search for an already existing reference to object o
    for (ObjectEntry oE : objects) {
      if (oE.getObject() == o) {
        System.out.println(" --> Object already added!");
        alreadyAdded = true;
        break;
      }
    }

    // Object annotations
    ObjectInfo objectInfo = null;

    Annotation[] objectAnnotations = o.getClass().getAnnotations();

    for (Annotation a : objectAnnotations) {
      if (a.annotationType().equals(ObjectInfo.class)) {
        objectInfo = (ObjectInfo) a;
        break;
      }
    }

    if (objectInfo != null && objectInfo.instances() <= numberOfInstances(o.getClass().getName())) {
      System.err.println(
          ">> Cannot add Object: only " + objectInfo.instances() + " instances allowed!");
      return false;
    }

    if (!alreadyAdded) {
      ObjectDescription oDesc = generateObjectDescription(o, objID, true);
      if (oDesc == null) {
        return false;
      }
      getObjectDescriptions().add(oDesc);
    } // end if(!alredyAdded)

    return !alreadyAdded;
  }