/*
 * 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());
    }

}

/*
 * 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 description;

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

    private ExperimentType(ExperimentType parent, String description) {
        this(description);
        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 getDescription() {
        return description;
    }

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

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

    public static ExperimentType get(String experimentTypeDescription) {
        return typeByDescription.get(experimentTypeDescription.toLowerCase());
    }

}

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