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

edu.uci.qa.performancedriver.thread.TreeNode Maven / Gradle / Ivy

The newest version!
package edu.uci.qa.performancedriver.thread;

import edu.uci.qa.performancedriver.component.CloneableComponent;
import edu.uci.qa.performancedriver.component.Component;
import edu.uci.qa.performancedriver.component.ComponentType;
import edu.uci.qa.performancedriver.event.EventService;
import edu.uci.qa.performancedriver.event.tree.ResultEvent;
import edu.uci.qa.performancedriver.result.Result;
import edu.uci.qa.performancedriver.result.ResultFactory;

final class TreeNode {
  int size = 0;
  boolean last;
  
  private int id;
  private ComponentType type;
  private Component value;
  private ResultFactory factory;
  
  TreeNode(TreeNode other) {
    value = (other.value instanceof CloneableComponent
        ? ((CloneableComponent)other.value).clone() : other.value);
    factory = other.factory;
    size = other.size;
    last = other.last;
    type = other.type;
    id = other.id;
  }
   
  TreeNode(Component value, ComponentType type, ResultFactory factory, int id) {
    this.value = value;
    this.type = type;
    this.factory = factory;
    this.id = id;
  }
  
  TreeNode(Component value, ComponentType type, ResultFactory factory, int id, boolean last,
      int size) {
    this(value, type, factory, id);
    this.last = last;
    this.size = size;
  }
  
  R run(ResultId id) {
    R data = factory.create(id);
    if (type != ComponentType.NORMAL) {
      data.disable(true);
    }
    data.setStartTime();
    data = value.run(data);
    if (data.getEndTime() <= 0) {
      data.setEndTime();
    }
    if (!data.isDisabled()) {
      EventService.queueEvent(new ResultEvent(data));
    }
    return data;
  }
  
  ComponentType type() {
    return type;
  }
  
  Component value() {
    return value;
  }
  
  int getId() {
    return id;
  }
  
  ResultFactory factory() {
    return factory;
  }
  
  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("TreeNode[");
    sb.append("id: '" + id + "',");
    sb.append(" type: '" + type + "',");
    sb.append(" last: '" + last + "',");
    sb.append(" size: '" + size + "'");
    sb.append("]");
    return sb.toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy