package uk.ac.ebi.quickgo.common.validator;

import java.util.regex.Pattern;

import static com.google.common.base.Preconditions.checkArgument;

/**
 * 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 final String database;

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

    //E.g. protein
    private final 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 final Pattern idValidationPattern;

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

    public GeneProductDbXRefIDFormat(String database, String entityType, String entityTypeName,
            String idValidationPattern, String databaseURL) {

        checkArgument(database != null, "The database ID should not be null");
        checkArgument(entityType != null, "The entity type should not be null");
        checkArgument(idValidationPattern != null,
                "The regex for the validation of ids from " + database + " is null and therefore invalid");
        this.database = database;
        this.entityType = entityType;
        this.idValidationPattern = Pattern.compile(idValidationPattern);
        this.entityTypeName = entityTypeName;
        this.databaseURL = databaseURL;
    }

    /**
     * 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 getDatabaseURL() {
        return databaseURL;
    }

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

@@ -316,19 +316,16 @@
 ype.%0A *%0A
- *%0A
  * @auth
@@ -479,28 +479,8 @@
 t %7B%0A
-    //E.g. UniProtKB
 %0A   
@@ -514,33 +514,8 @@
 ase;
-%0A%0A    //E.g. PR:000000001
 %0A   
@@ -551,28 +551,8 @@
 ype;
-%0A%0A    //E.g. protein
 %0A   
@@ -593,219 +593,54 @@
 me;%0A
-%0A    //E.g. regex for validation  (%5BOPQ%5D%5B0-9%5D%5BA-Z0-9%5D%7B3%7D%5B0-9%5D%7C%5BA-NR-Z%5D(%5B0-9%5D%5BA-Z%5D%5BA-Z0-9%5D%7B2%7D)%7B1,2%7D%5B0-9%5D)...%0A    private final Pattern idValidationPattern;%0A%0A    //E.g. http://www.uniprot.org/uniprot/%5Bexample_id%5D/
+    private final Pattern idValidationPattern;
 %0A   
@@ -1513,439 +1513,1259 @@
 m id
-%0A     * @return%0A     */%0A    public boolean matches(String id) %7B%0A        return idValidationPattern.matcher(id).matches();%0A    %7D%0A%0A    public String getDatabase() %7B%0A        return database;%0A    %7D%0A%0A    public String getEntityType() %7B%0A        return entityType;%0A    %7D%0A%0A    public String getEntityTypeName() %7B%0A        return entityTypeName;%0A    %7D%0A%0A    public Pattern getIdValidationPattern() %7B%0A        return idValidationPattern;%0A    %7D%0A
+ the gene product id to be checked%0A     * @return true if the gene product id is positively matched to the validation regular expression.3%0A     */%0A    public boolean matches(String id) %7B%0A        return idValidationPattern.matcher(id).matches();%0A    %7D%0A%0A    /**%0A     * @return the name of the database from which gene product ids can be validated, and which provided the%0A     * validation regular expression. E.g. UniProtKB%0A     */%0A    public String getDatabase() %7B%0A        return database;%0A    %7D%0A%0A    /**%0A     * @return  A code that uniquely identifies the type of entity that this class instance applies to e.g.%0A     * PR:000000001 for protein;  SO:0000704 for gene.%0A     */%0A    public String getEntityType() %7B%0A        return entityType;%0A    %7D%0A%0A    /**%0A     * @return A string that identifies the type of entity that this class instance applies to e.g. gene or protein.%0A     */%0A    public String getEntityTypeName() %7B%0A        return entityTypeName;%0A    %7D%0A%0A    /**%0A     * @return The regular expression used to verify an entity.%0A     */%0A    public Pattern getIdValidationPattern() %7B%0A        return idValidationPattern;%0A    %7D%0A%0A    /**%0A     * @return The URL of the source database of the entity. e.g. http://www.uniprot.org/uniprot/%5Bexample_id%5D/%0A     */
 %0A   

Replace inline comments with some proper javadoc.