| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 32 | | | |
| 33 | | | package org.jcoderz.commons.util; |
| 34 | | | |
| 35 | | | import java.io.Serializable; |
| 36 | | | import java.util.ArrayList; |
| 37 | | | import java.util.Arrays; |
| 38 | | | import java.util.Collection; |
| 39 | | | import java.util.Iterator; |
| 40 | | | import java.util.List; |
| 41 | | | import java.util.NoSuchElementException; |
| 42 | | | |
| 43 | | | |
| 44 | | | |
| 45 | | | {@link } |
| 46 | | | {@link } |
| 47 | | | |
| 48 | | | |
| 49 | | | |
| 50 | | | |
| 51 | | | |
| 52 | | | @author |
| 53 | | | |
| 54 | | | public final class SerializableIterator |
| 55 | | | implements Iterator, Serializable |
| 56 | | | { |
| 57 | | | static final long serialVersionUID = 1L; |
| 58 | | | |
| 59 | | | private final List mItems; |
| 60 | 100 | | private int mNextIndex = 0; |
| 61 | | | |
| 62 | | | |
| 63 | | | private SerializableIterator (Collection c) |
| 64 | 100 | | { |
| 65 | 100 | | mItems = new ArrayList(); |
| 66 | 100 | | mItems.addAll(c); |
| 67 | 100 | | } |
| 68 | | | |
| 69 | | | |
| 70 | | | |
| 71 | | | |
| 72 | | | |
| 73 | | | @param |
| 74 | | | |
| 75 | | | @return |
| 76 | | | |
| 77 | | | public static SerializableIterator fromCollection (Collection collection) |
| 78 | | | { |
| 79 | 100 | | Assert.notNull(collection, "collection"); |
| 80 | 100 | | return new SerializableIterator(collection); |
| 81 | | | } |
| 82 | | | |
| 83 | | | |
| 84 | | | |
| 85 | | | |
| 86 | | | |
| 87 | | | @param |
| 88 | | | |
| 89 | | | @return |
| 90 | | | |
| 91 | | | public static SerializableIterator fromArray (Object[] array) |
| 92 | | | { |
| 93 | 100 | | Assert.notNull(array, "array"); |
| 94 | 100 | | return new SerializableIterator(Arrays.asList(array)); |
| 95 | | | } |
| 96 | | | |
| 97 | | | |
| 98 | | | |
| 99 | | | @throws |
| 100 | | | @see |
| 101 | | | |
| 102 | | | public void remove () |
| 103 | | | throws UnsupportedOperationException |
| 104 | | | { |
| 105 | 0 | | throw new UnsupportedOperationException( |
| 106 | | | "Can't remove from a SerializableIterator"); |
| 107 | | | } |
| 108 | | | |
| 109 | | | {@inheritDoc} |
| 110 | | | public boolean hasNext () |
| 111 | | | { |
| 112 | 100 | | return mNextIndex < mItems.size(); |
| 113 | | | } |
| 114 | | | |
| 115 | | | {@inheritDoc} |
| 116 | | | public Object next () |
| 117 | | | { |
| 118 | 100 | | if (mNextIndex >= mItems.size()) |
| 119 | | | { |
| 120 | 100 | | throw new NoSuchElementException(); |
| 121 | | | } |
| 122 | 100 | | return mItems.get(mNextIndex++); |
| 123 | | | } |
| 124 | | | |
| 125 | | | {@inheritDoc} |
| 126 | | | public String toString () |
| 127 | | | { |
| 128 | 0 | | return "[SerializableIterator: " + mItems + "]"; |
| 129 | | | } |
| 130 | | | } |