appenditeratorfilter.java

来自「webwork source」· Java 代码 · 共 79 行

JAVA
79
字号
/* * WebWork, Web Application Framework * * Distributable under Apache license. * See terms of license at opensource.org */package webwork.util;import java.util.ArrayList;import java.util.Iterator;import java.util.List;/** *	A bean that takes several iterators and outputs them in sequence * *	@see <related> *	@author Rickard 謆erg (rickard@middleware-company.com) *	@version $Revision: 1.6 $ */public class AppendIteratorFilter   extends IteratorFilterSupport   implements java.util.Iterator, webwork.action.Action{   // Attributes ----------------------------------------------------   List sources = new ArrayList();   List iterators = new ArrayList();   // Public --------------------------------------------------------   public void setSource(Object anIterator)   {      sources.add(anIterator);   }   // Action implementation -----------------------------------------   public String execute()   {      // Make source transformations      for (int i = 0; i < sources.size(); i++)      {         Object source = sources.get(i);         iterators.add(getIterator(source));      }      return SUCCESS;   }   // Iterator implementation ---------------------------------------   public boolean hasNext()   {      if (iterators.size() > 0)      {         return (((Iterator)iterators.get(0)).hasNext());      } else         return false;   }   public Object next()   {      try      {         return ((Iterator)iterators.get(0)).next();      } finally      {         if (iterators.size() > 0)         {            if (!((Iterator)iterators.get(0)).hasNext())            {               iterators.remove(0);            }         }      }   }   public void remove()   {      throw new UnsupportedOperationException();   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?