package uk.ac.ebi.quickgo.annotation.common.document;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * The fields of an annotation document.
 *
 * Created 14/04/16
 * @author Edd
 */
public class AnnotationFields {

    // all fields from annotations's schema.xml
    public final static String ID = "id";
    public final static String GENE_PRODUCT_ID = "geneProductId";
    public final static String QUALIFIER = "qualifier";
    public final static String GO_ID = "goId";
    public final static String GO_EVIDENCE = "goEvidence";
    public final static String ECO_ID = "ecoId";
    public final static String REFERENCE = "reference";
    public final static String REFERENCE_SEARCH = "referenceSearch";
    public final static String WITH_FROM = "withFrom";
    public final static String WITH_FROM_SEARCH = "withFromSearch";
    public final static String INTERACTING_TAXON_ID = "interactingTaxonId";
    public final static String ASSIGNED_BY = "assignedBy";
    public final static String EXTENSION = "extension";
    public static final String DB_OBJECT_SYMBOL = "dbObjectSymbol";
    public static final String DB_OBJECT_TYPE = "dbObjectType";
    public static final String DB_SUBSET = "dbSubset";
    public static final String TAXON_ID = "taxonId";

    /**
     * Annotation fields that are stored, and can therefore be retrieved.
     */
    public static final class Retrievable extends AnnotationFields {
        private static final Set<String> VALUES = new HashSet<>();

        public static boolean isRetrievable(String field) {
            return VALUES.contains(field);
        }

        private static Set<String> retrievableFields() {
            return Collections.unmodifiableSet(VALUES);
        }
    }

    /**
     * Annotation fields that are indexed, and can therefore be searched.
     */
    public static final class Searchable {
        private static final Set<String> VALUES = new HashSet<>();

        static {
            storeAndGet(VALUES, ASSIGNED_BY);
            storeAndGet(VALUES, WITH_FROM_SEARCH);
            storeAndGet(VALUES, TAXON_ID);
            storeAndGet(VALUES, GO_EVIDENCE);
            storeAndGet(VALUES, QUALIFIER);
            storeAndGet(VALUES, REFERENCE_SEARCH);
            storeAndGet(VALUES, GENE_PRODUCT_ID);
            storeAndGet(VALUES, QUALIFIER);
            storeAndGet(VALUES, GO_ID);
        }

        public static boolean isSearchable(String field) {
            return VALUES.contains(field);
        }

        public static Set<String> searchableFields() {
            return Collections.unmodifiableSet(VALUES);
        }
    }

    private static String storeAndGet(Set<String> values, String value) {
        values.add(value);
        return value;
    }
}

@@ -1978,28 +1978,48 @@
     
-static %7B%0A           
+public static final String ASSIGNED_BY =
  sto
@@ -2035,16 +2035,33 @@
 VALUES, 
+AnnotationFields.
 ASSIGNED
@@ -2066,35 +2066,77 @@
 ED_BY);%0A        
-   
+public static final String WITH_FROM_SEARCH =
  storeAndGet(VAL
@@ -2140,16 +2140,33 @@
 VALUES, 
+AnnotationFields.
 WITH_FRO
@@ -2176,35 +2176,69 @@
 EARCH);%0A        
-   
+public static final String TAXON_ID =
  storeAndGet(VAL
@@ -2242,16 +2242,33 @@
 VALUES, 
+AnnotationFields.
 TAXON_ID
@@ -2270,35 +2270,72 @@
 ON_ID);%0A        
-   
+public static final String GO_EVIDENCE =
  storeAndGet(VAL
@@ -2339,16 +2339,33 @@
 VALUES, 
+AnnotationFields.
 GO_EVIDE
@@ -2370,35 +2370,72 @@
 DENCE);%0A        
-   
+public static final String QUALIFIER   =
  storeAndGet(VAL
@@ -2431,32 +2431,49 @@
 eAndGet(VALUES, 
+AnnotationFields.
 QUALIFIER);%0A    
@@ -2476,39 +2476,42 @@
         
-    storeAndGet(VALUES,
+public static final String
  REFEREN
@@ -2519,30 +2519,18 @@
 E_SEARCH
-);%0A          
  
+=
  storeAn
@@ -2542,31 +2542,49 @@
 VALUES, 
-G
+AnnotationFields.REFER
 EN
+C
 E_
-PRODUCT_ID
+SEARCH
 );%0A     
@@ -2590,93 +2590,194 @@
     
-    storeAndGet(VALUES, QUALIFIER);%0A            storeAndGet(VALUES, GO_ID);%0A        %7D
+public static final String GO_ID = storeAndGet(VALUES, AnnotationFields.GO_ID);%0A        public static final String GENEPRODUCT_ID = storeAndGet(VALUES, AnnotationFields.GENE_PRODUCT_ID);
 %0A%0A  

Put back assignation of storeAndGet values to static variables, which can then be referenced by other classes. Remove static block.