Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
031bce6a26
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +0,0 @@
|
|||||||
[submodule "testgitrepo"]
|
|
||||||
path = testgitrepo
|
|
||||||
url = /home/prd/Development/projects/idea/tutorials/spring-boot/src/main/resources/testgitrepo/
|
|
@ -4,7 +4,7 @@ before_install:
|
|||||||
- echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc
|
- echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc
|
||||||
|
|
||||||
install: skip
|
install: skip
|
||||||
script: travis_wait 60 mvn -q install
|
script: travis_wait 60 mvn -q install -Pdefault
|
||||||
|
|
||||||
sudo: required
|
sudo: required
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>JGitSnippets</artifactId>
|
<artifactId>JGitSnippets</artifactId>
|
||||||
@ -45,7 +46,6 @@
|
|||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<org.eclipse.jgit.version>4.5.0.201609210915-r</org.eclipse.jgit.version>
|
<org.eclipse.jgit.version>4.5.0.201609210915-r</org.eclipse.jgit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<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.mabsisa</groupId>
|
<groupId>com.mabsisa</groupId>
|
||||||
<artifactId>Twitter4J</artifactId>
|
<artifactId>Twitter4J</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
@ -14,17 +15,11 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.twitter4j</groupId>
|
<groupId>org.twitter4j</groupId>
|
||||||
<artifactId>twitter4j-stream</artifactId>
|
<artifactId>twitter4j-stream</artifactId>
|
||||||
<version>4.0.6</version>
|
<version>${twitter4j-stream.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
@ -49,4 +44,8 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<twitter4j-stream.version>4.0.6</twitter4j-stream.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>activejdbc</artifactId>
|
<artifactId>activejdbc</artifactId>
|
||||||
@ -15,12 +15,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.javalite</groupId>
|
<groupId>org.javalite</groupId>
|
||||||
<artifactId>activejdbc</artifactId>
|
<artifactId>activejdbc</artifactId>
|
||||||
@ -133,10 +127,8 @@
|
|||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<activejdbc.version>1.4.13</activejdbc.version>
|
<activejdbc.version>1.4.13</activejdbc.version>
|
||||||
<environments>development.test,development</environments>
|
<environments>development.test,development</environments>
|
||||||
<org.slf4j.version>1.7.9</org.slf4j.version>
|
|
||||||
<mysql.connector.version>5.1.34</mysql.connector.version>
|
<mysql.connector.version>5.1.34</mysql.connector.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>akka-streams</artifactId>
|
<artifactId>akka-streams</artifactId>
|
||||||
<name>akka-streams</name>
|
<name>akka-streams</name>
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
||||||
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
|
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/java-finite-automata)
|
||||||
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
||||||
- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers)
|
|
||||||
- [Example of Hill Climbing Algorithm](http://www.baeldung.com/java-hill-climbing-algorithm)
|
- [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)
|
- [Monte Carlo Tree Search for Tic-Tac-Toe Game](http://www.baeldung.com/java-monte-carlo-tree-search)
|
||||||
- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
|
- [String Search Algorithms for Large Texts](http://www.baeldung.com/java-full-text-search-algorithms)
|
||||||
@ -21,4 +20,6 @@
|
|||||||
- [Create a Sudoku Solver in Java](http://www.baeldung.com/java-sudoku)
|
- [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)
|
- [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)
|
- [A Collaborative Filtering Recommendation System in Java](http://www.baeldung.com/java-collaborative-filtering-recommendations)
|
||||||
- [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum)
|
- [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)
|
||||||
|
- [Find the Middle Element of a Linked List](http://www.baeldung.com/java-linked-list-middle-element)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>algorithms</artifactId>
|
<artifactId>algorithms</artifactId>
|
||||||
@ -79,7 +79,6 @@
|
|||||||
</reporting>
|
</reporting>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
|
||||||
<lombok.version>1.16.12</lombok.version>
|
<lombok.version>1.16.12</lombok.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<tradukisto.version>1.0.1</tradukisto.version>
|
<tradukisto.version>1.0.1</tradukisto.version>
|
||||||
|
@ -6,7 +6,6 @@ import com.baeldung.algorithms.ga.annealing.SimulatedAnnealing;
|
|||||||
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
|
import com.baeldung.algorithms.ga.ant_colony.AntColonyOptimization;
|
||||||
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
|
import com.baeldung.algorithms.ga.binary.SimpleGeneticAlgorithm;
|
||||||
import com.baeldung.algorithms.slope_one.SlopeOne;
|
import com.baeldung.algorithms.slope_one.SlopeOne;
|
||||||
import com.baeldung.algorithms.pairsaddupnumber.FindPairs;
|
|
||||||
|
|
||||||
public class RunAlgorithm {
|
public class RunAlgorithm {
|
||||||
|
|
||||||
@ -39,12 +38,6 @@ public class RunAlgorithm {
|
|||||||
case 5:
|
case 5:
|
||||||
System.out.println("Please run the DijkstraAlgorithmTest.");
|
System.out.println("Please run the DijkstraAlgorithmTest.");
|
||||||
break;
|
break;
|
||||||
case 6:
|
|
||||||
final FindPairs findPairs = new FindPairs();
|
|
||||||
final int[] input = {1, 4, 3, 2, 1, 4, 4, 3, 3};
|
|
||||||
final int sum = 6;
|
|
||||||
findPairs.execute(input, sum);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
System.out.println("Unknown option");
|
System.out.println("Unknown option");
|
||||||
break;
|
break;
|
||||||
|
@ -10,7 +10,7 @@ public class MonteCarloTreeSearch {
|
|||||||
|
|
||||||
private static final int WIN_SCORE = 10;
|
private static final int WIN_SCORE = 10;
|
||||||
private int level;
|
private int level;
|
||||||
private int oponent;
|
private int opponent;
|
||||||
|
|
||||||
public MonteCarloTreeSearch() {
|
public MonteCarloTreeSearch() {
|
||||||
this.level = 3;
|
this.level = 3;
|
||||||
@ -32,11 +32,11 @@ public class MonteCarloTreeSearch {
|
|||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
long end = start + 60 * getMillisForCurrentLevel();
|
long end = start + 60 * getMillisForCurrentLevel();
|
||||||
|
|
||||||
oponent = 3 - playerNo;
|
opponent = 3 - playerNo;
|
||||||
Tree tree = new Tree();
|
Tree tree = new Tree();
|
||||||
Node rootNode = tree.getRoot();
|
Node rootNode = tree.getRoot();
|
||||||
rootNode.getState().setBoard(board);
|
rootNode.getState().setBoard(board);
|
||||||
rootNode.getState().setPlayerNo(oponent);
|
rootNode.getState().setPlayerNo(opponent);
|
||||||
|
|
||||||
while (System.currentTimeMillis() < end) {
|
while (System.currentTimeMillis() < end) {
|
||||||
// Phase 1 - Selection
|
// Phase 1 - Selection
|
||||||
@ -93,7 +93,7 @@ public class MonteCarloTreeSearch {
|
|||||||
State tempState = tempNode.getState();
|
State tempState = tempNode.getState();
|
||||||
int boardStatus = tempState.getBoard().checkStatus();
|
int boardStatus = tempState.getBoard().checkStatus();
|
||||||
|
|
||||||
if (boardStatus == oponent) {
|
if (boardStatus == opponent) {
|
||||||
tempNode.getParent().getState().setWinScore(Integer.MIN_VALUE);
|
tempNode.getParent().getState().setWinScore(Integer.MIN_VALUE);
|
||||||
return boardStatus;
|
return boardStatus;
|
||||||
}
|
}
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
package com.baeldung.algorithms.prime;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
import java.util.stream.IntStream;
|
|
||||||
|
|
||||||
public class PrimeGenerator {
|
|
||||||
public static List<Integer> sieveOfEratosthenes(int n) {
|
|
||||||
final boolean prime[] = new boolean[n + 1];
|
|
||||||
Arrays.fill(prime, true);
|
|
||||||
|
|
||||||
for (int p = 2; p * p <= n; p++) {
|
|
||||||
if (prime[p]) {
|
|
||||||
for (int i = p * 2; i <= n; i += p)
|
|
||||||
prime[i] = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<Integer> primes = new LinkedList<>();
|
|
||||||
for (int i = 2; i <= n; i++) {
|
|
||||||
if (prime[i])
|
|
||||||
primes.add(i);
|
|
||||||
}
|
|
||||||
return primes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> primeNumbersBruteForce(int max) {
|
|
||||||
final List<Integer> primeNumbers = new LinkedList<Integer>();
|
|
||||||
for (int i = 2; i <= max; i++) {
|
|
||||||
if (isPrimeBruteForce(i)) {
|
|
||||||
primeNumbers.add(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return primeNumbers;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isPrimeBruteForce(int x) {
|
|
||||||
for (int i = 2; i < x; i++) {
|
|
||||||
if (x % i == 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<Integer> primeNumbersTill(int max) {
|
|
||||||
return IntStream.rangeClosed(2, max)
|
|
||||||
.filter(x -> isPrime(x))
|
|
||||||
.boxed()
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isPrime(int x) {
|
|
||||||
return IntStream.rangeClosed(2, (int) (Math.sqrt(x)))
|
|
||||||
.allMatch(n -> x % n != 0);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
package com.baeldung.algorithms.prime;
|
|
||||||
|
|
||||||
import static com.baeldung.algorithms.prime.PrimeGenerator.*;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import org.junit.Test;
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
public class PrimeGeneratorUnitTest {
|
|
||||||
@Test
|
|
||||||
public void whenBruteForced_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = primeNumbersBruteForce(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenOptimized_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = primeNumbersTill(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenSieveOfEratosthenes_returnsSuccessfully() {
|
|
||||||
final List<Integer> primeNumbers = sieveOfEratosthenes(20);
|
|
||||||
assertEquals(Arrays.asList(new Integer[] { 2, 3, 5, 7, 11, 13, 17, 19 }), primeNumbers);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
||||||
@ -14,15 +14,6 @@
|
|||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
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>annotation-processing</artifactId>
|
<artifactId>annotation-processing</artifactId>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>annotation-user</artifactId>
|
<artifactId>annotation-user</artifactId>
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
3
antlr/README.md
Normal file
3
antlr/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### Relevant Articles:
|
||||||
|
|
||||||
|
- [Java with ANTLR](http://www.baeldung.com/java-antlr)
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
||||||
<artifactId>antlr</artifactId>
|
<artifactId>antlr</artifactId>
|
||||||
<name>antlr</name>
|
<name>antlr</name>
|
||||||
@ -45,22 +45,14 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.antlr</groupId>
|
|
||||||
<artifactId>antlr4-runtime</artifactId>
|
|
||||||
<version>${antlr.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.antlr</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>antlr4-runtime</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>${antlr.version}</version>
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<antlr.version>4.7.1</antlr.version>
|
<antlr.version>4.7.1</antlr.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mojo.version>3.0.0</mojo.version>
|
<mojo.version>3.0.0</mojo.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
@ -1,5 +1,5 @@
|
|||||||
<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>apache-bval</groupId>
|
<groupId>apache-bval</groupId>
|
||||||
<artifactId>apache-bval</artifactId>
|
<artifactId>apache-bval</artifactId>
|
||||||
|
@ -28,12 +28,6 @@
|
|||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -47,12 +41,8 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
<mysql.connector.version>5.1.44</mysql.connector.version>
|
<mysql.connector.version>5.1.44</mysql.connector.version>
|
||||||
<cayenne.version>4.0.M5</cayenne.version>
|
<cayenne.version>4.0.M5</cayenne.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
||||||
<artifactId>apache-curator</artifactId>
|
<artifactId>apache-curator</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
||||||
<artifactId>cxf-aegis</artifactId>
|
<artifactId>cxf-aegis</artifactId>
|
||||||
|
|
||||||
@ -17,8 +17,4 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<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>
|
||||||
<artifactId>cxf-introduction</artifactId>
|
<artifactId>cxf-introduction</artifactId>
|
||||||
|
|
||||||
@ -36,9 +36,4 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<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>
|
||||||
<artifactId>cxf-jaxrs-implementation</artifactId>
|
<artifactId>cxf-jaxrs-implementation</artifactId>
|
||||||
|
|
||||||
@ -48,10 +48,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<httpclient.version>4.5.2</httpclient.version>
|
<httpclient.version>4.5.2</httpclient.version>
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
||||||
<artifactId>cxf-spring</artifactId>
|
<artifactId>cxf-spring</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
@ -101,11 +101,7 @@
|
|||||||
</profiles>
|
</profiles>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<cxf.version>3.1.8</cxf.version>
|
|
||||||
<spring.version>4.3.4.RELEASE</spring.version>
|
<spring.version>4.3.4.RELEASE</spring.version>
|
||||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
|
||||||
<surefire.version>2.19.1</surefire.version>
|
|
||||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-cxf</artifactId>
|
<artifactId>apache-cxf</artifactId>
|
||||||
@ -33,7 +33,7 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<exec-maven-plugin.version>1.5.0</exec-maven-plugin.version>
|
<cxf.version>3.1.8</cxf.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-fop</artifactId>
|
<artifactId>apache-fop</artifactId>
|
||||||
|
57
apache-meecrowave/pom.xml
Normal file
57
apache-meecrowave/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>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<artifactId>apache-meecrowave</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<name>apache-meecrowave</name>
|
||||||
|
<description>A sample REST API application with Meecrowave</description>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-core</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.meecrowave/meecrowave-jpa -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-jpa</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
|
<artifactId>okhttp</artifactId>
|
||||||
|
<version>3.10.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-junit</artifactId>
|
||||||
|
<version>1.2.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.10</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.meecrowave</groupId>
|
||||||
|
<artifactId>meecrowave-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1,30 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
public class Article {
|
||||||
|
private String name;
|
||||||
|
private String author;
|
||||||
|
|
||||||
|
public Article() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Article(String name, String author) {
|
||||||
|
this.author = author;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthor() {
|
||||||
|
return author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthor(String author) {
|
||||||
|
this.author = author;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
@RequestScoped
|
||||||
|
@Path("article")
|
||||||
|
public class ArticleEndpoints {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
ArticleService articleService;
|
||||||
|
|
||||||
|
@GET
|
||||||
|
public Response getArticle() {
|
||||||
|
return Response.ok()
|
||||||
|
.entity(new Article("name", "author"))
|
||||||
|
.build();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@POST
|
||||||
|
public Response createArticle(Article article) {
|
||||||
|
return Response.status(Status.CREATED)
|
||||||
|
.entity(articleService.createArticle(article))
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import javax.enterprise.context.ApplicationScoped;
|
||||||
|
|
||||||
|
@ApplicationScoped
|
||||||
|
public class ArticleService {
|
||||||
|
public Article createArticle(Article article) {
|
||||||
|
return article;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
import org.apache.meecrowave.Meecrowave;
|
||||||
|
|
||||||
|
public class Server {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
final Meecrowave.Builder builder = new Meecrowave.Builder();
|
||||||
|
builder.setScanningPackageIncludes("com.baeldung.meecrowave");
|
||||||
|
builder.setJaxrsMapping("/api/*");
|
||||||
|
builder.setJsonpPrettify(true);
|
||||||
|
|
||||||
|
try (Meecrowave meecrowave = new Meecrowave(builder)) {
|
||||||
|
meecrowave.bake().await();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.baeldung.meecrowave;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.meecrowave.Meecrowave;
|
||||||
|
import org.apache.meecrowave.junit.MonoMeecrowave;
|
||||||
|
import org.apache.meecrowave.testing.ConfigurationInject;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import okhttp3.OkHttpClient;
|
||||||
|
import okhttp3.Request;
|
||||||
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@RunWith(MonoMeecrowave.Runner.class)
|
||||||
|
public class ArticleEndpointsTest {
|
||||||
|
|
||||||
|
@ConfigurationInject
|
||||||
|
private Meecrowave.Builder config;
|
||||||
|
private static OkHttpClient client;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void setup() {
|
||||||
|
client = new OkHttpClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenRetunedArticle_thenCorrect() throws IOException {
|
||||||
|
final String base = "http://localhost:"+config.getHttpPort();
|
||||||
|
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(base+"/article")
|
||||||
|
.build();
|
||||||
|
Response response = client.newCall(request).execute();
|
||||||
|
assertEquals(200, response.code());
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>apache-opennlp</artifactId>
|
<artifactId>apache-opennlp</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
@ -24,12 +24,6 @@
|
|||||||
<version>${org.assertj.version}</version>
|
<version>${org.assertj.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>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-poi</artifactId>
|
<artifactId>apache-poi</artifactId>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>${org.springframework.boot.spring-boot-starter-parent.version}</version>
|
<version>1.5.2.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -57,10 +57,10 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.7.0</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source>
|
<source>${java.version}</source>
|
||||||
<target>1.8</target>
|
<target>${java.version}</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
@ -68,9 +68,10 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
|
<apache-shiro-core-version>1.4.0</apache-shiro-core-version>
|
||||||
|
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
<log4j-version>1.2.17</log4j-version>
|
<log4j-version>1.2.17</log4j-version>
|
||||||
<slf4j-version>1.7.25</slf4j-version>
|
<slf4j-version>1.7.25</slf4j-version>
|
||||||
<org.springframework.boot.spring-boot-starter-parent.version>1.5.2.RELEASE</org.springframework.boot.spring-boot-starter-parent.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-solrj</artifactId>
|
<artifactId>apache-solrj</artifactId>
|
||||||
|
@ -12,7 +12,7 @@ import org.apache.solr.common.SolrDocumentList;
|
|||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class SolrJavaIntegrationTest {
|
public class SolrJavaLiveTest {
|
||||||
|
|
||||||
private SolrJavaIntegration solrJavaIntegration;
|
private SolrJavaIntegration solrJavaIntegration;
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-spark</artifactId>
|
<artifactId>apache-spark</artifactId>
|
||||||
@ -21,16 +21,9 @@
|
|||||||
<artifactId>spark-core_2.10</artifactId>
|
<artifactId>spark-core_2.10</artifactId>
|
||||||
<version>${org.apache.spark.spark-core.version}</version>
|
<version>${org.apache.spark.spark-core.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<org.apache.spark.spark-core.version>2.2.0</org.apache.spark.spark-core.version>
|
<org.apache.spark.spark-core.version>2.2.0</org.apache.spark.spark-core.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-thrift</artifactId>
|
<artifactId>apache-thrift</artifactId>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-tika</artifactId>
|
<artifactId>apache-tika</artifactId>
|
||||||
|
@ -60,7 +60,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<jstl.version>1.2</jstl.version>
|
<jstl.version>1.2</jstl.version>
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
|
||||||
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
|
<org.apache.httpcomponents.version>4.5.2</org.apache.httpcomponents.version>
|
||||||
<velocity-version>1.7</velocity-version>
|
<velocity-version>1.7</velocity-version>
|
||||||
<velocity-tools-version>2.0</velocity-tools-version>
|
<velocity-tools-version>2.0</velocity-tools-version>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>apache-zookeeper</artifactId>
|
<artifactId>apache-zookeeper</artifactId>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>asciidoctor</artifactId>
|
<artifactId>asciidoctor</artifactId>
|
||||||
<name>asciidoctor</name>
|
<name>asciidoctor</name>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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.examples</groupId>
|
<groupId>com.baeldung.examples</groupId>
|
||||||
<artifactId>asm</artifactId>
|
<artifactId>asm</artifactId>
|
||||||
@ -54,10 +54,8 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<asm.version>5.2</asm.version>
|
<asm.version>5.2</asm.version>
|
||||||
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
<maven-jar-plugin.version>2.4</maven-jar-plugin.version>
|
||||||
<maven-surefire-plugin.version>2.9</maven-surefire-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,5 +1,5 @@
|
|||||||
<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.atomix.io</groupId>
|
<groupId>com.atomix.io</groupId>
|
||||||
<artifactId>atomix</artifactId>
|
<artifactId>atomix</artifactId>
|
||||||
@ -17,12 +17,6 @@
|
|||||||
<artifactId>atomix-all</artifactId>
|
<artifactId>atomix-all</artifactId>
|
||||||
<version>${atomix-all.version}</version>
|
<version>${atomix-all.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>log4j</groupId>
|
<groupId>log4j</groupId>
|
||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
@ -32,7 +26,6 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<atomix-all.version>1.0.0-rc9</atomix-all.version>
|
<atomix-all.version>1.0.0-rc9</atomix-all.version>
|
||||||
<log4j.version>1.2.17</log4j.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>autovalue</artifactId>
|
<artifactId>autovalue</artifactId>
|
||||||
|
3
aws-lambda/README.md
Normal file
3
aws-lambda/README.md
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
### 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)
|
@ -1,31 +1,30 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
|
|
||||||
<parent>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>aws-lambda</artifactId>
|
<artifactId>aws-lambda</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>aws-lambda</name>
|
<name>aws-lambda</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>parent-modules</artifactId>
|
||||||
|
<groupId>com.baeldung</groupId>
|
||||||
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
<artifactId>aws-java-sdk-dynamodb</artifactId>
|
||||||
<version>1.11.241</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
<artifactId>aws-java-sdk-core</artifactId>
|
<artifactId>aws-java-sdk-core</artifactId>
|
||||||
<version>1.11.241</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.amazonaws</groupId>
|
<groupId>com.amazonaws</groupId>
|
||||||
@ -65,26 +64,28 @@
|
|||||||
<version>${json-simple.version}</version>
|
<version>${json-simple.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>${maven-shade-plugin.version}</version>
|
<version>${maven-shade-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>shade</goal>
|
<goal>shade</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<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>
|
<org.json.version>20180130</org.json.version>
|
||||||
@ -92,8 +93,9 @@
|
|||||||
<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>
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
<aws-java-sdk-core.version>1.11.241</aws-java-sdk-core.version>
|
<aws-java-sdk.version>1.11.241</aws-java-sdk.version>
|
||||||
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
<maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
|
||||||
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
|
<maven-dependency-plugin.version>2.10</maven-dependency-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
60
aws-lambda/sam-templates/template-implicit.yaml
Normal file
60
aws-lambda/sam-templates/template-implicit.yaml
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
|
Transform: 'AWS::Serverless-2016-10-31'
|
||||||
|
Description: Baeldung Serverless Application Model Example with Implicit API Definition
|
||||||
|
Globals:
|
||||||
|
Api:
|
||||||
|
EndpointConfiguration: REGIONAL
|
||||||
|
Name: "TestAPI"
|
||||||
|
Resources:
|
||||||
|
PersonTable:
|
||||||
|
Type: AWS::Serverless::SimpleTable
|
||||||
|
Properties:
|
||||||
|
PrimaryKey:
|
||||||
|
Name: id
|
||||||
|
Type: Number
|
||||||
|
TableName: Person
|
||||||
|
StorePersonFunction:
|
||||||
|
Type: AWS::Serverless::Function
|
||||||
|
Properties:
|
||||||
|
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
|
||||||
|
Runtime: java8
|
||||||
|
Timeout: 15
|
||||||
|
MemorySize: 512
|
||||||
|
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
|
||||||
|
Policies:
|
||||||
|
- DynamoDBCrudPolicy:
|
||||||
|
TableName: !Ref PersonTable
|
||||||
|
Environment:
|
||||||
|
Variables:
|
||||||
|
TABLE_NAME: !Ref PersonTable
|
||||||
|
Events:
|
||||||
|
StoreApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons
|
||||||
|
Method: PUT
|
||||||
|
GetPersonByHTTPParamFunction:
|
||||||
|
Type: AWS::Serverless::Function
|
||||||
|
Properties:
|
||||||
|
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByParam
|
||||||
|
Runtime: java8
|
||||||
|
Timeout: 15
|
||||||
|
MemorySize: 512
|
||||||
|
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
|
||||||
|
Policies:
|
||||||
|
- DynamoDBReadPolicy:
|
||||||
|
TableName: !Ref PersonTable
|
||||||
|
Environment:
|
||||||
|
Variables:
|
||||||
|
TABLE_NAME: !Ref PersonTable
|
||||||
|
Events:
|
||||||
|
GetByPathApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons/{id}
|
||||||
|
Method: GET
|
||||||
|
GetByQueryApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons
|
||||||
|
Method: GET
|
112
aws-lambda/sam-templates/template-inline-swagger.yaml
Normal file
112
aws-lambda/sam-templates/template-inline-swagger.yaml
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
AWSTemplateFormatVersion: '2010-09-09'
|
||||||
|
Transform: 'AWS::Serverless-2016-10-31'
|
||||||
|
Description: Baeldung Serverless Application Model Example with Inline Swagger API Definition
|
||||||
|
Resources:
|
||||||
|
PersonTable:
|
||||||
|
Type: AWS::Serverless::SimpleTable
|
||||||
|
Properties:
|
||||||
|
PrimaryKey:
|
||||||
|
Name: id
|
||||||
|
Type: Number
|
||||||
|
TableName: Person
|
||||||
|
StorePersonFunction:
|
||||||
|
Type: AWS::Serverless::Function
|
||||||
|
Properties:
|
||||||
|
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleRequest
|
||||||
|
Runtime: java8
|
||||||
|
Timeout: 15
|
||||||
|
MemorySize: 512
|
||||||
|
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
|
||||||
|
Policies:
|
||||||
|
- DynamoDBCrudPolicy:
|
||||||
|
TableName: !Ref PersonTable
|
||||||
|
Environment:
|
||||||
|
Variables:
|
||||||
|
TABLE_NAME: !Ref PersonTable
|
||||||
|
Events:
|
||||||
|
StoreApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons
|
||||||
|
Method: PUT
|
||||||
|
RestApiId:
|
||||||
|
Ref: MyApi
|
||||||
|
GetPersonByHTTPParamFunction:
|
||||||
|
Type: AWS::Serverless::Function
|
||||||
|
Properties:
|
||||||
|
Handler: com.baeldung.lambda.apigateway.APIDemoHandler::handleGetByParam
|
||||||
|
Runtime: java8
|
||||||
|
Timeout: 15
|
||||||
|
MemorySize: 512
|
||||||
|
CodeUri: ../target/aws-lambda-0.1.0-SNAPSHOT.jar
|
||||||
|
Policies:
|
||||||
|
- DynamoDBReadPolicy:
|
||||||
|
TableName: !Ref PersonTable
|
||||||
|
Environment:
|
||||||
|
Variables:
|
||||||
|
TABLE_NAME: !Ref PersonTable
|
||||||
|
Events:
|
||||||
|
GetByPathApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons/{id}
|
||||||
|
Method: GET
|
||||||
|
RestApiId:
|
||||||
|
Ref: MyApi
|
||||||
|
GetByQueryApi:
|
||||||
|
Type: Api
|
||||||
|
Properties:
|
||||||
|
Path: /persons
|
||||||
|
Method: GET
|
||||||
|
RestApiId:
|
||||||
|
Ref: MyApi
|
||||||
|
MyApi:
|
||||||
|
Type: AWS::Serverless::Api
|
||||||
|
Properties:
|
||||||
|
StageName: test
|
||||||
|
EndpointConfiguration: REGIONAL
|
||||||
|
DefinitionBody:
|
||||||
|
swagger: "2.0"
|
||||||
|
info:
|
||||||
|
title: "TestAPI"
|
||||||
|
paths:
|
||||||
|
/persons:
|
||||||
|
get:
|
||||||
|
parameters:
|
||||||
|
- name: "id"
|
||||||
|
in: "query"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
x-amazon-apigateway-request-validator: "Validate query string parameters and\
|
||||||
|
\ headers"
|
||||||
|
x-amazon-apigateway-integration:
|
||||||
|
uri:
|
||||||
|
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByHTTPParamFunction.Arn}/invocations
|
||||||
|
responses: {}
|
||||||
|
httpMethod: "POST"
|
||||||
|
type: "aws_proxy"
|
||||||
|
put:
|
||||||
|
x-amazon-apigateway-integration:
|
||||||
|
uri:
|
||||||
|
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${StorePersonFunction.Arn}/invocations
|
||||||
|
responses: {}
|
||||||
|
httpMethod: "POST"
|
||||||
|
type: "aws_proxy"
|
||||||
|
/persons/{id}:
|
||||||
|
get:
|
||||||
|
parameters:
|
||||||
|
- name: "id"
|
||||||
|
in: "path"
|
||||||
|
required: true
|
||||||
|
type: "string"
|
||||||
|
responses: {}
|
||||||
|
x-amazon-apigateway-integration:
|
||||||
|
uri:
|
||||||
|
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetPersonByHTTPParamFunction.Arn}/invocations
|
||||||
|
responses: {}
|
||||||
|
httpMethod: "POST"
|
||||||
|
type: "aws_proxy"
|
||||||
|
x-amazon-apigateway-request-validators:
|
||||||
|
Validate query string parameters and headers:
|
||||||
|
validateRequestParameters: true
|
||||||
|
validateRequestBody: false
|
@ -15,152 +15,107 @@ import java.io.*;
|
|||||||
|
|
||||||
public class APIDemoHandler implements RequestStreamHandler {
|
public class APIDemoHandler implements RequestStreamHandler {
|
||||||
|
|
||||||
private JSONParser parser = new JSONParser();
|
private JSONParser parser = new JSONParser();
|
||||||
private static final String DYNAMODB_TABLE_NAME = System.getenv("TABLE_NAME");
|
private static final String DYNAMODB_TABLE_NAME = System.getenv("TABLE_NAME");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
|
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
JSONObject responseJson = new JSONObject();
|
JSONObject responseJson = new JSONObject();
|
||||||
|
|
||||||
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
|
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
|
||||||
DynamoDB dynamoDb = new DynamoDB(client);
|
DynamoDB dynamoDb = new DynamoDB(client);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject event = (JSONObject) parser.parse(reader);
|
JSONObject event = (JSONObject) parser.parse(reader);
|
||||||
|
|
||||||
if (event.get("body") != null) {
|
if (event.get("body") != null) {
|
||||||
|
|
||||||
Person person = new Person((String) event.get("body"));
|
Person person = new Person((String) event.get("body"));
|
||||||
|
|
||||||
dynamoDb.getTable(DYNAMODB_TABLE_NAME)
|
dynamoDb.getTable(DYNAMODB_TABLE_NAME)
|
||||||
.putItem(new PutItemSpec().withItem(new Item().withNumber("id", person.getId())
|
.putItem(new PutItemSpec().withItem(new Item().withNumber("id", person.getId())
|
||||||
.withString("firstName", person.getFirstName())
|
.withString("name", person.getName())));
|
||||||
.withString("lastName", person.getLastName()).withNumber("age", person.getAge())
|
}
|
||||||
.withString("address", person.getAddress())));
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject responseBody = new JSONObject();
|
JSONObject responseBody = new JSONObject();
|
||||||
responseBody.put("message", "New item created");
|
responseBody.put("message", "New item created");
|
||||||
|
|
||||||
JSONObject headerJson = new JSONObject();
|
JSONObject headerJson = new JSONObject();
|
||||||
headerJson.put("x-custom-header", "my custom header value");
|
headerJson.put("x-custom-header", "my custom header value");
|
||||||
|
|
||||||
responseJson.put("statusCode", 200);
|
responseJson.put("statusCode", 200);
|
||||||
responseJson.put("headers", headerJson);
|
responseJson.put("headers", headerJson);
|
||||||
responseJson.put("body", responseBody.toString());
|
responseJson.put("body", responseBody.toString());
|
||||||
|
|
||||||
} catch (ParseException pex) {
|
} catch (ParseException pex) {
|
||||||
responseJson.put("statusCode", 400);
|
responseJson.put("statusCode", 400);
|
||||||
responseJson.put("exception", pex);
|
responseJson.put("exception", pex);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
|
||||||
writer.write(responseJson.toString());
|
writer.write(responseJson.toString());
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleGetByPathParam(InputStream inputStream, OutputStream outputStream, Context context)
|
public void handleGetByParam(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
|
||||||
throws IOException {
|
|
||||||
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||||
JSONObject responseJson = new JSONObject();
|
JSONObject responseJson = new JSONObject();
|
||||||
|
|
||||||
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
|
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
|
||||||
DynamoDB dynamoDb = new DynamoDB(client);
|
DynamoDB dynamoDb = new DynamoDB(client);
|
||||||
|
|
||||||
Item result = null;
|
Item result = null;
|
||||||
try {
|
try {
|
||||||
JSONObject event = (JSONObject) parser.parse(reader);
|
JSONObject event = (JSONObject) parser.parse(reader);
|
||||||
JSONObject responseBody = new JSONObject();
|
JSONObject responseBody = new JSONObject();
|
||||||
|
|
||||||
if (event.get("pathParameters") != null) {
|
if (event.get("pathParameters") != null) {
|
||||||
|
|
||||||
JSONObject pps = (JSONObject) event.get("pathParameters");
|
JSONObject pps = (JSONObject) event.get("pathParameters");
|
||||||
if (pps.get("id") != null) {
|
if (pps.get("id") != null) {
|
||||||
|
|
||||||
int id = Integer.parseInt((String) pps.get("id"));
|
int id = Integer.parseInt((String) pps.get("id"));
|
||||||
result = dynamoDb.getTable(DYNAMODB_TABLE_NAME).getItem("id", id);
|
result = dynamoDb.getTable(DYNAMODB_TABLE_NAME)
|
||||||
}
|
.getItem("id", id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
} else if (event.get("queryStringParameters") != null) {
|
||||||
if (result != null) {
|
|
||||||
|
|
||||||
Person person = new Person(result.toJSON());
|
JSONObject qps = (JSONObject) event.get("queryStringParameters");
|
||||||
responseBody.put("Person", person);
|
if (qps.get("id") != null) {
|
||||||
responseJson.put("statusCode", 200);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
responseBody.put("message", "No item found");
|
int id = Integer.parseInt((String) qps.get("id"));
|
||||||
responseJson.put("statusCode", 404);
|
result = dynamoDb.getTable(DYNAMODB_TABLE_NAME)
|
||||||
}
|
.getItem("id", id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (result != null) {
|
||||||
|
|
||||||
JSONObject headerJson = new JSONObject();
|
Person person = new Person(result.toJSON());
|
||||||
headerJson.put("x-custom-header", "my custom header value");
|
responseBody.put("Person", person);
|
||||||
|
responseJson.put("statusCode", 200);
|
||||||
|
} else {
|
||||||
|
|
||||||
responseJson.put("headers", headerJson);
|
responseBody.put("message", "No item found");
|
||||||
responseJson.put("body", responseBody.toString());
|
responseJson.put("statusCode", 404);
|
||||||
|
}
|
||||||
|
|
||||||
} catch (ParseException pex) {
|
JSONObject headerJson = new JSONObject();
|
||||||
responseJson.put("statusCode", 400);
|
headerJson.put("x-custom-header", "my custom header value");
|
||||||
responseJson.put("exception", pex);
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
|
responseJson.put("headers", headerJson);
|
||||||
writer.write(responseJson.toString());
|
responseJson.put("body", responseBody.toString());
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void handleGetByQueryParam(InputStream inputStream, OutputStream outputStream, Context context)
|
} catch (ParseException pex) {
|
||||||
throws IOException {
|
responseJson.put("statusCode", 400);
|
||||||
|
responseJson.put("exception", pex);
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
}
|
||||||
JSONObject responseJson = new JSONObject();
|
|
||||||
|
|
||||||
AmazonDynamoDB client = AmazonDynamoDBClientBuilder.defaultClient();
|
|
||||||
DynamoDB dynamoDb = new DynamoDB(client);
|
|
||||||
|
|
||||||
Item result = null;
|
|
||||||
try {
|
|
||||||
JSONObject event = (JSONObject) parser.parse(reader);
|
|
||||||
JSONObject responseBody = new JSONObject();
|
|
||||||
|
|
||||||
if (event.get("queryStringParameters") != null) {
|
|
||||||
|
|
||||||
JSONObject qps = (JSONObject) event.get("queryStringParameters");
|
|
||||||
if (qps.get("id") != null) {
|
|
||||||
|
|
||||||
int id = Integer.parseInt((String) qps.get("id"));
|
|
||||||
result = dynamoDb.getTable(DYNAMODB_TABLE_NAME).getItem("id", id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != null) {
|
|
||||||
|
|
||||||
Person person = new Person(result.toJSON());
|
|
||||||
responseBody.put("Person", person);
|
|
||||||
responseJson.put("statusCode", 200);
|
|
||||||
} else {
|
|
||||||
|
|
||||||
responseBody.put("message", "No item found");
|
|
||||||
responseJson.put("statusCode", 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
JSONObject headerJson = new JSONObject();
|
|
||||||
headerJson.put("x-custom-header", "my custom header value");
|
|
||||||
|
|
||||||
responseJson.put("headers", headerJson);
|
|
||||||
responseJson.put("body", responseBody.toString());
|
|
||||||
|
|
||||||
} catch (ParseException pex) {
|
|
||||||
responseJson.put("statusCode", 400);
|
|
||||||
responseJson.put("exception", pex);
|
|
||||||
}
|
|
||||||
|
|
||||||
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
|
|
||||||
writer.write(responseJson.toString());
|
|
||||||
writer.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
OutputStreamWriter writer = new OutputStreamWriter(outputStream, "UTF-8");
|
||||||
|
writer.write(responseJson.toString());
|
||||||
|
writer.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,64 +5,34 @@ import com.google.gson.GsonBuilder;
|
|||||||
|
|
||||||
public class Person {
|
public class Person {
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
private String firstName;
|
private String name;
|
||||||
private String lastName;
|
|
||||||
private int age;
|
|
||||||
private String address;
|
|
||||||
|
|
||||||
public Person(String json) {
|
public Person(String json) {
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
Person request = gson.fromJson(json, Person.class);
|
Person request = gson.fromJson(json, Person.class);
|
||||||
this.id = request.getId();
|
this.id = request.getId();
|
||||||
this.firstName = request.getFirstName();
|
this.name = request.getName();
|
||||||
this.lastName = request.getLastName();
|
}
|
||||||
this.age = request.getAge();
|
|
||||||
this.address = request.getAddress();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
return gson.toJson(this);
|
return gson.toJson(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(int id) {
|
public void setId(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getName() {
|
||||||
return firstName;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
public void setName(String name) {
|
||||||
this.firstName = firstName;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastName() {
|
|
||||||
return lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
|
||||||
this.lastName = lastName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAge() {
|
|
||||||
return age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAge(int age) {
|
|
||||||
this.age = age;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAddress() {
|
|
||||||
return address;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAddress(String address) {
|
|
||||||
this.address = address;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
11
aws/pom.xml
11
aws/pom.xml
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>aws</artifactId>
|
<artifactId>aws</artifactId>
|
||||||
@ -19,13 +19,7 @@
|
|||||||
<artifactId>aws-java-sdk</artifactId>
|
<artifactId>aws-java-sdk</artifactId>
|
||||||
<version>${aws-java-sdk.version}</version>
|
<version>${aws-java-sdk.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>${mockito-core.version}</version>
|
<version>${mockito-core.version}</version>
|
||||||
@ -143,7 +137,6 @@
|
|||||||
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
<aws-lambda-java-core.version>1.1.0</aws-lambda-java-core.version>
|
||||||
<gson.version>2.8.0</gson.version>
|
<gson.version>2.8.0</gson.version>
|
||||||
<aws-java-sdk.version>1.11.290</aws-java-sdk.version>
|
<aws-java-sdk.version>1.11.290</aws-java-sdk.version>
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito-core.version>2.8.9</mockito-core.version>
|
<mockito-core.version>2.8.9</mockito-core.version>
|
||||||
<assertj-core.version>3.8.0</assertj-core.version>
|
<assertj-core.version>3.8.0</assertj-core.version>
|
||||||
<dynamodblocal.version>1.11.86</dynamodblocal.version>
|
<dynamodblocal.version>1.11.86</dynamodblocal.version>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>axon</artifactId>
|
<artifactId>axon</artifactId>
|
||||||
|
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>azure</artifactId>
|
<artifactId>azure</artifactId>
|
||||||
<version>0.1</version>
|
<version>0.1</version>
|
||||||
@ -17,11 +16,6 @@
|
|||||||
<relativePath>../parent-boot-2</relativePath>
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<azure.containerRegistry>baeldungadr</azure.containerRegistry>
|
|
||||||
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
@ -42,12 +36,13 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>mysql</groupId>
|
<groupId>mysql</groupId>
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
<artifactId>mysql-connector-java</artifactId>
|
||||||
<version>5.1.6</version>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -61,7 +56,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.spotify</groupId>
|
<groupId>com.spotify</groupId>
|
||||||
<artifactId>docker-maven-plugin</artifactId>
|
<artifactId>docker-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>{docker-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
|
||||||
<registryUrl>https://${docker.image.prefix}</registryUrl>
|
<registryUrl>https://${docker.image.prefix}</registryUrl>
|
||||||
@ -79,7 +74,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.microsoft.azure</groupId>
|
<groupId>com.microsoft.azure</groupId>
|
||||||
<artifactId>azure-webapp-maven-plugin</artifactId>
|
<artifactId>azure-webapp-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>${azure-webapp-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<authentication>
|
<authentication>
|
||||||
<serverId>azure-auth</serverId>
|
<serverId>azure-auth</serverId>
|
||||||
@ -87,45 +82,52 @@
|
|||||||
<resourceGroup>baeldung-group</resourceGroup>
|
<resourceGroup>baeldung-group</resourceGroup>
|
||||||
<appName>baeldung-webapp</appName>
|
<appName>baeldung-webapp</appName>
|
||||||
<appServicePlanName>baeldung-plan</appServicePlanName>
|
<appServicePlanName>baeldung-plan</appServicePlanName>
|
||||||
<javaVersion>1.8</javaVersion>
|
<javaVersion>{java.version}</javaVersion>
|
||||||
<!--<javaWebContainer>tomcat 8.5</javaWebContainer>-->
|
<!--<javaWebContainer>tomcat 8.5</javaWebContainer> -->
|
||||||
<!--<region>japanwest</region>-->
|
<!--<region>japanwest</region> -->
|
||||||
<!--<containerSettings>-->
|
<!--<containerSettings> -->
|
||||||
<!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName>-->
|
<!--<imageName>${docker.image.prefix}/${project.artifactId}</imageName> -->
|
||||||
<!--<registryUrl>https://${docker.image.prefix}</registryUrl>-->
|
<!--<registryUrl>https://${docker.image.prefix}</registryUrl> -->
|
||||||
<!--<serverId>${azure.containerRegistry}</serverId>-->
|
<!--<serverId>${azure.containerRegistry}</serverId> -->
|
||||||
<!--</containerSettings>-->
|
<!--</containerSettings> -->
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<property>
|
<property>
|
||||||
<name>spring.datasource.url</name>
|
<name>spring.datasource.url</name>
|
||||||
<value>jdbc:h2:file:~/test</value>
|
<value>jdbc:h2:file:~/test</value>
|
||||||
<!--<value>jdbc:mysql://127.0.0.1:55738/localdb</value>-->
|
<!--<value>jdbc:mysql://127.0.0.1:55738/localdb</value> -->
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<property>
|
||||||
<name>spring.datasource.username</name>
|
<name>spring.datasource.username</name>
|
||||||
<value>sa</value>
|
<value>sa</value>
|
||||||
<!--<value>azure</value>-->
|
<!--<value>azure</value> -->
|
||||||
</property>
|
</property>
|
||||||
<property>
|
<property>
|
||||||
<name>spring.datasource.password</name>
|
<name>spring.datasource.password</name>
|
||||||
<value></value>
|
<value></value>
|
||||||
<!--<value>replace-with-your-password</value>-->
|
<!--<value>replace-with-your-password</value> -->
|
||||||
</property>
|
</property>
|
||||||
</appSettings>
|
</appSettings>
|
||||||
<!--<deploymentType>ftp</deploymentType>-->
|
<!--<deploymentType>ftp</deploymentType> -->
|
||||||
<!--<resources>-->
|
<!--<resources> -->
|
||||||
<!--<resource>-->
|
<!--<resource> -->
|
||||||
<!--<directory>${project.basedir}/target</directory>-->
|
<!--<directory>${project.basedir}/target</directory> -->
|
||||||
<!--<targetPath>webapps</targetPath>-->
|
<!--<targetPath>webapps</targetPath> -->
|
||||||
<!--<includes>-->
|
<!--<includes> -->
|
||||||
<!--<include>*.war</include>-->
|
<!--<include>*.war</include> -->
|
||||||
<!--</includes>-->
|
<!--</includes> -->
|
||||||
<!--</resource>-->
|
<!--</resource> -->
|
||||||
<!--</resources>-->
|
<!--</resources> -->
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<azure.containerRegistry>baeldungadr</azure.containerRegistry>
|
||||||
|
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
|
||||||
|
<docker-maven-plugin.version>1.1.0</docker-maven-plugin.version>
|
||||||
|
<azure-webapp-maven-plugin.version>1.1.0</azure-webapp-maven-plugin.version>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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.bootique</groupId>
|
<groupId>com.baeldung.bootique</groupId>
|
||||||
<artifactId>bootique</artifactId>
|
<artifactId>bootique</artifactId>
|
||||||
@ -52,16 +52,21 @@
|
|||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>${maven-shade-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<main.class>com.baeldung.bootique.App</main.class>
|
<main.class>com.baeldung.bootique.App</main.class>
|
||||||
<bootique-bom.version>0.23</bootique-bom.version>
|
<bootique-bom.version>0.23</bootique-bom.version>
|
||||||
|
|
||||||
|
<maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
<artifactId>spring-boot-camel</artifactId>
|
<artifactId>spring-boot-camel</artifactId>
|
||||||
@ -60,8 +60,6 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<camel.version>2.19.1</camel.version>
|
<camel.version>2.19.1</camel.version>
|
||||||
<spring-boot-starter.version>1.5.4.RELEASE</spring-boot-starter.version>
|
<spring-boot-starter.version>1.5.4.RELEASE</spring-boot-starter.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>cas-secured-app</artifactId>
|
<artifactId>cas-secured-app</artifactId>
|
||||||
@ -13,7 +13,7 @@
|
|||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>1.5.13.RELEASE</version>
|
<version>1.5.13.RELEASE</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath /> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
@ -1,29 +1,28 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>cas-server</artifactId>
|
<artifactId>cas-server</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>1.0</version>
|
<version>1.0</version>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apereo.cas</groupId>
|
<groupId>org.apereo.cas</groupId>
|
||||||
<artifactId>cas-server-support-json-service-registry</artifactId>
|
<artifactId>cas-server-support-json-service-registry</artifactId>
|
||||||
<version>${cas.version}</version>
|
<version>${cas.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apereo.cas</groupId>
|
<groupId>org.apereo.cas</groupId>
|
||||||
<artifactId>cas-server-support-jdbc</artifactId>
|
<artifactId>cas-server-support-jdbc</artifactId>
|
||||||
<version>${cas.version}</version>
|
<version>${cas.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apereo.cas</groupId>
|
<groupId>org.apereo.cas</groupId>
|
||||||
<artifactId>cas-server-support-jdbc-drivers</artifactId>
|
<artifactId>cas-server-support-jdbc-drivers</artifactId>
|
||||||
<version>${cas.version}</version>
|
<version>${cas.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -31,7 +30,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.rimerosolutions.maven.plugins</groupId>
|
<groupId>com.rimerosolutions.maven.plugins</groupId>
|
||||||
<artifactId>wrapper-maven-plugin</artifactId>
|
<artifactId>wrapper-maven-plugin</artifactId>
|
||||||
<version>0.0.4</version>
|
<version>${wrapper-maven-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<verifyDownload>true</verifyDownload>
|
<verifyDownload>true</verifyDownload>
|
||||||
<checksumAlgorithm>MD5</checksumAlgorithm>
|
<checksumAlgorithm>MD5</checksumAlgorithm>
|
||||||
@ -58,7 +57,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>2.6</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<warName>cas</warName>
|
<warName>cas</warName>
|
||||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||||
@ -78,27 +77,12 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.3</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
<finalName>cas</finalName>
|
<finalName>cas</finalName>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
|
||||||
<cas.version>5.3.0-SNAPSHOT</cas.version>
|
|
||||||
<springboot.version>1.5.13.RELEASE</springboot.version>
|
|
||||||
<!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
|
|
||||||
<app.server>-tomcat</app.server>
|
|
||||||
|
|
||||||
<mainClassName>org.springframework.boot.loader.WarLauncher</mainClassName>
|
|
||||||
<isExecutable>false</isExecutable>
|
|
||||||
<manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>
|
|
||||||
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype-releases</id>
|
<id>sonatype-releases</id>
|
||||||
@ -140,9 +124,7 @@
|
|||||||
<type>war</type>
|
<type>war</type>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!--
|
<!-- ...Additional dependencies may be placed here... -->
|
||||||
...Additional dependencies may be placed here...
|
|
||||||
-->
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
@ -161,7 +143,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.soebes.maven.plugins</groupId>
|
<groupId>com.soebes.maven.plugins</groupId>
|
||||||
<artifactId>echo-maven-plugin</artifactId>
|
<artifactId>echo-maven-plugin</artifactId>
|
||||||
<version>0.3.0</version>
|
<version>${echo-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>prepare-package</phase>
|
<phase>prepare-package</phase>
|
||||||
@ -210,7 +192,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.github.s4u.plugins</groupId>
|
<groupId>com.github.s4u.plugins</groupId>
|
||||||
<artifactId>pgpverify-maven-plugin</artifactId>
|
<artifactId>pgpverify-maven-plugin</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>${pgpverify-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -230,4 +212,25 @@
|
|||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
</project>
|
|
||||||
|
<properties>
|
||||||
|
<cas.version>5.3.0-SNAPSHOT</cas.version>
|
||||||
|
<springboot.version>1.5.13.RELEASE</springboot.version>
|
||||||
|
<!-- app.server could be -jetty, -undertow, -tomcat, or blank if you plan to provide appserver -->
|
||||||
|
<app.server>-tomcat</app.server>
|
||||||
|
|
||||||
|
<mainClassName>org.springframework.boot.loader.WarLauncher</mainClassName>
|
||||||
|
<isExecutable>false</isExecutable>
|
||||||
|
<manifestFileToUse>${project.build.directory}/war/work/org.apereo.cas/cas-server-webapp${app.server}/META-INF/MANIFEST.MF</manifestFileToUse>
|
||||||
|
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<wrapper-maven-plugin.version>0.0.4</wrapper-maven-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>
|
||||||
|
<pgpverify-maven-plugin.version>1.1.0</pgpverify-maven-plugin.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
@ -1,2 +1,3 @@
|
|||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj)
|
- [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)
|
||||||
|
@ -17,19 +17,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
<version>1.3</version>
|
<version>${hamcrest-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.assertj</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>assertj-core</artifactId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<version>3.10.0</version>
|
<version>${assertj-core.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>4.12</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -58,6 +58,9 @@
|
|||||||
<properties>
|
<properties>
|
||||||
<aspectjweaver.version>1.8.9</aspectjweaver.version>
|
<aspectjweaver.version>1.8.9</aspectjweaver.version>
|
||||||
<weld-se-core.version>2.4.1.Final</weld-se-core.version>
|
<weld-se-core.version>2.4.1.Final</weld-se-core.version>
|
||||||
|
<hamcrest-core.version>1.3</hamcrest-core.version>
|
||||||
|
<assertj-core.version>3.10.0</assertj-core.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -66,8 +66,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${maven.compiler.source}</source>
|
<source>${java.version}</source>
|
||||||
<target>${maven.compiler.target}</target>
|
<target>${java.version}</target>
|
||||||
<!-- Uncomment the following line to use the type annotations compiler. -->
|
<!-- Uncomment the following line to use the type annotations compiler. -->
|
||||||
<!-- <fork>true</fork> -->
|
<!-- <fork>true</fork> -->
|
||||||
<compilerArguments>
|
<compilerArguments>
|
||||||
@ -113,8 +113,6 @@
|
|||||||
<checker.version>2.3.1</checker.version>
|
<checker.version>2.3.1</checker.version>
|
||||||
<jdk8.version>2.3.1</jdk8.version>
|
<jdk8.version>2.3.1</jdk8.version>
|
||||||
<checkerframework.compiler.version>2.3.1</checkerframework.compiler.version>
|
<checkerframework.compiler.version>2.3.1</checkerframework.compiler.version>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<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>
|
||||||
<artifactId>core-groovy</artifactId>
|
<artifactId>core-groovy</artifactId>
|
||||||
<version>1.0-SNAPSHOT</version>
|
<version>1.0-SNAPSHOT</version>
|
||||||
@ -101,24 +101,13 @@
|
|||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<kotlin-maven-plugin.version>1.1.2</kotlin-maven-plugin.version>
|
|
||||||
<kotlin-test-junit.version>1.1.2</kotlin-test-junit.version>
|
|
||||||
<kotlin-stdlib.version>1.1.2</kotlin-stdlib.version>
|
|
||||||
<kotlin-reflect.version>1.1.2</kotlin-reflect.version>
|
|
||||||
<kotlinx.version>0.15</kotlinx.version>
|
|
||||||
<mockito-kotlin.version>1.5.0</mockito-kotlin.version>
|
|
||||||
<junit.jupiter.version>5.0.0</junit.jupiter.version>
|
|
||||||
<junit.platform.version>1.0.0</junit.platform.version>
|
<junit.platform.version>1.0.0</junit.platform.version>
|
||||||
<junit.vintage.version>4.12.0</junit.vintage.version>
|
|
||||||
<junit4.version>4.12</junit4.version>
|
|
||||||
<groovy.version>2.4.13</groovy.version>
|
<groovy.version>2.4.13</groovy.version>
|
||||||
<groovy-all.version>2.4.13</groovy-all.version>
|
<groovy-all.version>2.4.13</groovy-all.version>
|
||||||
<groovy-sql.version>2.4.13</groovy-sql.version>
|
<groovy-sql.version>2.4.13</groovy-sql.version>
|
||||||
<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>
|
||||||
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
|
||||||
<maven-failsafe-plugin.version>2.19.1</maven-failsafe-plugin.version>
|
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
@ -1,45 +1,36 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-10</artifactId>
|
<artifactId>core-java-10</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-10</name>
|
<name>core-java-10</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<build>
|
||||||
<dependency>
|
<plugins>
|
||||||
<groupId>junit</groupId>
|
<plugin>
|
||||||
<artifactId>junit</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>${junit.version}</version>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<scope>test</scope>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</dependency>
|
<configuration>
|
||||||
</dependencies>
|
<source>${maven.compiler.source.version}</source>
|
||||||
|
<target>${maven.compiler.target.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<build>
|
<properties>
|
||||||
<plugins>
|
<maven.compiler.source.version>10</maven.compiler.source.version>
|
||||||
<plugin>
|
<maven.compiler.target.version>10</maven.compiler.target.version>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</properties>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source.version}</source>
|
|
||||||
<target>${maven.compiler.target.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source.version>10</maven.compiler.source.version>
|
|
||||||
<maven.compiler.target.version>10</maven.compiler.target.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.baeldung.java10.list;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CopyListServiceUnitTest {
|
||||||
|
|
||||||
|
@Test(expected = UnsupportedOperationException.class)
|
||||||
|
public void whenModifyCopyOfList_thenThrowsException() {
|
||||||
|
List<Integer> copyList = List.copyOf(Arrays.asList(1, 2, 3, 4));
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +1,36 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-11</artifactId>
|
<artifactId>core-java-11</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<name>core-java-11</name>
|
<name>core-java-11</name>
|
||||||
<url>http://maven.apache.org</url>
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-modules</artifactId>
|
<artifactId>parent-modules</artifactId>
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<build>
|
||||||
<dependency>
|
<plugins>
|
||||||
<groupId>junit</groupId>
|
<plugin>
|
||||||
<artifactId>junit</artifactId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<version>${junit.version}</version>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<scope>test</scope>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</dependency>
|
<configuration>
|
||||||
</dependencies>
|
<source>${maven.compiler.source.version}</source>
|
||||||
|
<target>${maven.compiler.target.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
<build>
|
<properties>
|
||||||
<plugins>
|
<maven.compiler.source.version>11</maven.compiler.source.version>
|
||||||
<plugin>
|
<maven.compiler.target.version>11</maven.compiler.target.version>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
</properties>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>${maven.compiler.source.version}</source>
|
|
||||||
<target>${maven.compiler.target.version}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<maven.compiler.source.version>11</maven.compiler.source.version>
|
|
||||||
<maven.compiler.target.version>11</maven.compiler.target.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -32,7 +32,6 @@
|
|||||||
- [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
|
- [“Stream has already been operated upon or closed” Exception in Java](http://www.baeldung.com/java-stream-operated-upon-or-closed-exception)
|
||||||
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
||||||
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
||||||
- [Generating Prime Numbers in Java](http://www.baeldung.com/java-generate-prime-numbers)
|
|
||||||
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
|
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
|
||||||
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
|
- [Iterable to Stream in Java](http://www.baeldung.com/java-iterable-to-stream)
|
||||||
- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream)
|
- [Converting String to Stream of chars](http://www.baeldung.com/java-string-to-stream)
|
||||||
@ -54,3 +53,5 @@
|
|||||||
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
|
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
|
||||||
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
|
- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
|
||||||
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
|
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
|
||||||
|
- [How to Get the Start and the End of a Day using Java](http://www.baeldung.com/java-day-start-end)
|
||||||
|
- [Generalized Target-Type Inference in Java](http://www.baeldung.com/java-generalized-target-type-inference)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-8</artifactId>
|
<artifactId>core-java-8</artifactId>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -94,6 +94,11 @@
|
|||||||
<artifactId>streamex</artifactId>
|
<artifactId>streamex</artifactId>
|
||||||
<version>${streamex.version}</version>
|
<version>${streamex.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>joda-time</groupId>
|
||||||
|
<artifactId>joda-time</artifactId>
|
||||||
|
<version>${joda.version}</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -125,86 +130,14 @@
|
|||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.1</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<source>1.8</source>
|
||||||
<manifest>
|
<target>1.8</target>
|
||||||
<addClasspath>true</addClasspath>
|
<compilerArgument>-parameters</compilerArgument>
|
||||||
<classpathPrefix>libs/</classpathPrefix>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<transformers>
|
|
||||||
<transformer
|
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.jolira</groupId>
|
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
<attachToBuild>true</attachToBuild>
|
|
||||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>one-jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>3.1</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
<compilerArgument>-parameters</compilerArgument>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
@ -225,10 +158,8 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>21.0</guava.version>
|
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<commons-io.version>2.5</commons-io.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>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
@ -236,6 +167,7 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
|
<joda.version>2.10</joda.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.baeldung.datetime;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
|
||||||
|
public class AddHoursToDate {
|
||||||
|
|
||||||
|
public Date addHoursToJavaUtilDate(Date date, int hours) {
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(date);
|
||||||
|
calendar.add(Calendar.HOUR_OF_DAY, hours);
|
||||||
|
return calendar.getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date addHoursToDateUsingInstant(Date date, int hours) {
|
||||||
|
return Date.from(date.toInstant()
|
||||||
|
.plus(Duration.ofHours(hours)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime addHoursToLocalDateTime(LocalDateTime localDateTime, int hours) {
|
||||||
|
return localDateTime.plusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime subtractHoursToLocalDateTime(LocalDateTime localDateTime, int hours) {
|
||||||
|
return localDateTime.minusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime addHoursToZonedDateTime(ZonedDateTime zonedDateTime, int hours) {
|
||||||
|
return zonedDateTime.plusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZonedDateTime subtractHoursToZonedDateTime(ZonedDateTime zonedDateTime, int hours) {
|
||||||
|
return zonedDateTime.minusHours(hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant addHoursToInstant(Instant instant, int hours) {
|
||||||
|
return instant.plus(hours, ChronoUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Instant subtractHoursToInstant(Instant instant, int hours) {
|
||||||
|
return instant.minus(hours, ChronoUnit.HOURS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date addHoursWithApacheCommons(Date date, int hours) {
|
||||||
|
return DateUtils.addHours(date, hours);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.baeldung.datetime.modify;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.time.DateUtils;
|
||||||
|
import org.joda.time.DateTime;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
public class DateIncrementer {
|
||||||
|
private static final Logger log = Logger.getLogger(DateIncrementer.class.getName());
|
||||||
|
private static final int INCREMENT_BY_IN_DAYS = 1;
|
||||||
|
|
||||||
|
public static String addOneDay(String date) {
|
||||||
|
return LocalDate
|
||||||
|
.parse(date)
|
||||||
|
.plusDays(INCREMENT_BY_IN_DAYS)
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayJodaTime(String date) {
|
||||||
|
DateTime dateTime = new DateTime(date);
|
||||||
|
return dateTime
|
||||||
|
.plusDays(INCREMENT_BY_IN_DAYS)
|
||||||
|
.toString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayCalendar(String date) throws ParseException {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Calendar c = Calendar.getInstance();
|
||||||
|
c.setTime(sdf.parse(date));
|
||||||
|
c.add(Calendar.DATE, 1);
|
||||||
|
return sdf.format(c.getTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String addOneDayApacheCommons(String date) throws ParseException {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
Date incrementedDate = DateUtils.addDays(sdf.parse(date), 1);
|
||||||
|
return sdf.format(incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws ParseException {
|
||||||
|
String date = LocalDate
|
||||||
|
.now()
|
||||||
|
.toString();
|
||||||
|
log.info("Current date = " + date);
|
||||||
|
|
||||||
|
String incrementedDateJava8 = DateIncrementer.addOneDay(date);
|
||||||
|
log.info("Date incremented by one day using (Java 8): " + incrementedDateJava8);
|
||||||
|
|
||||||
|
String incrementedDateJodaTime = DateIncrementer.addOneDayJodaTime(date);
|
||||||
|
log.info("Date incremented by one day using (Joda-Time): " + incrementedDateJodaTime);
|
||||||
|
|
||||||
|
String incrementedDateCalendar = addOneDayCalendar(date);
|
||||||
|
log.info("Date incremented by one day using (java.util.Calendar): " + incrementedDateCalendar);
|
||||||
|
|
||||||
|
String incrementedDateApacheCommons = addOneDayApacheCommons(date);
|
||||||
|
log.info("Date incremented by one day using (Apache Commons DateUtils): " + incrementedDateApacheCommons);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
package com.baeldung.list;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class CopyListService {
|
||||||
|
|
||||||
|
public List<Flower> copyListByConstructor(List<Flower> source) {
|
||||||
|
return new ArrayList<Flower>(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByConstructorAndEditOneFlowerInTheNewList(List<Flower> source) {
|
||||||
|
List<Flower> flowers = new ArrayList<>(source);
|
||||||
|
if(flowers.size() > 0) {
|
||||||
|
flowers.get(0).setPetals(flowers.get(0).getPetals() * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return flowers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByAddAllMethod(List<Flower> source) {
|
||||||
|
List<Flower> flowers = new ArrayList<>();
|
||||||
|
flowers.addAll(source);
|
||||||
|
return flowers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByAddAllMethodAndEditOneFlowerInTheNewList(List<Flower> source) {
|
||||||
|
List<Flower> flowers = new ArrayList<>();
|
||||||
|
flowers.addAll(source);
|
||||||
|
|
||||||
|
if(flowers.size() > 0) {
|
||||||
|
flowers.get(0).setPetals(flowers.get(0).getPetals() * 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
return flowers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> copyListByCopyMethod(List<Integer> source, List<Integer> dest) {
|
||||||
|
Collections.copy(dest, source);
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByStream(List<Flower> source) {
|
||||||
|
return source.stream().collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByStreamAndSkipFirstElement(List<Flower> source) {
|
||||||
|
return source.stream().skip(1).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByStreamWithFilter(List<Flower> source, Integer moreThanPetals) {
|
||||||
|
return source.stream().filter(f -> f.getPetals() > moreThanPetals).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByStreamWithOptional(List<Flower> source) {
|
||||||
|
return Optional.ofNullable(source)
|
||||||
|
.map(List::stream)
|
||||||
|
.orElseGet(Stream::empty)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Flower> copyListByStreamWithOptionalAndSkip(List<Flower> source) {
|
||||||
|
return Optional.ofNullable(source)
|
||||||
|
.map(List::stream)
|
||||||
|
.orElseGet(Stream::empty)
|
||||||
|
.skip(1)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
}
|
28
core-java-8/src/main/java/com/baeldung/list/Flower.java
Normal file
28
core-java-8/src/main/java/com/baeldung/list/Flower.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
package com.baeldung.list;
|
||||||
|
|
||||||
|
public class Flower {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private int petals;
|
||||||
|
|
||||||
|
public Flower(String name, int petals) {
|
||||||
|
this.name = name;
|
||||||
|
this.petals = petals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPetals() {
|
||||||
|
return petals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPetals(int petals) {
|
||||||
|
this.petals = petals;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package com.baeldung.datetime;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.Month;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.time.ZonedDateTime;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class AddHoursToDateUnitTest {
|
||||||
|
|
||||||
|
private final AddHoursToDate addHoursToDateObj = new AddHoursToDate();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenPositiveHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToJavaUtilDate(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenNegativeHours_thenMinusHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToJavaUtilDate(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingToInstantAndPostiveHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToDateUsingInstant(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingToInstantAndNegativeHours_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 3, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToDateUsingInstant(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLocalDateTime_whenUsingAddHoursToLocalDateTime_thenAddHours() {
|
||||||
|
LocalDateTime actualDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 5, 0);
|
||||||
|
LocalDateTime expectedDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 7, 0);
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToLocalDateTime(actualDateTime, 2)).isEqualTo(expectedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLocalDateTime_whenUsingMinusHoursToLocalDateTime_thenMinusHours() {
|
||||||
|
LocalDateTime actualDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 5, 0);
|
||||||
|
LocalDateTime expectedDateTime = LocalDateTime.of(2018, Month.JUNE, 25, 3, 0);
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToLocalDateTime(actualDateTime, 2)).isEqualTo(expectedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZonedDateTime_whenUsingAddHoursToZonedDateTime_thenAddHours() {
|
||||||
|
ZonedDateTime actualZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 5, 0), ZoneId.systemDefault());
|
||||||
|
ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 7, 0), ZoneId.systemDefault());
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToZonedDateTime(actualZonedDateTime, 2)).isEqualTo(expectedZonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenZonedDateTime_whenUsingMinusHoursToZonedDateTime_thenMinusHours() {
|
||||||
|
ZonedDateTime actualZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 5, 0), ZoneId.systemDefault());
|
||||||
|
ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(LocalDateTime.of(2018, Month.JUNE, 25, 3, 0), ZoneId.systemDefault());
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToZonedDateTime(actualZonedDateTime, 2)).isEqualTo(expectedZonedDateTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingPositiveHrsAndAddHoursWithApacheCommons_thenAddHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursWithApacheCommons(actualDate, 2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenJavaUtilDate_whenUsingNegativeHrsAndAddHoursWithApacheCommons_thenMinusHours() {
|
||||||
|
Date actualDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 7, 0).getTime();
|
||||||
|
Date expectedDate = new GregorianCalendar(2018, Calendar.JUNE, 25, 5, 0).getTime();
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursWithApacheCommons(actualDate, -2)).isEqualTo(expectedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInstant_whenUsingAddHoursToInstant_thenAddHours() {
|
||||||
|
Instant actualValue = Instant.parse("2018-06-25T05:12:35Z");
|
||||||
|
Instant expectedValue = Instant.parse("2018-06-25T07:12:35Z");
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.addHoursToInstant(actualValue, 2)).isEqualTo(expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenInstant_whenUsingSubtractHoursToInstant_thenMinusHours() {
|
||||||
|
Instant actualValue = Instant.parse("2018-06-25T07:12:35Z");
|
||||||
|
Instant expectedValue = Instant.parse("2018-06-25T05:12:35Z");
|
||||||
|
|
||||||
|
assertThat(addHoursToDateObj.subtractHoursToInstant(actualValue, 2)).isEqualTo(expectedValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.baeldung.datetime.modify;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class DateIncrementerUnitTest {
|
||||||
|
private final static String DATE_TO_INCREMENT = "2018-07-03";
|
||||||
|
private final static String EXPECTED_DATE = "2018-07-04";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingJava8_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDay(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingJodaTime_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayJodaTime(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingCalendar_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayCalendar(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenDate_whenUsingApacheCommons_thenAddOneDay() throws Exception {
|
||||||
|
String incrementedDate = DateIncrementer.addOneDayApacheCommons(DATE_TO_INCREMENT);
|
||||||
|
assertEquals(EXPECTED_DATE, incrementedDate);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.baeldung.fileToBase64StringConversion;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Base64;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class FileToBase64StringConversionUnitTest {
|
||||||
|
|
||||||
|
private String inputFilePath = "test_image.jpg";
|
||||||
|
private String outputFilePath = "test_image_copy.jpg";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fileToBase64StringConversion() throws IOException {
|
||||||
|
//load file from /src/test/resources
|
||||||
|
ClassLoader classLoader = getClass().getClassLoader();
|
||||||
|
File inputFile = new File(classLoader
|
||||||
|
.getResource(inputFilePath)
|
||||||
|
.getFile());
|
||||||
|
|
||||||
|
byte[] fileContent = FileUtils.readFileToByteArray(inputFile);
|
||||||
|
String encodedString = Base64
|
||||||
|
.getEncoder()
|
||||||
|
.encodeToString(fileContent);
|
||||||
|
|
||||||
|
//create output file
|
||||||
|
File outputFile = new File(inputFile
|
||||||
|
.getParentFile()
|
||||||
|
.getAbsolutePath() + File.pathSeparator + outputFilePath);
|
||||||
|
|
||||||
|
// decode the string and write to file
|
||||||
|
byte[] decodedBytes = Base64
|
||||||
|
.getDecoder()
|
||||||
|
.decode(encodedString);
|
||||||
|
FileUtils.writeByteArrayToFile(outputFile, decodedBytes);
|
||||||
|
|
||||||
|
assertTrue(FileUtils.contentEquals(inputFile, outputFile));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package com.baeldung.list;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class CopyListServiceUnitTest {
|
||||||
|
|
||||||
|
List<Flower> flowers;
|
||||||
|
|
||||||
|
private CopyListService copyListService;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() {
|
||||||
|
this.copyListService = new CopyListService();
|
||||||
|
this.flowers = new ArrayList<>();
|
||||||
|
|
||||||
|
Flower poppy = new Flower("Poppy", 12);
|
||||||
|
flowers.add(poppy);
|
||||||
|
Flower anemone = new Flower("Anemone", 8);
|
||||||
|
flowers.add(anemone);
|
||||||
|
Flower catmint = new Flower("Catmint", 12);
|
||||||
|
flowers.add(catmint);
|
||||||
|
Flower diascia = new Flower("Diascia", 5);
|
||||||
|
flowers.add(diascia);
|
||||||
|
Flower iris = new Flower("Iris", 3);
|
||||||
|
flowers.add(iris);
|
||||||
|
Flower pansy = new Flower("Pansy", 5);
|
||||||
|
flowers.add(pansy);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithTheSameElementsByConstructor() {
|
||||||
|
List<Flower> copy = copyListService.copyListByConstructor(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithOneModifiedElementByConstructor() {
|
||||||
|
List<Flower> copy = copyListService.copyListByConstructorAndEditOneFlowerInTheNewList(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithTheSameElementsByAddAllmethod() {
|
||||||
|
List<Flower> copy = copyListService.copyListByAddAllMethod(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithOneModifiedElementByAddAllmethod() {
|
||||||
|
List<Flower> copy = copyListService.copyListByAddAllMethodAndEditOneFlowerInTheNewList(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListsHaveSameSize_thenReturnAnotherListWithTheSameElementsByCopyMethod() {
|
||||||
|
List<Integer> source = Arrays.asList(1,2,3);
|
||||||
|
List<Integer> dest = Arrays.asList(4,5,6);
|
||||||
|
|
||||||
|
dest = copyListService.copyListByCopyMethod(source, dest);
|
||||||
|
assertEquals(dest.size(), source.size());
|
||||||
|
assertTrue(dest.containsAll(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListsHaveDifferentSize_thenReturnAnotherListWithTheSameElementsByCopyMethod() {
|
||||||
|
List<Integer> source = Arrays.asList(1,2,3);
|
||||||
|
List<Integer> dest = Arrays.asList(5,6,7,8,9,10);
|
||||||
|
|
||||||
|
dest = copyListService.copyListByCopyMethod(source, dest);
|
||||||
|
assertNotEquals(dest.size(), source.size());
|
||||||
|
assertTrue(dest.containsAll(source));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithTheSameElementsByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStream(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithOneElementLessByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStreamAndSkipFirstElement(flowers);
|
||||||
|
assertNotEquals(copy.size(), flowers.size());
|
||||||
|
assertEquals(copy.size() + 1, flowers.size());
|
||||||
|
assertFalse(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListDoesNotHaveNullElements_thenReturnAnotherListWithFilterElementsByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStreamWithFilter(flowers, 5);
|
||||||
|
assertNotEquals(copy.size(), flowers.size());
|
||||||
|
assertEquals(copy.size() + 3, flowers.size());
|
||||||
|
assertFalse(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListIsNull_thenReturnEmptyListByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStreamWithOptional(null);
|
||||||
|
assertNotNull(copy);
|
||||||
|
assertEquals(copy.size(), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListIsNotNull_thenReturnAnotherListWithTheElementsByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStreamWithOptional(flowers);
|
||||||
|
assertEquals(copy.size(), flowers.size());
|
||||||
|
assertTrue(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAList_whenListIsNotNull_thenReturnAnotherListWithOneElementLessByStreamProcess() {
|
||||||
|
List<Flower> copy = copyListService.copyListByStreamWithOptionalAndSkip(flowers);
|
||||||
|
assertNotEquals(copy.size(), flowers.size());
|
||||||
|
assertEquals(copy.size() + 1, flowers.size());
|
||||||
|
assertFalse(copy.containsAll(flowers));
|
||||||
|
}
|
||||||
|
}
|
BIN
core-java-8/src/test/resources/test_image.jpg
Normal file
BIN
core-java-8/src/test/resources/test_image.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-9</artifactId>
|
<artifactId>core-java-9</artifactId>
|
||||||
@ -13,34 +13,6 @@
|
|||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${ch.qos.logback.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -77,20 +49,7 @@
|
|||||||
</pluginRepositories>
|
</pluginRepositories>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<!-- project build encoding -->
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<ch.qos.logback.version>1.2.1</ch.qos.logback.version>
|
|
||||||
<!-- maven plugins -->
|
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito.version>1.10.19</mockito.version>
|
|
||||||
<awaitility.version>1.7.0</awaitility.version>
|
<awaitility.version>1.7.0</awaitility.version>
|
||||||
<maven.compiler.source>1.9</maven.compiler.source>
|
<maven.compiler.source>1.9</maven.compiler.source>
|
||||||
<maven.compiler.target>1.9</maven.compiler.target>
|
<maven.compiler.target>1.9</maven.compiler.target>
|
||||||
|
@ -1,60 +1,54 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-collections</artifactId>
|
<artifactId>core-java-collections</artifactId>
|
||||||
<version>0.1.0-SNAPSHOT</version>
|
<version>0.1.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>core-java-collections</name>
|
<name>core-java-collections</name>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>net.sourceforge.collections</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>collections-generic</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>${collections-generic.version}</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.apache.commons</groupId>
|
||||||
<groupId>net.sourceforge.collections</groupId>
|
<artifactId>commons-collections4</artifactId>
|
||||||
<artifactId>collections-generic</artifactId>
|
<version>${commons-collections4.version}</version>
|
||||||
<version>${collections-generic.version}</version>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<groupId>org.apache.commons</groupId>
|
<artifactId>awaitility</artifactId>
|
||||||
<artifactId>commons-collections4</artifactId>
|
<version>${avaitility.version}</version>
|
||||||
<version>${commons-collections4.version}</version>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${avaitility.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
<dependency>
|
<groupId>org.assertj</groupId>
|
||||||
<groupId>org.apache.commons</groupId>
|
<artifactId>assertj-core</artifactId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<version>${assertj.version}</version>
|
||||||
<version>${commons-lang3.version}</version>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
</dependencies>
|
||||||
<groupId>org.assertj</groupId>
|
|
||||||
<artifactId>assertj-core</artifactId>
|
|
||||||
<version>${assertj.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.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>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,80 @@
|
|||||||
|
package com.baeldung.java.list;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.iterators.ReverseListIterator;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides methods for iterating backward over a list.
|
||||||
|
*/
|
||||||
|
public class ReverseIterator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate using the for loop.
|
||||||
|
*
|
||||||
|
* @param list the list
|
||||||
|
*/
|
||||||
|
public void iterateUsingForLoop(final List<String> list) {
|
||||||
|
|
||||||
|
for (int i = list.size(); i-- > 0; ) {
|
||||||
|
System.out.println(list.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate using the Java {@link ListIterator}.
|
||||||
|
*
|
||||||
|
* @param list the list
|
||||||
|
*/
|
||||||
|
public void iterateUsingListIterator(final List<String> list) {
|
||||||
|
|
||||||
|
final ListIterator listIterator = list.listIterator(list.size());
|
||||||
|
while (listIterator.hasPrevious()) {
|
||||||
|
System.out.println(listIterator.previous());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate using Java {@link Collections} API.
|
||||||
|
*
|
||||||
|
* @param list the list
|
||||||
|
*/
|
||||||
|
public void iterateUsingCollections(final List<String> list) {
|
||||||
|
|
||||||
|
Collections.reverse(list);
|
||||||
|
for (final String item : list) {
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate using Apache Commons {@link ReverseListIterator}.
|
||||||
|
*
|
||||||
|
* @param list the list
|
||||||
|
*/
|
||||||
|
public void iterateUsingApacheReverseListIterator(final List<String> list) {
|
||||||
|
|
||||||
|
final ReverseListIterator listIterator = new ReverseListIterator(list);
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
System.out.println(listIterator.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Iterate using Guava {@link Lists} API.
|
||||||
|
*
|
||||||
|
* @param list the list
|
||||||
|
*/
|
||||||
|
public void iterateUsingGuava(final List<String> list) {
|
||||||
|
|
||||||
|
final List<String> reversedList = Lists.reverse(list);
|
||||||
|
for (final String item : reversedList) {
|
||||||
|
System.out.println(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.baeldung.java.list;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.iterators.ReverseListIterator;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
public class ReverseIteratorUnitTest {
|
||||||
|
|
||||||
|
private final ReverseIterator reverseIterator = new ReverseIterator();
|
||||||
|
|
||||||
|
private List<String> list;
|
||||||
|
|
||||||
|
private final String originalString = "ABCDE";
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
|
||||||
|
list = Lists.newArrayList("A", "B", "C", "D", "E");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenIteratingUsingForLoop_thenCorrect() {
|
||||||
|
|
||||||
|
String reverseString = "";
|
||||||
|
for (int i = list.size(); i-- > 0; ) {
|
||||||
|
reverseString += list.get(i);
|
||||||
|
}
|
||||||
|
assertEquals(reverseString, StringUtils.reverse(originalString));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenIteratingUsingListIterator_thenCorrect() {
|
||||||
|
|
||||||
|
String reverseString = "";
|
||||||
|
final ListIterator listIterator = list.listIterator(list.size());
|
||||||
|
while (listIterator.hasPrevious()) {
|
||||||
|
reverseString += listIterator.previous();
|
||||||
|
}
|
||||||
|
assertEquals(reverseString, StringUtils.reverse(originalString));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenIteratingUsingCollections_thenCorrect() {
|
||||||
|
|
||||||
|
String reverseString = "";
|
||||||
|
Collections.reverse(list);
|
||||||
|
for (final String item : list) {
|
||||||
|
reverseString += item;
|
||||||
|
}
|
||||||
|
assertEquals(reverseString, StringUtils.reverse(originalString));
|
||||||
|
|
||||||
|
assertEquals("E", list.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenIteratingUsingApacheReverseListIterator_thenCorrect() {
|
||||||
|
|
||||||
|
String reverseString = "";
|
||||||
|
final ReverseListIterator listIterator = new ReverseListIterator(list);
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
reverseString += listIterator.next();
|
||||||
|
}
|
||||||
|
assertEquals(reverseString, StringUtils.reverse(originalString));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenIteratingUsingGuava_thenCorrect() {
|
||||||
|
|
||||||
|
String reverseString = "";
|
||||||
|
final List<String> reversedList = Lists.reverse(list);
|
||||||
|
for (final String item : reversedList) {
|
||||||
|
reverseString += item;
|
||||||
|
}
|
||||||
|
assertEquals(reverseString, StringUtils.reverse(originalString));
|
||||||
|
|
||||||
|
assertEquals("A", list.get(0));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.baeldung.java.set;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.common.collect.Sets;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
public class HashSetInitalizingUnitTest {
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava_usingArraysStaticMethod_thenCorrectSize() {
|
||||||
|
Set<String> set = new HashSet<>(Arrays.asList("a", "b", "c"));
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava_usingAnonymousClass_thenCorrectSize() {
|
||||||
|
Set<String> set = new HashSet<String>(){{
|
||||||
|
add("a");
|
||||||
|
add("b");
|
||||||
|
add("c");
|
||||||
|
}};
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava_creatingSingletonSet_thenCorrectSize() {
|
||||||
|
Set<String> set = Collections.singleton("a");
|
||||||
|
assertEquals(1, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final <T> Set<T> newHashSet(T... objs) {
|
||||||
|
Set<T> set = new HashSet<T>();
|
||||||
|
Collections.addAll(set, objs);
|
||||||
|
return set;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava_usingCustomStaticUtilMethod_thenCorrectSize() {
|
||||||
|
Set<String> set = newHashSet("a","b","c");
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava8_usingCollectOnStream_thenCorrectSize() {
|
||||||
|
Set<String> set = Stream.of("a", "b", "c").collect(Collectors.toSet());
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void whenUsingJava8_fromStringArray_thenCorrectSize() {
|
||||||
|
String[] stringArray = {"a","b","c"};
|
||||||
|
Set<String> set = Arrays.stream(stringArray).collect(Collectors.toCollection(HashSet::new));
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Requires Java9 - uncomment if you are using Java 9 or higher
|
||||||
|
/*@Test
|
||||||
|
public void whenUsingJava9_usingCollectOnStream_thenCorrectSize() {
|
||||||
|
Set set = Set.of("a", "b", "c");
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingGoogleGuava_createMutableSet_thenCorrectSize() {
|
||||||
|
Set<String> set = Sets.newHashSet("a", "b", "c");
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingGoogleGuava_createImmutableSet_thenCorrectSize() {
|
||||||
|
Set<String> set = ImmutableSet.of("a", "b", "c");
|
||||||
|
assertEquals(3, set.size());
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-concurrency</artifactId>
|
<artifactId>core-java-concurrency</artifactId>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -75,93 +75,7 @@
|
|||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<addClasspath>true</addClasspath>
|
|
||||||
<classpathPrefix>libs/</classpathPrefix>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<transformers>
|
|
||||||
<transformer
|
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.jolira</groupId>
|
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
<attachToBuild>true</attachToBuild>
|
|
||||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>one-jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>spring-boot</classifier>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
@ -170,7 +84,6 @@
|
|||||||
<guava.version>21.0</guava.version>
|
<guava.version>21.0</guava.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<commons-io.version>2.5</commons-io.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>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-io</artifactId>
|
<artifactId>core-java-io</artifactId>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -74,23 +74,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -103,42 +86,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</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.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -253,7 +206,7 @@
|
|||||||
<argument>-Xmx300m</argument>
|
<argument>-Xmx300m</argument>
|
||||||
<argument>-XX:+UseParallelGC</argument>
|
<argument>-XX:+UseParallelGC</argument>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -318,7 +271,7 @@
|
|||||||
<executable>java</executable>
|
<executable>java</executable>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>org.openjdk.jmh.Main</argument>
|
<argument>org.openjdk.jmh.Main</argument>
|
||||||
<argument>.*</argument>
|
<argument>.*</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
@ -335,18 +288,12 @@
|
|||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>22.0</guava.version>
|
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<bouncycastle.version>1.55</bouncycastle.version>
|
<bouncycastle.version>1.55</bouncycastle.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.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>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
@ -358,15 +305,10 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<junit.version>4.12</junit.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
<maven-javadoc-plugin.version>3.0.0-M1</maven-javadoc-plugin.version>
|
||||||
|
@ -0,0 +1,54 @@
|
|||||||
|
package com.baeldung.symlink;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.DirectoryStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import static java.nio.file.StandardOpenOption.*;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
public class SymLinkExample {
|
||||||
|
|
||||||
|
public void createSymbolicLink(Path link, Path target) throws IOException {
|
||||||
|
if (Files.exists(link)) {
|
||||||
|
Files.delete(link);
|
||||||
|
}
|
||||||
|
Files.createSymbolicLink(link, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createHardLink(Path link, Path target) throws IOException {
|
||||||
|
if (Files.exists(link)) {
|
||||||
|
Files.delete(link);
|
||||||
|
}
|
||||||
|
Files.createLink(link, target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Path createTextFile() throws IOException {
|
||||||
|
byte[] content = IntStream.range(0, 10000)
|
||||||
|
.mapToObj(i -> i + System.lineSeparator())
|
||||||
|
.reduce("", String::concat)
|
||||||
|
.getBytes(StandardCharsets.UTF_8);
|
||||||
|
Path filePath = Paths.get(".", "target_link.txt");
|
||||||
|
Files.write(filePath, content, CREATE, TRUNCATE_EXISTING);
|
||||||
|
return filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void printLinkFiles(Path path) throws IOException {
|
||||||
|
try (DirectoryStream<Path> stream = Files.newDirectoryStream(path)) {
|
||||||
|
for (Path file : stream) {
|
||||||
|
if (Files.isDirectory(file)) {
|
||||||
|
printLinkFiles(file);
|
||||||
|
} else if (Files.isSymbolicLink(file)) {
|
||||||
|
System.out.format("File link '%s' with target '%s'%n", file, Files.readSymbolicLink(file));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
new SymLinkExample().printLinkFiles(Paths.get("."));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.symlink;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class SymLinkExampleUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingFiles_thenCreateSymbolicLink() throws IOException {
|
||||||
|
SymLinkExample example = new SymLinkExample();
|
||||||
|
Path filePath = example.createTextFile();
|
||||||
|
Path linkPath = Paths.get(".", "symbolic_link.txt");
|
||||||
|
example.createSymbolicLink(linkPath, filePath);
|
||||||
|
assertTrue(Files.isSymbolicLink(linkPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenUsingFiles_thenCreateHardLink() throws IOException {
|
||||||
|
SymLinkExample example = new SymLinkExample();
|
||||||
|
Path filePath = example.createTextFile();
|
||||||
|
Path linkPath = Paths.get(".", "hard_link.txt");
|
||||||
|
example.createHardLink(linkPath, filePath);
|
||||||
|
assertFalse(Files.isSymbolicLink(linkPath));
|
||||||
|
assertEquals(filePath.toFile()
|
||||||
|
.length(),
|
||||||
|
linkPath.toFile()
|
||||||
|
.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -14,8 +14,10 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
@ -111,6 +113,19 @@ public class JavaInputStreamToXUnitTest {
|
|||||||
|
|
||||||
assertThat(writer.toString(), equalTo(originalString));
|
assertThat(writer.toString(), equalTo(originalString));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public final void givenUsingTempFile_whenConvertingAnInputStreamToAString_thenCorrect() throws IOException {
|
||||||
|
final String originalString = randomAlphabetic(DEFAULT_SIZE);
|
||||||
|
final InputStream inputStream = new ByteArrayInputStream(originalString.getBytes());
|
||||||
|
|
||||||
|
// When
|
||||||
|
Path tempFile = java.nio.file.Files.createTempDirectory("").resolve(UUID.randomUUID().toString() + ".tmp");
|
||||||
|
java.nio.file.Files.copy(inputStream, tempFile, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
String result = new String(java.nio.file.Files.readAllBytes(tempFile));
|
||||||
|
|
||||||
|
assertThat(result, equalTo(originalString));
|
||||||
|
}
|
||||||
|
|
||||||
// tests - InputStream to byte[]
|
// tests - InputStream to byte[]
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<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">
|
<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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java-sun</artifactId>
|
<artifactId>core-java-sun</artifactId>
|
||||||
@ -9,8 +10,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -73,23 +74,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -102,42 +86,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</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.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.awaitility</groupId>
|
<groupId>com.jayway.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
@ -231,6 +185,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>${maven-jar-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
@ -241,79 +196,6 @@
|
|||||||
</archive>
|
</archive>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<phase>package</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>single</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<archiveBaseDirectory>${project.basedir}</archiveBaseDirectory>
|
|
||||||
<archive>
|
|
||||||
<manifest>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</manifest>
|
|
||||||
</archive>
|
|
||||||
<descriptorRefs>
|
|
||||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
|
||||||
</descriptorRefs>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>shade</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
|
||||||
<transformers>
|
|
||||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</transformer>
|
|
||||||
</transformers>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.jolira</groupId>
|
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<configuration>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
<attachToBuild>true</attachToBuild>
|
|
||||||
<filename>${project.build.finalName}-onejar.${project.packaging}</filename>
|
|
||||||
</configuration>
|
|
||||||
<goals>
|
|
||||||
<goal>one-jar</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<goals>
|
|
||||||
<goal>repackage</goal>
|
|
||||||
</goals>
|
|
||||||
<configuration>
|
|
||||||
<classifier>spring-boot</classifier>
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
|
||||||
</configuration>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
@ -325,7 +207,7 @@
|
|||||||
<argument>-Xmx300m</argument>
|
<argument>-Xmx300m</argument>
|
||||||
<argument>-XX:+UseParallelGC</argument>
|
<argument>-XX:+UseParallelGC</argument>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -381,7 +263,7 @@
|
|||||||
<executable>java</executable>
|
<executable>java</executable>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>org.openjdk.jmh.Main</argument>
|
<argument>org.openjdk.jmh.Main</argument>
|
||||||
<argument>.*</argument>
|
<argument>.*</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
@ -398,10 +280,6 @@
|
|||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<guava.version>23.0</guava.version>
|
<guava.version>23.0</guava.version>
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
@ -409,7 +287,6 @@
|
|||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.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>
|
<collections-generic.version>4.01</collections-generic.version>
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
@ -419,18 +296,16 @@
|
|||||||
<protonpack.version>1.13</protonpack.version>
|
<protonpack.version>1.13</protonpack.version>
|
||||||
<streamex.version>0.6.5</streamex.version>
|
<streamex.version>0.6.5</streamex.version>
|
||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
<spring-web.version>4.3.4.RELEASE</spring-web.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
<avaitility.version>1.7.0</avaitility.version>
|
<avaitility.version>1.7.0</avaitility.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
<sun-tools.version>1.8.0</sun-tools.version>
|
<sun-tools.version>1.8.0</sun-tools.version>
|
||||||
<spring-web.version>4.3.4.RELEASE</spring-web.version>
|
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -3,7 +3,6 @@
|
|||||||
## Core Java Cookbooks and Examples
|
## Core Java Cookbooks and Examples
|
||||||
|
|
||||||
### Relevant Articles:
|
### Relevant Articles:
|
||||||
- [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double)
|
|
||||||
- [Java – Generate Random String](http://www.baeldung.com/java-random-string)
|
- [Java – Generate Random String](http://www.baeldung.com/java-random-string)
|
||||||
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
|
- [Java Timer](http://www.baeldung.com/java-timer-and-timertask)
|
||||||
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
|
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
|
||||||
@ -38,7 +37,6 @@
|
|||||||
- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng)
|
- [A Quick JUnit vs TestNG Comparison](http://www.baeldung.com/junit-vs-testng)
|
||||||
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
|
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
|
||||||
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
|
- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
|
||||||
- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow)
|
|
||||||
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
|
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
|
||||||
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
|
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
|
||||||
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
|
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
|
||||||
@ -49,7 +47,6 @@
|
|||||||
- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend)
|
- [How to Add a Single Element to a Stream](http://www.baeldung.com/java-stream-append-prepend)
|
||||||
- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration)
|
- [Iterating Over Enum Values in Java](http://www.baeldung.com/java-enum-iteration)
|
||||||
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
|
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
|
||||||
- [How to Round a Number to N Decimal Places in Java](http://www.baeldung.com/java-round-decimal-number)
|
|
||||||
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
|
||||||
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
|
||||||
- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order)
|
- [Changing the Order in a Sum Operation Can Produce Different Results?](http://www.baeldung.com/java-floating-point-sum-order)
|
||||||
@ -77,7 +74,6 @@
|
|||||||
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
|
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
|
||||||
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
|
- [OutOfMemoryError: GC Overhead Limit Exceeded](http://www.baeldung.com/java-gc-overhead-limit-exceeded)
|
||||||
- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer)
|
- [StringBuilder and StringBuffer in Java](http://www.baeldung.com/java-string-builder-string-buffer)
|
||||||
- [Number of Digits in an Integer in Java](http://www.baeldung.com/java-number-of-digits-in-int)
|
|
||||||
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
- [Creating a Java Compiler Plugin](http://www.baeldung.com/java-build-compiler-plugin)
|
||||||
- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static)
|
- [A Guide to the Static Keyword in Java](http://www.baeldung.com/java-static)
|
||||||
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
|
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
|
||||||
@ -132,7 +128,6 @@
|
|||||||
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
|
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
|
||||||
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
|
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
|
||||||
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
|
- [Type Erasure in Java Explained](http://www.baeldung.com/java-type-erasure)
|
||||||
- [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger)
|
|
||||||
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
- [Display All Time Zones With GMT And UTC in Java](http://www.baeldung.com/java-time-zones)
|
||||||
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
|
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
|
||||||
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
|
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
|
||||||
@ -147,7 +142,6 @@
|
|||||||
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
||||||
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
|
- [Variable and Method Hiding in Java](http://www.baeldung.com/java-variable-method-hiding)
|
||||||
- [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers)
|
- [Access Modifiers in Java](http://www.baeldung.com/java-access-modifiers)
|
||||||
- [NaN in Java](http://www.baeldung.com/java-not-a-number)
|
|
||||||
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
- [Infinite Loops in Java](http://www.baeldung.com/infinite-loops-java)
|
||||||
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
||||||
- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns)
|
- [Introduction to Creational Design Patterns](http://www.baeldung.com/creational-design-patterns)
|
||||||
@ -160,3 +154,12 @@
|
|||||||
- [Guide to the super Java Keyword](http://www.baeldung.com/java-super)
|
- [Guide to the super Java Keyword](http://www.baeldung.com/java-super)
|
||||||
- [Guide to the this Java Keyword](http://www.baeldung.com/java-this)
|
- [Guide to the this Java Keyword](http://www.baeldung.com/java-this)
|
||||||
- [Jagged Arrays In Java](http://www.baeldung.com/java-jagged-arrays)
|
- [Jagged Arrays In Java](http://www.baeldung.com/java-jagged-arrays)
|
||||||
|
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
|
||||||
|
- [Extracting Year, Month and Day from Date in Java](http://www.baeldung.com/java-year-month-day)
|
||||||
|
- [Get Date Without Time in Java](http://www.baeldung.com/java-date-without-time)
|
||||||
|
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
|
||||||
|
- [How to Get the File Extension of a File in Java](http://www.baeldung.com/java-file-extension)
|
||||||
|
- [Immutable Objects in Java](http://www.baeldung.com/java-immutable-object)
|
||||||
|
- [Console I/O in Java](http://www.baeldung.com/java-console-input-output)
|
||||||
|
- [Guide to the java.util.Arrays Class](http://www.baeldung.com/java-util-arrays)
|
||||||
|
- [Create a Custom Exception in Java](http://www.baeldung.com/java-new-custom-exception)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<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>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>core-java</artifactId>
|
<artifactId>core-java</artifactId>
|
||||||
@ -10,8 +10,8 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>parent-java</artifactId>
|
<artifactId>parent-java</artifactId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-java</relativePath>
|
<relativePath>../parent-java</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -25,16 +25,6 @@
|
|||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.commons</groupId>
|
|
||||||
<artifactId>commons-math3</artifactId>
|
|
||||||
<version>${commons-math3.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.decimal4j</groupId>
|
|
||||||
<artifactId>decimal4j</artifactId>
|
|
||||||
<version>${decimal4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bouncycastle</groupId>
|
<groupId>org.bouncycastle</groupId>
|
||||||
<artifactId>bcprov-jdk15on</artifactId>
|
<artifactId>bcprov-jdk15on</artifactId>
|
||||||
@ -68,23 +58,6 @@
|
|||||||
<artifactId>log4j</artifactId>
|
<artifactId>log4j</artifactId>
|
||||||
<version>${log4j.version}</version>
|
<version>${log4j.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
@ -97,42 +70,12 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<!-- test scoped -->
|
<!-- test scoped -->
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-all</artifactId>
|
|
||||||
<version>${hamcrest-all.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<version>${junit.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-core</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hamcrest</groupId>
|
|
||||||
<artifactId>hamcrest-library</artifactId>
|
|
||||||
<version>${org.hamcrest.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</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.mockito</groupId>
|
|
||||||
<artifactId>mockito-core</artifactId>
|
|
||||||
<version>${mockito.version}</version>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-codec</groupId>
|
<groupId>commons-codec</groupId>
|
||||||
<artifactId>commons-codec</artifactId>
|
<artifactId>commons-codec</artifactId>
|
||||||
@ -198,11 +141,6 @@
|
|||||||
<artifactId>mail</artifactId>
|
<artifactId>mail</artifactId>
|
||||||
<version>${javax.mail.version}</version>
|
<version>${javax.mail.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javax.mail</groupId>
|
|
||||||
<artifactId>mail</artifactId>
|
|
||||||
<version>1.5.0-b01</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ibm.icu</groupId>
|
<groupId>com.ibm.icu</groupId>
|
||||||
<artifactId>icu4j</artifactId>
|
<artifactId>icu4j</artifactId>
|
||||||
@ -255,6 +193,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-jar-plugin</artifactId>
|
<artifactId>maven-jar-plugin</artifactId>
|
||||||
|
<version>${maven-jar-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
@ -293,6 +232,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>${maven-shade-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -301,8 +241,7 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<shadedArtifactAttached>true</shadedArtifactAttached>
|
<shadedArtifactAttached>true</shadedArtifactAttached>
|
||||||
<transformers>
|
<transformers>
|
||||||
<transformer
|
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
|
||||||
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
<mainClass>org.baeldung.executable.ExecutableMavenJar</mainClass>
|
||||||
</transformer>
|
</transformer>
|
||||||
</transformers>
|
</transformers>
|
||||||
@ -314,6 +253,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>com.jolira</groupId>
|
<groupId>com.jolira</groupId>
|
||||||
<artifactId>onejar-maven-plugin</artifactId>
|
<artifactId>onejar-maven-plugin</artifactId>
|
||||||
|
<version>${onejar-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<configuration>
|
<configuration>
|
||||||
@ -331,6 +271,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<version>${spring-boot-maven-plugin.version}</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -355,7 +296,7 @@
|
|||||||
<argument>-Xmx300m</argument>
|
<argument>-Xmx300m</argument>
|
||||||
<argument>-XX:+UseParallelGC</argument>
|
<argument>-XX:+UseParallelGC</argument>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
<argument>com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
@ -407,7 +348,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.mojo</groupId>
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
<artifactId>exec-maven-plugin</artifactId>
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>run-benchmarks</id>
|
<id>run-benchmarks</id>
|
||||||
@ -421,7 +361,7 @@
|
|||||||
<executable>java</executable>
|
<executable>java</executable>
|
||||||
<arguments>
|
<arguments>
|
||||||
<argument>-classpath</argument>
|
<argument>-classpath</argument>
|
||||||
<classpath/>
|
<classpath />
|
||||||
<argument>org.openjdk.jmh.Main</argument>
|
<argument>org.openjdk.jmh.Main</argument>
|
||||||
<argument>.*</argument>
|
<argument>.*</argument>
|
||||||
</arguments>
|
</arguments>
|
||||||
@ -439,18 +379,13 @@
|
|||||||
<jackson.version>2.8.5</jackson.version>
|
<jackson.version>2.8.5</jackson.version>
|
||||||
<gson.version>2.8.2</gson.version>
|
<gson.version>2.8.2</gson.version>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
|
||||||
<logback.version>1.1.7</logback.version>
|
|
||||||
<log4j.version>1.2.17</log4j.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<commons-lang3.version>3.5</commons-lang3.version>
|
<commons-lang3.version>3.5</commons-lang3.version>
|
||||||
<bouncycastle.version>1.55</bouncycastle.version>
|
<bouncycastle.version>1.55</bouncycastle.version>
|
||||||
<commons-codec.version>1.10</commons-codec.version>
|
<commons-codec.version>1.10</commons-codec.version>
|
||||||
|
<commons-io.version>2.5</commons-io.version>
|
||||||
<commons-math3.version>3.6.1</commons-math3.version>
|
<commons-math3.version>3.6.1</commons-math3.version>
|
||||||
<decimal4j.version>1.0.3</decimal4j.version>
|
<decimal4j.version>1.0.3</decimal4j.version>
|
||||||
<commons-io.version>2.5</commons-io.version>
|
|
||||||
<unix4j.version>0.4</unix4j.version>
|
<unix4j.version>0.4</unix4j.version>
|
||||||
<grep4j.version>1.8.7</grep4j.version>
|
<grep4j.version>1.8.7</grep4j.version>
|
||||||
<lombok.version>1.16.12</lombok.version>
|
<lombok.version>1.16.12</lombok.version>
|
||||||
@ -460,24 +395,23 @@
|
|||||||
<vavr.version>0.9.0</vavr.version>
|
<vavr.version>0.9.0</vavr.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- testing -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
|
||||||
<mockito.version>2.8.9</mockito.version>
|
|
||||||
<assertj.version>3.6.1</assertj.version>
|
<assertj.version>3.6.1</assertj.version>
|
||||||
|
|
||||||
<!-- maven plugins -->
|
<!-- maven plugins -->
|
||||||
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||||
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>
|
<springframework.spring-web.version>4.3.4.RELEASE</springframework.spring-web.version>
|
||||||
<springframework.boot.spring-boot-starter.version>1.5.8.RELEASE</springframework.boot.spring-boot-starter.version>
|
<springframework.boot.spring-boot-starter.version>1.5.8.RELEASE</springframework.boot.spring-boot-starter.version>
|
||||||
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
<javamoney.moneta.version>1.1</javamoney.moneta.version>
|
||||||
<hamcrest-all.version>1.3</hamcrest-all.version>
|
|
||||||
<h2database.version>1.4.197</h2database.version>
|
<h2database.version>1.4.197</h2database.version>
|
||||||
<esapi.version>2.1.0.1</esapi.version>
|
<esapi.version>2.1.0.1</esapi.version>
|
||||||
<jmh-core.version>1.19</jmh-core.version>
|
<jmh-core.version>1.19</jmh-core.version>
|
||||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.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>
|
||||||
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
|
|
||||||
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
<javax.mail.version>1.5.0-b01</javax.mail.version>
|
||||||
|
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
|
||||||
|
<onejar-maven-plugin.version>1.4.4</onejar-maven-plugin.version>
|
||||||
|
<maven-shade-plugin.version>3.1.1</maven-shade-plugin.version>
|
||||||
|
<spring-boot-maven-plugin.version>2.0.3.RELEASE</spring-boot-maven-plugin.version>
|
||||||
<icu4j.version>61.1</icu4j.version>
|
<icu4j.version>61.1</icu4j.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.console;
|
||||||
|
|
||||||
|
import java.io.Console;
|
||||||
|
|
||||||
|
public class ConsoleConsoleClass {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Console console = System.console();
|
||||||
|
|
||||||
|
if (console == null) {
|
||||||
|
System.out.print("No console available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String progLanguauge = console.readLine("Enter your favourite programming language: ");
|
||||||
|
console.printf(progLanguauge + " is very interesting!");
|
||||||
|
|
||||||
|
char[] pass = console.readPassword("To finish, enter password: ");
|
||||||
|
|
||||||
|
if ("BAELDUNG".equals(pass.toString().toUpperCase()))
|
||||||
|
console.printf("Good! Regards!");
|
||||||
|
else
|
||||||
|
console.printf("Nice try. Regards.");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,76 @@
|
|||||||
|
package com.baeldung.console;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
public class ConsoleScannerClass {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Please enter your name and surname: ");
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
String nameSurname = scanner.nextLine();
|
||||||
|
|
||||||
|
System.out.println("Please enter your gender: ");
|
||||||
|
|
||||||
|
char gender = scanner.next().charAt(0);
|
||||||
|
|
||||||
|
System.out.println("Please enter your age: ");
|
||||||
|
|
||||||
|
int age = scanner.nextInt();
|
||||||
|
|
||||||
|
System.out.println("Please enter your height in meters: ");
|
||||||
|
|
||||||
|
double height = scanner.nextDouble();
|
||||||
|
|
||||||
|
System.out.println(nameSurname + ", " + age + ", is a great " + (gender == 'm' ? "guy" : "girl") + " with " + height + " meters height" + " and " + (gender == 'm' ? "he" : "she") + " reads Baeldung.");
|
||||||
|
|
||||||
|
System.out.print("Have a good");
|
||||||
|
System.out.print(" one!");
|
||||||
|
|
||||||
|
System.out.println("\nPlease enter number of years of experience as a developer: ");
|
||||||
|
|
||||||
|
BufferedReader buffReader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
i = Integer.parseInt(buffReader.readLine());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("You are a " + (i > 5 ? "great" : "good") + " developer!");
|
||||||
|
|
||||||
|
int sum = 0, count = 0;
|
||||||
|
|
||||||
|
System.out.println("Please enter your college degrees. To finish, enter baeldung website url");
|
||||||
|
|
||||||
|
while (scanner.hasNextInt()) {
|
||||||
|
int nmbr = scanner.nextInt();
|
||||||
|
sum += nmbr;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
int mean = sum / count;
|
||||||
|
|
||||||
|
System.out.println("Your average degree is " + mean);
|
||||||
|
|
||||||
|
if (scanner.hasNext(Pattern.compile("www.baeldung.com")))
|
||||||
|
System.out.println("Correct!");
|
||||||
|
else
|
||||||
|
System.out.println("Baeldung website url is www.baeldung.com");
|
||||||
|
|
||||||
|
if (scanner != null)
|
||||||
|
scanner.close();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package com.baeldung.customexception;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class FileManager {
|
||||||
|
|
||||||
|
public static String getFirstLine(String fileName) throws IncorrectFileNameException {
|
||||||
|
try (Scanner file = new Scanner(new File(fileName))) {
|
||||||
|
if (file.hasNextLine()) {
|
||||||
|
return file.nextLine();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("Non readable file");
|
||||||
|
}
|
||||||
|
} catch (FileNotFoundException err) {
|
||||||
|
if (!isCorrectFileName(fileName)) {
|
||||||
|
throw new IncorrectFileNameException("Incorrect filename : " + fileName, err);
|
||||||
|
}
|
||||||
|
// Logging etc
|
||||||
|
} catch (IllegalArgumentException err) {
|
||||||
|
if (!containsExtension(fileName)) {
|
||||||
|
throw new IncorrectFileExtensionException("Filename does not contain extension : " + fileName, err);
|
||||||
|
}
|
||||||
|
// Other error cases and logging
|
||||||
|
}
|
||||||
|
return "Default First Line";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean containsExtension(String fileName) {
|
||||||
|
if (fileName.contains(".txt") || fileName.contains(".doc"))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isCorrectFileName(String fileName) {
|
||||||
|
if (fileName.equals("wrongFileName.txt"))
|
||||||
|
return false;
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.customexception;
|
||||||
|
|
||||||
|
public class IncorrectFileExtensionException extends RuntimeException{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public IncorrectFileExtensionException(String errorMessage, Throwable err) {
|
||||||
|
super(errorMessage, err);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
package com.baeldung.customexception;
|
||||||
|
|
||||||
|
public class IncorrectFileNameException extends Exception {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public IncorrectFileNameException(String errorMessage, Throwable err) {
|
||||||
|
super(errorMessage, err);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
package com.baeldung.encrypt;
|
||||||
|
|
||||||
|
import javax.crypto.*;
|
||||||
|
import javax.crypto.spec.IvParameterSpec;
|
||||||
|
import java.io.*;
|
||||||
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
|
import java.security.InvalidKeyException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
class FileEncrypterDecrypter {
|
||||||
|
|
||||||
|
private SecretKey secretKey;
|
||||||
|
private Cipher cipher;
|
||||||
|
|
||||||
|
FileEncrypterDecrypter(SecretKey secretKey, String cipher) throws NoSuchPaddingException, NoSuchAlgorithmException {
|
||||||
|
this.secretKey = secretKey;
|
||||||
|
this.cipher = Cipher.getInstance(cipher);
|
||||||
|
}
|
||||||
|
|
||||||
|
void encrypt(String content, String fileName) throws InvalidKeyException, IOException {
|
||||||
|
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
|
||||||
|
byte[] iv = cipher.getIV();
|
||||||
|
|
||||||
|
try (
|
||||||
|
FileOutputStream fileOut = new FileOutputStream(fileName);
|
||||||
|
CipherOutputStream cipherOut = new CipherOutputStream(fileOut, cipher)
|
||||||
|
) {
|
||||||
|
fileOut.write(iv);
|
||||||
|
cipherOut.write(content.getBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
String decrypt(String fileName) throws InvalidAlgorithmParameterException, InvalidKeyException, IOException {
|
||||||
|
|
||||||
|
String content;
|
||||||
|
|
||||||
|
try (FileInputStream fileIn = new FileInputStream(fileName)) {
|
||||||
|
byte[] fileIv = new byte[16];
|
||||||
|
fileIn.read(fileIv);
|
||||||
|
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(fileIv));
|
||||||
|
|
||||||
|
try (
|
||||||
|
CipherInputStream cipherIn = new CipherInputStream(fileIn, cipher);
|
||||||
|
InputStreamReader inputReader = new InputStreamReader(cipherIn);
|
||||||
|
BufferedReader reader = new BufferedReader(inputReader)
|
||||||
|
) {
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
sb.append(line);
|
||||||
|
}
|
||||||
|
content = sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class Arithmetic {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(Arithmetic.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
int result = 30 / 0; // Trying to divide by zero
|
||||||
|
} catch (ArithmeticException e) {
|
||||||
|
LOGGER.error("ArithmeticException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
public class ArrayIndexOutOfBounds {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ArrayIndexOutOfBounds.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
int[] nums = new int[] { 1, 2, 3 };
|
||||||
|
|
||||||
|
try {
|
||||||
|
int numFromNegativeIndex = nums[-1]; // Trying to access at negative index
|
||||||
|
int numFromGreaterIndex = nums[4]; // Trying to access at greater index
|
||||||
|
int numFromLengthIndex = nums[3]; // Trying to access at index equal to size of the array
|
||||||
|
} catch (ArrayIndexOutOfBoundsException e) {
|
||||||
|
LOGGER.error("ArrayIndexOutOfBoundsException caught");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.baeldung.exceptions;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
class Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Dog extends Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class Lion extends Animal {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ClassCast {
|
||||||
|
|
||||||
|
private static Logger LOGGER = LoggerFactory.getLogger(ClassCast.class);
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Animal animalOne = new Dog(); // At runtime the instance is dog
|
||||||
|
Dog bruno = (Dog) animalOne; // Downcasting
|
||||||
|
|
||||||
|
Animal animalTwo = new Lion(); // At runtime the instance is animal
|
||||||
|
Dog tommy = (Dog) animalTwo; // Downcasting
|
||||||
|
} catch (ClassCastException e) {
|
||||||
|
LOGGER.error("ClassCastException caught!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
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