use Appendable rather than StringBuffer for toJava()
[sbp.git] / src / edu / berkeley / sbp / ResultNode.java
1 // Copyright 2006-2007 all rights reserved; see LICENSE file for BSD-style license
2
3 package edu.berkeley.sbp;
4 import edu.berkeley.sbp.util.*;
5 import edu.berkeley.sbp.Sequence.Pos;
6 import edu.berkeley.sbp.Sequence.Pos;
7 import java.util.*;
8
9 final class ResultNode
10     extends Node<StateNode> {
11
12     private Pos reduction;
13     private Forest.Many f = new Forest.Many();
14
15     public void merge(Forest newf) { this.f.merge(newf); }
16     public Pos reduction() { return reduction; }
17     public boolean isDoomedState() { /* this is irrelevant */ return false; }
18     public Forest getForest() { return f; }
19     public String toString() { return super.toString()+"->"+phase(); }
20     public boolean hasPathToRoot() {
21         if (predecessorPhase()==null) return true;
22         return super.hasPathToRoot();
23     }
24
25     public void check() {
26         if (destroyed) return;
27         if (!hasSuccessors() || !hasPredecessors()) destroy();
28     }
29     protected void destroy() {
30         if (destroyed) return;
31         if (predecessorPhase()==null) return;  // never destroy the "primordeal" result
32         super.destroy();
33     }
34
35     protected void addPred(StateNode pred) {
36         super.addPred(pred);
37         // results should have at most one predecessor
38         //if (predecessors.size() > 1) throw new Error();
39     }
40         
41     public ResultNode() { this(null, null, null); }
42     public ResultNode(Forest f, Pos reduction, StateNode pred) {
43         super(pred==null ? null : pred.phase(),
44               pred==null ? null : pred.phase());
45         this.f.merge(f);
46         this.reduction = reduction;
47         if (pred != null) addPred(pred);
48     }
49 }