| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.util; |
| 18 |
|
| 19 |
import java.util.AbstractSet; |
| 20 |
import java.util.Iterator; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public final class FastImmutableArraySet<T> extends AbstractSet<T> { |
| 31 |
FastIterator<T> mIterator; |
| 32 |
T[] mContents; |
| 33 |
|
| 34 |
public FastImmutableArraySet(T[] contents) { |
| 35 |
mContents = contents; |
| 36 |
} |
| 37 |
|
| 38 |
@Override |
| 39 |
public Iterator<T> iterator() { |
| 40 |
FastIterator<T> it = mIterator; |
| 41 |
if (it == null) { |
| 42 |
it = new FastIterator<T>(mContents); |
| 43 |
mIterator = it; |
| 44 |
} else { |
| 45 |
it.mIndex = 0; |
| 46 |
} |
| 47 |
return it; |
| 48 |
} |
| 49 |
|
| 50 |
@Override |
| 51 |
public int size() { |
| 52 |
return mContents.length; |
| 53 |
} |
| 54 |
|
| 55 |
private static final class FastIterator<T> implements Iterator<T> { |
| 56 |
private final T[] mContents; |
| 57 |
int mIndex; |
| 58 |
|
| 59 |
public FastIterator(T[] contents) { |
| 60 |
mContents = contents; |
| 61 |
} |
| 62 |
|
| 63 |
@Override |
| 64 |
public boolean hasNext() { |
| 65 |
return mIndex != mContents.length; |
| 66 |
} |
| 67 |
|
| 68 |
@Override |
| 69 |
public T next() { |
| 70 |
return mContents[mIndex++]; |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public void remove() { |
| 75 |
throw new UnsupportedOperationException(); |
| 76 |
} |
| 77 |
} |
| 78 |
} |