001package de.monochromata.anaphors; 002 003import java.io.Serializable; 004 005import de.monochromata.anaphors.ast.AnaphorPart; 006import de.monochromata.anaphors.ast.RelatedExpressionPart; 007 008public class Anaphora implements Serializable { 009 010 private static final long serialVersionUID = -3898185327820196066L; 011 public final String kindOfRelatedExpression; 012 public final String kindOfAnaphorResolution; 013 public final String kindOfReferentialization; 014 public final String kind; 015 public final String anaphor; 016 017 /** 018 * Used in contract testing. 019 */ 020 @SuppressWarnings("unused") 021 protected Anaphora() { 022 this(null, null, null, null); 023 } 024 025 public Anaphora(final RelatedExpressionPart<?, ?, ?, ?, ?, ?, ?, ?, ?> relatedExpressionPart, 026 final AnaphorPart<?, ?, ?, ?, ?, ?, ?, ?, ?, ?> anaphorPart) { 027 this(relatedExpressionPart.getRelatedExpressionStrategy().getKind(), 028 anaphorPart.getAnaphorResolutionStrategy().getKind(), 029 anaphorPart.getReferentializationStrategy().getKind(), anaphorPart.getAnaphor()); 030 } 031 032 public Anaphora(final String kindOfRelatedExpression, final String kindOfAnaphorResolution, 033 final String kindOfReferentialization, final String anaphor) { 034 this.kindOfRelatedExpression = kindOfRelatedExpression; 035 this.kindOfAnaphorResolution = kindOfAnaphorResolution; 036 this.kindOfReferentialization = kindOfReferentialization; 037 kind = kindOfRelatedExpression + "-" + kindOfAnaphorResolution + "-" + kindOfReferentialization; 038 this.anaphor = anaphor; 039 } 040 041 @Override 042 public int hashCode() { 043 final int prime = 31; 044 int result = 1; 045 result = prime * result + ((anaphor == null) ? 0 : anaphor.hashCode()); 046 result = prime * result + ((kind == null) ? 0 : kind.hashCode()); 047 result = prime * result + ((kindOfAnaphorResolution == null) ? 0 : kindOfAnaphorResolution.hashCode()); 048 result = prime * result + ((kindOfReferentialization == null) ? 0 : kindOfReferentialization.hashCode()); 049 result = prime * result + ((kindOfRelatedExpression == null) ? 0 : kindOfRelatedExpression.hashCode()); 050 return result; 051 } 052 053 @Override 054 public boolean equals(final Object obj) { 055 if (this == obj) { 056 return true; 057 } 058 if (obj == null) { 059 return false; 060 } 061 if (getClass() != obj.getClass()) { 062 return false; 063 } 064 final Anaphora other = (Anaphora) obj; 065 if (anaphor == null) { 066 if (other.anaphor != null) { 067 return false; 068 } 069 } else if (!anaphor.equals(other.anaphor)) { 070 return false; 071 } 072 if (kind == null) { 073 if (other.kind != null) { 074 return false; 075 } 076 } else if (!kind.equals(other.kind)) { 077 return false; 078 } 079 if (kindOfAnaphorResolution == null) { 080 if (other.kindOfAnaphorResolution != null) { 081 return false; 082 } 083 } else if (!kindOfAnaphorResolution.equals(other.kindOfAnaphorResolution)) { 084 return false; 085 } 086 if (kindOfReferentialization == null) { 087 if (other.kindOfReferentialization != null) { 088 return false; 089 } 090 } else if (!kindOfReferentialization.equals(other.kindOfReferentialization)) { 091 return false; 092 } 093 if (kindOfRelatedExpression == null) { 094 if (other.kindOfRelatedExpression != null) { 095 return false; 096 } 097 } else if (!kindOfRelatedExpression.equals(other.kindOfRelatedExpression)) { 098 return false; 099 } 100 return true; 101 } 102 103 @Override 104 public String toString() { 105 return "Anaphora [kind=" + kind + ", anaphor=" + anaphor + "]"; 106 } 107 108}