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

hydra.langs.rdf.syntax.IriOrLiteral Maven / Gradle / Ivy

package hydra.langs.rdf.syntax;

import java.io.Serializable;

/**
 * An IRI or a literal; this type is a convenience for downstream models like SHACL which may exclude blank nodes
 */
public abstract class IriOrLiteral implements Serializable {
  public static final hydra.core.Name NAME = new hydra.core.Name("hydra/langs/rdf/syntax.IriOrLiteral");
  
  private IriOrLiteral () {
  
  }
  
  public abstract  R accept(Visitor visitor) ;
  
  public interface Visitor {
    R visit(Iri instance) ;
    
    R visit(Literal instance) ;
  }
  
  public interface PartialVisitor extends Visitor {
    default R otherwise(IriOrLiteral instance) {
      throw new IllegalStateException("Non-exhaustive patterns when matching: " + (instance));
    }
    
    default R visit(Iri instance) {
      return otherwise((instance));
    }
    
    default R visit(Literal instance) {
      return otherwise((instance));
    }
  }
  
  public static final class Iri extends hydra.langs.rdf.syntax.IriOrLiteral implements Serializable {
    public final hydra.langs.rdf.syntax.Iri value;
    
    public Iri (hydra.langs.rdf.syntax.Iri value) {
      this.value = value;
    }
    
    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Iri)) {
        return false;
      }
      Iri o = (Iri) (other);
      return value.equals(o.value);
    }
    
    @Override
    public int hashCode() {
      return 2 * value.hashCode();
    }
    
    @Override
    public  R accept(Visitor visitor) {
      return visitor.visit(this);
    }
  }
  
  public static final class Literal extends hydra.langs.rdf.syntax.IriOrLiteral implements Serializable {
    public final hydra.langs.rdf.syntax.Literal value;
    
    public Literal (hydra.langs.rdf.syntax.Literal value) {
      this.value = value;
    }
    
    @Override
    public boolean equals(Object other) {
      if (!(other instanceof Literal)) {
        return false;
      }
      Literal o = (Literal) (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