Resolves checkstyle errors for intercepting-filter, interpreter, iterator (#1065)
* Reduces checkstyle errors in intercepting-filter * Reduces checkstyle errors in interpreter * Reduces checkstyle errors in iterator
This commit is contained in:
committed by
Ilkka Seppälä
parent
dda09535e6
commit
7f06f3b78c
@ -39,8 +39,8 @@ import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* The Iterator pattern is a design pattern in which an iterator is used to traverse a container and
|
||||
* access the container's elements. The Iterator pattern decouples algorithms from containers.
|
||||
* <p>
|
||||
* In this example the Iterator ({@link Iterator}) adds abstraction layer on top of a collection
|
||||
*
|
||||
* <p>In this example the Iterator ({@link Iterator}) adds abstraction layer on top of a collection
|
||||
* ({@link TreasureChest}). This way the collection can change its internal implementation without
|
||||
* affecting its clients.
|
||||
*/
|
||||
@ -85,7 +85,7 @@ public class App {
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
|
@ -24,7 +24,8 @@
|
||||
package com.iluwatar.iterator;
|
||||
|
||||
/**
|
||||
* Iterator interface to be implemented by iterators over various data structures
|
||||
* Iterator interface to be implemented by iterators over various data structures.
|
||||
*
|
||||
* @param <T> generically typed for various objects
|
||||
*/
|
||||
public interface Iterator<T> {
|
||||
|
@ -32,7 +32,7 @@ import java.util.NoSuchElementException;
|
||||
* expect to retrieve TreeNodes according to the Integer's natural ordering (1, 2, 3...)
|
||||
*
|
||||
* @param <T> This Iterator has been implemented with generic typing to allow for TreeNodes of
|
||||
* different value types
|
||||
* different value types
|
||||
*/
|
||||
public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T>> {
|
||||
|
||||
@ -46,7 +46,7 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
|
||||
/**
|
||||
* This BstIterator manages to use O(h) extra space, where h is the height of the tree It achieves
|
||||
* this by maintaining a stack of the nodes to handle (pushing all left nodes first), before
|
||||
* handling self or right node
|
||||
* handling self or right node.
|
||||
*
|
||||
* @param node TreeNode that acts as root of the subtree we're interested in.
|
||||
*/
|
||||
@ -58,6 +58,8 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there exists next element.
|
||||
*
|
||||
* @return true if this iterator has a "next" element
|
||||
*/
|
||||
@Override
|
||||
@ -66,6 +68,8 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the next element.
|
||||
*
|
||||
* @return TreeNode next. The next element according to our in-order traversal of the given BST
|
||||
* @throws NoSuchElementException if this iterator does not have a next element
|
||||
*/
|
||||
|
@ -36,7 +36,7 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
private TreeNode<T> right;
|
||||
|
||||
/**
|
||||
* Creates a TreeNode with a given value, and null children
|
||||
* Creates a TreeNode with a given value, and null children.
|
||||
*
|
||||
* @param val The value of the given node
|
||||
*/
|
||||
@ -67,7 +67,7 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts new TreeNode based on a given value into the subtree represented by self
|
||||
* Inserts new TreeNode based on a given value into the subtree represented by self.
|
||||
*
|
||||
* @param valToInsert The value to insert as a new TreeNode
|
||||
*/
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.iterator.list;
|
||||
|
||||
/**
|
||||
*
|
||||
* Item
|
||||
*
|
||||
* Item.
|
||||
*/
|
||||
public class Item {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.iterator.list;
|
||||
|
||||
/**
|
||||
*
|
||||
* ItemType enumeration
|
||||
*
|
||||
* ItemType enumeration.
|
||||
*/
|
||||
public enum ItemType {
|
||||
|
||||
|
@ -28,29 +28,27 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* TreasureChest, the collection class.
|
||||
*
|
||||
*/
|
||||
public class TreasureChest {
|
||||
|
||||
private List<Item> items;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public TreasureChest() {
|
||||
items = List.of(
|
||||
new Item(ItemType.POTION, "Potion of courage"),
|
||||
new Item(ItemType.RING, "Ring of shadows"),
|
||||
new Item(ItemType.POTION, "Potion of wisdom"),
|
||||
new Item(ItemType.POTION, "Potion of blood"),
|
||||
new Item(ItemType.WEAPON, "Sword of silver +1"),
|
||||
new Item(ItemType.POTION, "Potion of rust"),
|
||||
new Item(ItemType.POTION, "Potion of healing"),
|
||||
new Item(ItemType.RING, "Ring of armor"),
|
||||
new Item(ItemType.WEAPON, "Steel halberd"),
|
||||
new Item(ItemType.WEAPON, "Dagger of poison"));
|
||||
new Item(ItemType.POTION, "Potion of courage"),
|
||||
new Item(ItemType.RING, "Ring of shadows"),
|
||||
new Item(ItemType.POTION, "Potion of wisdom"),
|
||||
new Item(ItemType.POTION, "Potion of blood"),
|
||||
new Item(ItemType.WEAPON, "Sword of silver +1"),
|
||||
new Item(ItemType.POTION, "Potion of rust"),
|
||||
new Item(ItemType.POTION, "Potion of healing"),
|
||||
new Item(ItemType.RING, "Ring of armor"),
|
||||
new Item(ItemType.WEAPON, "Steel halberd"),
|
||||
new Item(ItemType.WEAPON, "Dagger of poison"));
|
||||
}
|
||||
|
||||
public Iterator<Item> iterator(ItemType itemType) {
|
||||
@ -58,7 +56,7 @@ public class TreasureChest {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all items
|
||||
* Get all items.
|
||||
*/
|
||||
public List<Item> getItems() {
|
||||
return new ArrayList<>(items);
|
||||
|
@ -27,9 +27,7 @@ import com.iluwatar.iterator.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* TreasureChestItemIterator
|
||||
*
|
||||
* TreasureChestItemIterator.
|
||||
*/
|
||||
public class TreasureChestItemIterator implements Iterator<Item> {
|
||||
|
||||
@ -38,7 +36,7 @@ public class TreasureChestItemIterator implements Iterator<Item> {
|
||||
private ItemType type;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public TreasureChestItemIterator(TreasureChest chest, ItemType type) {
|
||||
this.chest = chest;
|
||||
|
Reference in New Issue
Block a user