Merge branch 'master' into core-java-move-2
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -30,7 +30,7 @@ out/
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
# Maven
|
# Maven
|
||||||
log/
|
log/*
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Gradle
|
# Gradle
|
||||||
@@ -84,3 +84,4 @@ software-security/sql-injection-samples/derby.log
|
|||||||
spring-soap/src/main/java/com/baeldung/springsoap/gen/
|
spring-soap/src/main/java/com/baeldung/springsoap/gen/
|
||||||
/report-*.json
|
/report-*.json
|
||||||
transaction.log
|
transaction.log
|
||||||
|
*-shell.log
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
## Relevant articles:
|
## Akka HTTP
|
||||||
|
|
||||||
|
This module contains articles about Akka HTTP.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Introduction to Akka HTTP](https://www.baeldung.com/akka-http)
|
- [Introduction to Akka HTTP](https://www.baeldung.com/akka-http)
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
## Akka Streams
|
||||||
|
|
||||||
|
This module contains articles about Akka Streams.
|
||||||
|
|
||||||
### Relevant articles
|
### Relevant articles
|
||||||
|
|
||||||
- [Guide to Akka Streams](https://www.baeldung.com/akka-streams)
|
- [Guide to Akka Streams](https://www.baeldung.com/akka-streams)
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
## Relevant articles:
|
## Genetic Algorithms
|
||||||
|
|
||||||
|
This module contains articles about genetic algorithms.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Introduction to Jenetics Library](https://www.baeldung.com/jenetics)
|
- [Introduction to Jenetics Library](https://www.baeldung.com/jenetics)
|
||||||
- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization)
|
- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization)
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
## Relevant articles:
|
## Algorithms - Miscellaneous
|
||||||
|
|
||||||
|
This module contains articles about algorithms. Some classes of algorithms, e.g., [sorting](/../algorithms-sorting) and
|
||||||
|
[genetic algorithms](/../algorithms-genetic), have their own dedicated modules.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata)
|
- [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata)
|
||||||
- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm)
|
- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm)
|
||||||
@@ -7,3 +12,4 @@
|
|||||||
- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
|
- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
|
||||||
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
|
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
|
||||||
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)
|
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)
|
||||||
|
- More articles: [[next -->]](/../algorithms-miscellaneous-2)
|
||||||
|
|||||||
@@ -1,4 +1,9 @@
|
|||||||
## Relevant articles:
|
## Algorithms - Miscellaneous
|
||||||
|
|
||||||
|
This module contains articles about algorithms. Some classes of algorithms, e.g., [sorting](/../algorithms-sorting) and
|
||||||
|
[genetic algorithms](/../algorithms-genetic), have their own dedicated modules.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Dijkstra Shortest Path Algorithm in Java](https://www.baeldung.com/java-dijkstra)
|
- [Dijkstra Shortest Path Algorithm in Java](https://www.baeldung.com/java-dijkstra)
|
||||||
- [Introduction to Cobertura](https://www.baeldung.com/cobertura)
|
- [Introduction to Cobertura](https://www.baeldung.com/cobertura)
|
||||||
@@ -8,3 +13,4 @@
|
|||||||
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
|
- [Create a Sudoku Solver in Java](https://www.baeldung.com/java-sudoku)
|
||||||
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
|
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
|
||||||
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||||
|
- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)
|
||||||
|
|||||||
@@ -14,4 +14,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
|
|||||||
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
|
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
|
||||||
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
|
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
|
||||||
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
||||||
|
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search)
|
||||||
|
- [The K-Means Clustering Algorithm in Java](https://www.baeldung.com/java-k-means-clustering-algorithm)
|
||||||
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)
|
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.baeldung.algorithms.breadthfirstsearch;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class BreadthFirstSearchAlgorithm {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(BreadthFirstSearchAlgorithm.class);
|
||||||
|
|
||||||
|
public static <T> Optional<Tree<T>> search(T value, Tree<T> root) {
|
||||||
|
Queue<Tree<T>> queue = new ArrayDeque<>();
|
||||||
|
queue.add(root);
|
||||||
|
|
||||||
|
Tree<T> currentNode;
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
currentNode = queue.remove();
|
||||||
|
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||||
|
|
||||||
|
if (currentNode.getValue().equals(value)) {
|
||||||
|
return Optional.of(currentNode);
|
||||||
|
} else {
|
||||||
|
queue.addAll(currentNode.getChildren());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Optional<Node<T>> search(T value, Node<T> start) {
|
||||||
|
Queue<Node<T>> queue = new ArrayDeque<>();
|
||||||
|
queue.add(start);
|
||||||
|
|
||||||
|
Node<T> currentNode;
|
||||||
|
Set<Node<T>> alreadyVisited = new HashSet<>();
|
||||||
|
|
||||||
|
while (!queue.isEmpty()) {
|
||||||
|
currentNode = queue.remove();
|
||||||
|
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||||
|
|
||||||
|
if (currentNode.getValue().equals(value)) {
|
||||||
|
return Optional.of(currentNode);
|
||||||
|
} else {
|
||||||
|
alreadyVisited.add(currentNode);
|
||||||
|
queue.addAll(currentNode.getNeighbors());
|
||||||
|
queue.removeAll(alreadyVisited);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.baeldung.algorithms.breadthfirstsearch;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class Node<T> {
|
||||||
|
|
||||||
|
private T value;
|
||||||
|
private Set<Node<T>> neighbors;
|
||||||
|
|
||||||
|
public Node(T value) {
|
||||||
|
this.value = value;
|
||||||
|
this.neighbors = new HashSet<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<Node<T>> getNeighbors() {
|
||||||
|
return Collections.unmodifiableSet(neighbors);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void connect(Node<T> node) {
|
||||||
|
if (this == node) throw new IllegalArgumentException("Can't connect node to itself");
|
||||||
|
this.neighbors.add(node);
|
||||||
|
node.neighbors.add(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.algorithms.breadthfirstsearch;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Tree<T> {
|
||||||
|
|
||||||
|
private T value;
|
||||||
|
private List<Tree<T>> children;
|
||||||
|
|
||||||
|
private Tree(T value) {
|
||||||
|
this.value = value;
|
||||||
|
this.children = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Tree<T> of(T value) {
|
||||||
|
return new Tree<>(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Tree<T>> getChildren() {
|
||||||
|
return Collections.unmodifiableList(children);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Tree<T> addChild(T value) {
|
||||||
|
Tree<T> newChild = new Tree<>(value);
|
||||||
|
children.add(newChild);
|
||||||
|
return newChild;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package com.baeldung.algorithms.breadthfirstsearch;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class BreadthFirstSearchAlgorithmUnitTest {
|
||||||
|
|
||||||
|
private Tree<Integer> root;
|
||||||
|
private Tree<Integer> rootFirstChild;
|
||||||
|
private Tree<Integer> depthMostChild;
|
||||||
|
private Tree<Integer> rootSecondChild;
|
||||||
|
|
||||||
|
private Node<Integer> start;
|
||||||
|
private Node<Integer> firstNeighbor;
|
||||||
|
private Node<Integer> firstNeighborNeighbor;
|
||||||
|
private Node<Integer> secondNeighbor;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTree_whenSearchTen_thenRoot() {
|
||||||
|
initTree();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(10, root)).isPresent().contains(root);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTree_whenSearchThree_thenDepthMostValue() {
|
||||||
|
initTree();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(3, root)).isPresent().contains(depthMostChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTree_whenSearchFour_thenRootSecondChild() {
|
||||||
|
initTree();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(4, root)).isPresent().contains(rootSecondChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenTree_whenSearchFive_thenNotFound() {
|
||||||
|
initTree();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(5, root)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTree() {
|
||||||
|
root = Tree.of(10);
|
||||||
|
rootFirstChild = root.addChild(2);
|
||||||
|
depthMostChild = rootFirstChild.addChild(3);
|
||||||
|
rootSecondChild = root.addChild(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNode_whenSearchTen_thenStart() {
|
||||||
|
initNode();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(10, firstNeighborNeighbor)).isPresent().contains(start);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNode_whenSearchThree_thenNeighborNeighbor() {
|
||||||
|
initNode();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(3, firstNeighborNeighbor)).isPresent().contains(firstNeighborNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNode_whenSearchFour_thenSecondNeighbor() {
|
||||||
|
initNode();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(4, firstNeighborNeighbor)).isPresent().contains(secondNeighbor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenNode_whenSearchFive_thenNotFound() {
|
||||||
|
initNode();
|
||||||
|
assertThat(BreadthFirstSearchAlgorithm.search(5, firstNeighborNeighbor)).isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initNode() {
|
||||||
|
start = new Node<>(10);
|
||||||
|
firstNeighbor = new Node<>(2);
|
||||||
|
start.connect(firstNeighbor);
|
||||||
|
|
||||||
|
firstNeighborNeighbor = new Node<>(3);
|
||||||
|
firstNeighbor.connect(firstNeighborNeighbor);
|
||||||
|
firstNeighborNeighbor.connect(start);
|
||||||
|
|
||||||
|
secondNeighbor = new Node<>(4);
|
||||||
|
start.connect(secondNeighbor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,9 @@
|
|||||||
## Relevant articles:
|
## Algorithms - Miscellaneous
|
||||||
|
|
||||||
|
This module contains articles about algorithms. Some classes of algorithms, e.g., [sorting](/../algorithms-sorting) and
|
||||||
|
[genetic algorithms](/../algorithms-genetic), have their own dedicated modules.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm)
|
- [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm)
|
||||||
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
|
- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
|
||||||
@@ -7,3 +12,4 @@
|
|||||||
- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)
|
- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)
|
||||||
- [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters)
|
- [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters)
|
||||||
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
|
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
|
||||||
|
- More articles: [[<-- prev]](/../algorithms-miscellaneous-3) [[next -->]](/../algorithms-miscellaneous-5)
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
## Relevant articles:
|
## Algorithms - Miscellaneous
|
||||||
|
|
||||||
|
This module contains articles about algorithms. Some classes of algorithms, e.g., [sorting](/../algorithms-sorting) and
|
||||||
|
[genetic algorithms](/../algorithms-genetic), have their own dedicated modules.
|
||||||
|
|
||||||
|
### Relevant articles:
|
||||||
|
|
||||||
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
|
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
|
||||||
- [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree)
|
- [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree)
|
||||||
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
|
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
|
||||||
|
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4)
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.algorithms.knapsack;
|
||||||
|
|
||||||
|
public class Knapsack {
|
||||||
|
|
||||||
|
public int knapsackRec(int[] w, int[] v, int n, int W) {
|
||||||
|
if (n <= 0) {
|
||||||
|
return 0;
|
||||||
|
} else if (w[n - 1] > W) {
|
||||||
|
return knapsackRec(w, v, n - 1, W);
|
||||||
|
} else {
|
||||||
|
return Math.max(knapsackRec(w, v, n - 1, W), v[n - 1] + knapsackRec(w, v, n - 1, W - w[n - 1]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int knapsackDP(int[] w, int[] v, int n, int W) {
|
||||||
|
if (n <= 0 || W <= 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int[][] m = new int[n + 1][W + 1];
|
||||||
|
for (int j = 0; j <= W; j++) {
|
||||||
|
m[0][j] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 1; i <= n; i++) {
|
||||||
|
for (int j = 1; j <= W; j++) {
|
||||||
|
if (w[i - 1] > j) {
|
||||||
|
m[i][j] = m[i - 1][j];
|
||||||
|
} else {
|
||||||
|
m[i][j] = Math.max(m[i - 1][j], m[i - 1][j - w[i - 1]] + v[i - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return m[n][W];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package com.baeldung.algorithms.knapsack;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
public class KnapsackUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenWeightsandValues_whenCalculateMax_thenOutputCorrectResult() {
|
||||||
|
final int[] w = new int[] { 23, 26, 20, 18, 32, 27, 29, 26, 30, 27 };
|
||||||
|
final int[] v = new int[] { 505, 352, 458, 220, 354, 414, 498, 545, 473, 543 };
|
||||||
|
final int n = 10;
|
||||||
|
final int W = 67;
|
||||||
|
final Knapsack knapsack = new Knapsack();
|
||||||
|
|
||||||
|
assertEquals(1270, knapsack.knapsackRec(w, v, n, W));
|
||||||
|
assertEquals(1270, knapsack.knapsackDP(w, v, n, W));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZeroItems_whenCalculateMax_thenOutputZero() {
|
||||||
|
final int[] w = new int[] {};
|
||||||
|
final int[] v = new int[] {};
|
||||||
|
final int n = 0;
|
||||||
|
final int W = 67;
|
||||||
|
final Knapsack knapsack = new Knapsack();
|
||||||
|
|
||||||
|
assertEquals(0, knapsack.knapsackRec(w, v, n, W));
|
||||||
|
assertEquals(0, knapsack.knapsackDP(w, v, n, W));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZeroWeightLimit_whenCalculateMax_thenOutputZero() {
|
||||||
|
final int[] w = new int[] { 23, 26, 20, 18, 32, 27, 29, 26, 30, 27 };
|
||||||
|
final int[] v = new int[] { 505, 352, 458, 220, 354, 414, 498, 545, 473, 543 };
|
||||||
|
final int n = 10;
|
||||||
|
final int W = 0;
|
||||||
|
final Knapsack knapsack = new Knapsack();
|
||||||
|
|
||||||
|
assertEquals(0, knapsack.knapsackRec(w, v, n, W));
|
||||||
|
assertEquals(0, knapsack.knapsackDP(w, v, n, W));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,3 +12,8 @@ This module contains articles about sorting algorithms.
|
|||||||
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
|
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
|
||||||
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
|
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
|
||||||
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
||||||
|
- [How an In-Place Sorting Algorithm Works](https://www.baeldung.com/java-in-place-sorting)
|
||||||
|
- [Selection Sort in Java](https://www.baeldung.com/java-selection-sort)
|
||||||
|
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
||||||
|
- [Radix Sort in Java](https://www.baeldung.com/java-radix-sort)
|
||||||
|
- [Sorting a String Alphabetically in Java](https://www.baeldung.com/java-sort-string-alphabetically)
|
||||||
|
|||||||
@@ -28,6 +28,12 @@
|
|||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-api</artifactId>
|
||||||
|
<version>${junit-jupiter-api.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
@@ -52,6 +58,7 @@
|
|||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||||
<commons-codec.version>1.11</commons-codec.version>
|
<commons-codec.version>1.11</commons-codec.version>
|
||||||
|
<junit-jupiter-api.version>5.3.1</junit-jupiter-api.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.string.sorting;
|
package com.baeldung.algorithms.stringsort;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
package com.baeldung.string.sorting;
|
package com.baeldung.algorithms.stringsort;
|
||||||
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import com.baeldung.string.sorting.AnagramValidator;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
class AnagramValidatorUnitTest {
|
class AnagramValidatorUnitTest {
|
||||||
|
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package com.baeldung.string.sorting;
|
package com.baeldung.algorithms.stringsort;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
class SortStringUnitTest {
|
class SortStringUnitTest {
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>animal-sniffer-mvn-plugin</name>
|
<name>animal-sniffer-mvn-plugin</name>
|
||||||
|
|||||||
@@ -14,12 +14,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-simple</artifactId>
|
<artifactId>slf4j-simple</artifactId>
|
||||||
@@ -46,15 +40,6 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.avro</groupId>
|
<groupId>org.apache.avro</groupId>
|
||||||
<artifactId>avro-maven-plugin</artifactId>
|
<artifactId>avro-maven-plugin</artifactId>
|
||||||
@@ -79,8 +64,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<compiler-plugin.version>3.5</compiler-plugin.version>
|
|
||||||
<avro.version>1.8.2</avro.version>
|
<avro.version>1.8.2</avro.version>
|
||||||
<slf4j.version>1.7.25</slf4j.version>
|
<slf4j.version>1.7.25</slf4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>apache-fop</artifactId>
|
<artifactId>apache-fop</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
<name>apache-fop</name>
|
<name>apache-fop</name>
|
||||||
|
|||||||
@@ -19,26 +19,8 @@
|
|||||||
<artifactId>geode-core</artifactId>
|
<artifactId>geode-core</artifactId>
|
||||||
<version>${geode.core}</version>
|
<version>${geode.core}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<geode.core>1.6.0</geode.core>
|
<geode.core>1.6.0</geode.core>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>apache-meecrowave</artifactId>
|
<artifactId>apache-meecrowave</artifactId>
|
||||||
<version>0.0.1</version>
|
<version>0.0.1</version>
|
||||||
<name>apache-meecrowave</name>
|
<name>apache-meecrowave</name>
|
||||||
@@ -38,13 +37,6 @@
|
|||||||
<version>${meecrowave-junit.version}</version>
|
<version>${meecrowave-junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>org.baeldung.examples.olingo2</groupId>
|
<groupId>org.baeldung.examples.olingo2</groupId>
|
||||||
<artifactId>olingo2</artifactId>
|
<artifactId>olingo2</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>olingo2</name>
|
<name>olingo2</name>
|
||||||
<description>Sample Olingo 2 Project</description>
|
<description>Sample Olingo 2 Project</description>
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<pulsar-client.version>2.1.1-incubating</pulsar-client.version>
|
<pulsar-client.version>2.1.1-incubating</pulsar-client.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ This module contains articles about Apache Shiro
|
|||||||
### Relevant articles:
|
### Relevant articles:
|
||||||
|
|
||||||
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
||||||
|
- [Permissions-Based Access Control with Apache Shiro](https://www.baeldung.com/apache-shiro-access-control)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>apache-solrj</artifactId>
|
<artifactId>apache-solrj</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>apache-solrj</name>
|
<name>apache-solrj</name>
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ This module contains articles about Apache Spark
|
|||||||
|
|
||||||
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
||||||
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
||||||
|
- [Machine Learning with Spark MLlib](https://www.baeldung.com/spark-mlib-machine-learning)
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>apache-spark</artifactId>
|
<artifactId>apache-spark</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>apache-spark</name>
|
<name>apache-spark</name>
|
||||||
@@ -59,15 +58,6 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${java.version}</source>
|
|
||||||
<target>${java.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<executions>
|
<executions>
|
||||||
@@ -95,7 +85,6 @@
|
|||||||
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
|
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
|
||||||
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
|
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
|
||||||
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
|
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
|
||||||
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
<artifactId>apache-velocity</artifactId>
|
<artifactId>apache-velocity</artifactId>
|
||||||
<name>apache-velocity</name>
|
<name>apache-velocity</name>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>aws-lambda</artifactId>
|
<artifactId>aws-lambda</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>aws-lambda</name>
|
<name>aws-lambda</name>
|
||||||
@@ -88,7 +87,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<json-simple.version>1.1.1</json-simple.version>
|
<json-simple.version>1.1.1</json-simple.version>
|
||||||
<org.json.version>20180130</org.json.version>
|
|
||||||
<commons-io.version>2.5</commons-io.version>
|
<commons-io.version>2.5</commons-io.version>
|
||||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>aws</artifactId>
|
<artifactId>aws</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>aws</name>
|
<name>aws</name>
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>azure</artifactId>
|
<artifactId>azure</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
<name>azure</name>
|
<name>azure</name>
|
||||||
|
|||||||
@@ -3,19 +3,14 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<!-- WITH THIS mvn integration-test DOES WORK -->
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>blade</artifactId>
|
<artifactId>blade</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
<name>blade</name>
|
<name>blade</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
<!-- WITH THIS mvn integration-test DOESN'T WORK -->
|
<groupId>com.baeldung</groupId>
|
||||||
<!-- <parent> -->
|
<artifactId>parent-modules</artifactId>
|
||||||
<!-- <groupId>com.baeldung</groupId> -->
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<!-- <artifactId>parent-modules</artifactId> -->
|
</parent>
|
||||||
<!-- <version>1.0.0-SNAPSHOT</version> -->
|
|
||||||
<!-- </parent> -->
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@@ -45,12 +40,6 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- TEST -->
|
<!-- TEST -->
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
@@ -79,20 +68,6 @@
|
|||||||
<build>
|
<build>
|
||||||
<finalName>sample-blade-app</finalName>
|
<finalName>sample-blade-app</finalName>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<forkCount>3</forkCount>
|
|
||||||
<reuseForks>true</reuseForks>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-failsafe-plugin</artifactId>
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
@@ -172,34 +147,19 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source}</source>
|
|
||||||
<target>${maven.compiler.target}</target>
|
|
||||||
<encoding>UTF-8</encoding>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<blade-mvc.version>2.0.14.RELEASE</blade-mvc.version>
|
<blade-mvc.version>2.0.14.RELEASE</blade-mvc.version>
|
||||||
<bootstrap.version>4.2.1</bootstrap.version>
|
<bootstrap.version>4.2.1</bootstrap.version>
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||||
<lombok.version>1.18.4</lombok.version>
|
<lombok.version>1.18.4</lombok.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<httpclient.version>4.5.6</httpclient.version>
|
<httpclient.version>4.5.6</httpclient.version>
|
||||||
<httpmime.version>4.5.6</httpmime.version>
|
<httpmime.version>4.5.6</httpmime.version>
|
||||||
<httpcore.version>4.4.10</httpcore.version>
|
<httpcore.version>4.4.10</httpcore.version>
|
||||||
<assertj-core.version>3.11.1</assertj-core.version>
|
<assertj-core.version>3.11.1</assertj-core.version>
|
||||||
<maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version>
|
<maven-failsafe-plugin.version>3.0.0-M3</maven-failsafe-plugin.version>
|
||||||
<process-exec-maven-plugin.version>0.7</process-exec-maven-plugin.version>
|
<process-exec-maven-plugin.version>0.7</process-exec-maven-plugin.version>
|
||||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -42,12 +42,6 @@
|
|||||||
<artifactId>bootique-test</artifactId>
|
<artifactId>bootique-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -198,7 +198,6 @@
|
|||||||
|
|
||||||
<wrapper-maven-plugin.version>0.0.4</wrapper-maven-plugin.version>
|
<wrapper-maven-plugin.version>0.0.4</wrapper-maven-plugin.version>
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||||
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
|
|
||||||
|
|
||||||
<echo-maven-plugin.version>0.3.0</echo-maven-plugin.version>
|
<echo-maven-plugin.version>0.3.0</echo-maven-plugin.version>
|
||||||
<pgpverify-maven-plugin.version>1.1.0</pgpverify-maven-plugin.version>
|
<pgpverify-maven-plugin.version>1.1.0</pgpverify-maven-plugin.version>
|
||||||
|
|||||||
@@ -36,12 +36,6 @@
|
|||||||
<version>${assertj-core.version}</version>
|
<version>${assertj-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>checker-plugin</artifactId>
|
<artifactId>checker-plugin</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
<name>checker-plugin</name>
|
<name>checker-plugin</name>
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>cf-uaa-oauth2-client</artifactId>
|
<artifactId>cf-uaa-oauth2-client</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>uaa-client-webapp</name>
|
<name>uaa-client-webapp</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung.cfuaa</groupId>
|
<groupId>com.baeldung.cfuaa</groupId>
|
||||||
<artifactId>cf-uaa-oauth2-resource-server</artifactId>
|
<artifactId>cf-uaa-oauth2-resource-server</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>cf-uaa-oauth2-resource-server</name>
|
<name>cf-uaa-oauth2-resource-server</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>code-generation</artifactId>
|
<artifactId>code-generation</artifactId>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
<name>code-generation</name>
|
<name>code-generation</name>
|
||||||
|
|||||||
@@ -11,4 +11,5 @@ This module contains articles about core Groovy concepts
|
|||||||
- [Integrating Groovy into Java Applications](https://www.baeldung.com/groovy-java-applications)
|
- [Integrating Groovy into Java Applications](https://www.baeldung.com/groovy-java-applications)
|
||||||
- [Concatenate Strings with Groovy](https://www.baeldung.com/groovy-concatenate-strings)
|
- [Concatenate Strings with Groovy](https://www.baeldung.com/groovy-concatenate-strings)
|
||||||
- [Metaprogramming in Groovy](https://www.baeldung.com/groovy-metaprogramming)
|
- [Metaprogramming in Groovy](https://www.baeldung.com/groovy-metaprogramming)
|
||||||
|
- [A Quick Guide to Working with Web Services in Groovy](https://www.baeldung.com/groovy-web-services)
|
||||||
- [[<-- Prev]](/core-groovy)
|
- [[<-- Prev]](/core-groovy)
|
||||||
@@ -181,10 +181,8 @@
|
|||||||
<hsqldb.version>2.4.0</hsqldb.version>
|
<hsqldb.version>2.4.0</hsqldb.version>
|
||||||
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
<spock-core.version>1.1-groovy-2.4</spock-core.version>
|
||||||
<groovy-wslite.version>1.1.3</groovy-wslite.version>
|
<groovy-wslite.version>1.1.3</groovy-wslite.version>
|
||||||
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>
|
|
||||||
<logback.version>1.2.3</logback.version>
|
<logback.version>1.2.3</logback.version>
|
||||||
<groovy.version>2.5.7</groovy.version>
|
<groovy.version>2.5.7</groovy.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
@@ -109,9 +109,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<junit.platform.version>1.0.0</junit.platform.version>
|
<junit.platform.version>1.0.0</junit.platform.version>
|
||||||
<!-- <groovy.version>2.4.13</groovy.version> -->
|
|
||||||
<!-- <groovy-all.version>2.4.13</groovy-all.version> -->
|
|
||||||
<!-- <groovy-sql.version>2.4.13</groovy-sql.version> -->
|
|
||||||
<groovy.version>2.5.6</groovy.version>
|
<groovy.version>2.5.6</groovy.version>
|
||||||
<groovy-all.version>2.5.6</groovy-all.version>
|
<groovy-all.version>2.5.6</groovy-all.version>
|
||||||
<groovy-sql.version>2.5.6</groovy-sql.version>
|
<groovy-sql.version>2.5.6</groovy-sql.version>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>core-java-8-2</artifactId>
|
<artifactId>core-java-8-2</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-8-2</name>
|
<name>core-java-8-2</name>
|
||||||
@@ -30,24 +29,7 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source}</source>
|
|
||||||
<target>${maven.compiler.target}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<icu.version>64.2</icu.version>
|
<icu.version>64.2</icu.version>
|
||||||
<assertj.version>3.12.2</assertj.version>
|
<assertj.version>3.12.2</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>core-java-8</artifactId>
|
<artifactId>core-java-8</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-8</name>
|
<name>core-java-8</name>
|
||||||
@@ -20,31 +19,11 @@
|
|||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
<version>${commons-collections4.version}</version>
|
<version>${commons-collections4.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-io</groupId>
|
|
||||||
<artifactId>commons-io</artifactId>
|
|
||||||
<version>${commons-io.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-math3</artifactId>
|
|
||||||
<version>${commons-math3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
<version>${commons-codec.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -58,64 +37,6 @@
|
|||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
|
||||||
<artifactId>awaitility</artifactId>
|
|
||||||
<version>${avaitility.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-core</artifactId>
|
|
||||||
<version>${jmh-core.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
|
||||||
<version>${jmh-generator.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-generator-bytecode</artifactId>
|
|
||||||
<version>${jmh-generator.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.codepoetics</groupId>
|
|
||||||
<artifactId>protonpack</artifactId>
|
|
||||||
<version>${protonpack.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.vavr</groupId>
|
|
||||||
<artifactId>vavr</artifactId>
|
|
||||||
<version>${vavr.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>joda-time</groupId>
|
|
||||||
<artifactId>joda-time</artifactId>
|
|
||||||
<version>${joda.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjrt</artifactId>
|
|
||||||
<version>${asspectj.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.aspectj</groupId>
|
|
||||||
<artifactId>aspectjweaver</artifactId>
|
|
||||||
<version>${asspectj.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.powermock</groupId>
|
|
||||||
<artifactId>powermock-module-junit4</artifactId>
|
|
||||||
<version>${powermock.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.powermock</groupId>
|
|
||||||
<artifactId>powermock-api-mockito2</artifactId>
|
|
||||||
<version>${powermock.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -149,22 +70,10 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<collections-generic.version>4.01</collections-generic.version>
|
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
|
||||||
<vavr.version>0.9.0</vavr.version>
|
|
||||||
<protonpack.version>1.13</protonpack.version>
|
|
||||||
<joda.version>2.10</joda.version>
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<asspectj.version>1.8.9</asspectj.version>
|
|
||||||
<powermock.version>2.0.0-RC.4</powermock.version>
|
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
|
||||||
<jmh-generator.version>1.19</jmh-generator.version>
|
|
||||||
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
|
||||||
<!-- plugins -->
|
<!-- plugins -->
|
||||||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
|
<spring-boot-maven-plugin.version>2.0.4.RELEASE</spring-boot-maven-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package com.baeldung.java_8_features.groupingby;
|
package com.baeldung.java_8_features.groupingby;
|
||||||
|
|
||||||
public class Tuple {
|
import java.util.Objects;
|
||||||
|
|
||||||
private BlogPostType type;
|
public class Tuple {
|
||||||
private String author;
|
private final BlogPostType type;
|
||||||
|
private final String author;
|
||||||
|
|
||||||
public Tuple(BlogPostType type, String author) {
|
public Tuple(BlogPostType type, String author) {
|
||||||
super();
|
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.author = author;
|
this.author = author;
|
||||||
}
|
}
|
||||||
@@ -15,20 +15,27 @@ public class Tuple {
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setType(BlogPostType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return author;
|
return author;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthor(String author) {
|
@Override
|
||||||
this.author = author;
|
public boolean equals(Object o) {
|
||||||
|
if (this == o)
|
||||||
|
return true;
|
||||||
|
if (o == null || getClass() != o.getClass())
|
||||||
|
return false;
|
||||||
|
Tuple tuple = (Tuple) o;
|
||||||
|
return type == tuple.type && author.equals(tuple.author);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(type, author);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Tuple [type=" + type + ", author=" + author + ", getType()=" + getType() + ", getAuthor()=" + getAuthor() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()=" + super.toString() + "]";
|
return "Tuple{" + "type=" + type + ", author='" + author + '\'' + '}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,32 @@
|
|||||||
package com.baeldung.java_8_features.groupingby;
|
package com.baeldung.java_8_features.groupingby;
|
||||||
|
|
||||||
import com.baeldung.java_8_features.groupingby.BlogPost;
|
import static java.util.Comparator.comparingInt;
|
||||||
import com.baeldung.java_8_features.groupingby.BlogPostType;
|
import static java.util.stream.Collectors.averagingInt;
|
||||||
import org.junit.Test;
|
import static java.util.stream.Collectors.counting;
|
||||||
|
import static java.util.stream.Collectors.groupingBy;
|
||||||
|
import static java.util.stream.Collectors.groupingByConcurrent;
|
||||||
|
import static java.util.stream.Collectors.joining;
|
||||||
|
import static java.util.stream.Collectors.mapping;
|
||||||
|
import static java.util.stream.Collectors.maxBy;
|
||||||
|
import static java.util.stream.Collectors.summarizingInt;
|
||||||
|
import static java.util.stream.Collectors.summingInt;
|
||||||
|
import static java.util.stream.Collectors.toList;
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Arrays;
|
||||||
|
import java.util.EnumMap;
|
||||||
|
import java.util.IntSummaryStatistics;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import static java.util.Comparator.comparingInt;
|
import org.junit.Test;
|
||||||
import static java.util.stream.Collectors.*;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class Java8GroupingByCollectorUnitTest {
|
public class Java8GroupingByCollectorUnitTest {
|
||||||
|
|
||||||
@@ -180,4 +197,19 @@ public class Java8GroupingByCollectorUnitTest {
|
|||||||
assertEquals(15, newsLikeStatistics.getMin());
|
assertEquals(15, newsLikeStatistics.getMin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAListOfPosts_whenGroupedByComplexMapKeyType_thenGetAMapBetweenTupleAndList() {
|
||||||
|
Map<Tuple, List<BlogPost>> postsPerTypeAndAuthor = posts.stream()
|
||||||
|
.collect(groupingBy(post -> new Tuple(post.getType(), post.getAuthor())));
|
||||||
|
|
||||||
|
List<BlogPost> result = postsPerTypeAndAuthor.get(new Tuple(BlogPostType.GUIDE, "Author 1"));
|
||||||
|
|
||||||
|
assertThat(result.size()).isEqualTo(1);
|
||||||
|
|
||||||
|
BlogPost blogPost = result.get(0);
|
||||||
|
|
||||||
|
assertThat(blogPost.getTitle()).isEqualTo("Programming guide");
|
||||||
|
assertThat(blogPost.getType()).isEqualTo(BlogPostType.GUIDE);
|
||||||
|
assertThat(blogPost.getAuthor()).isEqualTo("Author 1");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>core-java-annotations</artifactId>
|
<artifactId>core-java-annotations</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-annotations</name>
|
<name>core-java-annotations</name>
|
||||||
@@ -14,42 +13,6 @@
|
|||||||
<relativePath>../../parent-java</relativePath>
|
<relativePath>../../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<!-- test scoped -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<version>${assertj.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-core</artifactId>
|
|
||||||
<version>${jmh-core.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
|
||||||
<version>${jmh-generator.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.openjdk.jmh</groupId>
|
|
||||||
<artifactId>jmh-generator-bytecode</artifactId>
|
|
||||||
<version>${jmh-generator.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<finalName>core-java-annotations</finalName>
|
<finalName>core-java-annotations</finalName>
|
||||||
<resources>
|
<resources>
|
||||||
@@ -60,13 +23,4 @@
|
|||||||
</resources>
|
</resources>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<!-- testing -->
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
|
||||||
<asspectj.version>1.8.9</asspectj.version>
|
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
|
||||||
<jmh-generator.version>1.19</jmh-generator.version>
|
|
||||||
<!-- plugins -->
|
|
||||||
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
|
|
||||||
</properties>
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>core-java-arrays-2</artifactId>
|
<artifactId>core-java-arrays-2</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-arrays-2</name>
|
<name>core-java-arrays-2</name>
|
||||||
|
|||||||
@@ -193,14 +193,47 @@ public class ArrayOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Integer[] intersectionSimple(final Integer[] a, final Integer[] b) {
|
public static Integer[] intersectionSimple(final Integer[] a, final Integer[] b) {
|
||||||
return Stream.of(a).filter(Arrays.asList(b)::contains).toArray(Integer[]::new);
|
return Stream.of(a)
|
||||||
|
.filter(Arrays.asList(b)::contains)
|
||||||
|
.toArray(Integer[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer[] intersectionSet(final Integer[] a, final Integer[] b) {
|
public static Integer[] intersectionSet(final Integer[] a, final Integer[] b) {
|
||||||
return Stream.of(a).filter(Arrays.asList(b)::contains).distinct().toArray(Integer[]::new);
|
return Stream.of(a)
|
||||||
|
.filter(Arrays.asList(b)::contains)
|
||||||
|
.distinct()
|
||||||
|
.toArray(Integer[]::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Integer[] intersectionMultiSet(final Integer[] a, final Integer[] b) {
|
public static Integer[] intersectionMultiSet(final Integer[] a, final Integer[] b) {
|
||||||
return Stream.of(a).filter(new LinkedList<>(Arrays.asList(b))::remove).toArray(Integer[]::new);
|
return Stream.of(a)
|
||||||
|
.filter(new LinkedList<>(Arrays.asList(b))::remove)
|
||||||
|
.toArray(Integer[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Integer[] addElementUsingPureJava(Integer[] srcArray, int elementToAdd) {
|
||||||
|
Integer[] destArray = new Integer[srcArray.length + 1];
|
||||||
|
|
||||||
|
for (int i = 0; i < srcArray.length; i++) {
|
||||||
|
destArray[i] = srcArray[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
destArray[destArray.length - 1] = elementToAdd;
|
||||||
|
return destArray;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[] insertAnElementAtAGivenIndex(final int[] srcArray, int index, int newElement) {
|
||||||
|
int[] destArray = new int[srcArray.length + 1];
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < destArray.length - 1; i++) {
|
||||||
|
|
||||||
|
if (i == index) {
|
||||||
|
destArray[i] = newElement;
|
||||||
|
} else {
|
||||||
|
destArray[i] = srcArray[j];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return destArray;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.arraylist.operations;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ArrayListOperations {
|
||||||
|
|
||||||
|
public static Integer getAnIntegerElement(ArrayList<Integer> anArrayList, int index) {
|
||||||
|
return anArrayList.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void modifyAnIntegerElement(ArrayList<Integer> anArrayList, int index, Integer newElement) {
|
||||||
|
anArrayList.set(index, newElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void appendAnIntegerElement(ArrayList<Integer> anArrayList, Integer newElement) {
|
||||||
|
anArrayList.add(newElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void insertAnIntegerElementAtIndex(ArrayList<Integer> anArrayList, int index, Integer newElement) {
|
||||||
|
anArrayList.add(index, newElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,12 +1,11 @@
|
|||||||
package com.baeldung.array.operations;
|
package com.baeldung.array.operations;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import org.assertj.core.api.Condition;
|
import org.assertj.core.api.Condition;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
|
||||||
public class ArrayOperationsUnitTest {
|
public class ArrayOperationsUnitTest {
|
||||||
|
|
||||||
@@ -262,8 +261,7 @@ public class ArrayOperationsUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenMapIntArrayToString_thenReturnArray() {
|
public void whenMapIntArrayToString_thenReturnArray() {
|
||||||
String[] expectedArray = new String[] { "Value: 3", "Value: 5", "Value: 2", "Value: 5", "Value: 14",
|
String[] expectedArray = new String[] { "Value: 3", "Value: 5", "Value: 2", "Value: 5", "Value: 14", "Value: 4" };
|
||||||
"Value: 4" };
|
|
||||||
String[] output = ArrayOperations.mapIntArrayToString(defaultIntArray);
|
String[] output = ArrayOperations.mapIntArrayToString(defaultIntArray);
|
||||||
|
|
||||||
assertThat(output).containsExactly(expectedArray);
|
assertThat(output).containsExactly(expectedArray);
|
||||||
@@ -313,13 +311,10 @@ public class ArrayOperationsUnitTest {
|
|||||||
int[] output5 = ArrayOperations.shuffleIntArray(defaultIntArray);
|
int[] output5 = ArrayOperations.shuffleIntArray(defaultIntArray);
|
||||||
int[] output6 = ArrayOperations.shuffleIntArray(defaultIntArray);
|
int[] output6 = ArrayOperations.shuffleIntArray(defaultIntArray);
|
||||||
|
|
||||||
Condition<int[]> atLeastOneArraysIsNotEqual = new Condition<int[]>(
|
Condition<int[]> atLeastOneArraysIsNotEqual = new Condition<int[]>("at least one output should be different (order-wise)") {
|
||||||
"at least one output should be different (order-wise)") {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(int[] value) {
|
public boolean matches(int[] value) {
|
||||||
return !Arrays.equals(value, output) || !Arrays.equals(value, output2) || !Arrays.equals(value, output3)
|
return !Arrays.equals(value, output) || !Arrays.equals(value, output2) || !Arrays.equals(value, output3) || !Arrays.equals(value, output4) || !Arrays.equals(value, output5) || !Arrays.equals(value, output6);
|
||||||
|| !Arrays.equals(value, output4) || !Arrays.equals(value, output5)
|
|
||||||
|| !Arrays.equals(value, output6);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -335,13 +330,10 @@ public class ArrayOperationsUnitTest {
|
|||||||
Integer[] output5 = ArrayOperations.shuffleObjectArray(defaultObjectArray);
|
Integer[] output5 = ArrayOperations.shuffleObjectArray(defaultObjectArray);
|
||||||
Integer[] output6 = ArrayOperations.shuffleObjectArray(defaultObjectArray);
|
Integer[] output6 = ArrayOperations.shuffleObjectArray(defaultObjectArray);
|
||||||
|
|
||||||
Condition<Integer[]> atLeastOneArraysIsNotEqual = new Condition<Integer[]>(
|
Condition<Integer[]> atLeastOneArraysIsNotEqual = new Condition<Integer[]>("at least one output should be different (order-wise)") {
|
||||||
"at least one output should be different (order-wise)") {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matches(Integer[] value) {
|
public boolean matches(Integer[] value) {
|
||||||
return !Arrays.equals(value, output) || !Arrays.equals(value, output2) || !Arrays.equals(value, output3)
|
return !Arrays.equals(value, output) || !Arrays.equals(value, output2) || !Arrays.equals(value, output3) || !Arrays.equals(value, output4) || !Arrays.equals(value, output5) || !Arrays.equals(value, output6);
|
||||||
|| !Arrays.equals(value, output4) || !Arrays.equals(value, output5)
|
|
||||||
|| !Arrays.equals(value, output6);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,4 +354,27 @@ public class ArrayOperationsUnitTest {
|
|||||||
|
|
||||||
assertThat(defaultObjectArray).contains(output);
|
assertThat(defaultObjectArray).contains(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenSourceArrayAndElement_whenAddElementUsingPureJavaIsInvoked_thenNewElementMustBeAdded() {
|
||||||
|
Integer[] sourceArray = { 1, 2, 3, 4 };
|
||||||
|
int elementToAdd = 5;
|
||||||
|
|
||||||
|
Integer[] destArray = ArrayOperations.addElementUsingPureJava(sourceArray, elementToAdd);
|
||||||
|
|
||||||
|
Integer[] expectedArray = { 1, 2, 3, 4, 5 };
|
||||||
|
assertArrayEquals(expectedArray, destArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInsertAnElementAtAGivenIndexCalled_thenShiftTheFollowingElementsAndInsertTheElementInArray() {
|
||||||
|
int[] expectedArray = { 1, 4, 2, 3, 0 };
|
||||||
|
int[] anArray = new int[4];
|
||||||
|
anArray[0] = 1;
|
||||||
|
anArray[1] = 2;
|
||||||
|
anArray[2] = 3;
|
||||||
|
int[] outputArray = ArrayOperations.insertAnElementAtAGivenIndex(anArray, 1, 4);
|
||||||
|
|
||||||
|
assertThat(outputArray).containsExactly(expectedArray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.baeldung.arraylist.operations;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
public class ArrayListOperationsUnitTest {
|
||||||
|
|
||||||
|
private ArrayList<Integer> anArrayList;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setupDefaults() {
|
||||||
|
anArrayList = new ArrayList<>();
|
||||||
|
anArrayList.add(2);
|
||||||
|
anArrayList.add(3);
|
||||||
|
anArrayList.add(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenGetAnIntegerElementCalled_thenReturnTheIntegerElement() {
|
||||||
|
Integer output = ArrayListOperations.getAnIntegerElement(anArrayList, 1);
|
||||||
|
|
||||||
|
assertThat(output).isEqualTo(3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenModifyAnIntegerElementCalled_thenModifyTheIntegerElement() {
|
||||||
|
ArrayListOperations.modifyAnIntegerElement(anArrayList, 2, 5);
|
||||||
|
Integer output = ArrayListOperations.getAnIntegerElement(anArrayList, 2);
|
||||||
|
|
||||||
|
assertThat(output).isEqualTo(5);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenAppendAnIntegerElementCalled_thenTheIntegerElementIsAppendedToArrayList() {
|
||||||
|
ArrayListOperations.appendAnIntegerElement(anArrayList, 6);
|
||||||
|
Integer output = ArrayListOperations.getAnIntegerElement(anArrayList, anArrayList.size() - 1);
|
||||||
|
|
||||||
|
assertThat(output).isEqualTo(6);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenInsertAnIntegerAtIndexCalled_thenTheIntegerElementIsInseredToArrayList() {
|
||||||
|
ArrayListOperations.insertAnIntegerElementAtIndex(anArrayList, 1, 10);
|
||||||
|
Integer output = ArrayListOperations.getAnIntegerElement(anArrayList, 1);
|
||||||
|
|
||||||
|
assertThat(output).isEqualTo(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>core-java-arrays</artifactId>
|
<artifactId>core-java-arrays</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-arrays</name>
|
<name>core-java-arrays</name>
|
||||||
@@ -20,16 +19,6 @@
|
|||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>log4j</groupId>
|
|
||||||
<artifactId>log4j</artifactId>
|
|
||||||
<version>${log4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
@@ -47,11 +36,6 @@
|
|||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
<version>${jmh-generator-annprocess.version}</version>
|
<version>${jmh-generator-annprocess.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework</groupId>
|
|
||||||
<artifactId>spring-web</artifactId>
|
|
||||||
<version>${springframework.spring-web.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -64,21 +48,6 @@
|
|||||||
</resources>
|
</resources>
|
||||||
|
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<excludes>
|
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
|
||||||
<exclude>**/*IntegrationTest.java</exclude>
|
|
||||||
<exclude>**/*IntTest.java</exclude>
|
|
||||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
|
||||||
<exclude>**/*ManualTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
<testFailureIgnore>true</testFailureIgnore>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-dependency-plugin</artifactId>
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
@@ -398,8 +367,6 @@
|
|||||||
<assertj-core.version>3.10.0</assertj-core.version>
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
|
|
||||||
<!-- maven and spring plugins -->
|
<!-- maven and spring plugins -->
|
||||||
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
|
|
||||||
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>
|
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||||
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>core-java-collections-2</artifactId>
|
<artifactId>core-java-collections-2</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<name>core-java-collections-2</name>
|
<name>core-java-collections-2</name>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|||||||
@@ -8,3 +8,5 @@ This module contains articles about the Java ArrayList collection
|
|||||||
- [Add Multiple Items to an Java ArrayList](http://www.baeldung.com/java-add-items-array-list)
|
- [Add Multiple Items to an Java ArrayList](http://www.baeldung.com/java-add-items-array-list)
|
||||||
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
|
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
|
||||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||||
|
- [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element)
|
||||||
|
|
||||||
|
|||||||
@@ -19,28 +19,16 @@
|
|||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
<version>${commons-collections4.version}</version>
|
<version>${commons-collections4.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -19,11 +19,6 @@
|
|||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
<version>${commons-collections4.version}</version>
|
<version>${commons-collections4.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
@@ -40,7 +35,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package com.baeldung.findastring;
|
||||||
|
|
||||||
|
import com.google.common.base.Predicates;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
import org.apache.commons.collections4.IterableUtils;
|
||||||
|
import org.apache.commons.collections4.IteratorUtils;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class FindAStringInGivenList {
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> findUsingLoopWithRegex(String search, List<String> list) {
|
||||||
|
|
||||||
|
List<String> matches = new ArrayList<String>();
|
||||||
|
|
||||||
|
String pattern = ".*"+search+".*";
|
||||||
|
Pattern p = Pattern.compile(pattern);
|
||||||
|
|
||||||
|
for(String str: list) {
|
||||||
|
if (p.matcher(str).matches()) {
|
||||||
|
matches.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> findUsingLoop(String search, List<String> list) {
|
||||||
|
|
||||||
|
List<String> matches = new ArrayList<String>();
|
||||||
|
|
||||||
|
for(String str: list) {
|
||||||
|
if (str.contains(search)) {
|
||||||
|
matches.add(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findUsingStream(String search, List<String> list) {
|
||||||
|
|
||||||
|
List<String> matchingElements =
|
||||||
|
list.stream()
|
||||||
|
.filter(str -> str.trim().contains(search))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return matchingElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findUsingGuava(String search, List<String> list) {
|
||||||
|
Iterable<String> result = Iterables.filter(list, Predicates.containsPattern(search));
|
||||||
|
|
||||||
|
return Lists.newArrayList(result.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> findUsingCommonsCollection(String search, List<String> list) {
|
||||||
|
Iterable<String> result = IterableUtils.filteredIterable(list, new org.apache.commons.collections4.Predicate<String>() {
|
||||||
|
public boolean evaluate(String listElement) {
|
||||||
|
return listElement.contains(search);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return IteratorUtils.toList(result.iterator());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package com.baeldung.findastring;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import org.junit.Test;
|
||||||
|
public class FindAStringInListUnitTest {
|
||||||
|
|
||||||
|
private static List<String> list = new ArrayList<>();
|
||||||
|
|
||||||
|
static {
|
||||||
|
list.add("Jack and Jill");
|
||||||
|
list.add("James and Sarah");
|
||||||
|
list.add("Sam and Louise");
|
||||||
|
list.add("Jack");
|
||||||
|
list.add("");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static FindAStringInGivenList findAStringInGivenList = new FindAStringInGivenList();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenFoundUsingLoopWithRegex_thenReturnList() {
|
||||||
|
List matchingElements = findAStringInGivenList.findUsingLoopWithRegex("Jack", list);
|
||||||
|
assertEquals(2, matchingElements.size());
|
||||||
|
assertEquals("Jack and Jill", matchingElements.get(0));
|
||||||
|
assertEquals("Jack", matchingElements.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenFoundUsingLoop_thenReturnList() {
|
||||||
|
List matchingElements = findAStringInGivenList.findUsingLoop("Jack", list);
|
||||||
|
assertEquals(2, matchingElements.size());
|
||||||
|
assertEquals("Jack and Jill", matchingElements.get(0));
|
||||||
|
assertEquals("Jack", matchingElements.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenFoundUsingStream_thenReturnList(){
|
||||||
|
List matchingElements = findAStringInGivenList.findUsingStream("Jack", list);
|
||||||
|
assertEquals(2, matchingElements.size());
|
||||||
|
assertEquals("Jack and Jill", matchingElements.get(0));
|
||||||
|
assertEquals("Jack", matchingElements.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenFoundUsingCommonsCollection_thenReturnList(){
|
||||||
|
List matchingElements = findAStringInGivenList.findUsingCommonsCollection("Jack", list);
|
||||||
|
assertEquals(2, matchingElements.size());
|
||||||
|
assertEquals("Jack and Jill", matchingElements.get(0));
|
||||||
|
assertEquals("Jack", matchingElements.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAString_whenFoundUsingGuava_thenReturnList(){
|
||||||
|
List matchingElements = findAStringInGivenList.findUsingGuava("Jack", list);
|
||||||
|
assertEquals(2, matchingElements.size());
|
||||||
|
assertEquals("Jack and Jill", matchingElements.get(0));
|
||||||
|
assertEquals("Jack", matchingElements.get(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -19,23 +19,12 @@
|
|||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
<version>${commons-collections4.version}</version>
|
<version>${commons-collections4.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-lang3</artifactId>
|
|
||||||
<version>${commons-lang3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.sf.trove4j</groupId>
|
<groupId>net.sf.trove4j</groupId>
|
||||||
@@ -67,7 +56,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<trove4j.version>3.0.2</trove4j.version>
|
<trove4j.version>3.0.2</trove4j.version>
|
||||||
<fastutil.version>8.1.0</fastutil.version>
|
<fastutil.version>8.1.0</fastutil.version>
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.baeldung.list;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Demo different approaches to get count of duplicated elements in an
|
||||||
|
* arrayList
|
||||||
|
*/
|
||||||
|
public class DuplicatesCounter {
|
||||||
|
|
||||||
|
public static <T> Map<T, Long> countByClassicalLoop(List<T> inputList) {
|
||||||
|
Map<T, Long> resultMap = new HashMap<>();
|
||||||
|
for (T element : inputList) {
|
||||||
|
if (resultMap.containsKey(element)) {
|
||||||
|
resultMap.put(element, resultMap.get(element) + 1L);
|
||||||
|
} else {
|
||||||
|
resultMap.put(element, 1L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Map<T, Long> countByClassicalLoopWithMapCompute(List<T> inputList) {
|
||||||
|
Map<T, Long> resultMap = new HashMap<>();
|
||||||
|
for (T element : inputList) {
|
||||||
|
resultMap.compute(element, (k, v) -> v == null ? 1 : v + 1);
|
||||||
|
}
|
||||||
|
return resultMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Map<T, Long> countByStreamToMap(List<T> inputList) {
|
||||||
|
return inputList.stream().collect(Collectors.toMap(Function.identity(), v -> 1L, Long::sum));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Map<T, Long> countByStreamGroupBy(List<T> inputList) {
|
||||||
|
return inputList.stream().collect(Collectors.groupingBy(k -> k, Collectors.counting()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.baeldung.list;
|
||||||
|
|
||||||
|
import org.assertj.core.util.Lists;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.data.MapEntry.entry;
|
||||||
|
|
||||||
|
class DuplicatesCounterUnitTest {
|
||||||
|
|
||||||
|
|
||||||
|
private static List<String> INPUT_LIST = Lists.list(
|
||||||
|
"expect1",
|
||||||
|
"expect2", "expect2",
|
||||||
|
"expect3", "expect3", "expect3",
|
||||||
|
"expect4", "expect4", "expect4", "expect4");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenInput_whenCountByClassicalLoop_thenGetResultMap() {
|
||||||
|
Map<String, Long> result = DuplicatesCounter.countByClassicalLoop(INPUT_LIST);
|
||||||
|
verifyResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenInput_whenCountByClassicalLoopWithMapCompute_thenGetResultMap() {
|
||||||
|
Map<String, Long> result = DuplicatesCounter.countByClassicalLoopWithMapCompute(INPUT_LIST);
|
||||||
|
verifyResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenInput_whenCountByStreamToMap_thenGetResultMap() {
|
||||||
|
Map<String, Long> result = DuplicatesCounter.countByStreamToMap(INPUT_LIST);
|
||||||
|
verifyResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenInput_whenCountByStreamGroupBy_thenGetResultMap() {
|
||||||
|
Map<String, Long> result = DuplicatesCounter.countByStreamGroupBy(INPUT_LIST);
|
||||||
|
verifyResult(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyResult(Map<String, Long> resultMap) {
|
||||||
|
assertThat(resultMap)
|
||||||
|
.isNotEmpty().hasSize(4)
|
||||||
|
.containsExactly(
|
||||||
|
entry("expect1", 1L),
|
||||||
|
entry("expect2", 2L),
|
||||||
|
entry("expect3", 3L),
|
||||||
|
entry("expect4", 4L));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,18 +30,11 @@
|
|||||||
<version>${assertj.version}</version>
|
<version>${assertj.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.1</commons-collections4.version>
|
<commons-collections4.version>4.1</commons-collections4.version>
|
||||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||||
<assertj.version>3.11.1</assertj.version>
|
<assertj.version>3.11.1</assertj.version>
|
||||||
<trove4j.version>3.0.2</trove4j.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -14,11 +14,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>com.google.guava</groupId>
|
|
||||||
<artifactId>guava</artifactId>
|
|
||||||
<version>${guava.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-collections4</artifactId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
@@ -38,7 +33,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-collections4.version>4.3</commons-collections4.version>
|
<commons-collections4.version>4.3</commons-collections4.version>
|
||||||
<guava.version>27.1-jre</guava.version>
|
|
||||||
<gson.version>2.8.5</gson.version>
|
<gson.version>2.8.5</gson.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
@@ -30,12 +30,6 @@
|
|||||||
<artifactId>jmh-generator-annprocess</artifactId>
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
<version>${openjdk.jmh.version}</version>
|
<version>${openjdk.jmh.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
<version>${lombok.version}</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|||||||
19
core-java-modules/core-java-concurrency-advanced-2/README.md
Normal file
19
core-java-modules/core-java-concurrency-advanced-2/README.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
=========
|
||||||
|
|
||||||
|
## Core Java Concurrency Advanced Examples
|
||||||
|
|
||||||
|
This module contains articles about advanced topics about multithreading with core Java.
|
||||||
|
|
||||||
|
### Relevant Articles:
|
||||||
|
- [Semaphores in Java](https://www.baeldung.com/java-semaphore)
|
||||||
|
- [Daemon Threads in Java](https://www.baeldung.com/java-daemon-thread)
|
||||||
|
- [Priority-based Job Scheduling in Java](https://www.baeldung.com/java-priority-job-schedule)
|
||||||
|
- [Brief Introduction to Java Thread.yield()](https://www.baeldung.com/java-thread-yield)
|
||||||
|
- [Print Even and Odd Numbers Using 2 Threads](https://www.baeldung.com/java-even-odd-numbers-with-2-threads)
|
||||||
|
- [Java CyclicBarrier vs CountDownLatch](https://www.baeldung.com/java-cyclicbarrier-countdownlatch)
|
||||||
|
- [Guide to the Fork/Join Framework in Java](https://www.baeldung.com/java-fork-join)
|
||||||
|
- [Guide to ThreadLocalRandom in Java](https://www.baeldung.com/java-thread-local-random)
|
||||||
|
- [The Thread.join() Method in Java](https://www.baeldung.com/java-thread-join)
|
||||||
|
- [Passing Parameters to Java Threads](https://www.baeldung.com/java-thread-parameters)
|
||||||
|
|
||||||
|
[[<-- previous]](/core-java-modules/core-java-concurrency-advanced)[[next -->]](/core-java-modules/core-java-concurrency-advanced-3)
|
||||||
59
core-java-modules/core-java-concurrency-advanced-2/pom.xml
Normal file
59
core-java-modules/core-java-concurrency-advanced-2/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>core-java-concurrency-advanced-2</artifactId>
|
||||||
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
|
<name>core-java-concurrency-advanced-2</name>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>parent-java</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<relativePath>../../parent-java</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-lang3</artifactId>
|
||||||
|
<version>${commons-lang3.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-core</artifactId>
|
||||||
|
<version>${jmh-core.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.openjdk.jmh</groupId>
|
||||||
|
<artifactId>jmh-generator-annprocess</artifactId>
|
||||||
|
<version>${jmh-generator-annprocess.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>${assertj.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<finalName>core-java-concurrency-advanced-2</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<jmh-core.version>1.19</jmh-core.version>
|
||||||
|
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||||
|
|
||||||
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
||||||
@@ -4,6 +4,7 @@ import java.util.concurrent.BrokenBarrierException;
|
|||||||
import java.util.concurrent.CyclicBarrier;
|
import java.util.concurrent.CyclicBarrier;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public class CyclicBarrierResetExample {
|
public class CyclicBarrierResetExample {
|
||||||
@@ -36,6 +37,11 @@ public class CyclicBarrierResetExample {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
es.shutdown();
|
es.shutdown();
|
||||||
|
try {
|
||||||
|
es.awaitTermination(1, TimeUnit.SECONDS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return updateCount.get();
|
return updateCount.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.concurrent.daemon;
|
||||||
|
|
||||||
|
public class NewThread extends Thread {
|
||||||
|
public void run() {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
while (true) {
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
System.out.println(this.getName() + ": New Thread is running..." + i);
|
||||||
|
try {
|
||||||
|
//Wait for one sec so it doesn't print too fast
|
||||||
|
Thread.sleep(1000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// prevent the Thread to run forever. It will finish it's execution after 2 seconds
|
||||||
|
if (System.currentTimeMillis() - startTime > 2000) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.concurrent.parameter;
|
package com.baeldung.concurrent.parameters;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.baeldung.concurrent.parameter;
|
package com.baeldung.concurrent.parameters;
|
||||||
|
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
@@ -1,14 +1,13 @@
|
|||||||
package com.baeldung.parameters;
|
package com.baeldung.concurrent.parameters;
|
||||||
|
|
||||||
import com.baeldung.concurrent.parameter.AverageCalculator;
|
import static org.junit.Assert.assertEquals;
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ParameterizedThreadUnitTest {
|
public class ParameterizedThreadUnitTest {
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user