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

hydra.langs.shacl.model.Reference Maven / Gradle / Ivy

package hydra.langs.shacl.model;

import java.io.Serializable;

/**
 * Either an instance of a type like sh:Shape or sh:NodeShape, or an IRI which refers to an instance of that type
 */
public abstract class Reference implements Serializable {
  public static final hydra.core.Name NAME = new hydra.core.Name("hydra/langs/shacl/model.Reference");
  
  private Reference () {
  
  }
  
  public abstract  R accept(Visitor visitor) ;
  
  public interface Visitor {
    R visit(Named instance) ;
    
    R visit(Anonymous instance) ;
    
    R visit(Definition instance) ;
  }
  
  public interface PartialVisitor extends Visitor {
    default R otherwise(Reference instance) {
      throw new IllegalStateException("Non-exhaustive patterns when matching: " + (instance));
    }
    
    default R visit(Named instance) {
      return otherwise((instance));
    }
    
    default R visit(Anonymous instance) {
      return otherwise((instance));
    }
    
    default R visit(Definition instance) {
      return otherwise((instance));
    }
  }
  
  public static final class Named extends hydra.langs.shacl.model.Reference implements Serializable {
    public final hydra.langs.rdf.syntax.Iri value;
    
    public Named (hydra.langs.rdf.syntax.Iri value) {
      this.value = value;
    }
    
    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Named)) {
        return false;
      }
      Named o = (Named) (other);
      return value.equals(o.value);
    }
    
    @Override
    public int hashCode() {
      return 2 * value.hashCode();
    }
    
    @Override
    public  R accept(Visitor visitor) {
      return visitor.visit(this);
    }
  }
  
  /**
   * An anonymous instance
   */
  public static final class Anonymous extends hydra.langs.shacl.model.Reference implements Serializable {
    /**
     * An anonymous instance
     */
    public final A value;
    
    public Anonymous (A value) {
      this.value = value;
    }
    
    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Anonymous)) {
        return false;
      }
      Anonymous o = (Anonymous) (other);
      return value.equals(o.value);
    }
    
    @Override
    public int hashCode() {
      return 2 * value.hashCode();
    }
    
    @Override
    public  R accept(Visitor visitor) {
      return visitor.visit(this);
    }
  }
  
  /**
   * An inline definition
   */
  public static final class Definition extends hydra.langs.shacl.model.Reference implements Serializable {
    /**
     * An inline definition
     */
    public final hydra.langs.shacl.model.Definition value;
    
    public Definition (hydra.langs.shacl.model.Definition value) {
      this.value = value;
    }
    
    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Definition)) {
        return false;
      }
      Definition o = (Definition) (other);
      return value.equals(o.value);
    }
    
    @Override
    public int hashCode() {
      return 2 * value.hashCode();
    }
    
    @Override
    public  R accept(Visitor visitor) {
      return visitor.visit(this);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy