All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.simy4.xpath.view.NodeView Maven / Gradle / Ivy

There is a newer version: 2.3.9
Show newest version
package com.github.simy4.xpath.view;

import com.github.simy4.xpath.XmlBuilderException;
import com.github.simy4.xpath.navigator.Node;

import java.util.Collections;
import java.util.Iterator;

public final class NodeView implements IterableNodeView {

    private final N node;
    private boolean isNew;

    public NodeView(N node) {
        this(node, false);
    }

    public NodeView(N node, boolean isNew) {
        this.node = node;
        this.isNew = isNew;
    }

    @Override
    public int compareTo(View other) {
        return toString().compareTo(other.toString());
    }

    @Override
    public boolean toBoolean() {
        return true;
    }

    @Override
    public double toNumber() {
        try {
            return Double.parseDouble(node.getText());
        } catch (NumberFormatException nfe) {
            return Double.NaN;
        }
    }

    @Override
    public String toString() {
        return node.getText();
    }

    @Override
    public  T visit(ViewVisitor visitor) throws XmlBuilderException {
        return visitor.visit(this);
    }

    @Override
    public Iterator> iterator() {
        return Collections.singleton(this).iterator();
    }

    @Override
    public boolean equals(Object o) {
        return this == o || (o instanceof View && toString().equals(o.toString()));
    }

    @Override
    public int hashCode() {
        return toString().hashCode();
    }

    public N getNode() {
        return node;
    }

    public boolean isNew() {
        return isNew;
    }

    public void mark() {
        isNew = true;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy