package uk.ac.ebi.quickgo.geneproduct.model;

import com.google.common.base.Preconditions;
import java.util.regex.Pattern;

/**
 * The information for a single Database cross reference.
 * This information is used, for example, to validate gene product ids based on source database and the id type.
 *
 * @author Tony Wardell
 *         Date: 18/04/2016
 *         Time: 13:52
 *         Created with IntelliJ IDEA.
 */
public class GeneProductDbXRefIDFormat {

    //E.g. UniProtKB
    private String database;

    //E.g. PR:000000001
    private String entityType;

    //E.g. protein
    private String entityTypeName;

    //E.g. regex for validation  ([OPQ][0-9][A-Z0-9]{3}[0-9]|[A-NR-Z]([0-9][A-Z][A-Z0-9]{2}){1,2}[0-9])...
    private Pattern idValidationPattern;

    //E.g. http://www.uniprot.org/uniprot/[example_id]/
    private String URLSyntax;

    public GeneProductDbXRefIDFormat(String database, String entityType, String entityTypeName, String idValidationPattern,
            String URLSyntax) {
        Preconditions.checkNotNull(idValidationPattern,
                "The regex for the validation of ids from " + database + " is null and therefore invalid");
        this.database = database;
        this.entityType = entityType;
        this.entityTypeName = entityTypeName;
        this.idValidationPattern = Pattern.compile(idValidationPattern);
        this.URLSyntax = URLSyntax;
    }

    /**
     * Does the argument match the regular expression that determines validity of the entity?
     * @param id
     * @return
     */
    public boolean matches(String id) {
        return idValidationPattern.matcher(id).matches();
    }

    public String getDatabase() {
        return database;
    }

    public String getEntityType() {
        return entityType;
    }

    public String getEntityTypeName() {
        return entityTypeName;
    }

    public Pattern getIdValidationPattern() {
        return idValidationPattern;
    }

    public String getURLSyntax() {
        return URLSyntax;
    }

    @Override
    public String toString() {
        return "GeneProductXrefEntity{" +
                "database='" + database + '\'' +
                ", entityType='" + entityType + '\'' +
                ", entityTypeName='" + entityTypeName + '\'' +
                ", idValidationPattern=" + idValidationPattern +
                ", URLSyntax='" + URLSyntax + '\'' +
                '}';
    }
}

@@ -841,25 +841,27 @@
  String 
-URLSyntax
+databaseURL
 ;%0A%0A    p
@@ -998,25 +998,27 @@
  String 
-URLSyntax
+databaseURL
 ) %7B%0A    
@@ -1385,29 +1385,33 @@
 his.
-URLSyntax = URLSyntax
+databaseURL = databaseURL
 ;%0A  
@@ -1986,25 +1986,27 @@
 ring get
-URLSyntax
+DatabaseURL
 () %7B%0A   
@@ -2017,25 +2017,27 @@
  return 
-URLSyntax
+databaseURL
 ;%0A    %7D%0A
@@ -2379,32 +2379,36 @@
  %22, 
-URLSyntax='%22 + URLSyntax
+databaseURL='%22 + databaseURL
  + '

Change name of variable from URLSyntax to databaseURL;