package com.zing.mode.iterator;

/**
 * @author zing
 * @date 2018/3/6 15:34
 */
public class BookShelf implements Aggregate {

    private Book[] books;
    private int last = 0;

    public BookShelf(int shelfSize) {
        this.books = new Book[shelfSize];
    }

    public Book getBookAt(int index) {
        return books[index];
    }

    public Iterator iterator() {
        return new BookshelfIterator(this);
    }

    public int getLength() {
        return last;
    }

    public void setBooks(Book[] books) {
        this.books = books;
        this.last = books.length;
    }
}

@@ -26,16 +26,93 @@
 rator;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A
 /**%0A * @
@@ -210,22 +210,31 @@
 private 
+ArrayList%3C
 Book
-%5B%5D
+%3E
  books;%0A
@@ -285,21 +285,8 @@
 elf(
-int shelfSize
 ) %7B%0A
@@ -314,23 +314,25 @@
 new 
-Book%5BshelfSize%5D
+ArrayList%3CBook%3E()
 ;%0A  
@@ -399,15 +399,19 @@
 ooks
-%5B
+.get(
 index
-%5D
+)
 ;%0A  
@@ -576,11 +576,11 @@
 oid 
-set
+add
 Book
@@ -589,20 +589,16 @@
 Book%5B%5D b
-ooks
 ) %7B%0A    
@@ -605,26 +605,64 @@
     
-this.books = books
+List%3CBook%3E l = Arrays.asList(b);%0A        books.addAll(l)
 ;%0A  
@@ -689,14 +689,14 @@
 oks.
-length
+size()
 ;%0A  

change Array to ArrayList