You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by mb...@apache.org on 2012/08/20 19:49:15 UTC
svn commit: r1375137 [3/3] - in
/ant/core/trunk/src/main/org/apache/tools/ant: ./ property/ taskdefs/
types/ util/
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java?rev=1375137&r1=1375136&r2=1375137&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/MacroDef.java Mon Aug 20 17:49:13 2012
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Map;
import java.util.Locale;
import java.util.HashMap;
-import java.util.Iterator;
import org.apache.tools.ant.AntTypeDefinition;
import org.apache.tools.ant.BuildException;
@@ -45,8 +44,8 @@ public class MacroDef extends AntlibDefi
private NestedSequential nestedSequential;
private String name;
private boolean backTrace = true;
- private List attributes = new ArrayList();
- private Map elements = new HashMap();
+ private List<Attribute> attributes = new ArrayList<Attribute>();
+ private Map<String, TemplateElement> elements = new HashMap<String, TemplateElement>();
private String textName = null;
private Text text = null;
private boolean hasImplicitElement = false;
@@ -74,8 +73,7 @@ public class MacroDef extends AntlibDefi
"the text nested element needed a \"name\" attribute");
}
// Check if used by attributes
- for (Iterator i = attributes.iterator(); i.hasNext();) {
- Attribute attribute = (Attribute) i.next();
+ for (Attribute attribute : attributes) {
if (text.getName().equals(attribute.getName())) {
throw new BuildException(
"the name \"" + text.getName()
@@ -134,7 +132,7 @@ public class MacroDef extends AntlibDefi
* This is a simple task container.
*/
public static class NestedSequential implements TaskContainer {
- private List nested = new ArrayList();
+ private List<Task> nested = new ArrayList<Task>();
/**
* Add a task or type to the container.
@@ -148,7 +146,7 @@ public class MacroDef extends AntlibDefi
/**
* @return the list of unknown elements
*/
- public List getNested() {
+ public List<Task> getNested() {
return nested;
}
@@ -201,7 +199,7 @@ public class MacroDef extends AntlibDefi
*
* @return the nested Attributes
*/
- public List getAttributes() {
+ public List<Attribute> getAttributes() {
return attributes;
}
@@ -211,7 +209,7 @@ public class MacroDef extends AntlibDefi
* @return the map nested elements, keyed by element name, with
* {@link TemplateElement} values.
*/
- public Map getElements() {
+ public Map<String, TemplateElement> getElements() {
return elements;
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java?rev=1375137&r1=1375136&r2=1375137&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java Mon Aug 20 17:49:13 2012
@@ -177,13 +177,13 @@ public class FilterSet extends DataType
private String endOfToken = DEFAULT_TOKEN_END;
/** Contains a list of parsed tokens */
- private Vector passedTokens;
+ private Vector<String> passedTokens;
/** if a duplicate token is found, this is set to true */
private boolean duplicateToken = false;
private boolean recurse = true;
- private Hashtable filterHash = null;
- private Vector filtersFiles = new Vector();
+ private Hashtable<String, String> filterHash = null;
+ private Vector<File> filtersFiles = new Vector<File>();
private OnMissing onMissingFiltersFile = OnMissing.FAIL;
private boolean readingFiles = false;
@@ -192,7 +192,7 @@ public class FilterSet extends DataType
/**
* List of ordered filters and filter files.
*/
- private Vector filters = new Vector();
+ private Vector<Filter> filters = new Vector<Filter>();
/**
* Default constructor.
@@ -207,7 +207,9 @@ public class FilterSet extends DataType
*/
protected FilterSet(FilterSet filterset) {
super();
- this.filters = (Vector) filterset.getFilters().clone();
+ @SuppressWarnings("unchecked")
+ Vector<Filter> clone = (Vector<Filter>) filterset.getFilters().clone();
+ this.filters = clone;
}
/**
@@ -215,7 +217,7 @@ public class FilterSet extends DataType
*
* @return a Vector of Filter instances.
*/
- protected synchronized Vector getFilters() {
+ protected synchronized Vector<Filter> getFilters() {
if (isReference()) {
return getRef().getFilters();
}
@@ -247,15 +249,15 @@ public class FilterSet extends DataType
*
* @return The hash of the tokens and values for quick lookup.
*/
- public synchronized Hashtable getFilterHash() {
+ public synchronized Hashtable<String, String> getFilterHash() {
if (isReference()) {
return getRef().getFilterHash();
}
dieOnCircularReference();
if (filterHash == null) {
- filterHash = new Hashtable(getFilters().size());
- for (Enumeration e = getFilters().elements(); e.hasMoreElements();) {
- Filter filter = (Filter) e.nextElement();
+ filterHash = new Hashtable<String, String>(getFilters().size());
+ for (Enumeration<Filter> e = getFilters().elements(); e.hasMoreElements();) {
+ Filter filter = e.nextElement();
filterHash.put(filter.getToken(), filter.getValue());
}
}
@@ -368,8 +370,8 @@ public class FilterSet extends DataType
in = new FileInputStream(filtersFile);
props.load(in);
- Enumeration e = props.propertyNames();
- Vector filts = getFilters();
+ Enumeration<?> e = props.propertyNames();
+ Vector<Filter> filts = getFilters();
while (e.hasMoreElements()) {
String strPropName = (String) e.nextElement();
String strValue = props.getProperty(strPropName);
@@ -450,8 +452,8 @@ public class FilterSet extends DataType
if (isReference()) {
throw noChildrenAllowed();
}
- for (Enumeration e = filterSet.getFilters().elements(); e.hasMoreElements();) {
- addFilter((Filter) e.nextElement());
+ for (Filter filter : filterSet.getFilters()) {
+ addFilter(filter);
}
}
@@ -477,7 +479,9 @@ public class FilterSet extends DataType
}
try {
FilterSet fs = (FilterSet) super.clone();
- fs.filters = (Vector) getFilters().clone();
+ @SuppressWarnings("unchecked")
+ Vector<Filter> clonedFilters = (Vector<Filter>) getFilters().clone();
+ fs.filters = clonedFilters;
fs.setProject(getProject());
return fs;
} catch (CloneNotSupportedException e) {
@@ -515,9 +519,9 @@ public class FilterSet extends DataType
int index = line.indexOf(beginToken);
if (index > -1) {
- Hashtable tokens = getFilterHash();
+ Hashtable<String, String> tokens = getFilterHash();
try {
- StringBuffer b = new StringBuffer();
+ StringBuilder b = new StringBuilder();
int i = 0;
String token = null;
String value = null;
@@ -533,7 +537,7 @@ public class FilterSet extends DataType
= line.substring(index + beginToken.length(), endIndex);
b.append(line.substring(i, index));
if (tokens.containsKey(token)) {
- value = (String) tokens.get(token);
+ value = tokens.get(token);
if (recurse && !value.equals(token)) {
// we have another token, let's parse it.
value = replaceTokens(value, token);
@@ -577,7 +581,7 @@ public class FilterSet extends DataType
String beginToken = getBeginToken();
String endToken = getEndToken();
if (recurseDepth == 0) {
- passedTokens = new VectorSet();
+ passedTokens = new VectorSet<String>();
}
recurseDepth++;
if (passedTokens.contains(parent) && !duplicateToken) {
@@ -605,7 +609,7 @@ public class FilterSet extends DataType
}
}
} else if (passedTokens.size() > 0) {
- // remove last seen token when crawling out of recursion
+ // remove last seen token when crawling out of recursion
passedTokens.remove(passedTokens.size() - 1);
}
recurseDepth--;
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java?rev=1375137&r1=1375136&r2=1375137&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/CollectionUtils.java Mon Aug 20 17:49:13 2012
@@ -39,8 +39,9 @@ public class CollectionUtils {
/**
* Collections.emptyList() is Java5+.
*/
- public static final List EMPTY_LIST =
- Collections.unmodifiableList(new ArrayList(0));
+ @SuppressWarnings("rawtypes")
+ @Deprecated
+ public static final List EMPTY_LIST = Collections.EMPTY_LIST;
/**
* Please use Vector.equals() or List.equals().
@@ -50,7 +51,7 @@ public class CollectionUtils {
* @since Ant 1.5
* @deprecated since 1.6.x.
*/
- public static boolean equals(Vector v1, Vector v2) {
+ public static boolean equals(Vector<?> v1, Vector<?> v2) {
if (v1 == v2) {
return true;
}
@@ -73,7 +74,7 @@ public class CollectionUtils {
* @since Ant 1.5
* @deprecated since 1.6.x.
*/
- public static boolean equals(Dictionary d1, Dictionary d2) {
+ public static boolean equals(Dictionary<?, ?> d1, Dictionary<?, ?> d2) {
if (d1 == d2) {
return true;
}
@@ -86,7 +87,7 @@ public class CollectionUtils {
return false;
}
- Enumeration e1 = d1.keys();
+ Enumeration<?> e1 = d1.keys();
while (e1.hasMoreElements()) {
Object key = e1.nextElement();
Object value1 = d1.get(key);
@@ -108,16 +109,13 @@ public class CollectionUtils {
*
* @since Ant 1.8.0
*/
- public static String flattenToString(Collection c) {
- Iterator iter = c.iterator();
- boolean first = true;
- StringBuffer sb = new StringBuffer();
- while (iter.hasNext()) {
- if (!first) {
+ public static String flattenToString(Collection<?> c) {
+ final StringBuilder sb = new StringBuilder();
+ for (Object o : c) {
+ if (sb.length() != 0) {
sb.append(",");
}
- sb.append(String.valueOf(iter.next()));
- first = false;
+ sb.append(o);
}
return sb.toString();
}
@@ -129,9 +127,9 @@ public class CollectionUtils {
* @since Ant 1.6
* @deprecated since 1.6.x.
*/
- public static void putAll(Dictionary m1, Dictionary m2) {
- for (Enumeration it = m2.keys(); it.hasMoreElements();) {
- Object key = it.nextElement();
+ public static <K, V> void putAll(Dictionary<? super K, ? super V> m1, Dictionary<? extends K, ? extends V> m2) {
+ for (Enumeration<? extends K> it = m2.keys(); it.hasMoreElements();) {
+ K key = it.nextElement();
m1.put(key, m2.get(key));
}
}
@@ -140,7 +138,7 @@ public class CollectionUtils {
* An empty enumeration.
* @since Ant 1.6
*/
- public static final class EmptyEnumeration implements Enumeration {
+ public static final class EmptyEnumeration<E> implements Enumeration<E> {
/** Constructor for the EmptyEnumeration */
public EmptyEnumeration() {
}
@@ -156,7 +154,7 @@ public class CollectionUtils {
* @return nothing.
* @throws NoSuchElementException always.
*/
- public Object nextElement() throws NoSuchElementException {
+ public E nextElement() throws NoSuchElementException {
throw new NoSuchElementException();
}
}
@@ -169,8 +167,8 @@ public class CollectionUtils {
* @return an enumeration representing e1 followed by e2.
* @since Ant 1.6.3
*/
- public static Enumeration append(Enumeration e1, Enumeration e2) {
- return new CompoundEnumeration(e1, e2);
+ public static <E> Enumeration<E> append(Enumeration<E> e1, Enumeration<E> e2) {
+ return new CompoundEnumeration<E>(e1, e2);
}
/**
@@ -178,12 +176,12 @@ public class CollectionUtils {
* @param iter the Iterator to adapt.
* @return an Enumeration.
*/
- public static Enumeration asEnumeration(final Iterator iter) {
- return new Enumeration() {
+ public static <E> Enumeration<E> asEnumeration(final Iterator<E> iter) {
+ return new Enumeration<E>() {
public boolean hasMoreElements() {
return iter.hasNext();
}
- public Object nextElement() {
+ public E nextElement() {
return iter.next();
}
};
@@ -194,12 +192,12 @@ public class CollectionUtils {
* @param e the Enumeration to adapt.
* @return an Iterator.
*/
- public static Iterator asIterator(final Enumeration e) {
- return new Iterator() {
+ public static <E> Iterator<E> asIterator(final Enumeration<E> e) {
+ return new Iterator<E>() {
public boolean hasNext() {
return e.hasMoreElements();
}
- public Object next() {
+ public E next() {
return e.nextElement();
}
public void remove() {
@@ -221,11 +219,11 @@ public class CollectionUtils {
return l;
}
- private static final class CompoundEnumeration implements Enumeration {
+ private static final class CompoundEnumeration<E> implements Enumeration<E> {
- private final Enumeration e1, e2;
+ private final Enumeration<E> e1, e2;
- public CompoundEnumeration(Enumeration e1, Enumeration e2) {
+ public CompoundEnumeration(Enumeration<E> e1, Enumeration<E> e2) {
this.e1 = e1;
this.e2 = e2;
}
@@ -234,7 +232,7 @@ public class CollectionUtils {
return e1.hasMoreElements() || e2.hasMoreElements();
}
- public Object nextElement() throws NoSuchElementException {
+ public E nextElement() throws NoSuchElementException {
if (e1.hasMoreElements()) {
return e1.nextElement();
} else {
@@ -250,11 +248,11 @@ public class CollectionUtils {
*
* @since Ant 1.8.0
*/
- public static int frequency(Collection c, Object o) {
+ public static int frequency(Collection<?> c, Object o) {
// same as Collections.frequency introduced with JDK 1.5
int freq = 0;
if (c != null) {
- for (Iterator i = c.iterator(); i.hasNext(); ) {
+ for (Iterator<?> i = c.iterator(); i.hasNext(); ) {
Object test = i.next();
if (o == null ? test == null : o.equals(test)) {
freq++;
@@ -263,5 +261,5 @@ public class CollectionUtils {
}
return freq;
}
-
+
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java?rev=1375137&r1=1375136&r2=1375137&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/JavaEnvUtils.java Mon Aug 20 17:49:13 2012
@@ -108,7 +108,7 @@ public final class JavaEnvUtils {
private static boolean harmonyDetected;
/** array of packages in the runtime */
- private static Vector jrePackages;
+ private static Vector<String> jrePackages;
static {
@@ -376,7 +376,7 @@ public final class JavaEnvUtils {
*/
private static void buildJrePackages() {
- jrePackages = new Vector();
+ jrePackages = new Vector<String>();
switch(javaVersionNumber) {
case VERSION_1_8:
case VERSION_1_7:
@@ -479,7 +479,7 @@ public final class JavaEnvUtils {
* that platforms runtime jar(s)
* @return list of packages.
*/
- public static Vector getJrePackages() {
+ public static Vector<String> getJrePackages() {
if (jrePackages == null) {
buildJrePackages();
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/VectorSet.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/VectorSet.java?rev=1375137&r1=1375136&r2=1375137&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/VectorSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/VectorSet.java Mon Aug 20 17:49:13 2012
@@ -19,7 +19,6 @@ package org.apache.tools.ant.util;
import java.util.Collection;
import java.util.HashSet;
-import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.Vector;
@@ -38,8 +37,10 @@ import java.util.Vector;
*
* @since Ant 1.8.0
*/
-public final class VectorSet extends Vector {
- private final HashSet set = new HashSet();
+public final class VectorSet<E> extends Vector<E> {
+ private static final long serialVersionUID = 1L;
+
+ private final HashSet<E> set = new HashSet<E>();
public VectorSet() { super(); }
@@ -49,15 +50,15 @@ public final class VectorSet extends Vec
super(initialCapacity, capacityIncrement);
}
- public VectorSet(Collection c) {
+ public VectorSet(Collection<? extends E> c) {
if (c != null) {
- for (Iterator i = c.iterator(); i.hasNext(); ) {
- add(i.next());
+ for (E e : c) {
+ add(e);
}
}
}
- public synchronized boolean add(Object o) {
+ public synchronized boolean add(E o) {
if (!set.contains(o)) {
doAdd(size(), o);
return true;
@@ -69,11 +70,11 @@ public final class VectorSet extends Vec
* This implementation may not add the element at the given index
* if it is already contained in the collection.
*/
- public void add(int index, Object o) {
+ public void add(int index, E o) {
doAdd(index, o);
}
- private synchronized void doAdd(int index, Object o) {
+ private synchronized void doAdd(int index, E o) {
// Vector.add seems to delegate to insertElementAt, but this
// is not documented so we may better implement it ourselves
if (set.add(o)) {
@@ -88,14 +89,14 @@ public final class VectorSet extends Vec
}
}
- public synchronized void addElement(Object o) {
+ public synchronized void addElement(E o) {
doAdd(size(), o);
}
- public synchronized boolean addAll(Collection c) {
+ public synchronized boolean addAll(Collection<? extends E> c) {
boolean changed = false;
- for (Iterator i = c.iterator(); i.hasNext(); ) {
- changed |= add(i.next());
+ for (E e : c) {
+ changed |= add(e);
}
return changed;
}
@@ -104,12 +105,11 @@ public final class VectorSet extends Vec
* This implementation may not add all elements at the given index
* if any of them are already contained in the collection.
*/
- public synchronized boolean addAll(int index, Collection c) {
+ public synchronized boolean addAll(int index, Collection<? extends E> c) {
boolean changed = false;
- for (Iterator i = c.iterator(); i.hasNext(); ) {
- Object o = i.next();
- if (!set.contains(o)) {
- doAdd(index++, o);
+ for (E e : c) {
+ if (!set.contains(e)) {
+ doAdd(index++, e);
changed = true;
}
}
@@ -122,7 +122,8 @@ public final class VectorSet extends Vec
}
public Object clone() {
- VectorSet vs = (VectorSet) super.clone();
+ @SuppressWarnings("unchecked")
+ final VectorSet<E> vs = (VectorSet<E>) super.clone();
vs.set.addAll(set);
return vs;
}
@@ -131,16 +132,16 @@ public final class VectorSet extends Vec
return set.contains(o);
}
- public synchronized boolean containsAll(Collection c) {
+ public synchronized boolean containsAll(Collection<?> c) {
return set.containsAll(c);
}
- public void insertElementAt(Object o, int index) {
+ public void insertElementAt(E o, int index) {
doAdd(index, o);
}
- public synchronized Object remove(int index) {
- Object o = get(index);
+ public synchronized E remove(int index) {
+ E o = get(index);
remove(o);
return o;
}
@@ -164,10 +165,10 @@ public final class VectorSet extends Vec
return false;
}
- public synchronized boolean removeAll(Collection c) {
+ public synchronized boolean removeAll(Collection<?> c) {
boolean changed = false;
- for (Iterator i = c.iterator(); i.hasNext(); ) {
- changed |= remove(i.next());
+ for (Object o : c) {
+ changed |= remove(o);
}
return changed;
}
@@ -191,13 +192,12 @@ public final class VectorSet extends Vec
}
}
- public synchronized boolean retainAll(Collection c) {
+ public synchronized boolean retainAll(Collection<?> c) {
if (!(c instanceof Set)) {
- c = new HashSet(c);
+ c = new HashSet<Object>(c);
}
- LinkedList l = new LinkedList();
- for (Iterator i = iterator(); i.hasNext(); ) {
- Object o = i.next();
+ LinkedList<E> l = new LinkedList<E>();
+ for (E o : this) {
if (!c.contains(o)) {
l.addLast(o);
}
@@ -209,8 +209,8 @@ public final class VectorSet extends Vec
return false;
}
- public synchronized Object set(int index, Object o) {
- Object orig = get(index);
+ public synchronized E set(int index, E o) {
+ E orig = get(index);
if (set.add(o)) {
elementData[index] = o;
set.remove(orig);
@@ -223,7 +223,7 @@ public final class VectorSet extends Vec
return orig;
}
- public void setElementAt(Object o, int index) {
+ public void setElementAt(E o, int index) {
set(index, o);
}