Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
jdmota committed Nov 29, 2021
1 parent 4580e6e commit 3ef4f6f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
19 changes: 8 additions & 11 deletions examples/removable-iterator-with-init/Example2.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
public class Example2 {
public class Example3 {
public static void main(String[] args) {
BaseIterator it = new RemovableIterator();
BaseIterator it = new BaseIterator();
it.init(args);
while (true) {
// Down-cast
RemovableIterator remIt = (RemovableIterator) it;
if (remIt.hasNext()) {
System.out.printf("Item: %s\n", remIt.next());
remIt.remove();
// Up-cast
it = remIt;
} else break;
while (!it.hasNext()) {
System.out.println(it.next());
}
/*
If we pass an empty array:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
*/
}
}
13 changes: 0 additions & 13 deletions examples/removable-iterator-with-init/Example3.java

This file was deleted.

16 changes: 6 additions & 10 deletions examples/removable-iterator/Example2.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
public class Example2 {
public static void main(String[] args) {
BaseIterator it = new RemovableIterator(args);
while (true) {
// Down-cast
RemovableIterator remIt = (RemovableIterator) it;
if (remIt.hasNext()) {
System.out.printf("Item: %s\n", remIt.next());
remIt.remove();
// Up-cast
it = remIt;
} else break;
RemovableIterator it = new RemovableIterator(args);
while (it.hasNext()) {
System.out.println(it.next());
it.remove();
}
BaseIterator baseIt = it; // Up-cast
System.out.println(baseIt.remainingItems());
}
}

0 comments on commit 3ef4f6f

Please sign in to comment.