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

com.github.simy4.xpath.view.BooleanView 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 BooleanView implements View {

    private static final BooleanView FALSE = new BooleanView(false);
    private static final BooleanView TRUE = new BooleanView(true);

    @SuppressWarnings("unchecked")
    public static  BooleanView of(boolean bool) {
        return (BooleanView) (bool ? TRUE : FALSE);
    }

    private final boolean bool;

    private BooleanView(boolean bool) {
        this.bool = bool;
    }

    @Override
    public int compareTo(View other) {
        final boolean thatBool = other.toBoolean();
        return (bool == thatBool) ? 0 : (bool ? 1 : -1);
    }

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

    @Override
    public double toNumber() {
        return bool ? 1.0 : 0.0;
    }

    @Override
    public String toString() {
        return Boolean.toString(bool);
    }

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

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

    @Override
    public int hashCode() {
        return bool ? 1 : 0;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy