You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rd...@apache.org on 2004/08/05 00:16:55 UTC
cvs commit: jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy TuneBean.java
rdonkin 2004/08/04 15:16:54
Modified: betwixt Tag: RELEASE_0_6_BRANCH project.xml
betwixt/src/java/org/apache/commons/betwixt/expression Tag:
RELEASE_0_6_BRANCH IteratorExpression.java
betwixt/src/java/org/apache/commons/betwixt/schema Tag:
RELEASE_0_6_BRANCH GlobalComplexType.java
LocalComplexType.java Schema.java
betwixt/src/test/org/apache/commons/betwixt Tag:
RELEASE_0_6_BRANCH CustomerBean.java
TestBeanReader.java
betwixt/src/test/org/apache/commons/betwixt/strategy Tag:
RELEASE_0_6_BRANCH TuneBean.java
Log:
Removed commons collections dependency
Revision Changes Path
No revision
No revision
1.40.2.2 +5 -9 jakarta-commons/betwixt/project.xml
Index: project.xml
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/project.xml,v
retrieving revision 1.40.2.1
retrieving revision 1.40.2.2
diff -u -r1.40.2.1 -r1.40.2.2
--- project.xml 3 Aug 2004 22:01:01 -0000 1.40.2.1
+++ project.xml 4 Aug 2004 22:16:53 -0000 1.40.2.2
@@ -141,17 +141,13 @@
</dependency>
<dependency>
- <id>commons-beanutils</id>
- <version>1.6.1</version>
+ <groupId>commons-beanutils</groupId>
+ <typeId>jar</typeId>
+ <artifactId>commons-beanutils-core</artifactId>
+ <version>1.7.0</version>
<url>http://jakarta.apache.org/commons/beanutils.html</url>
</dependency>
-
- <dependency>
- <id>commons-collections</id>
- <version>2.1</version>
- <url>http://jakarta.apache.org/commons/collections.html</url>
- </dependency>
-
+
<dependency>
<id>commons-digester</id>
<version>1.5</version>
No revision
No revision
1.8.4.1 +350 -3 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/expression/IteratorExpression.java
Index: IteratorExpression.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/expression/IteratorExpression.java,v
retrieving revision 1.8
retrieving revision 1.8.4.1
diff -u -r1.8 -r1.8.4.1
--- IteratorExpression.java 28 Feb 2004 13:38:32 -0000 1.8
+++ IteratorExpression.java 4 Aug 2004 22:16:54 -0000 1.8.4.1
@@ -16,14 +16,14 @@
package org.apache.commons.betwixt.expression;
+import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
-import org.apache.commons.collections.iterators.ArrayIterator;
-import org.apache.commons.collections.iterators.EnumerationIterator;
/** <p><code>IteratorExpression</code> returns an iterator over the current context.</p>
*
@@ -100,4 +100,351 @@
public String toString() {
return "IteratorExpression [expression=" + expression + "]";
}
+
+
+ /**
+ * <code>ArrayIterator</code> originated in commons-collections. Added
+ * as a private inner class to break dependency.
+ *
+ * @author James Strachan
+ * @author Mauricio S. Moura
+ * @author Michael A. Smith
+ * @author Neil O'Toole
+ * @author Stephen Colebourne
+ */
+ private static final class ArrayIterator implements Iterator {
+
+ /** The array to iterate over */
+ protected Object array;
+
+ /** The start index to loop from */
+ protected int startIndex = 0;
+
+ /** The end index to loop to */
+ protected int endIndex = 0;
+
+ /** The current iterator index */
+ protected int index = 0;
+
+ // Constructors
+ // ----------------------------------------------------------------------
+ /**
+ * Constructor for use with <code>setArray</code>.
+ * <p>
+ * Using this constructor, the iterator is equivalent to an empty
+ * iterator until {@link #setArray(Object)}is called to establish the
+ * array to iterate over.
+ */
+ public ArrayIterator() {
+ super();
+ }
+
+ /**
+ * Constructs an ArrayIterator that will iterate over the values in the
+ * specified array.
+ *
+ * @param array
+ * the array to iterate over.
+ * @throws IllegalArgumentException
+ * if <code>array</code> is not an array.
+ * @throws NullPointerException
+ * if <code>array</code> is <code>null</code>
+ */
+ public ArrayIterator(final Object array) {
+ super();
+ setArray(array);
+ }
+
+ /**
+ * Constructs an ArrayIterator that will iterate over the values in the
+ * specified array from a specific start index.
+ *
+ * @param array
+ * the array to iterate over.
+ * @param startIndex
+ * the index to start iterating at.
+ * @throws IllegalArgumentException
+ * if <code>array</code> is not an array.
+ * @throws NullPointerException
+ * if <code>array</code> is <code>null</code>
+ * @throws IndexOutOfBoundsException
+ * if the index is invalid
+ */
+ public ArrayIterator(final Object array, final int startIndex) {
+ super();
+ setArray(array);
+ checkBound(startIndex, "start");
+ this.startIndex = startIndex;
+ this.index = startIndex;
+ }
+
+ /**
+ * Construct an ArrayIterator that will iterate over a range of values
+ * in the specified array.
+ *
+ * @param array
+ * the array to iterate over.
+ * @param startIndex
+ * the index to start iterating at.
+ * @param endIndex
+ * the index to finish iterating at.
+ * @throws IllegalArgumentException
+ * if <code>array</code> is not an array.
+ * @throws NullPointerException
+ * if <code>array</code> is <code>null</code>
+ * @throws IndexOutOfBoundsException
+ * if either index is invalid
+ */
+ public ArrayIterator(final Object array, final int startIndex,
+ final int endIndex) {
+ super();
+ setArray(array);
+ checkBound(startIndex, "start");
+ checkBound(endIndex, "end");
+ if (endIndex < startIndex) {
+ throw new IllegalArgumentException(
+ "End index must not be less than start index.");
+ }
+ this.startIndex = startIndex;
+ this.endIndex = endIndex;
+ this.index = startIndex;
+ }
+
+ /**
+ * Checks whether the index is valid or not.
+ *
+ * @param bound
+ * the index to check
+ * @param type
+ * the index type (for error messages)
+ * @throws IndexOutOfBoundsException
+ * if the index is invalid
+ */
+ protected void checkBound(final int bound, final String type) {
+ if (bound > this.endIndex) {
+ throw new ArrayIndexOutOfBoundsException(
+ "Attempt to make an ArrayIterator that " + type
+ + "s beyond the end of the array. ");
+ }
+ if (bound < 0) {
+ throw new ArrayIndexOutOfBoundsException(
+ "Attempt to make an ArrayIterator that " + type
+ + "s before the start of the array. ");
+ }
+ }
+
+ // Iterator interface
+ //-----------------------------------------------------------------------
+ /**
+ * Returns true if there are more elements to return from the array.
+ *
+ * @return true if there is a next element to return
+ */
+ public boolean hasNext() {
+ return (index < endIndex);
+ }
+
+ /**
+ * Returns the next element in the array.
+ *
+ * @return the next element in the array
+ * @throws NoSuchElementException
+ * if all the elements in the array have already been
+ * returned
+ */
+ public Object next() {
+ if (hasNext() == false) {
+ throw new NoSuchElementException();
+ }
+ return Array.get(array, index++);
+ }
+
+ /**
+ * Throws {@link UnsupportedOperationException}.
+ *
+ * @throws UnsupportedOperationException
+ * always
+ */
+ public void remove() {
+ throw new UnsupportedOperationException(
+ "remove() method is not supported");
+ }
+
+ // Properties
+ //-----------------------------------------------------------------------
+ /**
+ * Gets the array that this iterator is iterating over.
+ *
+ * @return the array this iterator iterates over, or <code>null</code>
+ * if the no-arg constructor was used and
+ * {@link #setArray(Object)}has never been called with a valid
+ * array.
+ */
+ public Object getArray() {
+ return array;
+ }
+
+ /**
+ * Sets the array that the ArrayIterator should iterate over.
+ * <p>
+ * If an array has previously been set (using the single-arg constructor
+ * or this method) then that array is discarded in favour of this one.
+ * Iteration is restarted at the start of the new array. Although this
+ * can be used to reset iteration, the {@link #reset()}method is a more
+ * effective choice.
+ *
+ * @param array
+ * the array that the iterator should iterate over.
+ * @throws IllegalArgumentException
+ * if <code>array</code> is not an array.
+ * @throws NullPointerException
+ * if <code>array</code> is <code>null</code>
+ */
+ public void setArray(final Object array) {
+ // Array.getLength throws IllegalArgumentException if the object is
+ // not
+ // an array or NullPointerException if the object is null. This call
+ // is made before saving the array and resetting the index so that
+ // the
+ // array iterator remains in a consistent state if the argument is
+ // not
+ // an array or is null.
+ this.endIndex = Array.getLength(array);
+ this.startIndex = 0;
+ this.array = array;
+ this.index = 0;
+ }
+
+ /**
+ * Resets the iterator back to the start index.
+ */
+ public void reset() {
+ this.index = this.startIndex;
+ }
+
+ }
+
+
+ /**
+ * Adapter to make {@link Enumeration Enumeration}instances appear to be
+ * {@link Iterator Iterator}instances. Originated in commons-collections.
+ * Added as a private inner class to break dependency.
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan </a>
+ * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall </a>
+ */
+ private static final class EnumerationIterator implements Iterator {
+
+ /** The collection to remove elements from */
+ private Collection collection;
+
+ /** The enumeration being converted */
+ private Enumeration enumeration;
+
+ /** The last object retrieved */
+ private Object last;
+
+ // Constructors
+ //-----------------------------------------------------------------------
+ /**
+ * Constructs a new <code>EnumerationIterator</code> that will not
+ * function until {@link #setEnumeration(Enumeration)} is called.
+ */
+ public EnumerationIterator() {
+ this(null, null);
+ }
+
+ /**
+ * Constructs a new <code>EnumerationIterator</code> that provides
+ * an iterator view of the given enumeration.
+ *
+ * @param enumeration the enumeration to use
+ */
+ public EnumerationIterator(final Enumeration enumeration) {
+ this(enumeration, null);
+ }
+
+ /**
+ * Constructs a new <code>EnumerationIterator</code> that will remove
+ * elements from the specified collection.
+ *
+ * @param enumeration the enumeration to use
+ * @param collection the collection to remove elements form
+ */
+ public EnumerationIterator(final Enumeration enumeration,
+ final Collection collection) {
+ super();
+ this.enumeration = enumeration;
+ this.collection = collection;
+ this.last = null;
+ }
+
+ // Iterator interface
+ //-----------------------------------------------------------------------
+ /**
+ * Returns true if the underlying enumeration has more elements.
+ *
+ * @return true if the underlying enumeration has more elements
+ * @throws NullPointerException if the underlying enumeration is null
+ */
+ public boolean hasNext() {
+ return enumeration.hasMoreElements();
+ }
+
+ /**
+ * Returns the next object from the enumeration.
+ *
+ * @return the next object from the enumeration
+ * @throws NullPointerException if the enumeration is null
+ */
+ public Object next() {
+ last = enumeration.nextElement();
+ return last;
+ }
+
+ /**
+ * Removes the last retrieved element if a collection is attached.
+ * <p>
+ * Functions if an associated <code>Collection</code> is known.
+ * If so, the first occurrence of the last returned object from this
+ * iterator will be removed from the collection.
+ *
+ * @exception IllegalStateException <code>next()</code> not called.
+ * @exception UnsupportedOperationException if no associated collection
+ */
+ public void remove() {
+ if (collection != null) {
+ if (last != null) {
+ collection.remove(last);
+ } else {
+ throw new IllegalStateException(
+ "next() must have been called for remove() to function");
+ }
+ } else {
+ throw new UnsupportedOperationException(
+ "No Collection associated with this Iterator");
+ }
+ }
+
+ // Properties
+ //-----------------------------------------------------------------------
+ /**
+ * Returns the underlying enumeration.
+ *
+ * @return the underlying enumeration
+ */
+ public Enumeration getEnumeration() {
+ return enumeration;
+ }
+
+ /**
+ * Sets the underlying enumeration.
+ *
+ * @param enumeration the new underlying enumeration
+ */
+ public void setEnumeration(final Enumeration enumeration) {
+ this.enumeration = enumeration;
+ }
+ }
+
}
No revision
No revision
1.2.2.1 +19 -4 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java
Index: GlobalComplexType.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/GlobalComplexType.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- GlobalComplexType.java 16 Jun 2004 11:21:26 -0000 1.2
+++ GlobalComplexType.java 4 Aug 2004 22:16:54 -0000 1.2.2.1
@@ -18,9 +18,9 @@
import java.beans.IntrospectionException;
import java.util.Iterator;
+import java.util.Collection;
import org.apache.commons.betwixt.ElementDescriptor;
-import org.apache.commons.collections.CollectionUtils;
/**
* Models a <code>complexType</code> from an XML schema.
@@ -68,8 +68,8 @@
if (obj instanceof GlobalComplexType) {
GlobalComplexType complexType = (GlobalComplexType) obj;
result = isEqual(name, complexType.name) &&
- CollectionUtils.isEqualCollection(attributes, complexType.attributes) &&
- CollectionUtils.isEqualCollection(elements, complexType.elements);
+ equalContents(attributes, complexType.attributes) &&
+ equalContents(elements, complexType.elements);
}
return result;
@@ -77,6 +77,21 @@
public int hashCode() {
return 0;
+ }
+
+ private boolean equalContents(Collection one, Collection two)
+ {
+ // doesn't check cardinality but should be ok
+ if (one.size() != two.size()) {
+ return false;
+ }
+ for (Iterator it=one.iterator();it.hasNext();) {
+ Object object = it.next();
+ if (!two.contains(object)) {
+ return false;
+ }
+ }
+ return true;
}
/**
1.2.2.1 +20 -4 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/LocalComplexType.java
Index: LocalComplexType.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/LocalComplexType.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- LocalComplexType.java 16 Jun 2004 11:21:26 -0000 1.2
+++ LocalComplexType.java 4 Aug 2004 22:16:54 -0000 1.2.2.1
@@ -18,9 +18,9 @@
import java.beans.IntrospectionException;
import java.util.Iterator;
+import java.util.Collection;
import org.apache.commons.betwixt.ElementDescriptor;
-import org.apache.commons.collections.CollectionUtils;
/**
* @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
@@ -40,12 +40,28 @@
if (obj instanceof GlobalComplexType) {
GlobalComplexType complexType = (GlobalComplexType) obj;
result =
- CollectionUtils.isEqualCollection(attributes, complexType.attributes) &&
- CollectionUtils.isEqualCollection(elements, complexType.elements);
+ equalContents(attributes, complexType.attributes) &&
+ equalContents(elements, complexType.elements);
}
return result;
}
+
+
+ private boolean equalContents(Collection one, Collection two)
+ {
+ // doesn't check cardinality but should be ok
+ if (one.size() != two.size()) {
+ return false;
+ }
+ for (Iterator it=one.iterator();it.hasNext();) {
+ Object object = it.next();
+ if (!two.contains(object)) {
+ return false;
+ }
+ }
+ return true;
+ }
public int hashCode() {
return 0;
1.2.2.1 +20 -5 jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Schema.java
Index: Schema.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/java/org/apache/commons/betwixt/schema/Schema.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- Schema.java 16 Jun 2004 11:21:26 -0000 1.2
+++ Schema.java 4 Aug 2004 22:16:54 -0000 1.2.2.1
@@ -20,11 +20,11 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Collection;
import org.apache.commons.betwixt.ElementDescriptor;
import org.apache.commons.betwixt.XMLBeanInfo;
import org.apache.commons.betwixt.XMLIntrospector;
-import org.apache.commons.collections.CollectionUtils;
/**
* Model for top level element in an XML Schema
@@ -130,11 +130,26 @@
if (obj instanceof Schema) {
Schema schema = (Schema) obj;
result =
- CollectionUtils.isEqualCollection(elements, schema.elements) &&
- CollectionUtils.isEqualCollection(complexTypes, schema.complexTypes) &&
- CollectionUtils.isEqualCollection(simpleTypes, schema.simpleTypes);
+ equalContents(elements, schema.elements) &&
+ equalContents(complexTypes, schema.complexTypes) &&
+ equalContents(simpleTypes, schema.simpleTypes);
}
return result;
+ }
+
+ private boolean equalContents(Collection one, Collection two)
+ {
+ // doesn't check cardinality but should be ok
+ if (one.size() != two.size()) {
+ return false;
+ }
+ for (Iterator it=one.iterator();it.hasNext();) {
+ Object object = it.next();
+ if (!two.contains(object)) {
+ return false;
+ }
+ }
+ return true;
}
public int hashCode() {
No revision
No revision
1.12.4.1 +79 -1 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/CustomerBean.java
Index: CustomerBean.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/CustomerBean.java,v
retrieving revision 1.12
retrieving revision 1.12.4.1
diff -u -r1.12 -r1.12.4.1
--- CustomerBean.java 28 Feb 2004 13:38:34 -0000 1.12
+++ CustomerBean.java 4 Aug 2004 22:16:54 -0000 1.12.4.1
@@ -27,7 +27,6 @@
import java.util.List;
import java.util.Map;
-import org.apache.commons.collections.iterators.IteratorEnumeration;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -273,5 +272,84 @@
public void setBigInteger(BigInteger bigInteger) {
this.bigInteger = bigInteger;
}
+
+ /**
+ * Adapter to make an {@link Iterator Iterator} instance appear to be
+ * an {@link Enumeration Enumeration} instance.
+ * Originate in commons collections
+ *
+ * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
+ */
+ private static final class IteratorEnumeration implements Enumeration {
+
+ /** The iterator being decorated. */
+ private Iterator iterator;
+
+ /**
+ * Constructs a new <code>IteratorEnumeration</code> that will not
+ * function until {@link #setIterator(Iterator) setIterator} is
+ * invoked.
+ */
+ public IteratorEnumeration() {
+ super();
+ }
+
+ /**
+ * Constructs a new <code>IteratorEnumeration</code> that will use
+ * the given iterator.
+ *
+ * @param iterator the iterator to use
+ */
+ public IteratorEnumeration( Iterator iterator ) {
+ super();
+ this.iterator = iterator;
+ }
+
+ // Iterator interface
+ //-------------------------------------------------------------------------
+
+ /**
+ * Returns true if the underlying iterator has more elements.
+ *
+ * @return true if the underlying iterator has more elements
+ */
+ public boolean hasMoreElements() {
+ return iterator.hasNext();
+ }
+
+ /**
+ * Returns the next element from the underlying iterator.
+ *
+ * @return the next element from the underlying iterator.
+ * @throws java.util.NoSuchElementException if the underlying iterator has no
+ * more elements
+ */
+ public Object nextElement() {
+ return iterator.next();
+ }
+
+ // Properties
+ //-------------------------------------------------------------------------
+
+ /**
+ * Returns the underlying iterator.
+ *
+ * @return the underlying iterator
+ */
+ public Iterator getIterator() {
+ return iterator;
+ }
+
+ /**
+ * Sets the underlying iterator.
+ *
+ * @param iterator the new underlying iterator
+ */
+ public void setIterator( Iterator iterator ) {
+ this.iterator = iterator;
+ }
+
+ }
+
}
1.23.2.1 +4 -2 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java
Index: TestBeanReader.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/TestBeanReader.java,v
retrieving revision 1.23
retrieving revision 1.23.2.1
diff -u -r1.23 -r1.23.2.1
--- TestBeanReader.java 13 Jun 2004 21:32:46 -0000 1.23
+++ TestBeanReader.java 4 Aug 2004 22:16:54 -0000 1.23.2.1
@@ -31,6 +31,7 @@
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
+import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
@@ -43,7 +44,6 @@
import org.apache.commons.betwixt.io.BeanWriter;
import org.apache.commons.betwixt.strategy.ConvertUtilsObjectStringConverter;
import org.apache.commons.betwixt.strategy.HyphenatedNameMapper;
-import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.digester.ExtendedBaseRules;
import org.apache.commons.digester.Rule;
import org.xml.sax.Attributes;
@@ -706,7 +706,9 @@
assertEquals("Number of children", 6, bean.getSize());
ArrayList list = new ArrayList();
- CollectionUtils.addAll(list, bean.getChildren());
+ for (Iterator it=bean.getChildren();it.hasNext();) {
+ list.add(it.next());
+ }
DoubleLinkedChildBean childZero = (DoubleLinkedChildBean) list.get(0);
DoubleLinkedChildBean childOne = (DoubleLinkedChildBean) list.get(1);
No revision
No revision
1.2.2.1 +12 -3 jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TuneBean.java
Index: TuneBean.java
===================================================================
RCS file: /home/cvs/jakarta-commons/betwixt/src/test/org/apache/commons/betwixt/strategy/TuneBean.java,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -r1.2 -r1.2.2.1
--- TuneBean.java 13 Jun 2004 21:32:49 -0000 1.2
+++ TuneBean.java 4 Aug 2004 22:16:54 -0000 1.2.2.1
@@ -21,7 +21,6 @@
import java.util.Collection;
import java.util.Iterator;
-import org.apache.commons.collections.CollectionUtils;
/**
* @author <a href='http://jakarta.apache.org/'>Jakarta Commons Team</a>
@@ -74,6 +73,16 @@
}
public boolean sameComposers(Collection otherComposers) {
- return CollectionUtils.isEqualCollection(otherComposers, composers);
+ // doesn't check cardinality but should be ok
+ if (otherComposers.size() != composers.size()) {
+ return false;
+ }
+ for (Iterator it=composers.iterator();it.hasNext();) {
+ Object object = it.next();
+ if (!otherComposers.contains(object)) {
+ return false;
+ }
+ }
+ return true;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org