Java tutorial
/* * 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 com.google.common.collect.ImmutableSet; import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.Set; public enum ExperimentType { RNASEQ_MRNA_BASELINE("rnaseq_mrna_baseline"), RNASEQ_MRNA_DIFFERENTIAL( "rnaseq_mrna_differential"), MICROARRAY_ANY( "microarray parent type"), MICROARRAY_1COLOUR_MRNA_DIFFERENTIAL(MICROARRAY_ANY, "microarray_1colour_mrna_differential"), MICROARRAY_2COLOUR_MRNA_DIFFERENTIAL( MICROARRAY_ANY, "microarray_2colour_mrna_differential"), MICROARRAY_1COLOUR_MICRORNA_DIFFERENTIAL( MICROARRAY_ANY, "microarray_1colour_microrna_differential"), PROTEOMICS_BASELINE( "proteomics_baseline"); 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_ANY); } public boolean isBaseline() { return equals(RNASEQ_MRNA_BASELINE) || equals(PROTEOMICS_BASELINE); } public boolean isProteomicsBaseline() { return equals(PROTEOMICS_BASELINE); } public boolean isMicroRna() { return equals(MICROARRAY_1COLOUR_MICRORNA_DIFFERENTIAL); } public boolean isRnaSeqDifferential() { return equals(RNASEQ_MRNA_DIFFERENTIAL); } public boolean isDifferential() { return equals(RNASEQ_MRNA_DIFFERENTIAL) || isMicroarray(); } public boolean isTwoColour() { return equals(MICROARRAY_2COLOUR_MRNA_DIFFERENTIAL); } public ExperimentType getParent() { return parent == null ? this : parent; } public String getDescription() { return description; } private static final Map<String, ExperimentType> TYPE_BY_DESCRIPTION = new HashMap<>(); static { for (ExperimentType experimentType : EnumSet.allOf(ExperimentType.class)) { TYPE_BY_DESCRIPTION.put(experimentType.getDescription(), experimentType); } } public static ExperimentType get(String experimentTypeDescription) { return TYPE_BY_DESCRIPTION.get(experimentTypeDescription.toLowerCase()); } public static boolean containsBaseline(Set<String> experimentTypes) { return experimentTypes.contains(RNASEQ_MRNA_BASELINE.getDescription()) || experimentTypes.contains(PROTEOMICS_BASELINE.getDescription()); } public static boolean containsDifferential(ImmutableSet<String> experimentTypes) { return experimentTypes.contains(RNASEQ_MRNA_DIFFERENTIAL.getDescription()) || experimentTypes.contains(MICROARRAY_1COLOUR_MRNA_DIFFERENTIAL.getDescription()) || experimentTypes.contains(MICROARRAY_2COLOUR_MRNA_DIFFERENTIAL.getDescription()) || experimentTypes.contains(MICROARRAY_1COLOUR_MICRORNA_DIFFERENTIAL.getDescription()); } }