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