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

org.coode.oppl.generated.RegexpGeneratedVariable Maven / Gradle / Ivy

There is a newer version: 5.0.0
Show newest version
package org.coode.oppl.generated;

import static org.coode.oppl.utils.ArgCheck.checkNotNull;

import java.util.regex.Pattern;

import org.coode.oppl.ConstraintSystem;
import org.coode.oppl.ManchesterVariableSyntax;
import org.coode.oppl.Variable;
import org.coode.oppl.VariableVisitor;
import org.coode.oppl.VariableVisitorEx;
import org.coode.oppl.function.OPPLFunction;
import org.coode.oppl.variabletypes.VariableType;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLObject;

/** @author Luigi Iannone
 * @param 
 *            type */
public class RegexpGeneratedVariable implements Variable {
    private final OPPLFunction patternGeneratingOPPLFunction;
    private final String name;
    private final VariableType type;
    private final IRI iri;

    /** @param name
     *            name
     * @param type
     *            type
     * @param patternGeneratingOPPLFunction
     *            patternGeneratingOPPLFunction */
    public RegexpGeneratedVariable(String name, VariableType type,
            OPPLFunction patternGeneratingOPPLFunction) {
        this.name = checkNotNull(name, "name");
        this.type = checkNotNull(type, "type");
        this.patternGeneratingOPPLFunction = checkNotNull(patternGeneratingOPPLFunction,
                "patternGeneratingOPPLFunction");
        this.iri = IRI.create(ManchesterVariableSyntax.NAMESPACE + this.getName());
    }

    @Override
    public void accept(VariableVisitor visitor) {
        visitor.visit(this);
    }

    @Override
    public  T accept(VariableVisitorEx visitor) {
        return visitor.visit(this);
    }

    @Override
    public IRI getIRI() {
        return this.iri;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public VariableType getType() {
        return this.type;
    }

    @Override
    public String render(ConstraintSystem constraintSystem) {
        return String.format("%s:%s= MATCH (%s)", this.getName(), this.getType(), this
                .getPatternGeneratingOPPLFunction().render(constraintSystem));
    }

    /** @return the patternGeneratingOPPLFunction */
    public OPPLFunction getPatternGeneratingOPPLFunction() {
        return this.patternGeneratingOPPLFunction;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + (this.name == null ? 0 : this.name.hashCode());
        result = prime * result + (this.type == null ? 0 : this.type.hashCode());
        return result;
    }

    @Override
    public String toString() {
        return String.format("%s:%s", this.getName(), this.getType());
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (this.getClass() != obj.getClass()) {
            return false;
        }
        RegexpGeneratedVariable other = (RegexpGeneratedVariable) obj;
        if (this.name == null) {
            if (other.name != null) {
                return false;
            }
        } else if (!this.name.equals(other.name)) {
            return false;
        }
        if (this.type == null) {
            if (other.type != null) {
                return false;
            }
        } else if (!this.type.equals(other.type)) {
            return false;
        }
        return true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy