Mercurial > dive4elements > river
changeset 1639:12235a2ace21
Add positional-conflict-awareness when merging Facets in attribute
of a collection. Apply "first come first serve"-rule.
flys-artifacts/trunk@2824 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Mon, 26 Sep 2011 13:17:55 +0000 |
parents | f45bbc80bd3d |
children | fb296bdf815f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java |
diffstat | 2 files changed, 45 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Sep 26 13:10:40 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Sep 26 13:17:55 2011 +0000 @@ -1,3 +1,14 @@ +2011-09-26 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + Add positional-conflict-awareness when merging Facets for a + FLYSArtifactCollection. First come first serve. + + * src/main/java/de/intevation/flys/collections/AttributeWriter.java: + (writeFacets): First, sort incoming facets into 2 groups: + "genuinely new" and "already there", then for each new check + whether the position is already taken. If so, push "up" (position++) + until no conflict exists anymore. + 2011-09-26 Ingo Weinzierl <ingo@intevation.de> flys/issue296 (Karte: Bezeichnungen verbessern) @@ -11,7 +22,7 @@ src/main/resources/messages_de.properties: Added strings for the wsplgen and barriers WMS layers. -2011-09-23 Felix Wolfsteller <felix.wolfsteller@intevation.de> +2011-09-26 Felix Wolfsteller <felix.wolfsteller@intevation.de> Fix (revert) access to position in ManagedDomFacet.
--- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Mon Sep 26 13:10:40 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Mon Sep 26 13:17:55 2011 +0000 @@ -1,5 +1,6 @@ package de.intevation.flys.collections; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -129,11 +130,42 @@ // Add all new Facets either in their old state or (if really // new) as they are. + List<ManagedFacet> currentFacets = new ArrayList<ManagedFacet>(); + List<ManagedFacet> genuinelyNewFacets = new ArrayList<ManagedFacet>(); for (int i = 0; i < num; i++) { ManagedFacet facet = (ManagedFacet) newFacets.get(i); ManagedFacet picked = pickFacet(facet, oldFacets); - Node node = picked.toXML(doc); + if (facet.equals(picked)) { + genuinelyNewFacets.add(picked); + } + else { + currentFacets.add(picked); + } + } + + // For each genuinely new Facet check positional conflicts. + for (ManagedFacet newMF: genuinelyNewFacets) { + boolean conflicts = true; + // Loop until all conflicts resolved. + while (conflicts) { + conflicts = false; + for (ManagedFacet oldMF: currentFacets) { + if (newMF.getPosition() == oldMF.getPosition()) { + conflicts = true; + logger.debug("Positional conflict while merging " + + "facets, pushing newest facet 1 up ("+newMF.getPosition()+")"); + newMF.setPosition(newMF.getPosition() + 1); + break; + } + } + } + currentFacets.add(newMF); + } + + // Now add all facets. + for (ManagedFacet oldMF: currentFacets) { + Node node = oldMF.toXML(doc); if (node != null) { output.appendChild(node); }