Java 类org.antlr.v4.runtime.misc.OrderedHashSet 实例源码

项目:codebuff    文件:Graph.java   
/** DFS-based topological sort.  A valid sort is the reverse of
 *  the post-order DFA traversal.  Amazingly simple but true.
 *  For sorting, I'm not following convention here since ANTLR
 *  needs the opposite.  Here's what I assume for sorting:
 *
 *    If there exists an edge u -> v then u depends on v and v
 *    must happen before u.
 *
 *  So if this gives nonreversed postorder traversal, I get the order
 *  I want.
 */
public List<T> sort() {
    Set<Node<T>> visited = new OrderedHashSet<Node<T>>();
    ArrayList<T> sorted = new ArrayList<T>();
    while ( visited.size() < nodes.size() ) {
        // pick any unvisited node, n
        Node<T> n = null;
        for (Node<T> tNode : nodes.values()) {
            n = tNode;
            if ( !visited.contains(n) ) break;
        }
        if (n!=null) { // if at least one unvisited
            DFS(n, visited, sorted);
        }
    }
    return sorted;
}
项目:codebuff    文件:LeftRecursionDetector.java   
/** enclosingRule calls targetRule. Find the cycle containing
 *  the target and add the caller.  Find the cycle containing the caller
 *  and add the target.  If no cycles contain either, then create a new
 *  cycle.
 */
protected void addRulesToCycle(Rule enclosingRule, Rule targetRule) {
    //System.err.println("left-recursion to "+targetRule.name+" from "+enclosingRule.name);
    boolean foundCycle = false;
    for (Set<Rule> rulesInCycle : listOfRecursiveCycles) {
        // ensure both rules are in same cycle
        if (rulesInCycle.contains(targetRule)) {
            rulesInCycle.add(enclosingRule);
            foundCycle = true;
        }
        if (rulesInCycle.contains(enclosingRule)) {
            rulesInCycle.add(targetRule);
            foundCycle = true;
        }
    }
    if ( !foundCycle ) {
        Set<Rule> cycle = new OrderedHashSet<Rule>();
        cycle.add(targetRule);
        cycle.add(enclosingRule);
        listOfRecursiveCycles.add(cycle);
    }
}
项目:poly-ql    文件:FormEventManager.java   
/**
 * Subscribes given component to given identifier. If there are no subscriptions
 * yet for this identifier, an entry in the subscriptions map is created.
 *
 * @param formComponent the component to subscribe.
 * @param identifier    the identifier the given component should be
 *                      subscribed to.
 */
private void subscribeComponentToIdentifier(AbstractFormComponent formComponent,
                                            String identifier) {
    if (hasSubscriptionsForIdentifier(identifier)) {
        subscriptions.get(identifier).add(formComponent);
    } else {
        HashSet<AbstractFormComponent> subscribedComponents =
                new OrderedHashSet<AbstractFormComponent>();
        subscribedComponents.add(formComponent);
        subscriptions.put(identifier, subscribedComponents);
    }
}
项目:poly-ql    文件:FormFrameBuilder.java   
private FormFrameBuilder(Form form, GUIController controller) {
    formComponents = new OrderedHashSet<AbstractFormComponent>();
    EvaluationVisitor evaluator = new EvaluationVisitor();
    FormEventManager eventManager = new FormEventManager(evaluator);
    formFrame = new FormFrame(form.getName(), evaluator, eventManager);
    AbstractFormComponent topComponent = form.getBody().accept(this);
    initValues();
    formFrame.initUI(topComponent, controller);
}
项目:codebuff    文件:RuleFunction.java   
/** Add local var decl */
public void addLocalDecl(Decl d) {
    if ( locals ==null ) locals = new OrderedHashSet<Decl>();
    locals.add(d);
    d.isLocal = true;
}
项目:codebuff    文件:CodeBlock.java   
/** Add local var decl */
public void addLocalDecl(Decl d) {
    if ( locals==null ) locals = new OrderedHashSet<Decl>();
    locals.add(d);
    d.isLocal = true;
}