/*
 * @author Ranides Atterwim <ranides@gmail.com>
 * @copyright Ranides Atterwim
 * @license WTFPL
 * @url http://ranides.net/projects/assira
 */
package net.ranides.assira.xml.impl;

import java.util.function.Predicate;
import net.ranides.assira.xml.XMLContext;
import net.ranides.assira.xml.XMLElement;
import net.ranides.assira.xml.XMLElements;
import net.ranides.assira.xml.XMLSelector;

/**
 *
 * @author Ranides Atterwim <ranides@gmail.com>
 */
public class CContext implements XMLContext {
    
    private int index;
    private XMLElement node;
    
    @Override
    public XMLElement node() {
        return node;
    }

    @Override
    public int index() {
        return index;
    }
    
    boolean test(XMLElement node, Predicate<XMLContext> selector) {
        this.index++;
        this.node = node;
        return selector.test(this);
    }
    
    XMLElements select(XMLElement node, XMLSelector selector) {
        this.index++;
        this.node = node;
        return selector.apply(this);
    }
    
}
