Exemple #1
0
  /**
   * Merges two network configurations into a single configuraiton.
   *
   * @param base The base configuration.
   * @param merge The configuration to merge.
   * @return The combined configuration.
   */
  public static NetworkConfig mergeNetworks(NetworkConfig base, NetworkConfig merge) {
    if (!base.getName().equals(merge.getName())) {
      throw new IllegalArgumentException("Cannot merge networks of different names.");
    }

    for (ComponentConfig<?> component : merge.getComponents()) {
      if (!base.hasComponent(component.getName())) {
        base.addComponent(component);
      }
    }

    for (ConnectionConfig connection : merge.getConnections()) {
      boolean exists = false;
      for (ConnectionConfig existing : base.getConnections()) {
        if (existing.equals(connection)) {
          exists = true;
          break;
        }
      }
      if (!exists) {
        base.createConnection(connection);
      }
    }
    return base;
  }
  @Override
  public NetworkBuilder validate() {

    // Validate network
    Validators.validate(network, NetworkValidator.class);

    // Validate Components
    network
        .getComponents()
        .forEach(
            component -> {
              Validators.validate(component, ComponentValidator.class);

              // Validate component inputs
              component
                  .getInput()
                  .getPorts()
                  .forEach(port -> Validators.validate(port, PortValidator.class));

              // Validate component outputs
              component
                  .getOutput()
                  .getPorts()
                  .forEach(port -> Validators.validate(port, PortValidator.class));
            });

    // Validate connections
    network
        .getConnections()
        .forEach(connection -> Validators.validate(connection, ConnectionValidator.class));

    return this;
  }
Exemple #3
0
  /**
   * Unmerges one network configuration from another.
   *
   * @param base The base network configuration.
   * @param unmerge The configuration to extract.
   * @return The cleaned configuration.
   */
  public static NetworkConfig unmergeNetworks(NetworkConfig base, NetworkConfig unmerge) {
    if (!base.getName().equals(unmerge.getName())) {
      throw new IllegalArgumentException("Cannot merge networks of different names.");
    }

    for (ComponentConfig<?> component : unmerge.getComponents()) {
      base.removeComponent(component.getName());
    }

    for (ConnectionConfig connection : unmerge.getConnections()) {
      base.destroyConnection(connection);
    }
    return base;
  }