MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / CollectionSequence

Class CollectionSequence

collections/CollectionSequence.java:8–32  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6import java.util.*;
7
8public class CollectionSequence
9extends AbstractCollection<Pet> {
10 private Pet[] pets = new PetCreator().array(8);
11 @Override
12 public int size() { return pets.length; }
13 @Override public Iterator<Pet> iterator() {
14 return new Iterator<Pet>() { // [1]
15 private int index = 0;
16 @Override public boolean hasNext() {
17 return index < pets.length;
18 }
19 @Override
20 public Pet next() { return pets[index++]; }
21 @Override
22 public void remove() { // Not implemented
23 throw new UnsupportedOperationException();
24 }
25 };
26 }
27 public static void main(String[] args) {
28 CollectionSequence c = new CollectionSequence();
29 InterfaceVsIterator.display(c);
30 InterfaceVsIterator.display(c.iterator());
31 }
32}
33/* Output:
340:Rat 1:Manx 2:Cymric 3:Mutt 4:Pug 5:Cymric 6:Pug
357:Manx

Callers

nothing calls this directly

Calls 1

arrayMethod · 0.45

Tested by

no test coverage detected