webwork/src/main/webwork/util IteratorGenerator.java,1.7,1.8 SortIteratorFilter.java,1.6,1.7 SubsetIteratorFilter.java,1.7,1.8
[email protected] Sun, 23 Jun 2002 16:51:30 -0700
| Newsgroups | gmane.comp.java.webwork.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/webwork/webwork/src/main/webwork/util
In directory usw-pr-cvs1:/tmp/cvs-serv29734
Modified Files:
IteratorGenerator.java SortIteratorFilter.java
SubsetIteratorFilter.java
Log Message:
added support null iterator
Index: IteratorGenerator.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/util/IteratorGenerator.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- IteratorGenerator.java 8 May 2002 20:39:38 -0000 1.7
+++ IteratorGenerator.java 23 Jun 2002 23:51:28 -0000 1.8
@@ -55,30 +55,34 @@
// Action implementation -----------------------------------------
public String execute()
{
- values = new ArrayList();
- if (separator != null)
- {
- StringTokenizer tokens = new StringTokenizer(value.toString(), separator);
- while (tokens.hasMoreTokens())
+ if (value==null) {
+ return ERROR;
+ } else {
+ values = new ArrayList();
+ if (separator != null)
{
- values.add(tokens.nextToken());
+ StringTokenizer tokens = new StringTokenizer(value.toString(), separator);
+ while (tokens.hasMoreTokens())
+ {
+ values.add(tokens.nextToken());
+ }
+ } else
+ {
+ values.add(value.toString());
}
- } else
- {
- values.add(value.toString());
- }
- // Count default is the size of the list of values
- if (count == 0)
- count = values.size();
+ // Count default is the size of the list of values
+ if (count == 0)
+ count = values.size();
- return SUCCESS;
+ return SUCCESS;
+ }
}
// Iterator implementation ---------------------------------------
public boolean hasNext()
{
- return currentCount < count || count == -1;
+ return (value==null) ? false : (currentCount < count || count == -1);
}
public Object next()
Index: SortIteratorFilter.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/util/SortIteratorFilter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- SortIteratorFilter.java 8 May 2002 20:39:38 -0000 1.6
+++ SortIteratorFilter.java 23 Jun 2002 23:51:28 -0000 1.7
@@ -6,6 +6,8 @@
*/
package webwork.util;
+import org.apache.log4j.Category;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Comparator;
@@ -35,8 +37,6 @@
// Public --------------------------------------------------------
public void setSource(Object anIterator)
{
- if (anIterator == null)
- throw new IllegalArgumentException("Source may not be null");
source = anIterator;
}
@@ -52,52 +52,56 @@
// Action implementation -----------------------------------------
public String execute()
{
- try
- {
- // Check variants of input
- if (source instanceof Enumeration)
+ if (source==null) {
+ return ERROR;
+ } else {
+ try
{
- list = new ArrayList();
- Enumeration sourceEnum = (Enumeration)source;
- while (sourceEnum.hasMoreElements())
+ // Check variants of input
+ if (source instanceof Enumeration)
{
- Object o = (Object) sourceEnum.nextElement();
- list.add(o);
- }
- } if (source instanceof Iterator)
- {
- list = new ArrayList();
- Iterator sourceIterator = (Iterator)source;
- while (sourceIterator.hasNext())
+ list = new ArrayList();
+ Enumeration sourceEnum = (Enumeration)source;
+ while (sourceEnum.hasMoreElements())
+ {
+ Object o = (Object) sourceEnum.nextElement();
+ list.add(o);
+ }
+ } if (source instanceof Iterator)
{
- Object o = (Object) sourceIterator.next();
- list.add(o);
+ list = new ArrayList();
+ Iterator sourceIterator = (Iterator)source;
+ while (sourceIterator.hasNext())
+ {
+ Object o = (Object) sourceIterator.next();
+ list.add(o);
+ }
+ } else if (source instanceof Collection)
+ {
+ list = new ArrayList((Collection)source);
+ } else if (source instanceof Map)
+ {
+ list = new ArrayList(((Map)source).entrySet());
}
- } else if (source instanceof Collection)
- {
- list = new ArrayList((Collection)source);
- } else if (source instanceof Map)
- {
- list = new ArrayList(((Map)source).entrySet());
- }
- // Sort it
- Collections.sort(list, comparator);
+ // Sort it
+ Collections.sort(list, comparator);
- iterator = list.iterator();
+ iterator = list.iterator();
- return SUCCESS;
- } catch (Exception e)
- {
- e.printStackTrace();
- return ERROR;
+ return SUCCESS;
+ } catch (Exception e)
+ {
+ Category.getInstance(SortIteratorFilter.class.getName()).warn("Error creating sort iterator.", e);
+ return ERROR;
+ }
}
}
// Iterator implementation ---------------------------------------
public boolean hasNext()
{
- return iterator.hasNext();
+ return (source==null) ? false : iterator.hasNext();
}
public Object next()
Index: SubsetIteratorFilter.java
===================================================================
RCS file: /cvsroot/webwork/webwork/src/main/webwork/util/SubsetIteratorFilter.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- SubsetIteratorFilter.java 11 Mar 2002 09:02:35 -0000 1.7
+++ SubsetIteratorFilter.java 23 Jun 2002 23:51:28 -0000 1.8
@@ -6,6 +6,8 @@
*/
package webwork.util;
+import org.apache.log4j.Category;
+
import java.util.ArrayList;
import java.util.Iterator;
@@ -29,8 +31,6 @@
// Public --------------------------------------------------------
public void setSource(Object anIterator)
{
- if (anIterator == null)
- throw new IllegalArgumentException("Source may not be null");
source = anIterator;
}
@@ -47,6 +47,11 @@
// Action implementation -----------------------------------------
public String execute()
{
+ if (source==null) {
+ Category.getInstance(SubsetIteratorFilter.class.getName()).warn("Source is null returning empty set.");
+ return ERROR;
+ }
+
// Make source transformations
source = getIterator(source);
@@ -80,7 +85,7 @@
// Iterator implementation ---------------------------------------
public boolean hasNext()
{
- return iterator.hasNext() && (count == -1 || currentCount < count);
+ return (iterator==null) ? false: iterator.hasNext() && (count == -1 || currentCount < count);
}
public Object next()
-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/