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

import java.util.function.Predicate;
import net.ranides.assira.collection.maps.IntMap;
import net.ranides.assira.generic.EnumUtils;
import org.w3c.dom.Node;

/**
 *
 * @author ranides
 */
public enum XMLType implements Predicate<XMLContext> {
    
    /** The node is an <code>Element</code>. */
    ELEMENT(1),
    
    /** The node is an <code>Attr</code>. */
    ATTRIBUTE(2),
    
    /** The node is a <code>Text</code> node. */
    TEXT(3),
    
    /** The node is a <code>CDATASection</code>. */
    CDATA(4),
    
    /** The node is an <code>EntityReference</code>. */
    REFERENCE(5),
    
    /** The node is an <code>Entity</code>. */
    ENTITY(6),
    
    /** The node is a <code>ProcessingInstruction</code>.*/
    PROCESSING(7),
    
    /** The node is a <code>Comment</code>.*/
    COMMENT(8),
    
    /** The node is a <code>Document</code>.*/
    DOCUMENT(9),
    
    /** The node is a <code>DocumentType</code>.*/
    DOCTYPE(10),
    
    /** The node is a <code>DocumentFragment</code>.*/
    FRAGMENT(11),
    
    /** The node is a <code>Notation</code>.*/
    NOTATION(12),
    
    ;
    
    private static final IntMap<XMLType> MAP = EnumUtils.intmap(XMLType.class, n -> n.value);
    
    private final int value;

    private XMLType(int value) {
        this.value = value;
    }

    public static XMLType valueOf(Node node) {
        return valueOf(node.getNodeType());
    }
    
    public static XMLType valueOf(int value) {
        return MAP.get(value);
    }

    @Override
    public boolean test(XMLContext c) {
        return this.equals(c.node().nodetype());
    }
    
}
