Example #1
0
 private List<ObjectInstance> objectListDifference(
     List<ObjectInstance> objects, List<String> toRemove) {
   List<ObjectInstance> remaining = new ArrayList<ObjectInstance>(objects.size());
   for (ObjectInstance oi : objects) {
     String oname = oi.getName();
     if (!toRemove.contains(oname)) {
       remaining.add(oi);
     }
   }
   return remaining;
 }
Example #2
0
  /**
   * This method computes a matching from objects in the receiver to value-identical objects in the
   * parameter state so. The matching is returned as a map from the object names in the receiving
   * state to the matched objects in state so. If enforceStateExactness is set to true, then the
   * returned matching will be an empty map if the two states are not OO-MDP-wise identical (i.e.,
   * if there is a not a bijection between value-identical objects of the two states). If
   * enforceExactness is false and the states are not identical, the the method will return the
   * largest matching between objects that can be made.
   *
   * @param so the state to whose objects the receiving state's objects should be matched
   * @param enforceStateExactness whether to require that states are identical to return a matching
   * @return a matching from this receiving state's objects to objects in so that have identical
   *     values.
   */
  public Map<String, String> getObjectMatchingTo(State so, boolean enforceStateExactness) {

    Map<String, String> matching = new HashMap<String, String>();

    if (this.numTotalObjets() != so.numTotalObjets() && enforceStateExactness) {
      return new HashMap<String, String>(); // states are not equal and therefore cannot be matched
    }

    Set<String> matchedObs = new HashSet<String>();

    for (List<ObjectInstance> objects : objectIndexByTrueClass.values()) {

      String oclass = objects.get(0).getTrueClassName();
      List<ObjectInstance> oobjects = so.getObjectsOfTrueClass(oclass);
      if (objects.size() != oobjects.size() && enforceStateExactness) {
        return new HashMap<
            String, String>(); // states are not equal and therefore cannot be matched
      }

      for (ObjectInstance o : objects) {
        boolean foundMatch = false;
        for (ObjectInstance oo : oobjects) {
          if (matchedObs.contains(oo.getName())) {
            continue; // already matched this one; check another
          }
          if (o.valueEquals(oo)) {
            foundMatch = true;
            matchedObs.add(oo.getName());
            matching.put(o.getName(), oo.getName());
            break;
          }
        }
        if (!foundMatch && enforceStateExactness) {
          return new HashMap<
              String, String>(); // states are not equal and therefore cannot be matched
        }
      }
    }

    return matching;
  }
Example #3
0
  @Override
  public boolean equals(Object other) {

    if (this == other) {
      return true;
    }

    if (!(other instanceof State)) {
      return false;
    }

    State so = (State) other;

    if (this.numTotalObjets() != so.numTotalObjets()) {
      return false;
    }

    Set<String> matchedObjects = new HashSet<String>();
    for (List<ObjectInstance> objects : objectIndexByTrueClass.values()) {

      String oclass = objects.get(0).getTrueClassName();
      List<ObjectInstance> oobjects = so.getObjectsOfTrueClass(oclass);
      if (objects.size() != oobjects.size()) {
        return false;
      }

      for (ObjectInstance o : objects) {
        boolean foundMatch = false;
        for (ObjectInstance oo : oobjects) {
          String ooname = oo.getName();
          if (matchedObjects.contains(ooname)) {
            continue;
          }
          if (o.valueEquals(oo)) {
            foundMatch = true;
            matchedObjects.add(ooname);
            break;
          }
        }
        if (!foundMatch) {
          return false;
        }
      }
    }

    return true;
  }
Example #4
0
  /**
   * Adds object instance o to this state.
   *
   * @param o the object instance to be added to this state.
   */
  public void addObject(ObjectInstance o) {

    String oname = o.getName();

    if (objectMap.containsKey(oname)) {
      return; // don't add an object that conflicts with another object of the same name
    }

    objectMap.put(oname, o);

    if (o.getObjectClass().hidden) {
      hiddenObjectInstances.add(o);
    } else {
      objectInstances.add(o);
    }

    this.addObjectClassIndexing(o);
  }
Example #5
0
  /**
   * Removes the object instance o from this state.
   *
   * @param o the object instance to remove from this state.
   */
  public void removeObject(ObjectInstance o) {
    if (o == null) {
      return;
    }

    String oname = o.getName();

    if (!objectMap.containsKey(oname)) {
      return; // make sure we're removing something that actually exists in this state!
    }

    if (o.getObjectClass().hidden) {
      hiddenObjectInstances.remove(o);
    } else {
      objectInstances.remove(o);
    }

    objectMap.remove(oname);

    this.removeObjectClassIndexing(o);
  }
Example #6
0
 /**
  * Renames the identifier for object instance o in this state to newName.
  *
  * @param o the object instance to rename in this state
  * @param newName the new name of the object instance
  */
 public void renameObject(ObjectInstance o, String newName) {
   String originalName = o.getName();
   o.setName(newName);
   objectMap.remove(originalName);
   objectMap.put(newName, o);
 }