예제 #1
0
  private static Entity getEntity(String[] names, double simTime, Entity thisEnt, Entity objEnt)
      throws Error {

    Entity ent;
    if (names[0].equals("this")) ent = thisEnt;
    else if (names[0].equals("obj")) ent = objEnt;
    else ent = Entity.getNamedEntity(names[0]);

    if (ent == null) {
      throw new Error(String.format("Could not find entity: %s", names[0]));
    }
    // Run the output chain up to the second last name
    for (int i = 1; i < names.length - 1; ++i) {
      String outputName = names[i];
      OutputHandle oh = ent.getOutputHandle(outputName);
      if (oh == null) {
        throw new Error(
            String.format("Output '%s' not found on entity '%s'", outputName, ent.getInputName()));
      }
      if (!Entity.class.isAssignableFrom(oh.getReturnType())) {
        throw new Error(String.format("Output '%s' is not an entity output", outputName));
      }

      ent = oh.getValue(simTime, Entity.class);
    }
    return ent;
  }
예제 #2
0
    @Override
    public ExpResult getVariableValue(String[] names) {
      try {
        errorString = null;
        Entity ent = getEntity(names, simTime, thisEnt, objEnt);
        String outputName = names[names.length - 1];
        OutputHandle oh = ent.getOutputHandle(outputName);
        if (oh == null) {
          errorString =
              String.format(
                  "Could not find output '%s' on entity '%s'", outputName, ent.getInputName());
          return null;
        }
        return new ExpResult(oh.getValueAsDouble(simTime, 0));

      } catch (Exception e) {
        errorString = e.getMessage();
      }
      return null;
    }