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

com.github.simy4.xpath.view.LiteralView 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;

public final class LiteralView implements View {

    private final String literal;

    public LiteralView(String literal) {
        this.literal = literal;
    }

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

    @Override
    public boolean toBoolean() {
        return !literal.isEmpty();
    }

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

    @Override
    public String toString() {
        return literal;
    }

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

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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy