Package plugin.graph

Source Code of plugin.graph.Graph

package plugin.graph;

import backend.controller.BackendLogger;
import plugin.common.*;
import plugin.communicationdata.taggedtypes.TaggedType;
import plugin.connector.*;
import plugin.controller.PluginController;

/**
* Represents the connection between Plugins via Ports as a bipartite
* multigraph.
*
* @author skomp
*
*/
public class Graph {

  private int capacity = 10;

  private int size = 0;

  private TaggedType[][][] graph = new TaggedType[10][10][TaggedType.values().length];

  private Plugin[] plugins = new Plugin[10];

  private Port[] ports = new Port[10];

  public Graph() {

  }

  /**
   * removes a Plugin a its input Port from the graph
   *
   * @param connected
   * @return
   */
  private Port getInputPort(Plugin connected) {
    for (int i = 0; i < size; i++) {
      if (plugins[i] == connected) {
        return ports[i];
      }
    }
    return null;
  }

  protected synchronized boolean addPlugin(Plugin toAdd)
      throws UndefinedTaggedTypeException {
    assert toAdd != null;
    plugins[size] = toAdd;
    TaggedType in = PluginController.getInstance().getPluginIO(toAdd).get(
        "In")[0];
    switch (in) {
    case NULL:
      plugins[size] = toAdd;
      break;
    case VECTOR:
      ports[size] = PortFactory.createPort(PluginController.getInstance()
          .getPluginIO(toAdd).get("In"));
      plugins[size] = toAdd;
      size++;
      break;
    case DOUBLE:
    case INT:
    case STRING:
    case LONG:
      plugins[size] = toAdd;
      try {
        ports[size] = PortFactory.createPort(in);
      } catch (UndefinedTaggedTypeException e) {
        BackendLogger.getInstance().throwing(
            this.getClass().toString(), "addPlugin(" + toAdd + ")",
            e);
        e.printStackTrace();
        plugins[size] = null;
        return false;
      }
      size++;
      break;
    default:
      throw new UndefinedTaggedTypeException(in.toString());
    }
    if (size > capacity * .7) {
      resize();
    }
    return true;
  }

  protected synchronized void removePlugin(Plugin toRemove) {

  }

  private void resize() {
    Plugin[] plgtmp = new Plugin[capacity = capacity * 2];
    Port[] prttmp = new Port[capacity];
    TaggedType[][][] tttmp = new TaggedType[capacity][capacity][graph[0][0].length];
    for (int i = 0; i < size; i++) {
      plgtmp[i] = plugins[i];
      prttmp[i] = prttmp[i];
      for (int j = 0; j < size; j++) {
        for (int k = 0; k < graph[0][0].length; k++) {
          tttmp[i][j][k] = graph[i][j][k];
        }
      }
    }
    plugins = plgtmp;
    ports = prttmp;
    graph = tttmp;
  }

}
TOP

Related Classes of plugin.graph.Graph

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.