Example usage for org.apache.commons.collections15 IteratorUtils toList

List of usage examples for org.apache.commons.collections15 IteratorUtils toList

Introduction

In this page you can find the example usage for org.apache.commons.collections15 IteratorUtils toList.

Prototype

public static <E> List<E> toList(Iterator<E> iterator) 

Source Link

Document

Gets a list based on an iterator.

Usage

From source file:org.deri.iris.rules.compiler.RuleCompiler.java

/**
 * Compile a rule. No optimisations of any kind are attempted.
 * /* w  w  w  .  ja v  a2s .c  o m*/
 * @param rule The rule to be compiled
 * @return The compiled rule, ready to be evaluated
 * @throws EvaluationException If the query can not be compiled for any
 *             reason.
 */
public ICompiledRule compile(IRule rule) throws EvaluationException {
    LinkedHashMap<RuleElement, ILiteral> elementsToLiteral = compileBody(rule.getBody());
    List<RuleElement> elements = IteratorUtils.toList(elementsToLiteral.keySet().iterator());

    List<IVariable> variables;

    if (elements.size() == 0)
        variables = new ArrayList<IVariable>();
    else {
        RuleElement lastElement = elements.get(elements.size() - 1);
        variables = lastElement.getOutputVariables();
    }

    ILiteral headLiteral = rule.getHead().get(0);
    IAtom headAtom = headLiteral.getAtom();
    ITuple headTuple = headAtom.getTuple();

    HeadSubstituter substituter;

    // We create a special head substituter for rules with head
    // equality, that establishes equivalence relation between terms in the
    // equivalent terms data-structure.
    if (RuleHeadEquality.hasRuleHeadEquality(rule)) {
        substituter = new RuleHeadEqualitySubstituter(variables, headTuple, elementsToLiteral, mEquivalentTerms,
                mConfiguration);
    } else {
        substituter = new HeadSubstituter(variables, headTuple, elementsToLiteral, mConfiguration);
    }

    elements.add(substituter);

    //Amir added
    for (int e = 0; e < elements.size() - 2; e++) {
        RuleElement elt = elements.get(e);
        elt.FindIndices(elements);
    }

    return new CompiledRule(elements, headAtom.getPredicate(), headLiteral, mConfiguration);
}

From source file:org.deri.iris.rules.compiler.RuleCompiler.java

/**
 * Compile a query. No optimisations of any kind are attempted.
 * /*  w ww.  j  a  v a  2s  .c om*/
 * @param query The query to be compiled
 * @return The compiled query, ready to be evaluated
 * @throws EvaluationException If the query can not be compiled for any
 *             reason.
 */
public ICompiledRule compile(IQuery query) throws EvaluationException {
    List<RuleElement> elements = IteratorUtils.toList(compileBody(query.getLiterals()).keySet().iterator());

    return new CompiledRule(elements, null, null, mConfiguration);
}

From source file:org.openanzo.glitter.MockEngineConfig.java

@Override
public Iterable<TreeRewriter> getTreeRewriters() {
    if (rewriters == null)
        return super.getTreeRewriters();

    List<TreeRewriter> rewriterList = IteratorUtils.toList(super.getTreeRewriters().iterator());
    rewriterList.addAll(rewriters);//from ww  w.j  a v a2s.  c om
    return rewriterList;
}