comparison flys-artifacts/src/main/java/de/intevation/flys/exports/OutputHelper.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 8e66293c5369
children e8a4d2fd25cc
comparison
equal deleted inserted replaced
4252:5ebaa0a62d2c 4255:670e98f5a441
1 package de.intevation.flys.exports; 1 package de.intevation.flys.exports;
2 2
3 import java.io.IOException; 3 import java.io.IOException;
4 import java.util.ArrayList; 4 import java.util.ArrayList;
5 import java.util.Collections;
5 import java.util.HashMap; 6 import java.util.HashMap;
6 import java.util.List; 7 import java.util.List;
7 import java.util.Map; 8 import java.util.Map;
8 9
9 import javax.xml.xpath.XPathConstants; 10 import javax.xml.xpath.XPathConstants;
468 /** 469 /**
469 * Inner class to structure/order the themes of a chart. 470 * Inner class to structure/order the themes of a chart.
470 */ 471 */
471 private static class ThemeList { 472 private static class ThemeList {
472 private Logger logger = Logger.getLogger(ThemeList.class); 473 private Logger logger = Logger.getLogger(ThemeList.class);
473 protected Map<Integer, ManagedFacet> themes; 474 protected List<ManagedFacet> themes;
474 475
475 public ThemeList(Document output) { 476 public ThemeList(Document output) {
476 themes = new HashMap<Integer, ManagedFacet>(); 477 themes = new ArrayList<ManagedFacet>();
477 parse(output); 478 parse(output);
478 } 479 }
479 480
480 protected void parse(Document output) { 481 protected void parse(Document output) {
481 NodeList themeList = (NodeList) XMLUtils.xpath( 482 NodeList themeList = (NodeList) XMLUtils.xpath(
494 495
495 for (int i = 0; i < num; i++) { 496 for (int i = 0; i < num; i++) {
496 Element theme = (Element) themeList.item(i); 497 Element theme = (Element) themeList.item(i);
497 498
498 ManagedDomFacet facet = new ManagedDomFacet(theme); 499 ManagedDomFacet facet = new ManagedDomFacet(theme);
499 themes.put(Integer.valueOf(facet.getPosition()-1), facet); 500 themes.add(facet);
500 } 501 }
502
503 Collections.sort(themes);
501 } 504 }
502 505
503 public ManagedFacet get(int idx) { 506 public ManagedFacet get(int idx) {
504 return themes.get(Integer.valueOf(idx)); 507 return themes.get(idx);
505 } 508 }
506 509
507 public int size() { 510 public int size() {
508 return themes.size(); 511 return themes.size();
509 } 512 }

http://dive4elements.wald.intevation.org