comparison artifact-database/src/main/java/de/intevation/artifactdatabase/state/DefaultSection.java @ 419:92b51af2d02d

Keep insertion order of attributes in DefaultSection. artifacts/trunk@5301 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 30 Aug 2012 00:09:14 +0000
parents ab3900303f25
children
comparison
equal deleted inserted replaced
418:8d8aed23c323 419:92b51af2d02d
1 package de.intevation.artifactdatabase.state; 1 package de.intevation.artifactdatabase.state;
2 2
3 import java.util.ArrayList; 3 import java.util.ArrayList;
4 import java.util.HashMap; 4 import java.util.LinkedHashMap;
5 import java.util.List; 5 import java.util.List;
6 import java.util.Map; 6 import java.util.Map;
7 import java.util.Set; 7 import java.util.Set;
8 8
9 import org.w3c.dom.Document; 9 import org.w3c.dom.Document;
10 import org.w3c.dom.Element; 10 import org.w3c.dom.Element;
11 import org.w3c.dom.Node; 11 import org.w3c.dom.Node;
12 12
13 /** 13 /**
14 * Attributes keep the order in which they were inserted.
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 15 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
15 */ 16 */
16 public class DefaultSection implements Section { 17 public class DefaultSection implements Section {
17 18
18 protected String id; 19 protected String id;
19 20
20 protected List<Section> subsections; 21 protected List<Section> subsections;
21 22
23 /** Attribute-map. */
22 protected Map<String, Attribute> attributes; 24 protected Map<String, Attribute> attributes;
23 25
24 26
25 /** 27 /**
26 * Creates a new DefaultSection instance. <b>Note, that the <i>id</i> is used 28 * Creates a new DefaultSection instance. <b>Note, that the <i>id</i> is used
27 * as Node name of the new Element that is created in toXML().</b> 29 * as Node name of the new Element that is created in toXML().</b>
28 */ 30 */
29 public DefaultSection(String id) { 31 public DefaultSection(String id) {
30 this.id = id; 32 this.id = id;
31 this.attributes = new HashMap<String, Attribute>(); 33 // Use LinkedHashMap to keep insertion order.
34 this.attributes = new LinkedHashMap<String, Attribute>();
32 this.subsections = new ArrayList<Section>(); 35 this.subsections = new ArrayList<Section>();
33 } 36 }
34 37
35 38
36 @Override 39 @Override
61 64
62 return null; 65 return null;
63 } 66 }
64 67
65 68
69 /** Adding attribute to end of list. */
66 @Override 70 @Override
67 public void addAttribute(String key, Attribute attribute) { 71 public void addAttribute(String key, Attribute attribute) {
68 if (key != null && key.length() > 0 && attribute != null) { 72 if (key != null && key.length() > 0 && attribute != null) {
69 attributes.put(key, attribute); 73 attributes.put(key, attribute);
70 } 74 }

http://dive4elements.wald.intevation.org