1 28 29 package simple; 30 31 import java.util.Iterator ; 32 33 public class Customers6 34 { 35 private int fillPosition; 36 private Object [] customers; 37 38 private void setCustomerCount(int count) { 39 customers = new Object [count]; 40 fillPosition = 0; 41 } 42 43 private int getCustomerCount() { 44 return fillPosition; 45 } 46 47 private void addCustomer(Object obj) { 48 customers[fillPosition++] = obj; 49 } 50 51 private Iterator getCustomerIterator() { 52 return new CustomerIterator(); 53 } 54 55 private class CustomerIterator implements Iterator { 56 57 int nextIndex; 58 59 private CustomerIterator() { 60 nextIndex = 0; 61 } 62 63 public boolean hasNext() { 64 return nextIndex < fillPosition; 65 } 66 67 public Object next() { 68 if (nextIndex < fillPosition) { 69 return customers[nextIndex++]; 70 } else { 71 return null; 72 } 73 } 74 75 public void remove() { 76 throw new UnsupportedOperationException ("No remove support"); 77 } 78 } 79 } 80 | Popular Tags |