Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/collections/AttributeWriter.java @ 1635:1b5204203e18
Minor refactoring, documentation.
flys-artifacts/trunk@2814 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 23 Sep 2011 07:19:41 +0000 |
parents | cc47828a1390 |
children | 12235a2ace21 |
comparison
equal
deleted
inserted
replaced
1634:cc47828a1390 | 1635:1b5204203e18 |
---|---|
120 */ | 120 */ |
121 protected void writeFacets( | 121 protected void writeFacets( |
122 Document doc, | 122 Document doc, |
123 ElementCreator cr, | 123 ElementCreator cr, |
124 Element output, | 124 Element output, |
125 List<Facet> a, /* new facets */ | 125 List<Facet> newFacets, |
126 List<Facet> b) /* old facets */ | 126 List<Facet> oldFacets) |
127 { | 127 { |
128 int num = a.size(); | 128 int num = newFacets.size(); |
129 | 129 |
130 // Add all new Facets either in their old state or (if really | |
131 // new) as they are. | |
130 for (int i = 0; i < num; i++) { | 132 for (int i = 0; i < num; i++) { |
131 ManagedFacet fA = (ManagedFacet) a.get(i); | 133 ManagedFacet facet = (ManagedFacet) newFacets.get(i); |
132 | 134 |
133 if (!mergeFacets(doc, cr, output, fA, b)) { | 135 ManagedFacet picked = pickFacet(facet, oldFacets); |
134 Node n = fA.toXML(doc); | 136 Node node = picked.toXML(doc); |
135 | 137 if (node != null) { |
136 if (n != null) { | 138 output.appendChild(node); |
137 output.appendChild(n); | |
138 } | |
139 } | 139 } |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 | 143 |
144 /** | 144 /** |
145 * @param a new facets | 145 * Returns the facet to be added to Document. |
146 * @param list old facets | 146 * Return the new facet only if the "same" facet was not present before. |
147 * Return the "old" facet otherwise (user-defined information sticks | |
148 * to it). | |
149 * @param facet the new facet. | |
150 * @param oldFacets the old facets, new facet is compared against each of | |
151 * these. | |
152 * @return facet if genuinely new, matching old facet otherwise. | |
147 */ | 153 */ |
148 protected boolean mergeFacets( | 154 protected ManagedFacet pickFacet(ManagedFacet facet, |
149 Document doc, | 155 List<Facet> oldFacets) { |
150 ElementCreator cr, | 156 if (oldFacets == null) { |
151 Element output, | 157 logger.debug("No old facets to compare a new to found."); |
152 ManagedFacet a, /* new facets */ | 158 return facet; |
153 List<Facet> list) /* old facets */ | 159 } |
154 { | 160 |
155 String nameA = a.getName() + a.getIndex(); | 161 String hash = facet.getName() + facet.getIndex() + facet.getArtifact(); |
156 | 162 |
157 if (list == null) { | 163 // Compare "new" facet with all old facets. |
158 logger.debug("No old facets found."); | 164 // Take oldFacet if that facet was already present (otherwise |
159 return false; | 165 // information is lost, the new one otherwise. |
160 } | 166 for (Facet oFacet: oldFacets) { |
161 | 167 ManagedFacet oldFacet = (ManagedFacet) oFacet; |
162 for (Facet facet: list) { | 168 String oldHash = oldFacet.getName() |
163 String nameB = facet.getName() + facet.getIndex(); | 169 + oldFacet.getIndex() |
164 | 170 + oldFacet.getArtifact(); |
165 if (nameA.equals(nameB)) { | 171 if (hash.equals(oldHash)) { |
166 ManagedFacet b = (ManagedFacet) facet; | 172 return oldFacet; |
167 | |
168 if (!b.getArtifact().equals(a.getArtifact())) { | |
169 continue; | |
170 } | |
171 | |
172 Node n = facet.toXML(doc); | |
173 | |
174 if (n != null) { | |
175 output.appendChild(n); | |
176 } | |
177 | |
178 return true; | |
179 } | 173 } |
180 } | 174 } |
181 | 175 return facet; |
182 return false; | |
183 } | 176 } |
184 } | 177 } |
185 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 178 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |