/*
 * Copyright 2008-2013 Microarray Informatics Team, EMBL-European Bioinformatics Institute
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *
 * For further details of the Gene Expression Atlas project, including source code,
 * downloads and documentation, please see:
 *
 * http://gxa.github.com/gxa
 */

package uk.ac.ebi.atlas.model;


import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;

public enum ExperimentType {

    BASELINE("rnaseq_mrna_baseline")
    ,DIFFERENTIAL("rnaseq_mrna_differential")
    ,MICROARRAY("1color_microarray_mrna_differential")
    ,TWOCOLOUR(MICROARRAY, "2color_microarray_mrna_differential")
    ,MICRORNA(MICROARRAY, "1color_microarray_microrna_differential");

    private ExperimentType parent;
    private String key;

    private ExperimentType(String key) {
        this.key = key;
    }

    private ExperimentType(ExperimentType parent, String key) {
        this(key);
        this.parent = parent;
    }

    public boolean isMicroarray() {
        return getParent().equals(MICROARRAY);
    }

    public boolean isBaseline() {
        return equals(BASELINE);
    }

    public boolean isMicroRna() {
        return equals(MICRORNA);
    }

    public boolean isDifferential() {
        return equals(DIFFERENTIAL);
    }

    public boolean isTwoColour() {
        return equals(TWOCOLOUR);
    }

    public ExperimentType getParent() {
        return parent == null ? this : parent;
    }

    public String getKey() {
        return key;
    }

    @Override
    public String toString() {
        return key;
    }

    private static final Map<String,ExperimentType> lookup = new HashMap<>();

    static {
        for(ExperimentType experimentType : EnumSet.allOf(ExperimentType.class))
            lookup.put(experimentType.toString(), experimentType);
    }

    public static ExperimentType get(String experimentType) {
        return lookup.get(experimentType.toLowerCase());
    }

}

@@ -1279,19 +1279,27 @@
  String 
-key
+description
 ;%0A%0A    p
@@ -1323,27 +1323,35 @@
 Type(String 
-key
+description
 ) %7B%0A        
@@ -1359,17 +1359,33 @@
 his.
-key = key
+description = description
 ;%0A  
@@ -1446,19 +1446,27 @@
  String 
-key
+description
 ) %7B%0A    
@@ -1474,19 +1474,27 @@
    this(
-key
+description
 );%0A     
@@ -2040,11 +2040,19 @@
  get
-Key
+Description
 () %7B
@@ -2071,83 +2071,19 @@
 urn 
-key;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return key
+description
 ;%0A  
@@ -2139,22 +2139,33 @@
 ntType%3E 
-lookup
+typeByDescription
  = new H
@@ -2283,22 +2283,33 @@
         
-lookup
+typeByDescription
 .put(exp
@@ -2324,16 +2324,22 @@
 ype.
-toString
+getDescription
 (), 
@@ -2420,16 +2420,27 @@
 mentType
+Description
 ) %7B%0A    
@@ -2454,14 +2454,25 @@
 urn 
-lookup
+typeByDescription
 .get
@@ -2486,16 +2486,27 @@
 mentType
+Description
 .toLower

fix experiments not loading (b/c expecting type name not description)