resolve merge conflicts
This commit is contained in:
commit
2d02097aff
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,6 +4,7 @@ bin/
|
||||
*.class
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
### Relevant articles
|
||||
|
||||
- [Guide to Akka Streams](http://www.baeldung.com/akka-streams)
|
||||
- [Guide to Akka Streams](https://www.baeldung.com/akka-streams)
|
||||
|
@ -1,6 +1,6 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
||||
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
||||
- [Introduction to Jenetics Library](https://www.baeldung.com/jenetics)
|
||||
- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization)
|
||||
- [Design a Genetic Algorithm in Java](https://www.baeldung.com/java-genetic-algorithm)
|
||||
- [The Traveling Salesman Problem in Java](https://www.baeldung.com/java-simulated-annealing-for-traveling-salesman)
|
||||
|
4
algorithms-miscellaneous-1/.gitignore
vendored
4
algorithms-miscellaneous-1/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
/target/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
@ -1,18 +1,9 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
|
||||
- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
|
||||
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
|
||||
- [Binary Search Algorithm in Java](http://www.baeldung.com/java-binary-search)
|
||||
- [Introduction to Minimax Algorithm](http://www.baeldung.com/java-minimax-algorithm)
|
||||
- [How to Calculate Levenshtein Distance in Java?](http://www.baeldung.com/java-levenshtein-distance)
|
||||
- [How to Find the Kth Largest Element in Java](http://www.baeldung.com/java-kth-largest-element)
|
||||
- [Multi-Swarm Optimization Algorithm in Java](http://www.baeldung.com/java-multi-swarm-algorithm)
|
||||
- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
|
||||
- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
|
||||
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
|
||||
- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial)
|
||||
- [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)
|
||||
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
|
||||
- [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm)
|
||||
- [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)
|
||||
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
|
||||
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search)
|
||||
- [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 Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)
|
4
algorithms-miscellaneous-2/.gitignore
vendored
4
algorithms-miscellaneous-2/.gitignore
vendored
@ -1,4 +0,0 @@
|
||||
/target/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
@ -1,19 +1,10 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra)
|
||||
- [Introduction to Cobertura](http://www.baeldung.com/cobertura)
|
||||
- [Test a Linked List for Cyclicity](http://www.baeldung.com/java-linked-list-cyclicity)
|
||||
- [Introduction to JGraphT](http://www.baeldung.com/jgrapht)
|
||||
- [A Maze Solver in Java](http://www.baeldung.com/java-solve-maze)
|
||||
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
|
||||
- [Displaying Money Amounts in Words](http://www.baeldung.com/java-money-into-words)
|
||||
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||
- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
|
||||
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
|
||||
- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
|
||||
- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
|
||||
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
|
||||
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
|
||||
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
|
||||
- [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)
|
||||
- [Dijkstra Shortest Path Algorithm in Java](https://www.baeldung.com/java-dijkstra)
|
||||
- [Introduction to Cobertura](https://www.baeldung.com/cobertura)
|
||||
- [Test a Linked List for Cyclicity](https://www.baeldung.com/java-linked-list-cyclicity)
|
||||
- [Introduction to JGraphT](https://www.baeldung.com/jgrapht)
|
||||
- [A Maze Solver in Java](https://www.baeldung.com/java-solve-maze)
|
||||
- [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)
|
||||
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||
|
@ -1,10 +1,17 @@
|
||||
## 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:
|
||||
|
||||
- [Java Two Pointer Technique](https://www.baeldung.com/java-two-pointer-technique)
|
||||
- [Implementing Simple State Machines with Java Enums](https://www.baeldung.com/java-enum-simple-state-machine)
|
||||
- [Converting Between Roman and Arabic Numerals in Java](http://www.baeldung.com/java-convert-roman-arabic)
|
||||
- [Practical Java Examples of the Big O Notation](http://www.baeldung.com/java-algorithm-complexity)
|
||||
- [Converting Between Roman and Arabic Numerals in Java](https://www.baeldung.com/java-convert-roman-arabic)
|
||||
- [Practical Java Examples of the Big O Notation](https://www.baeldung.com/java-algorithm-complexity)
|
||||
- [Checking If a List Is Sorted in Java](https://www.baeldung.com/java-check-if-list-sorted)
|
||||
- [Checking if a Java Graph has a Cycle](https://www.baeldung.com/java-graph-has-a-cycle)
|
||||
- [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)
|
||||
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
||||
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)
|
@ -54,6 +54,21 @@
|
||||
<version>1.1.0</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>
|
||||
@ -73,5 +88,7 @@
|
||||
<commons-collections4.version>4.3</commons-collections4.version>
|
||||
<guava.version>28.0-jre</guava.version>
|
||||
<retrofit.version>2.6.0</retrofit.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator.version>1.19</jmh-generator.version>
|
||||
</properties>
|
||||
</project>
|
9
algorithms-miscellaneous-4/README.md
Normal file
9
algorithms-miscellaneous-4/README.md
Normal file
@ -0,0 +1,9 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [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)
|
||||
- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
|
||||
- [Find the Middle Element of a Linked List](https://www.baeldung.com/java-linked-list-middle-element)
|
||||
- [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)
|
||||
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
|
51
algorithms-miscellaneous-4/pom.xml
Normal file
51
algorithms-miscellaneous-4/pom.xml
Normal file
@ -0,0 +1,51 @@
|
||||
<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>
|
||||
<artifactId>algorithms-miscellaneous-4</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>algorithms-miscellaneous-4</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
5
algorithms-miscellaneous-5/README.md
Normal file
5
algorithms-miscellaneous-5/README.md
Normal file
@ -0,0 +1,5 @@
|
||||
## Relevant articles:
|
||||
|
||||
- [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)
|
||||
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
|
57
algorithms-miscellaneous-5/pom.xml
Normal file
57
algorithms-miscellaneous-5/pom.xml
Normal file
@ -0,0 +1,57 @@
|
||||
<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>
|
||||
<artifactId>algorithms-miscellaneous-5</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>algorithms-miscellaneous-5</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>pl.allegro.finance</groupId>
|
||||
<artifactId>tradukisto</artifactId>
|
||||
<version>${tradukisto.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>${exec-maven-plugin.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<tradukisto.version>1.0.1</tradukisto.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,9 +1,14 @@
|
||||
## Relevant articles:
|
||||
## Algorithms - Sorting
|
||||
|
||||
- [Bubble Sort in Java](http://www.baeldung.com/java-bubble-sort)
|
||||
This module contains articles about sorting algorithms.
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Bubble Sort in Java](https://www.baeldung.com/java-bubble-sort)
|
||||
- [Merge Sort in Java](https://www.baeldung.com/java-merge-sort)
|
||||
- [Quicksort Algorithm Implementation in Java](https://www.baeldung.com/java-quicksort)
|
||||
- [Insertion Sort in Java](https://www.baeldung.com/java-insertion-sort)
|
||||
- [Heap Sort in Java](https://www.baeldung.com/java-heap-sort)
|
||||
- [Shell Sort in Java](https://www.baeldung.com/java-shell-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)
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.baeldung.bucketsort;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class IntegerBucketSorter implements Sorter<Integer> {
|
||||
|
||||
private final Comparator<Integer> comparator;
|
||||
|
||||
public IntegerBucketSorter(Comparator<Integer> comparator) {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
public IntegerBucketSorter() {
|
||||
comparator = Comparator.naturalOrder();
|
||||
}
|
||||
|
||||
public List<Integer> sort(List<Integer> arrayToSort) {
|
||||
|
||||
List<List<Integer>> buckets = splitIntoUnsortedBuckets(arrayToSort);
|
||||
|
||||
for(List<Integer> bucket : buckets){
|
||||
bucket.sort(comparator);
|
||||
}
|
||||
|
||||
return concatenateSortedBuckets(buckets);
|
||||
}
|
||||
|
||||
private List<Integer> concatenateSortedBuckets(List<List<Integer>> buckets){
|
||||
List<Integer> sortedArray = new LinkedList<>();
|
||||
for(List<Integer> bucket : buckets){
|
||||
sortedArray.addAll(bucket);
|
||||
}
|
||||
return sortedArray;
|
||||
}
|
||||
|
||||
private List<List<Integer>> splitIntoUnsortedBuckets(List<Integer> initialList){
|
||||
|
||||
final int max = findMax(initialList);
|
||||
final int numberOfBuckets = (int) Math.sqrt(initialList.size());
|
||||
|
||||
List<List<Integer>> buckets = new ArrayList<>();
|
||||
for(int i = 0; i < numberOfBuckets; i++) buckets.add(new ArrayList<>());
|
||||
|
||||
//distribute the data
|
||||
for (int i : initialList) {
|
||||
buckets.get(hash(i, max, numberOfBuckets)).add(i);
|
||||
}
|
||||
return buckets;
|
||||
|
||||
}
|
||||
|
||||
private int findMax(List<Integer> input){
|
||||
int m = Integer.MIN_VALUE;
|
||||
for (int i : input){
|
||||
m = Math.max(i, m);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static int hash(int i, int max, int numberOfBuckets) {
|
||||
return (int) ((double) i / max * (numberOfBuckets - 1));
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
package com.baeldung.bucketsort;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Sorter<T> {
|
||||
|
||||
List<T> sort(List<T> arrayToSort);
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
package com.baeldung.algorithms.radixsort;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class RadixSort {
|
||||
|
||||
public static void sort(int numbers[]) {
|
||||
int maximumNumber = findMaximumNumberIn(numbers);
|
||||
|
||||
int numberOfDigits = calculateNumberOfDigitsIn(maximumNumber);
|
||||
|
||||
int placeValue = 1;
|
||||
|
||||
while (numberOfDigits-- > 0) {
|
||||
applyCountingSortOn(numbers, placeValue);
|
||||
placeValue *= 10;
|
||||
}
|
||||
}
|
||||
|
||||
private static void applyCountingSortOn(int[] numbers, int placeValue) {
|
||||
int range = 10; // radix or the base
|
||||
|
||||
int length = numbers.length;
|
||||
int[] frequency = new int[range];
|
||||
int[] sortedValues = new int[length];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
int digit = (numbers[i] / placeValue) % range;
|
||||
frequency[digit]++;
|
||||
}
|
||||
|
||||
for (int i = 1; i < range; i++) {
|
||||
frequency[i] += frequency[i - 1];
|
||||
}
|
||||
|
||||
for (int i = length - 1; i >= 0; i--) {
|
||||
int digit = (numbers[i] / placeValue) % range;
|
||||
sortedValues[frequency[digit] - 1] = numbers[i];
|
||||
frequency[digit]--;
|
||||
}
|
||||
|
||||
System.arraycopy(sortedValues, 0, numbers, 0, length);
|
||||
}
|
||||
|
||||
private static int calculateNumberOfDigitsIn(int number) {
|
||||
return (int) Math.log10(number) + 1; // valid only if number > 0
|
||||
}
|
||||
|
||||
private static int findMaximumNumberIn(int[] arr) {
|
||||
return Arrays.stream(arr).max().getAsInt();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.baeldung.bucketsort;
|
||||
|
||||
import com.baeldung.bucketsort.IntegerBucketSorter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class IntegerBucketSorterUnitTest {
|
||||
|
||||
private IntegerBucketSorter sorter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
sorter = new IntegerBucketSorter();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUnsortedList_whenSortedUsingBucketSorter_checkSortingCorrect() {
|
||||
|
||||
List<Integer> unsorted = Arrays.asList(80,50,60,30,20,10,70,0,40,500,600,602,200,15);
|
||||
List<Integer> expected = Arrays.asList(0,10,15,20,30,40,50,60,70,80,200,500,600,602);
|
||||
|
||||
List<Integer> actual = sorter.sort(unsorted);
|
||||
|
||||
assertEquals(expected, actual);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package com.baeldung.algorithms.radixsort;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class RadixSortUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenUnsortedArray_whenRadixSort_thenArraySorted() {
|
||||
int[] numbers = { 387, 468, 134, 123, 68, 221, 769, 37, 7 };
|
||||
RadixSort.sort(numbers);
|
||||
int[] numbersSorted = { 7, 37, 68, 123, 134, 221, 387, 468, 769 };
|
||||
assertArrayEquals(numbersSorted, numbers);
|
||||
}
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Animal Sniffer Maven Plugin
|
||||
|
||||
[Introduction to Animal Sniffer Maven Plugin](http://www.baeldung.com/maven-animal-sniffer)
|
||||
This module contains articles about the Animal Sniffer Maven Plugin
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
[Introduction to Animal Sniffer Maven Plugin](https://www.baeldung.com/maven-animal-sniffer)
|
||||
|
7
annotations/README.md
Normal file
7
annotations/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## Annotations
|
||||
|
||||
This module contains articles about Java annotations
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java Annotation Processing and Creating a Builder](https://www.baeldung.com/java-annotation-processing-builder)
|
@ -1,2 +0,0 @@
|
||||
### Relevant Articles:
|
||||
- [Java Annotation Processing and Creating a Builder](http://www.baeldung.com/java-annotation-processing-builder)
|
@ -1,3 +1,7 @@
|
||||
## ANTLR
|
||||
|
||||
This module contains articles about ANTLR
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java with ANTLR](http://www.baeldung.com/java-antlr)
|
||||
- [Java with ANTLR](https://www.baeldung.com/java-antlr)
|
||||
|
@ -1,2 +1,6 @@
|
||||
## Apache Avro
|
||||
|
||||
This module contains articles about Apache Avro
|
||||
|
||||
### Relevant Articles:
|
||||
- [Guide to Apache Avro](http://www.baeldung.com/java-apache-avro)
|
||||
- [Guide to Apache Avro](https://www.baeldung.com/java-apache-avro)
|
||||
|
@ -1,2 +1,7 @@
|
||||
## Apache BVal
|
||||
|
||||
This module contains articles about Apache BVal
|
||||
|
||||
### Relevant Articles:
|
||||
- [Intro to Apache BVal](http://www.baeldung.com/apache-bval)
|
||||
|
||||
- [Intro to Apache BVal](https://www.baeldung.com/apache-bval)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Apache Curator
|
||||
|
||||
This module contains articles about Apache Curator
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to Apache Curator](http://www.baeldung.com/apache-curator)
|
||||
- [Introduction to Apache Curator](https://www.baeldung.com/apache-curator)
|
||||
|
@ -1,6 +1,10 @@
|
||||
## Apache CXF
|
||||
|
||||
This module contains articles about Apache CXF
|
||||
|
||||
## Relevant Articles:
|
||||
- [Introduction to Apache CXF Aegis Data Binding](http://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
- [Apache CXF Support for RESTful Web Services](http://www.baeldung.com/apache-cxf-rest-api)
|
||||
- [A Guide to Apache CXF with Spring](http://www.baeldung.com/apache-cxf-with-spring)
|
||||
- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Introduction to Apache CXF Aegis Data Binding](https://www.baeldung.com/aegis-data-binding-in-apache-cxf)
|
||||
- [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api)
|
||||
- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring)
|
||||
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
|
||||
- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse)
|
||||
|
@ -1,5 +1,5 @@
|
||||
=========
|
||||
## Apache FOP
|
||||
|
||||
## Core Java Cookbooks and Examples
|
||||
This module contains articles about Apache FOP
|
||||
|
||||
### Relevant Articles:
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Apache Geode
|
||||
|
||||
This module contains articles about Apache Geode
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Quick Guide to Apache Geode](https://www.baeldung.com/apache-geode)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Apache Meecrowave
|
||||
|
||||
This module contains articles about Apache Meecrowave
|
||||
|
||||
### Relevant Articles:
|
||||
================================
|
||||
- [Building a Microservice with Apache Meecrowave](http://www.baeldung.com/apache-meecrowave)
|
||||
|
||||
- [Building a Microservice with Apache Meecrowave](https://www.baeldung.com/apache-meecrowave)
|
@ -1,3 +1,8 @@
|
||||
## Relevant articles:
|
||||
## Apache Olingo
|
||||
|
||||
This module contains articles about Apache Olingo
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [OData Protocol Guide](https://www.baeldung.com/odata)
|
||||
- [Intro to OData with Olingo](https://www.baeldung.com/olingo)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Apache OpenNLP
|
||||
|
||||
This module contains articles about Apache OpenNLP
|
||||
|
||||
### Relevant Articles
|
||||
|
||||
- [Intro to Apache OpenNLP](http://www.baeldung.com/apache-open-nlp)
|
||||
- [Intro to Apache OpenNLP](https://www.baeldung.com/apache-open-nlp)
|
||||
|
@ -1,4 +1,8 @@
|
||||
## Apache POI
|
||||
|
||||
This module contains articles about Apache POI
|
||||
|
||||
### Relevant Articles:
|
||||
- [Microsoft Word Processing in Java with Apache POI](http://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Working with Microsoft Excel in Java](http://www.baeldung.com/java-microsoft-excel)
|
||||
- [Creating a MS PowerPoint Presentation in Java](http://www.baeldung.com/apache-poi-slideshow)
|
||||
- [Microsoft Word Processing in Java with Apache POI](https://www.baeldung.com/java-microsoft-word-with-apache-poi)
|
||||
- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel)
|
||||
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Apache Pulsar
|
||||
|
||||
This module contains articles about Apache Pulsar
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Introduction to Apache Pulsar](https://www.baeldung.com/apache-pulsar)
|
||||
|
@ -1,2 +1,7 @@
|
||||
### Relevant articles
|
||||
- [Introduction to Apache Shiro](http://www.baeldung.com/apache-shiro)
|
||||
## Apache Shiro
|
||||
|
||||
This module contains articles about Apache Shiro
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
@ -38,17 +38,6 @@
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j-version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
@ -56,4 +45,4 @@
|
||||
<log4j-version>1.2.17</log4j-version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
@ -18,22 +18,17 @@ import javax.servlet.http.HttpServletRequest;
|
||||
@Controller
|
||||
public class ShiroSpringController {
|
||||
|
||||
|
||||
|
||||
@GetMapping("/")
|
||||
public String index() {
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping( value = "/login", method = {RequestMethod.GET, RequestMethod.POST})
|
||||
public String login(HttpServletRequest req, UserCredentials cred, RedirectAttributes attr) {
|
||||
|
||||
if(req.getMethod().equals(RequestMethod.GET.toString())) {
|
||||
return "login";
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
Subject subject = SecurityUtils.getSubject();
|
||||
|
||||
if(!subject.isAuthenticated()) {
|
||||
|
@ -0,0 +1,68 @@
|
||||
package com.baeldung.shiro.permissions.custom;
|
||||
|
||||
import com.baeldung.MyCustomRealm;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.apache.shiro.authc.*;
|
||||
import org.apache.shiro.config.Ini;
|
||||
import org.apache.shiro.mgt.DefaultSecurityManager;
|
||||
import org.apache.shiro.mgt.SecurityManager;
|
||||
import org.apache.shiro.realm.Realm;
|
||||
import org.apache.shiro.realm.text.IniRealm;
|
||||
import org.apache.shiro.session.Session;
|
||||
import org.apache.shiro.subject.Subject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final transient Logger log = LoggerFactory.getLogger(Main.class);
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
IniRealm realm = new IniRealm();
|
||||
Ini ini = Ini.fromResourcePath(Main.class.getResource("/com/baeldung/shiro/permissions/custom/shiro.ini").getPath());
|
||||
realm.setIni(ini);
|
||||
realm.setPermissionResolver(new PathPermissionResolver());
|
||||
realm.init();
|
||||
SecurityManager securityManager = new DefaultSecurityManager(realm);
|
||||
|
||||
SecurityUtils.setSecurityManager(securityManager);
|
||||
Subject currentUser = SecurityUtils.getSubject();
|
||||
|
||||
if (!currentUser.isAuthenticated()) {
|
||||
UsernamePasswordToken token = new UsernamePasswordToken("paul.reader", "password4");
|
||||
token.setRememberMe(true);
|
||||
try {
|
||||
currentUser.login(token);
|
||||
} catch (UnknownAccountException uae) {
|
||||
log.error("Username Not Found!", uae);
|
||||
} catch (IncorrectCredentialsException ice) {
|
||||
log.error("Invalid Credentials!", ice);
|
||||
} catch (LockedAccountException lae) {
|
||||
log.error("Your Account is Locked!", lae);
|
||||
} catch (AuthenticationException ae) {
|
||||
log.error("Unexpected Error!", ae);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("User [" + currentUser.getPrincipal() + "] logged in successfully.");
|
||||
|
||||
if (currentUser.hasRole("admin")) {
|
||||
log.info("Welcome Admin");
|
||||
} else if(currentUser.hasRole("editor")) {
|
||||
log.info("Welcome, Editor!");
|
||||
} else if(currentUser.hasRole("author")) {
|
||||
log.info("Welcome, Author");
|
||||
} else {
|
||||
log.info("Welcome, Guest");
|
||||
}
|
||||
|
||||
if(currentUser.isPermitted("/articles/drafts/new-article")) {
|
||||
log.info("You can access articles");
|
||||
} else {
|
||||
log.info("You cannot access articles!");
|
||||
}
|
||||
currentUser.logout();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.baeldung.shiro.permissions.custom;
|
||||
|
||||
import org.apache.shiro.authz.Permission;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class PathPermission implements Permission {
|
||||
|
||||
private final Path path;
|
||||
|
||||
public PathPermission(Path path) {
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean implies(Permission p) {
|
||||
if(p instanceof PathPermission) {
|
||||
return ((PathPermission) p).path.startsWith(path);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package com.baeldung.shiro.permissions.custom;
|
||||
|
||||
import org.apache.shiro.authz.Permission;
|
||||
import org.apache.shiro.authz.permission.PermissionResolver;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
|
||||
public class PathPermissionResolver implements PermissionResolver {
|
||||
@Override
|
||||
public Permission resolvePermission(String permissionString) {
|
||||
return new PathPermission(Paths.get(permissionString));
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
[users]
|
||||
jane.admin = password, admin
|
||||
john.editor = password2, editor
|
||||
zoe.author = password3, author
|
||||
paul.reader = password4
|
||||
|
||||
[roles]
|
||||
admin = /
|
||||
editor = /articles
|
||||
author = /articles/drafts
|
@ -1,4 +1,7 @@
|
||||
## Apache Solrj Tutorials Project
|
||||
## Apache Solrj
|
||||
|
||||
### Relevant Articles
|
||||
- [Guide to Solr in Java with Apache Solrj](http://www.baeldung.com/apache-solrj)
|
||||
This module contains articles about Apache Solrj
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Guide to Solr in Java with Apache Solrj](https://www.baeldung.com/apache-solrj)
|
@ -1,4 +1,8 @@
|
||||
### Relevant articles
|
||||
## Apache Spark
|
||||
|
||||
- [Introduction to Apache Spark](http://www.baeldung.com/apache-spark)
|
||||
This module contains articles about Apache Spark
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [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)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Apache Thrift
|
||||
|
||||
- [Working with Apache Thrift](http://www.baeldung.com/apache-thrift)
|
||||
This module contains articles about Apache Thrift
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Working with Apache Thrift](https://www.baeldung.com/apache-thrift)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Apache Tika
|
||||
|
||||
- [Content Analysis with Apache Tika](http://www.baeldung.com/apache-tika)
|
||||
This module contains articles about Apache Tika
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Content Analysis with Apache Tika](https://www.baeldung.com/apache-tika)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Apache Velocity
|
||||
|
||||
- [Introduction to Apache Velocity](http://www.baeldung.com/apache-velocity)
|
||||
This module contains articles about Apache Velocity
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Apache Velocity](https://www.baeldung.com/apache-velocity)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Apache Zookeeper
|
||||
|
||||
- [Getting Started with Java and Zookeeper](http://www.baeldung.com/java-zookeeper)
|
||||
This module contains articles about Apache Zookeeper
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Getting Started with Java and Zookeeper](https://www.baeldung.com/java-zookeeper)
|
||||
|
@ -1,4 +1,8 @@
|
||||
### Relevant articles
|
||||
## Asciidoctor
|
||||
|
||||
- [Generating a Book with Asciidoctor](http://www.baeldung.com/asciidoctor-book)
|
||||
- [Introduction to Asciidoctor in Java](http://www.baeldung.com/asciidoctor)
|
||||
This module contains articles about Asciidoctor
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Generating a Book with Asciidoctor](https://www.baeldung.com/asciidoctor-book)
|
||||
- [Introduction to Asciidoctor in Java](https://www.baeldung.com/asciidoctor)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## ASM
|
||||
|
||||
This module contains articles about ASM
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [A Guide to Java Bytecode Manipulation with ASM](http://www.baeldung.com/java-asm)
|
||||
- [A Guide to Java Bytecode Manipulation with ASM](https://www.baeldung.com/java-asm)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Relevant articles:
|
||||
## Atomix
|
||||
|
||||
- [Introduction to Atomix](http://www.baeldung.com/atomix)
|
||||
This module contains articles about Atomix
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Atomix](https://www.baeldung.com/atomix)
|
||||
|
@ -1,4 +0,0 @@
|
||||
### Relevant Articles:
|
||||
- [Introduction to AutoValue](http://www.baeldung.com/introduction-to-autovalue)
|
||||
- [Introduction to AutoFactory](http://www.baeldung.com/autofactory)
|
||||
- [Google AutoService](https://www.baeldung.com/google-autoservice)
|
@ -1,3 +1,7 @@
|
||||
## AWS Lambda
|
||||
|
||||
This module contains articles about AWS Lambda
|
||||
|
||||
### Relevant Articles:
|
||||
- [Using AWS Lambda with API Gateway](http://www.baeldung.com/aws-lambda-api-gateway)
|
||||
- [Introduction to AWS Serverless Application Model](http://www.baeldung.com/aws-serverless)
|
||||
- [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway)
|
||||
- [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless)
|
||||
|
@ -1,11 +1,15 @@
|
||||
## AWS
|
||||
|
||||
This module contains articles about AWS
|
||||
|
||||
### Relevant articles
|
||||
|
||||
- [AWS Lambda Using DynamoDB With Java](http://www.baeldung.com/aws-lambda-dynamodb-java)
|
||||
- [AWS S3 with Java](http://www.baeldung.com/aws-s3-java)
|
||||
- [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda)
|
||||
- [Managing EC2 Instances in Java](http://www.baeldung.com/ec2-java)
|
||||
- [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload)
|
||||
- [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests)
|
||||
- [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3)
|
||||
- [Managing Amazon SQS Queues in Java](http://www.baeldung.com/aws-queues-java)
|
||||
- [AWS Lambda Using DynamoDB With Java](https://www.baeldung.com/aws-lambda-dynamodb-java)
|
||||
- [AWS S3 with Java](https://www.baeldung.com/aws-s3-java)
|
||||
- [AWS Lambda With Java](https://www.baeldung.com/java-aws-lambda)
|
||||
- [Managing EC2 Instances in Java](https://www.baeldung.com/ec2-java)
|
||||
- [Multipart Uploads in Amazon S3 with Java](https://www.baeldung.com/aws-s3-multipart-upload)
|
||||
- [Integration Testing with a Local DynamoDB Instance](https://www.baeldung.com/dynamodb-local-integration-tests)
|
||||
- [Using the JetS3t Java Client With Amazon S3](https://www.baeldung.com/jets3t-amazon-s3)
|
||||
- [Managing Amazon SQS Queues in Java](https://www.baeldung.com/aws-queues-java)
|
||||
- [Guide to AWS Aurora RDS with Java](https://www.baeldung.com/aws-aurora-rds-java)
|
||||
|
@ -1,3 +1,7 @@
|
||||
## Axon
|
||||
|
||||
This module contains articles about Axon
|
||||
|
||||
### Relevant articles
|
||||
|
||||
- [A Guide to the Axon Framework](http://www.baeldung.com/axon-cqrs-event-sourcing)
|
||||
- [A Guide to the Axon Framework](https://www.baeldung.com/axon-cqrs-event-sourcing)
|
||||
|
@ -1,4 +1,8 @@
|
||||
## Azure
|
||||
|
||||
This module contains articles about Azure
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Deploy a Spring Boot App to Azure](http://www.baeldung.com/spring-boot-azure)
|
||||
- [Deploy a Spring Boot App to Azure](https://www.baeldung.com/spring-boot-azure)
|
||||
|
||||
|
7
bazel/README.md
Normal file
7
bazel/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## Bazel
|
||||
|
||||
This module contains articles about Bazel
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Building Java Applications with Bazel](https://www.baeldung.com/bazel-build-tool)
|
@ -16,14 +16,17 @@
|
||||
<dependency>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>bazelgreeting</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<version>${bazelgreeting.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.9</version>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<bazelgreeting.version>1.0.0-SNAPSHOT</bazelgreeting.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -1,5 +1,5 @@
|
||||
### Relevant Articles:
|
||||
|
||||
- [Blade – A Complete Guidebook](http://www.baeldung.com/blade)
|
||||
- [Blade – A Complete Guidebook](https://www.baeldung.com/blade)
|
||||
|
||||
Run Integration Tests with `mvn integration-test`
|
||||
|
@ -1,2 +1,6 @@
|
||||
## Bootique
|
||||
|
||||
This module contains articles about Bootique
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Bootique](http://www.baeldung.com/bootique)
|
||||
- [Introduction to Bootique](https://www.baeldung.com/bootique)
|
||||
|
7
cas/README.md
Normal file
7
cas/README.md
Normal file
@ -0,0 +1,7 @@
|
||||
## CAS
|
||||
|
||||
This module contains articles about the Central Authentication Service (CAS)
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [CAS SSO With Spring Security](baeldung.com/spring-security-cas-sso)
|
@ -1,5 +1,9 @@
|
||||
## CDI
|
||||
|
||||
This module contains articles about Contexts and Dependency Injection (CDI)
|
||||
|
||||
### Relevant Articles:
|
||||
- [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
|
||||
- [An Introduction to CDI (Contexts and Dependency Injection) in Java](http://www.baeldung.com/java-ee-cdi)
|
||||
- [CDI Interceptor vs Spring AspectJ](https://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
|
||||
- [An Introduction to CDI (Contexts and Dependency Injection) in Java](https://www.baeldung.com/java-ee-cdi)
|
||||
- [Introduction to the Event Notification Model in CDI 2.0](https://www.baeldung.com/cdi-event-notification)
|
||||
|
||||
|
@ -1,15 +1,16 @@
|
||||
package com.baeldung.cdi.cdi2observers.application;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import javax.enterprise.inject.se.SeContainer;
|
||||
import javax.enterprise.inject.se.SeContainerInitializer;
|
||||
|
||||
public class BootstrappingApplication {
|
||||
|
||||
public static void main(String... args) {
|
||||
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
|
||||
try (SeContainer container = containerInitializer.initialize()) {
|
||||
container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.application;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
|
||||
import javax.enterprise.inject.se.SeContainer;
|
||||
import javax.enterprise.inject.se.SeContainerInitializer;
|
||||
|
||||
public class BootstrappingApplication {
|
||||
|
||||
public static void main(String... args) {
|
||||
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
|
||||
try (SeContainer container = containerInitializer.initialize()) {
|
||||
container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.baeldung.cdi.cdi2observers.events;
|
||||
|
||||
public class ExampleEvent {
|
||||
|
||||
private final String eventMessage;
|
||||
|
||||
public ExampleEvent(String eventMessage) {
|
||||
this.eventMessage = eventMessage;
|
||||
}
|
||||
|
||||
public String getEventMessage() {
|
||||
return eventMessage;
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.events;
|
||||
|
||||
public class ExampleEvent {
|
||||
|
||||
private final String eventMessage;
|
||||
|
||||
public ExampleEvent(String eventMessage) {
|
||||
this.eventMessage = eventMessage;
|
||||
}
|
||||
|
||||
public String getEventMessage() {
|
||||
return eventMessage;
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
package com.baeldung.cdi.cdi2observers.events;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ExampleEventSource {
|
||||
|
||||
@Inject
|
||||
Event<ExampleEvent> exampleEvent;
|
||||
|
||||
public void fireEvent() {
|
||||
exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.events;
|
||||
|
||||
import javax.enterprise.event.Event;
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ExampleEventSource {
|
||||
|
||||
@Inject
|
||||
Event<ExampleEvent> exampleEvent;
|
||||
|
||||
public void fireEvent() {
|
||||
exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!"));
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package com.baeldung.cdi.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class AnotherExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(2) ExampleEvent event) {
|
||||
return event.getEventMessage();
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class AnotherExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(2) ExampleEvent event) {
|
||||
return event.getEventMessage();
|
||||
}
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
package com.baeldung.cdi.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
|
||||
import com.baeldung.cdi.cdi2observers.services.TextService;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class ExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) {
|
||||
return textService.parseText(event.getEventMessage());
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.observers;
|
||||
|
||||
import com.baeldung.cdi2observers.events.ExampleEvent;
|
||||
import com.baeldung.cdi2observers.services.TextService;
|
||||
import javax.annotation.Priority;
|
||||
import javax.enterprise.event.Observes;
|
||||
|
||||
public class ExampleEventObserver {
|
||||
|
||||
public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) {
|
||||
return textService.parseText(event.getEventMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package com.baeldung.cdi.cdi2observers.services;
|
||||
|
||||
public class TextService {
|
||||
|
||||
public String parseText(String text) {
|
||||
return text.toUpperCase();
|
||||
}
|
||||
}
|
||||
package com.baeldung.cdi2observers.services;
|
||||
|
||||
public class TextService {
|
||||
|
||||
public String parseText(String text) {
|
||||
return text.toUpperCase();
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,8 @@
|
||||
<beans xmlns="http://java.sun.com/xml/ns/javaee"
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/beans_1_2.xsd">
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
|
||||
bean-discovery-mode="all">
|
||||
<interceptors>
|
||||
<class>com.baeldung.interceptor.AuditedInterceptor</class>
|
||||
</interceptors>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user