mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-18 09:25:54 +00:00
deps: Refactor dependencies (#3224)
* remove spring dep move junit, logging, mockito under dep mgmt * upgrade anti-corruption-layer deps * async method invocation * balking, bloc * bridge to bytecode * caching * callback - cqrs * component - health check * hexagonal - metadata mapping * rest of the patterns * remove checkstyle, take spotless into use
This commit is contained in:
@@ -33,7 +33,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>> {
|
||||
|
||||
@@ -83,5 +83,4 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
|
||||
pushPathToNextSmallest(next.getRight());
|
||||
return next;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,13 +37,9 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
|
||||
private final T val;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private TreeNode<T> left;
|
||||
@Getter @Setter private TreeNode<T> left;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private TreeNode<T> right;
|
||||
@Getter @Setter private TreeNode<T> right;
|
||||
|
||||
/**
|
||||
* Creates a TreeNode with a given value, and null children.
|
||||
@@ -129,5 +125,4 @@ public class TreeNode<T extends Comparable<T>> {
|
||||
public String toString() {
|
||||
return val.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,15 +28,11 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Item.
|
||||
*/
|
||||
/** Item. */
|
||||
@AllArgsConstructor
|
||||
public class Item {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private ItemType type;
|
||||
@Getter @Setter private ItemType type;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,11 +24,10 @@
|
||||
*/
|
||||
package com.iluwatar.iterator.list;
|
||||
|
||||
/**
|
||||
* ItemType enumeration.
|
||||
*/
|
||||
/** ItemType enumeration. */
|
||||
public enum ItemType {
|
||||
|
||||
ANY, WEAPON, RING, POTION
|
||||
|
||||
ANY,
|
||||
WEAPON,
|
||||
RING,
|
||||
POTION
|
||||
}
|
||||
|
||||
@@ -28,39 +28,33 @@ import com.iluwatar.iterator.Iterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* TreasureChest, the collection class.
|
||||
*/
|
||||
/** TreasureChest, the collection class. */
|
||||
public class TreasureChest {
|
||||
|
||||
private final 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"));
|
||||
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"));
|
||||
}
|
||||
|
||||
public Iterator<Item> iterator(ItemType itemType) {
|
||||
return new TreasureChestItemIterator(this, itemType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all items.
|
||||
*/
|
||||
/** Get all items. */
|
||||
public List<Item> getItems() {
|
||||
return new ArrayList<>(items);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,18 +26,14 @@ package com.iluwatar.iterator.list;
|
||||
|
||||
import com.iluwatar.iterator.Iterator;
|
||||
|
||||
/**
|
||||
* TreasureChestItemIterator.
|
||||
*/
|
||||
/** TreasureChestItemIterator. */
|
||||
public class TreasureChestItemIterator implements Iterator<Item> {
|
||||
|
||||
private final TreasureChest chest;
|
||||
private int idx;
|
||||
private final ItemType type;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
/** Constructor. */
|
||||
public TreasureChestItemIterator(TreasureChest chest, ItemType type) {
|
||||
this.chest = chest;
|
||||
this.type = type;
|
||||
|
||||
@@ -24,17 +24,15 @@
|
||||
*/
|
||||
package com.iluwatar.iterator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
/**
|
||||
* Application Test
|
||||
*/
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/** Application Test */
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
void shouldExecuteApplicationWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
assertDoesNotThrow(() -> App.main(new String[] {}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ class BstIteratorTest {
|
||||
@Test
|
||||
void nextForEmptyTree() {
|
||||
var iter = new BstIterator<>(emptyRoot);
|
||||
assertThrows(NoSuchElementException.class, iter::next,
|
||||
assertThrows(
|
||||
NoSuchElementException.class,
|
||||
iter::next,
|
||||
"next() should throw an IllegalStateException if hasNext() is false.");
|
||||
}
|
||||
|
||||
@@ -100,5 +102,4 @@ class BstIteratorTest {
|
||||
assertEquals(Integer.valueOf(7), iter.next().getVal(), "Sixth Node is 7.");
|
||||
assertFalse(iter.hasNext(), "Iterator hasNext() should be false, end of tree.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,10 +32,7 @@ import java.util.List;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
/**
|
||||
* TreasureChestTest
|
||||
*
|
||||
*/
|
||||
/** TreasureChestTest */
|
||||
class TreasureChestTest {
|
||||
|
||||
/**
|
||||
@@ -45,17 +42,16 @@ class TreasureChestTest {
|
||||
*/
|
||||
public static List<Object[]> dataProvider() {
|
||||
return List.of(
|
||||
new Object[]{new Item(ItemType.POTION, "Potion of courage")},
|
||||
new Object[]{new Item(ItemType.RING, "Ring of shadows")},
|
||||
new Object[]{new Item(ItemType.POTION, "Potion of wisdom")},
|
||||
new Object[]{new Item(ItemType.POTION, "Potion of blood")},
|
||||
new Object[]{new Item(ItemType.WEAPON, "Sword of silver +1")},
|
||||
new Object[]{new Item(ItemType.POTION, "Potion of rust")},
|
||||
new Object[]{new Item(ItemType.POTION, "Potion of healing")},
|
||||
new Object[]{new Item(ItemType.RING, "Ring of armor")},
|
||||
new Object[]{new Item(ItemType.WEAPON, "Steel halberd")},
|
||||
new Object[]{new Item(ItemType.WEAPON, "Dagger of poison")}
|
||||
);
|
||||
new Object[] {new Item(ItemType.POTION, "Potion of courage")},
|
||||
new Object[] {new Item(ItemType.RING, "Ring of shadows")},
|
||||
new Object[] {new Item(ItemType.POTION, "Potion of wisdom")},
|
||||
new Object[] {new Item(ItemType.POTION, "Potion of blood")},
|
||||
new Object[] {new Item(ItemType.WEAPON, "Sword of silver +1")},
|
||||
new Object[] {new Item(ItemType.POTION, "Potion of rust")},
|
||||
new Object[] {new Item(ItemType.POTION, "Potion of healing")},
|
||||
new Object[] {new Item(ItemType.RING, "Ring of armor")},
|
||||
new Object[] {new Item(ItemType.WEAPON, "Steel halberd")},
|
||||
new Object[] {new Item(ItemType.WEAPON, "Dagger of poison")});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,7 +78,6 @@ class TreasureChestTest {
|
||||
}
|
||||
|
||||
fail("Expected to find item [" + expectedItem + "] using iterator, but we didn't.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -109,7 +104,5 @@ class TreasureChestTest {
|
||||
}
|
||||
|
||||
fail("Expected to find item [" + expectedItem + "] in the item list, but we didn't.");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user