예제 #1
0
  /**
   * Locate each unexpanded Structure|Sequence and: 1. check that none of its fields is referenced
   * => do not expand 2. add all of its fields as leaves Note that #2 may end up adding additional
   * leaf structs &/or seqs
   */
  public void expand() {
    // Create a queue of unprocessed leaf compounds
    Queue<DapVariable> queue = new ArrayDeque<DapVariable>();

    for (int i = 0; i < variables.size(); i++) {
      DapVariable var = variables.get(i);
      if (!var.isTopLevel()) continue;
      // prime the queue
      if (var.getSort() == DapSort.STRUCTURE || var.getSort() == DapSort.SEQUENCE) {
        DapStructure struct = (DapStructure) var; // remember Sequence subclass Structure
        if (expansionCount(struct) == 0) queue.add(var);
      }
    }
    // Process the queue in prefix order
    while (queue.size() > 0) {
      DapVariable vvstruct = queue.remove();
      DapStructure dstruct = (DapStructure) vvstruct;
      for (DapVariable field : dstruct.getFields()) {
        if (findVariableIndex(field) < 0) {
          // Add field as leaf
          this.segments.add(new Segment(field));
          this.variables.add(field);
        }
        if (field.getSort() == DapSort.STRUCTURE || field.getSort() == DapSort.SEQUENCE) {
          if (expansionCount((DapStructure) field) == 0) queue.add(field);
        }
      }
    }
    this.expansion = Expand.EXPANDED;
  }
예제 #2
0
 /**
  * Locate each Structure|Sequence and: 1. check that all of its fields are referenced recursively
  * and not constrained, otherwise ignore 2. contract by removing all of the fields of the
  * Structure or Sequence. This is intended to be (not quite) the dual of expand();
  */
 public void contract() {
   // Create a set of contracted compounds
   Set<DapStructure> contracted = new HashSet<>();
   for (int i = 0; i < variables.size(); i++) {
     DapVariable var = variables.get(i);
     if (var.isTopLevel()) {
       if (var.getSort() == DapSort.STRUCTURE || var.getSort() == DapSort.SEQUENCE) {
         contractR((DapStructure) var, contracted);
       }
     }
   }
   this.expansion = Expand.CONTRACTED;
 }