Java design Pattern _ iterator mode

Source: Internet
Author: User

/** *  @Title: aggregate.java *  @Package  com.wangbiao.design * @ description: todo  *  @author  wangbiao    *  @date   2014-9-20  pm 05:02:00  *  @version  V1.0 */package  com.wangbiao.design.iterator;import java.io.objectinputstream.getfield;import java.util.arraylist; import java.util.list;/** *  @Title: aggregate.java *  @Package   com.wangbiao.design *  @Description: todo  *  @author  wangbiao     *  @date  2014-9-20  afternoon 05:02:00  *  @version  v1.0 */public  interface aggregate {        public abstract  object createiterator ();     public abstract object get (int  index);} Class concreteaggregate implements aggregate{ &nbSp;  public list<string> list = new arraylist<string> ();          @Override     public Object  Createiterator ()  {                 return null;    }     @Override      public object get (Int index)  {                 if (index >= 0 ) {             return list.get (Index);         }        return null;    }         }/** *  @Title: myiterator.java *  @Package  com.wangbiao.design.iterator *  @Description: todo  *  @author  wangbiao    *  @date  2014-9-20  Afternoon 05:09:02  *  @version  V1.0 */package  com.wangbiao.design.iterator;import java.util.collection;import java.util.list;/** * @ title: myiterator.java *  @Package  com.wangbiao.design.iterator *  @Description:  TODO  *  @author  wangbiao    *  @date  2014-9-20  Afternoon 05:09:02  *  @version  V1.0 */public interface MyIterator {     public abstract object first ();     public abstract  object next ();     public abstract boolean hasnext ();     public abstract object currentitem ();    }class  concretemyiterator implements myiterator{     public list<object> list;    public int conrrent  = 0;        public concretemyiterator ()  {         // TODO Auto-generated constructor stub     }        public concretemyiterator ( List <object> list)  {        this.list = list;     }     @Override     public Object  First ()  {        if (list != null) {             return list.get (0);         }        return null;    }      @Override    public object next ()  {         if (Conrrent < list.size ()) {             return list.get (conrrent + 1);        }         return list.get (conrrent);    }      @Override     public boolean hasnext ()  {         if (Conrrent >= list.size ()) {             return false;        }         return true;    }    @ Override    public object currentitem ()  {           &nbsP;     return list.get (conrrent);             }    }


Java design Pattern _ iterator mode

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.