diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1771:c62ff9e72cea

Restore mapping of state id to facets (revert, rev 3083 and 3088). flys-artifacts/trunk@3092 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 27 Oct 2011 09:32:05 +0000
parents 5d8b3880a553
children a8aa343799a2
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Wed Oct 26 12:55:32 2011 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java	Thu Oct 27 09:32:05 2011 +0000
@@ -97,8 +97,8 @@
     /** The data that have been inserted into this artifact. */
     protected Map<String, StateData> data;
 
-    /** The list of facets produced by this artifact. */
-    protected List<Facet> facets;
+    /** Mapping of state names to created facets. */
+    protected Map<String, List<Facet>> facets;
 
     /**
      * Used to generates "view" on the facets (hides facets not matching the
@@ -113,7 +113,7 @@
     public FLYSArtifact() {
         data             = new TreeMap<String, StateData>();
         previousStateIds = new ArrayList<String>();
-        facets           = new ArrayList<Facet>();
+        facets           = new HashMap<String, List<Facet>>();
     }
 
 
@@ -208,13 +208,18 @@
 
     /**
      * Return a copy of the facet mapping.
-     * @return Copy of facets list.
+     * @return Mapping of state-ids to facets.
      */
-    protected List<Facet> cloneFacets() {
-        List copy = new ArrayList<Facet>(facets.size());
+    protected Map<String, List<Facet>> cloneFacets() {
+        Map copy = new HashMap<String, List<Facet>>();
 
-        for (Facet facet: facets) {
-            copy.add(facet.deepCopy());
+        for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) {
+            List<Facet> facets      = entry.getValue();
+            List<Facet> facetCopies = new ArrayList<Facet>(facets.size());
+            for (Facet facet: facets) {
+                facetCopies.add(facet.deepCopy());
+            }
+            copy.put(entry.getKey(), facetCopies);
         }
 
         return copy;
@@ -223,6 +228,7 @@
 
     /**
      * (called from setup).
+     * @param artifact master-artifact (if any, otherwise initialize is not called).
      */
     protected void initialize(
         Artifact artifact,
@@ -540,13 +546,21 @@
     }
 
 
+    /**
+     * Get facet as stored internally, with equalling name and index than given
+     * facet.
+     * @param facet that defines index and name of facet searched.
+     * @return facet instance or null if not found.
+     */
     public Facet getNativeFacet(Facet facet) {
         String name  = facet.getName();
         int    index = facet.getIndex();
 
-        for (Facet f: facets) {
-            if (f.getIndex() == index && f.getName().equals(name)) {
-                return f;
+        for (Map.Entry<String, List<Facet>> facetList: facets.entrySet()) {
+            for (Facet f: facetList.getValue()) {
+                if (f.getIndex() == index && f.getName().equals(name)) {
+                    return f;
+                }
             }
         }
 
@@ -775,12 +789,14 @@
             return new ArrayList<Output>();
         }
 
-        if (facets == null || facets.size() == 0) {
+        List<Facet> fs = facets.get(state.getID());
+
+        if (fs == null || fs.size() == 0) {
             logger.debug("No facets found.");
             return new ArrayList<Output>();
         }
 
-        return generateOutputs(list, facets);
+        return generateOutputs(list, fs);
     }
 
 
@@ -951,10 +967,10 @@
         finally {
             if (generateFacets) {
                 if (fs.isEmpty()) {
-                    facets.removeAll(fs);
+                    facets.remove(stateID);
                 }
                 else {
-                    facets.addAll(fs);
+                    facets.put(stateID, fs);
                 }
             }
         }

http://dive4elements.wald.intevation.org