Exemple #1
0
  /**
   * Implementation of the OCL <tt>Collection::product(c : Collection(T2)) : Set(Tuple(first : T,
   * second : T2))</tt> operations.
   *
   * @param evalEnv the current evaluation environment (for construction of tuples)
   * @param env the current OCL environment (for introspection of the tuple type)
   * @param self the source collection
   * @param c another collection
   * @return the product of the collections
   */
  public static <PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> Set<Tuple<O, P>> product(
      EvaluationEnvironment<C, O, P, CLS, E> evalEnv,
      Environment<PK, C, O, P, EL, PM, S, COA, SSA, CT, CLS, E> env,
      Collection<?> self,
      Collection<?> c,
      C tupleType) {

    Set<Tuple<O, P>> result = createNewSet();

    Map<P, Object> propertyValues = new HashMap<P, Object>();
    P firstProperty = env.lookupProperty(tupleType, OCLStandardLibraryUtil.PRODUCT_FIRST);
    P secondProperty = env.lookupProperty(tupleType, OCLStandardLibraryUtil.PRODUCT_SECOND);

    for (Object next1 : self) {
      for (Object next2 : c) {
        propertyValues.put(firstProperty, next1);
        propertyValues.put(secondProperty, next2);

        result.add(evalEnv.createTuple(tupleType, propertyValues));
      }
    }

    return result;
  }