mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-15 14:59:25 +00:00
Java 11 migrate remaining (g,h,i) (#1116)
* Moves game-loop to Java 11 * Moves guarded-suspension to Java 11 * Moves half-sync-half-async to Java 11 * Moves hexagonal to Java 11 * Moves intercepting-filter to Java 11 * Moves interpreter to Java 11 * Moves iterator to Java 11
This commit is contained in:
committed by
Ilkka Seppälä
parent
7d0a5c0edb
commit
f835d3d516
@@ -30,7 +30,6 @@ import static com.iluwatar.iterator.list.ItemType.WEAPON;
|
||||
|
||||
import com.iluwatar.iterator.bst.BstIterator;
|
||||
import com.iluwatar.iterator.bst.TreeNode;
|
||||
import com.iluwatar.iterator.list.Item;
|
||||
import com.iluwatar.iterator.list.ItemType;
|
||||
import com.iluwatar.iterator.list.TreasureChest;
|
||||
import org.slf4j.Logger;
|
||||
@@ -53,7 +52,7 @@ public class App {
|
||||
private static void demonstrateTreasureChestIteratorForType(ItemType itemType) {
|
||||
LOGGER.info("------------------------");
|
||||
LOGGER.info("Item Iterator for ItemType " + itemType + ": ");
|
||||
Iterator<Item> itemIterator = TREASURE_CHEST.iterator(itemType);
|
||||
var itemIterator = TREASURE_CHEST.iterator(itemType);
|
||||
while (itemIterator.hasNext()) {
|
||||
LOGGER.info(itemIterator.next().toString());
|
||||
}
|
||||
@@ -62,15 +61,15 @@ public class App {
|
||||
private static void demonstrateBstIterator() {
|
||||
LOGGER.info("------------------------");
|
||||
LOGGER.info("BST Iterator: ");
|
||||
TreeNode<Integer> root = buildIntegerBst();
|
||||
BstIterator bstIterator = new BstIterator<>(root);
|
||||
var root = buildIntegerBst();
|
||||
var bstIterator = new BstIterator<Integer>(root);
|
||||
while (bstIterator.hasNext()) {
|
||||
LOGGER.info("Next node: " + bstIterator.next().getVal());
|
||||
}
|
||||
}
|
||||
|
||||
private static TreeNode<Integer> buildIntegerBst() {
|
||||
TreeNode<Integer> root = new TreeNode<>(8);
|
||||
var root = new TreeNode<>(8);
|
||||
|
||||
root.insert(3);
|
||||
root.insert(10);
|
||||
|
||||
@@ -78,7 +78,7 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
|
||||
if (pathStack.isEmpty()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
TreeNode<T> next = pathStack.pop();
|
||||
var next = pathStack.pop();
|
||||
pushPathToNextSmallest(next.getRight());
|
||||
return next;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public TreeNode next() throws IllegalStateException {
|
||||
if (pathStack.isEmpty()) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
TreeNode next = pathStack.pop();
|
||||
var next = pathStack.pop();
|
||||
// follow right child to next smallest node
|
||||
pushPathToNextSmallest(next.getRight());
|
||||
return next;
|
||||
|
||||
@@ -72,7 +72,7 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
* @param valToInsert The value to insert as a new TreeNode
|
||||
*/
|
||||
public void insert(T valToInsert) {
|
||||
TreeNode<T> parent = getParentNodeOfValueToBeInserted(valToInsert);
|
||||
var parent = getParentNodeOfValueToBeInserted(valToInsert);
|
||||
parent.insertNewChild(valToInsert);
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
*/
|
||||
private TreeNode<T> getParentNodeOfValueToBeInserted(T valToInsert) {
|
||||
TreeNode<T> parent = null;
|
||||
TreeNode<T> curr = this;
|
||||
var curr = this;
|
||||
|
||||
while (curr != null) {
|
||||
parent = curr;
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
package com.iluwatar.iterator.list;
|
||||
|
||||
import com.iluwatar.iterator.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TreasureChestItemIterator.
|
||||
@@ -59,10 +58,9 @@ public class TreasureChestItemIterator implements Iterator<Item> {
|
||||
}
|
||||
|
||||
private int findNextIdx() {
|
||||
List<Item> items = chest.getItems();
|
||||
boolean found = false;
|
||||
int tempIdx = idx;
|
||||
while (!found) {
|
||||
var items = chest.getItems();
|
||||
var tempIdx = idx;
|
||||
while (true) {
|
||||
tempIdx++;
|
||||
if (tempIdx >= items.size()) {
|
||||
tempIdx = -1;
|
||||
|
||||
Reference in New Issue
Block a user