001/*
002 * This file is part of McIDAS-V
003 *
004 * Copyright 2007-2023
005 * Space Science and Engineering Center (SSEC)
006 * University of Wisconsin - Madison
007 * 1225 W. Dayton Street, Madison, WI 53706, USA
008 * https://www.ssec.wisc.edu/mcidas
009 * 
010 * All Rights Reserved
011 * 
012 * McIDAS-V is built on Unidata's IDV and SSEC's VisAD libraries, and
013 * some McIDAS-V source code is based on IDV and VisAD source code.  
014 * 
015 * McIDAS-V is free software; you can redistribute it and/or modify
016 * it under the terms of the GNU Lesser Public License as published by
017 * the Free Software Foundation; either version 3 of the License, or
018 * (at your option) any later version.
019 * 
020 * McIDAS-V is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
023 * GNU Lesser Public License for more details.
024 * 
025 * You should have received a copy of the GNU Lesser Public License
026 * along with this program.  If not, see http://www.gnu.org/licenses.
027 */
028
029package edu.wisc.ssec.mcidasv.data.hydra;
030
031import java.util.HashMap;
032
033import ucar.unidata.data.DataCategory;
034import ucar.unidata.data.DataChoice;
035import ucar.unidata.data.DataSource;
036
037public class HydraContext {
038
039  private static HashMap<DataSource, HydraContext> dataSourceToContextMap = new HashMap<DataSource, HydraContext>(); 
040  private static HashMap<DataChoice, HydraContext> dataChoiceToContextMap = new HashMap<DataChoice, HydraContext>(); 
041  private static HashMap<DataCategory, HydraContext> dataCategoryToContextMap = new HashMap<DataCategory, HydraContext>(); 
042
043  private static HashMap<DataSource, HashMap<DataCategory, HydraContext>> contextMap = new HashMap<DataSource, HashMap<DataCategory, HydraContext>>();
044
045  private static HydraContext hydraContext = null;
046  private MultiDimensionSubset subset = null;
047  private Object selectBox = null;
048
049  public static HydraContext getHydraContext(DataSource source, DataCategory dataCategory) {
050    if (dataCategory == null) {
051      return getHydraContext(source);
052    }
053    if (contextMap.containsKey(source)) {
054      if ((contextMap.get(source)).containsKey(dataCategory)) {
055        return contextMap.get(source).get(dataCategory);
056      }
057      else {
058        HashMap<DataCategory, HydraContext> catMap = contextMap.get(source);
059        HydraContext hydraContext = new HydraContext();
060        catMap.put(dataCategory, hydraContext);
061        return hydraContext;
062      }
063    }
064    else {
065      HydraContext hydraContext = new HydraContext();
066      HashMap<DataCategory, HydraContext> catMap = new HashMap<>();
067      catMap.put(dataCategory, hydraContext);
068      contextMap.put(source, catMap);
069      return hydraContext;
070    }
071  }
072
073  public static HydraContext getHydraContext(DataSource source) {
074    if (dataSourceToContextMap.isEmpty()) {
075      HydraContext hydraContext = new HydraContext();
076      dataSourceToContextMap.put(source, hydraContext);
077      return hydraContext;
078    }
079
080    if (dataSourceToContextMap.containsKey(source)) {
081      return dataSourceToContextMap.get(source);
082    }
083    else {
084      HydraContext hydraContext = new HydraContext();
085      dataSourceToContextMap.put(source, hydraContext);
086      return hydraContext;
087    }
088  }
089
090  public static HydraContext getHydraContext(DataChoice choice) {
091    if (dataChoiceToContextMap.isEmpty()) {
092      HydraContext hydraContext = new HydraContext();
093      dataChoiceToContextMap.put(choice, hydraContext);
094      return hydraContext;
095    }
096
097    if (dataChoiceToContextMap.containsKey(choice)) {
098      return dataChoiceToContextMap.get(choice);
099    }
100    else {
101      HydraContext hydraContext = new HydraContext();
102      dataChoiceToContextMap.put(choice, hydraContext);
103      return hydraContext;
104    }
105  }
106
107  public static HydraContext getHydraContext(DataCategory choice) {
108    if (dataCategoryToContextMap.isEmpty()) {
109      HydraContext hydraContext = new HydraContext();
110      dataCategoryToContextMap.put(choice, hydraContext);
111      return hydraContext;
112    }
113
114    if (dataCategoryToContextMap.containsKey(choice)) {
115      return dataCategoryToContextMap.get(choice);
116    }
117    else {
118      HydraContext hydraContext = new HydraContext();
119      dataCategoryToContextMap.put(choice, hydraContext);
120      return hydraContext;
121    }
122  }
123
124
125  public static HydraContext getHydraContext() {
126    if (hydraContext == null) {
127      hydraContext =  new HydraContext();
128    }
129    return hydraContext;
130  }
131 
132
133  public HydraContext() {
134  }
135
136
137  public synchronized void setMultiDimensionSubset(MultiDimensionSubset subset) {
138    this.subset = subset;
139  }
140
141  public void setSelectBox(Object box) {
142    selectBox = box;
143  }
144
145  public Object getSelectBox() {
146    return selectBox;
147  }
148
149  public synchronized MultiDimensionSubset getMultiDimensionSubset() {
150    return subset;
151  }
152
153
154}