# HG changeset patch # User Felix Wolfsteller # Date 1316762381 0 # Node ID 1b5204203e186b84226e32dbb67cb5f112768b7f # Parent cc47828a1390f7cc2c54215c788181bdb7028141 Minor refactoring, documentation. flys-artifacts/trunk@2814 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r cc47828a1390 -r 1b5204203e18 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Fri Sep 23 04:21:16 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Sep 23 07:19:41 2011 +0000 @@ -1,3 +1,12 @@ +2011-09-23 Felix Wolfsteller + + Refactoring, doc. + + * src/main/java/de/intevation/flys/collections/AttributeWriter.java: + (mergeFacets): Removed, replaced in parts by pickFacet. + (pickFacet): New, return facet to be added to document. + Documentation added. + 2011-09-23 Felix Wolfsteller Cosmetics, docs. diff -r cc47828a1390 -r 1b5204203e18 flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java --- a/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Fri Sep 23 04:21:16 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java Fri Sep 23 07:19:41 2011 +0000 @@ -122,64 +122,57 @@ Document doc, ElementCreator cr, Element output, - List a, /* new facets */ - List b) /* old facets */ + List newFacets, + List oldFacets) { - int num = a.size(); + int num = newFacets.size(); + // Add all new Facets either in their old state or (if really + // new) as they are. for (int i = 0; i < num; i++) { - ManagedFacet fA = (ManagedFacet) a.get(i); + ManagedFacet facet = (ManagedFacet) newFacets.get(i); - if (!mergeFacets(doc, cr, output, fA, b)) { - Node n = fA.toXML(doc); - - if (n != null) { - output.appendChild(n); - } + ManagedFacet picked = pickFacet(facet, oldFacets); + Node node = picked.toXML(doc); + if (node != null) { + output.appendChild(node); } } } /** - * @param a new facets - * @param list old facets + * Returns the facet to be added to Document. + * Return the new facet only if the "same" facet was not present before. + * Return the "old" facet otherwise (user-defined information sticks + * to it). + * @param facet the new facet. + * @param oldFacets the old facets, new facet is compared against each of + * these. + * @return facet if genuinely new, matching old facet otherwise. */ - protected boolean mergeFacets( - Document doc, - ElementCreator cr, - Element output, - ManagedFacet a, /* new facets */ - List list) /* old facets */ - { - String nameA = a.getName() + a.getIndex(); - - if (list == null) { - logger.debug("No old facets found."); - return false; + protected ManagedFacet pickFacet(ManagedFacet facet, + List oldFacets) { + if (oldFacets == null) { + logger.debug("No old facets to compare a new to found."); + return facet; } + + String hash = facet.getName() + facet.getIndex() + facet.getArtifact(); - for (Facet facet: list) { - String nameB = facet.getName() + facet.getIndex(); - - if (nameA.equals(nameB)) { - ManagedFacet b = (ManagedFacet) facet; - - if (!b.getArtifact().equals(a.getArtifact())) { - continue; - } - - Node n = facet.toXML(doc); - - if (n != null) { - output.appendChild(n); - } - - return true; + // Compare "new" facet with all old facets. + // Take oldFacet if that facet was already present (otherwise + // information is lost, the new one otherwise. + for (Facet oFacet: oldFacets) { + ManagedFacet oldFacet = (ManagedFacet) oFacet; + String oldHash = oldFacet.getName() + + oldFacet.getIndex() + + oldFacet.getArtifact(); + if (hash.equals(oldHash)) { + return oldFacet; } } - - return false; + return facet; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :