All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dakusui.floorplan.utils.FloorPlanUtils Maven / Gradle / Ivy

Go to download

A library to model a heterogeneous and distributed software system for testing

There is a newer version: 5.1.1
Show newest version
package com.github.dakusui.floorplan.utils;

import com.github.dakusui.actionunit.core.Action;
import com.github.dakusui.floorplan.component.Attribute;
import com.github.dakusui.floorplan.component.Component;
import com.github.dakusui.floorplan.component.Configurator;
import com.github.dakusui.floorplan.component.Ref;
import com.github.dakusui.floorplan.core.Fixture;
import com.github.dakusui.floorplan.policy.Policy;

import java.util.Arrays;
import java.util.function.Function;

import static com.github.dakusui.actionunit.core.ActionSupport.parallel;
import static com.github.dakusui.actionunit.core.ActionSupport.sequential;
import static java.util.stream.Collectors.toList;

/**
 * A utility class that collects useful methods for users of the 'FloorPlan' library.
 */
public enum FloorPlanUtils {
  ;

  public static Action createGroupedAction(
      boolean parallel,
      Function, Action> actionFactoryCreator,
      Fixture fixture,
      Ref... refs
  ) {
    Action[] actions = Arrays.stream(
        refs
    ).map(
        fixture::lookUp
    ).map(
        actionFactoryCreator::apply
    ).collect(
        toList()
    ).toArray(
        new Action[refs.length]
    );
    return parallel ?
        parallel(actions) :
        sequential(actions);
  }

  @SuppressWarnings("unchecked")
  public static  T resolve(A attr, Configurator configurator, Policy policy) {
    return (T) Function.class.cast(Function.class.cast(configurator.resolverFor(attr, policy).apply(attr)).apply(configurator)).apply(policy);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy