Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 1765:5d8b3880a553
Do not store association of states to facets, let artifacts keep facets in a pure list.
flys-artifacts/trunk@3083 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 26 Oct 2011 12:23:47 +0000 |
parents | 0e748e8972b5 |
children | c62ff9e72cea |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed Oct 26 12:03:59 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java Wed Oct 26 12:23:47 2011 +0000 @@ -85,7 +85,6 @@ /** The constant string that shows that an operation failed. */ public static final String OPERATION_FAILED = "FAILURE"; - /** The identifier of the current state. */ protected String currentStateId; @@ -98,8 +97,8 @@ /** The data that have been inserted into this artifact. */ protected Map<String, StateData> data; - /** The list of facets supported by this artifact. */ - protected Map<String, List<Facet>> facets; + /** The list of facets produced by this artifact. */ + protected List<Facet> facets; /** * Used to generates "view" on the facets (hides facets not matching the @@ -114,7 +113,7 @@ public FLYSArtifact() { data = new TreeMap<String, StateData>(); previousStateIds = new ArrayList<String>(); - facets = new HashMap<String, List<Facet>>(); + facets = new ArrayList<Facet>(); } @@ -209,24 +208,22 @@ /** * Return a copy of the facet mapping. - * @return Mapping of outputnames to facets. + * @return Copy of facets list. */ - protected Map<String, List<Facet>> cloneFacets() { - Map copy = new HashMap<String, List<Facet>>(); + protected List<Facet> cloneFacets() { + List copy = new ArrayList<Facet>(facets.size()); - 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); + for (Facet facet: facets) { + copy.add(facet.deepCopy()); } return copy; } + /** + * (called from setup). + */ protected void initialize( Artifact artifact, Object context, @@ -547,11 +544,9 @@ String name = facet.getName(); int index = facet.getIndex(); - for (Map.Entry<String, List<Facet>> entry: facets.entrySet()) { - for (Facet f: entry.getValue()) { - if (f.getIndex() == index && f.getName().equals(name)) { - return f; - } + for (Facet f: facets) { + if (f.getIndex() == index && f.getName().equals(name)) { + return f; } } @@ -729,6 +724,12 @@ } + /** + * Get all outputs that the Artifact can do in this state (which includes + * all previous states). + * + * @return list of outputs + */ public List<Output> getOutputs(Object context) { List<String> stateIds = getPreviousStateIds(); List<Output> generated = new ArrayList<Output>(); @@ -744,6 +745,10 @@ } + /** + * Get output(s) for current state. + * @return list of outputs for current state. + */ public List<Output> getCurrentOutputs(Object context) { DefaultState cur = (DefaultState) getCurrentState(context); @@ -758,6 +763,11 @@ } + /** + * Get output(s) for a specific state. + * @param state State of interest + * @return list of output(s) for given state. + */ protected List<Output> getOutputForState(DefaultState state) { List<Output> list = state.getOutputs(); if (list == null || list.size() == 0) { @@ -765,13 +775,12 @@ return new ArrayList<Output>(); } - List<Facet> fs = facets.get(state.getID()); - if (fs == null || fs.size() == 0) { + if (facets == null || facets.size() == 0) { logger.debug("No facets found."); return new ArrayList<Output>(); } - return generateOutputs(list, fs); + return generateOutputs(list, facets); } @@ -885,6 +894,8 @@ /** + * Let current state compute and register facets. + * * @param key key of state * @param state state * @param type Type of compute @@ -940,10 +951,10 @@ finally { if (generateFacets) { if (fs.isEmpty()) { - facets.remove(stateID); + facets.removeAll(fs); } else { - facets.put(stateID, fs); + facets.addAll(fs); } } }