Example #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;
  }
Example #2
0
 @Override
 public ComponentBuilder component(String name) {
   return new ComponentBuilderImpl(
       this, network.hasComponent(name) ? network.getComponent(name) : network.addComponent(name));
 }
Example #3
0
 @Override
 public ComponentBuilder component() {
   return new ComponentBuilderImpl(this, network.addComponent(UUID.randomUUID().toString()));
 }