Author: bodewig
Date: Wed Feb 17 09:14:55 2010
New Revision: 910874
URL: http://svn.apache.org/viewvc?rev=910874&view=rev
Log:
embrace Java 1.4 and use LinkedHashMap instead of a Hashtable and a separate
index to keep insert order
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Manifest.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Manifest.java
URL:
http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Manifest.java?rev=910874&r1=910873&r2=910874&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Manifest.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Manifest.java Wed Feb
17 09:14:55 2010
@@ -27,11 +27,13 @@
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.Enumeration;
-import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
import java.util.Vector;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.util.CollectionUtils;
import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.ant.util.VectorSet;
/**
* Holds the data of a jar manifest.
@@ -399,10 +401,7 @@
private String name = null;
/** The section's attributes.*/
- private Hashtable attributes = new Hashtable();
-
- /** Index used to retain the attribute ordering */
- private Vector attributeIndex = new VectorSet();
+ private Map attributes = new LinkedHashMap();
/**
* The name of the section; optional -default is the main section.
@@ -597,7 +596,7 @@
* key of an attribute of the section.
*/
public Enumeration getAttributeKeys() {
- return attributeIndex.elements();
+ return
CollectionUtils.asEnumeration(attributes.keySet().iterator());
}
/**
@@ -624,7 +623,6 @@
public void removeAttribute(String attributeName) {
String key = attributeName.toLowerCase();
attributes.remove(key);
- attributeIndex.removeElement(key);
}
/**
@@ -732,9 +730,6 @@
}
String attributeKey = attribute.getKey();
attributes.put(attributeKey, attribute);
- if (!attributeIndex.contains(attributeKey)) {
- attributeIndex.addElement(attributeKey);
- }
}
/**
@@ -782,10 +777,7 @@
private Section mainSection = new Section();
/** The named sections of this manifest */
- private Hashtable sections = new Hashtable();
-
- /** Index of sections - used to retain order of sections in manifest */
- private Vector sectionIndex = new VectorSet();
+ private Map sections = new LinkedHashMap();
/**
* Construct a manifest from Ant's default manifest file.
@@ -899,9 +891,6 @@
throw new BuildException("Sections must have a name");
}
sections.put(sectionName, section);
- if (!sectionIndex.contains(sectionName)) {
- sectionIndex.addElement(sectionName);
- }
}
/**
@@ -1042,9 +1031,9 @@
}
}
- Enumeration e = sectionIndex.elements();
- while (e.hasMoreElements()) {
- String sectionName = (String) e.nextElement();
+ Iterator e = sections.keySet().iterator();
+ while (e.hasNext()) {
+ String sectionName = (String) e.next();
Section section = getSection(sectionName);
section.write(writer, flatten);
}
@@ -1080,9 +1069,9 @@
}
// create a vector and add in the warnings for all the sections
- Enumeration e = sections.elements();
- while (e.hasMoreElements()) {
- Section section = (Section) e.nextElement();
+ Iterator e = sections.values().iterator();
+ while (e.hasNext()) {
+ Section section = (Section) e.next();
Enumeration e2 = section.getWarnings();
while (e2.hasMoreElements()) {
warnings.addElement(e2.nextElement());
@@ -1173,6 +1162,6 @@
* @return an Enumeration of section names
*/
public Enumeration getSectionNames() {
- return sectionIndex.elements();
+ return CollectionUtils.asEnumeration(sections.keySet().iterator());
}
}