Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL-12185
This commit is contained in:
commit
c69690d22c
|
@ -39,6 +39,11 @@
|
|||
<version>${org.assertj.core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.dpaukov</groupId>
|
||||
<artifactId>combinatoricslib3</artifactId>
|
||||
<version>3.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -77,7 +82,7 @@
|
|||
<commons-math3.version>3.6.1</commons-math3.version>
|
||||
<org.assertj.core.version>3.9.0</org.assertj.core.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<guava.version>25.1-jre</guava.version>
|
||||
<guava.version>27.0.1-jre</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,29 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.math3.util.CombinatoricsUtils;
|
||||
|
||||
public class ApacheCommonsCombinationGenerator {
|
||||
|
||||
private static final int N = 6;
|
||||
private static final int R = 3;
|
||||
|
||||
/**
|
||||
* Print all combinations of r elements from a set
|
||||
* @param n - number of elements in set
|
||||
* @param r - number of elements in selection
|
||||
*/
|
||||
public static void generate(int n, int r) {
|
||||
Iterator<int[]> iterator = CombinatoricsUtils.combinationsIterator(n, r);
|
||||
while (iterator.hasNext()) {
|
||||
final int[] combination = iterator.next();
|
||||
System.out.println(Arrays.toString(combination));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
generate(N, R);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import org.paukov.combinatorics3.Generator;
|
||||
|
||||
public class CombinatoricsLibCombinationGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Generator.combination(0, 1, 2, 3, 4, 5)
|
||||
.simple(3)
|
||||
.stream()
|
||||
.forEach(System.out::println);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
public class GuavaCombinationsGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Set<Set<Integer>> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3);
|
||||
System.out.println(combinations.size());
|
||||
System.out.println(Arrays.toString(combinations.toArray()));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class IterativeCombinationGenerator {
|
||||
|
||||
private static final int N = 5;
|
||||
private static final int R = 2;
|
||||
|
||||
/**
|
||||
* Generate all combinations of r elements from a set
|
||||
* @param n the number of elements in input set
|
||||
* @param r the number of elements in a combination
|
||||
* @return the list containing all combinations
|
||||
*/
|
||||
public List<int[]> generate(int n, int r) {
|
||||
List<int[]> combinations = new ArrayList<>();
|
||||
int[] combination = new int[r];
|
||||
|
||||
// initialize with lowest lexicographic combination
|
||||
for (int i = 0; i < r; i++) {
|
||||
combination[i] = i;
|
||||
}
|
||||
|
||||
while (combination[r - 1] < n) {
|
||||
combinations.add(combination.clone());
|
||||
|
||||
// generate next combination in lexicographic order
|
||||
int t = r - 1;
|
||||
while (t != 0 && combination[t] == n - r + t) {
|
||||
t--;
|
||||
}
|
||||
combination[t]++;
|
||||
for (int i = t + 1; i < r; i++) {
|
||||
combination[i] = combination[i - 1] + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return combinations;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
|
||||
List<int[]> combinations = generator.generate(N, R);
|
||||
System.out.println(combinations.size());
|
||||
for (int[] combination : combinations) {
|
||||
System.out.println(Arrays.toString(combination));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SelectionRecursiveCombinationGenerator {
|
||||
|
||||
private static final int N = 6;
|
||||
private static final int R = 3;
|
||||
|
||||
/**
|
||||
* Generate all combinations of r elements from a set
|
||||
* @param n - number of elements in input set
|
||||
* @param r - number of elements to be chosen
|
||||
* @return the list containing all combinations
|
||||
*/
|
||||
public List<int[]> generate(int n, int r) {
|
||||
List<int[]> combinations = new ArrayList<>();
|
||||
helper(combinations, new int[r], 0, n - 1, 0);
|
||||
return combinations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose elements from set by recursing over elements selected
|
||||
* @param combinations - List to store generated combinations
|
||||
* @param data - current combination
|
||||
* @param start - starting element of remaining set
|
||||
* @param end - last element of remaining set
|
||||
* @param index - number of elements chosen so far.
|
||||
*/
|
||||
private void helper(List<int[]> combinations, int data[], int start, int end, int index) {
|
||||
if (index == data.length) {
|
||||
int[] combination = data.clone();
|
||||
combinations.add(combination);
|
||||
} else {
|
||||
int max = Math.min(end, end + 1 - data.length + index);
|
||||
for (int i = start; i <= max; i++) {
|
||||
data[index] = i;
|
||||
helper(combinations, data, i + 1, end, index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
|
||||
List<int[]> combinations = generator.generate(N, R);
|
||||
for (int[] combination : combinations) {
|
||||
System.out.println(Arrays.toString(combination));
|
||||
}
|
||||
System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SetRecursiveCombinationGenerator {
|
||||
|
||||
private static final int N = 5;
|
||||
private static final int R = 2;
|
||||
|
||||
/**
|
||||
* Generate all combinations of r elements from a set
|
||||
* @param n - number of elements in set
|
||||
* @param r - number of elements in selection
|
||||
* @return the list containing all combinations
|
||||
*/
|
||||
public List<int[]> generate(int n, int r) {
|
||||
List<int[]> combinations = new ArrayList<>();
|
||||
helper(combinations, new int[r], 0, n-1, 0);
|
||||
return combinations;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param combinations - List to contain the generated combinations
|
||||
* @param data - List of elements in the selection
|
||||
* @param start - index of the starting element in the remaining set
|
||||
* @param end - index of the last element in the set
|
||||
* @param index - number of elements selected so far
|
||||
*/
|
||||
private void helper(List<int[]> combinations, int data[], int start, int end, int index) {
|
||||
if (index == data.length) {
|
||||
int[] combination = data.clone();
|
||||
combinations.add(combination);
|
||||
} else if (start <= end) {
|
||||
data[index] = start;
|
||||
helper(combinations, data, start + 1, end, index + 1);
|
||||
helper(combinations, data, start + 1, end, index);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
|
||||
List<int[]> combinations = generator.generate(N, R);
|
||||
for (int[] combination : combinations) {
|
||||
System.out.println(Arrays.toString(combination));
|
||||
}
|
||||
System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package com.baeldung.algorithms.combination;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CombinationUnitTest {
|
||||
|
||||
private static final int N = 5;
|
||||
private static final int R = 3;
|
||||
private static final int nCr = 10;
|
||||
|
||||
@Test
|
||||
public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() {
|
||||
SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator();
|
||||
List<int[]> selection = generator.generate(N, R);
|
||||
assertEquals(nCr, selection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() {
|
||||
SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator();
|
||||
List<int[]> selection = generator.generate(N, R);
|
||||
assertEquals(nCr, selection.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() {
|
||||
IterativeCombinationGenerator generator = new IterativeCombinationGenerator();
|
||||
List<int[]> selection = generator.generate(N, R);
|
||||
assertEquals(nCr, selection.size());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.baeldung.algorithms.reversingtree;
|
||||
|
||||
public class TreeNode {
|
||||
|
||||
private int value;
|
||||
private TreeNode rightChild;
|
||||
private TreeNode leftChild;
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public TreeNode getRightChild() {
|
||||
return rightChild;
|
||||
}
|
||||
|
||||
public void setRightChild(TreeNode rightChild) {
|
||||
this.rightChild = rightChild;
|
||||
}
|
||||
|
||||
public TreeNode getLeftChild() {
|
||||
return leftChild;
|
||||
}
|
||||
|
||||
public void setLeftChild(TreeNode leftChild) {
|
||||
this.leftChild = leftChild;
|
||||
}
|
||||
|
||||
public TreeNode(int value, TreeNode rightChild, TreeNode leftChild) {
|
||||
this.value = value;
|
||||
this.rightChild = rightChild;
|
||||
this.leftChild = leftChild;
|
||||
}
|
||||
|
||||
public TreeNode(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
package com.baeldung.algorithms.reversingtree;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
public class TreeReverser {
|
||||
|
||||
public TreeNode createBinaryTree() {
|
||||
|
||||
TreeNode leaf1 = new TreeNode(3);
|
||||
TreeNode leaf2 = new TreeNode(1);
|
||||
TreeNode leaf3 = new TreeNode(9);
|
||||
TreeNode leaf4 = new TreeNode(6);
|
||||
|
||||
TreeNode nodeLeft = new TreeNode(2, leaf1, leaf2);
|
||||
TreeNode nodeRight = new TreeNode(7, leaf3, leaf4);
|
||||
|
||||
TreeNode root = new TreeNode(4, nodeRight, nodeLeft);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public void reverseRecursive(TreeNode treeNode) {
|
||||
if (treeNode == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
TreeNode temp = treeNode.getLeftChild();
|
||||
treeNode.setLeftChild(treeNode.getRightChild());
|
||||
treeNode.setRightChild(temp);
|
||||
|
||||
reverseRecursive(treeNode.getLeftChild());
|
||||
reverseRecursive(treeNode.getRightChild());
|
||||
}
|
||||
|
||||
public void reverseIterative(TreeNode treeNode) {
|
||||
LinkedList<TreeNode> queue = new LinkedList<TreeNode>();
|
||||
|
||||
if (treeNode != null) {
|
||||
queue.add(treeNode);
|
||||
}
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
|
||||
TreeNode node = queue.poll();
|
||||
if (node.getLeftChild() != null)
|
||||
queue.add(node.getLeftChild());
|
||||
if (node.getRightChild() != null)
|
||||
queue.add(node.getRightChild());
|
||||
|
||||
TreeNode temp = node.getLeftChild();
|
||||
node.setLeftChild(node.getRightChild());
|
||||
node.setRightChild(temp);
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(TreeNode root) {
|
||||
if (root == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer(String.valueOf(root.getValue())).append(" ");
|
||||
|
||||
buffer.append(toString(root.getLeftChild()));
|
||||
buffer.append(toString(root.getRightChild()));
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.baeldung.algorithms.reversingtree;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TreeReverserUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenTreeWhenReversingRecursivelyThenReversed() {
|
||||
TreeReverser reverser = new TreeReverser();
|
||||
|
||||
TreeNode treeNode = reverser.createBinaryTree();
|
||||
|
||||
reverser.reverseRecursive(treeNode);
|
||||
|
||||
assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
|
||||
.trim());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTreeWhenReversingIterativelyThenReversed() {
|
||||
TreeReverser reverser = new TreeReverser();
|
||||
|
||||
TreeNode treeNode = reverser.createBinaryTree();
|
||||
|
||||
reverser.reverseIterative(treeNode);
|
||||
|
||||
assertEquals("4 7 9 6 2 3 1", reverser.toString(treeNode)
|
||||
.trim());
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
- [AWS S3 with Java](http://www.baeldung.com/aws-s3-java)
|
||||
- [AWS Lambda With Java](http://www.baeldung.com/java-aws-lambda)
|
||||
- [Managing EC2 Instances in Java](http://www.baeldung.com/ec2-java)
|
||||
- [http://www.baeldung.com/aws-s3-multipart-upload](https://github.com/eugenp/tutorials/tree/master/aws)
|
||||
- [Multipart Uploads in Amazon S3 with Java](http://www.baeldung.com/aws-s3-multipart-upload)
|
||||
- [Integration Testing with a Local DynamoDB Instance](http://www.baeldung.com/dynamodb-local-integration-tests)
|
||||
- [Using the JetS3t Java Client With Amazon S3](http://www.baeldung.com/jets3t-amazon-s3)
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>cas</artifactId>
|
||||
<name>cas</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>cas-secured-app</module>
|
||||
<module>cas-server</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,73 @@
|
|||
issuer:
|
||||
uri: http://localhost:8080/uaa
|
||||
|
||||
spring_profiles: postgresql,default
|
||||
|
||||
database.driverClassName: org.postgresql.Driver
|
||||
database.url: jdbc:postgresql:uaadb2
|
||||
database.username: postgres
|
||||
database.password: postgres
|
||||
|
||||
encryption:
|
||||
active_key_label: CHANGE-THIS-KEY
|
||||
encryption_keys:
|
||||
- label: CHANGE-THIS-KEY
|
||||
passphrase: CHANGEME
|
||||
|
||||
login:
|
||||
serviceProviderKey: |
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIICXQIBAAKBgQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5
|
||||
L39WqS9u0hnA+O7MCA/KlrAR4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vA
|
||||
fpOwznoD66DDCnQVpbCjtDYWX+x6imxn8HCYxhMol6ZnTbSsFW6VZjFMjQIDAQAB
|
||||
AoGAVOj2Yvuigi6wJD99AO2fgF64sYCm/BKkX3dFEw0vxTPIh58kiRP554Xt5ges
|
||||
7ZCqL9QpqrChUikO4kJ+nB8Uq2AvaZHbpCEUmbip06IlgdA440o0r0CPo1mgNxGu
|
||||
lhiWRN43Lruzfh9qKPhleg2dvyFGQxy5Gk6KW/t8IS4x4r0CQQD/dceBA+Ndj3Xp
|
||||
ubHfxqNz4GTOxndc/AXAowPGpge2zpgIc7f50t8OHhG6XhsfJ0wyQEEvodDhZPYX
|
||||
kKBnXNHzAkEAyCA76vAwuxqAd3MObhiebniAU3SnPf2u4fdL1EOm92dyFs1JxyyL
|
||||
gu/DsjPjx6tRtn4YAalxCzmAMXFSb1qHfwJBAM3qx3z0gGKbUEWtPHcP7BNsrnWK
|
||||
vw6By7VC8bk/ffpaP2yYspS66Le9fzbFwoDzMVVUO/dELVZyBnhqSRHoXQcCQQCe
|
||||
A2WL8S5o7Vn19rC0GVgu3ZJlUrwiZEVLQdlrticFPXaFrn3Md82ICww3jmURaKHS
|
||||
N+l4lnMda79eSp3OMmq9AkA0p79BvYsLshUJJnvbk76pCjR28PK4dV1gSDUEqQMB
|
||||
qy45ptdwJLqLJCeNoR0JUcDNIRhOCuOPND7pcMtX6hI/
|
||||
-----END RSA PRIVATE KEY-----
|
||||
serviceProviderKeyPassword: password
|
||||
serviceProviderCertificate: |
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDSTCCArKgAwIBAgIBADANBgkqhkiG9w0BAQQFADB8MQswCQYDVQQGEwJhdzEO
|
||||
MAwGA1UECBMFYXJ1YmExDjAMBgNVBAoTBWFydWJhMQ4wDAYDVQQHEwVhcnViYTEO
|
||||
MAwGA1UECxMFYXJ1YmExDjAMBgNVBAMTBWFydWJhMR0wGwYJKoZIhvcNAQkBFg5h
|
||||
cnViYUBhcnViYS5hcjAeFw0xNTExMjAyMjI2MjdaFw0xNjExMTkyMjI2MjdaMHwx
|
||||
CzAJBgNVBAYTAmF3MQ4wDAYDVQQIEwVhcnViYTEOMAwGA1UEChMFYXJ1YmExDjAM
|
||||
BgNVBAcTBWFydWJhMQ4wDAYDVQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmExHTAb
|
||||
BgkqhkiG9w0BCQEWDmFydWJhQGFydWJhLmFyMIGfMA0GCSqGSIb3DQEBAQUAA4GN
|
||||
ADCBiQKBgQDHtC5gUXxBKpEqZTLkNvFwNGnNIkggNOwOQVNbpO0WVHIivig5L39W
|
||||
qS9u0hnA+O7MCA/KlrAR4bXaeVVhwfUPYBKIpaaTWFQR5cTR1UFZJL/OF9vAfpOw
|
||||
znoD66DDCnQVpbCjtDYWX+x6imxn8HCYxhMol6ZnTbSsFW6VZjFMjQIDAQABo4Ha
|
||||
MIHXMB0GA1UdDgQWBBTx0lDzjH/iOBnOSQaSEWQLx1syGDCBpwYDVR0jBIGfMIGc
|
||||
gBTx0lDzjH/iOBnOSQaSEWQLx1syGKGBgKR+MHwxCzAJBgNVBAYTAmF3MQ4wDAYD
|
||||
VQQIEwVhcnViYTEOMAwGA1UEChMFYXJ1YmExDjAMBgNVBAcTBWFydWJhMQ4wDAYD
|
||||
VQQLEwVhcnViYTEOMAwGA1UEAxMFYXJ1YmExHTAbBgkqhkiG9w0BCQEWDmFydWJh
|
||||
QGFydWJhLmFyggEAMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADgYEAYvBJ
|
||||
0HOZbbHClXmGUjGs+GS+xC1FO/am2suCSYqNB9dyMXfOWiJ1+TLJk+o/YZt8vuxC
|
||||
KdcZYgl4l/L6PxJ982SRhc83ZW2dkAZI4M0/Ud3oePe84k8jm3A7EvH5wi5hvCkK
|
||||
RpuRBwn3Ei+jCRouxTbzKPsuCVB+1sNyxMTXzf0=
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
#The secret that an external login server will use to authenticate to the uaa using the id `login`
|
||||
LOGIN_SECRET: loginsecret
|
||||
|
||||
jwt:
|
||||
token:
|
||||
signing-key: |
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
MIIEpAIBAAKCAQEAqUeygEfDGxI6c1VDQ6xIyUSLrP6iz1y97iHFbtXSxXaArL4a
|
||||
...
|
||||
v6Mtt5LcRAAVP7pemunTdju4h8Q/noKYlVDVL30uLYUfKBL4UKfOBw==
|
||||
-----END RSA PRIVATE KEY-----
|
||||
verification-key: |
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqUeygEfDGxI6c1VDQ6xI
|
||||
...
|
||||
AwIDAQAB
|
||||
-----END PUBLIC KEY-----
|
|
@ -0,0 +1,43 @@
|
|||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.example</groupId>
|
||||
<artifactId>cf-uaa-oauth2-client</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>uaa-client-webapp</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-oauth2-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.cfuaa.oauth2.client;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CFUAAOAuth2ClientApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CFUAAOAuth2ClientApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package com.baeldung.cfuaa.oauth2.client;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClient;
|
||||
import org.springframework.security.oauth2.client.OAuth2AuthorizedClientService;
|
||||
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
|
||||
import org.springframework.security.oauth2.core.OAuth2AccessToken;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
@RestController
|
||||
public class CFUAAOAuth2ClientController {
|
||||
|
||||
@Value("${resource.server.url}")
|
||||
private String remoteResourceServer;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
private OAuth2AuthorizedClientService authorizedClientService;
|
||||
|
||||
public CFUAAOAuth2ClientController(OAuth2AuthorizedClientService authorizedClientService) {
|
||||
this.authorizedClientService = authorizedClientService;
|
||||
this.restTemplate = new RestTemplate();
|
||||
}
|
||||
|
||||
@RequestMapping("/")
|
||||
public String index(OAuth2AuthenticationToken authenticationToken) {
|
||||
OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName());
|
||||
OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken();
|
||||
|
||||
String response = "Hello, " + authenticationToken.getPrincipal().getName();
|
||||
response += "</br></br>";
|
||||
response += "Here is your accees token :</br>" + oAuth2AccessToken.getTokenValue();
|
||||
response += "</br>";
|
||||
response += "</br>You can use it to call these Resource Server APIs:";
|
||||
response += "</br></br>";
|
||||
response += "<a href='/read'>Call Resource Server Read API</a>";
|
||||
response += "</br>";
|
||||
response += "<a href='/write'>Call Resource Server Write API</a>";
|
||||
return response;
|
||||
}
|
||||
|
||||
@RequestMapping("/read")
|
||||
public String read(OAuth2AuthenticationToken authenticationToken) {
|
||||
String url = remoteResourceServer + "/read";
|
||||
return callResourceServer(authenticationToken, url);
|
||||
}
|
||||
|
||||
@RequestMapping("/write")
|
||||
public String write(OAuth2AuthenticationToken authenticationToken) {
|
||||
String url = remoteResourceServer + "/write";
|
||||
return callResourceServer(authenticationToken, url);
|
||||
}
|
||||
|
||||
private String callResourceServer(OAuth2AuthenticationToken authenticationToken, String url) {
|
||||
OAuth2AuthorizedClient oAuth2AuthorizedClient = this.authorizedClientService.loadAuthorizedClient(authenticationToken.getAuthorizedClientRegistrationId(), authenticationToken.getName());
|
||||
OAuth2AccessToken oAuth2AccessToken = oAuth2AuthorizedClient.getAccessToken();
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("Authorization", "Bearer " + oAuth2AccessToken.getTokenValue());
|
||||
|
||||
HttpEntity<String> entity = new HttpEntity<>("parameters", headers);
|
||||
ResponseEntity<String> responseEntity = null;
|
||||
|
||||
String response = null;
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
||||
response = responseEntity.getBody();
|
||||
} catch (HttpClientErrorException e) {
|
||||
response = e.getMessage();
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
# SECURITY OAUTH2 CLIENT (OAuth2ClientProperties)
|
||||
#spring.security.oauth2.client.provider.*= # OAuth provider details.
|
||||
#spring.security.oauth2.client.registration.*= # OAuth client registrations.
|
||||
|
||||
server.port=8081
|
||||
#server.servlet.context-path=/uaa-client-webapp
|
||||
|
||||
uaa.url=http://localhost:8080/uaa
|
||||
resource.server.url=http://localhost:8082
|
||||
|
||||
spring.security.oauth2.client.registration.uaa.client-name=UAA OAuth2 Client
|
||||
spring.security.oauth2.client.registration.uaa.client-id=client1
|
||||
spring.security.oauth2.client.registration.uaa.client-secret=client1
|
||||
spring.security.oauth2.client.registration.uaa.authorization-grant-type=authorization_code
|
||||
spring.security.oauth2.client.registration.uaa.scope=resource.read,resource.write,openid,profile
|
||||
spring.security.oauth2.client.registration.uaa.redirect-uri=http://localhost:8081/login/oauth2/code/uaa
|
||||
#spring.security.oauth2.client.registration.uaa.redirect-uri=http://localhost:8081/**
|
||||
|
||||
spring.security.oauth2.client.provider.uaa.token-uri=${uaa.url}/oauth/token
|
||||
spring.security.oauth2.client.provider.uaa.authorization-uri=${uaa.url}/oauth/authorize
|
||||
spring.security.oauth2.client.provider.uaa.jwk-set-uri=${uaa.url}/token_keys
|
||||
spring.security.oauth2.client.provider.uaa.user-info-uri=${uaa.url}/userinfo
|
||||
spring.security.oauth2.client.provider.uaa.user-name-attribute=user_name
|
|
@ -0,0 +1 @@
|
|||
tintin
|
|
@ -0,0 +1,43 @@
|
|||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.3.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<groupId>com.baeldung.cfuaa</groupId>
|
||||
<artifactId>cf-uaa-oauth2-resource-server</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>cf-uaa-oauth2-resource-server</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.cfuaa.oauth2.resourceserver;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class CFUAAOAuth2ResourceServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CFUAAOAuth2ResourceServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.cfuaa.oauth2.resourceserver;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@RestController
|
||||
public class CFUAAOAuth2ResourceServerRestController {
|
||||
|
||||
@GetMapping("/")
|
||||
public String index(@AuthenticationPrincipal Jwt jwt) {
|
||||
return String.format("Hello, %s!", jwt.getSubject());
|
||||
}
|
||||
|
||||
@GetMapping("/read")
|
||||
public String read(JwtAuthenticationToken jwtAuthenticationToken) {
|
||||
return "Hello write: " + jwtAuthenticationToken.getTokenAttributes();
|
||||
}
|
||||
|
||||
@GetMapping("/write")
|
||||
public String write(Principal principal) {
|
||||
return "Hello write: " + principal.getName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.baeldung.cfuaa.oauth2.resourceserver;
|
||||
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@EnableWebSecurity
|
||||
public class CFUAAOAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http
|
||||
.authorizeRequests()
|
||||
.antMatchers("/read/**").hasAuthority("SCOPE_resource.read")
|
||||
.antMatchers("/write/**").hasAuthority("SCOPE_resource.write")
|
||||
.anyRequest().authenticated()
|
||||
.and()
|
||||
.oauth2ResourceServer()
|
||||
.jwt();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
server.port=8082
|
||||
|
||||
uaa.url=http://localhost:8080/uaa
|
||||
|
||||
#approch1
|
||||
spring.security.oauth2.resourceserver.jwt.issuer-uri=${uaa.url}/oauth/token
|
||||
|
||||
#approch2
|
||||
#spring.security.oauth2.resourceserver.jwt.jwk-set-uri=${uaa.url}/token_key
|
||||
|
||||
# SECURITY OAUTH2 CLIENT (OAuth2ClientProperties)
|
||||
#security.oauth2.client.client-id=client1
|
||||
#security.oauth2.client.client-secret=client1
|
||||
|
||||
#security.oauth2.resource.jwt.key-uri=${uaa.url}/token_key
|
||||
#security.oauth2.resource.token-info-uri=${uaa.url}/oauth/check_token
|
|
@ -4,3 +4,7 @@
|
|||
|
||||
- [JDBC with Groovy](http://www.baeldung.com/jdbc-groovy)
|
||||
- [Working with JSON in Groovy](http://www.baeldung.com/groovy-json)
|
||||
- [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read)
|
||||
- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings)
|
||||
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
|
||||
- [An Introduction to Traits in Groovy](https://www.baeldung.com/groovy-traits)
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.io
|
||||
|
||||
class Task implements Serializable {
|
||||
String description
|
||||
Date startDate
|
||||
Date dueDate
|
||||
int status
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
|
@ -0,0 +1,4 @@
|
|||
First line of text
|
||||
Second line of text
|
||||
Third line of text
|
||||
Fourth line of text
|
|
@ -0,0 +1,3 @@
|
|||
Line one of output example
|
||||
Line two of output example
|
||||
Line three of output example
|
Binary file not shown.
|
@ -0,0 +1,51 @@
|
|||
package com.baeldung.io
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
class DataAndObjectsUnitTest {
|
||||
@Test
|
||||
void whenUsingWithDataOutputStream_thenDataIsSerializedToAFile() {
|
||||
String message = 'This is a serialized string'
|
||||
int length = message.length()
|
||||
boolean valid = true
|
||||
new File('src/main/resources/ioData.txt').withDataOutputStream { out ->
|
||||
out.writeUTF(message)
|
||||
out.writeInt(length)
|
||||
out.writeBoolean(valid)
|
||||
}
|
||||
|
||||
String loadedMessage = ""
|
||||
int loadedLength
|
||||
boolean loadedValid
|
||||
|
||||
new File('src/main/resources/ioData.txt').withDataInputStream { is ->
|
||||
loadedMessage = is.readUTF()
|
||||
loadedLength = is.readInt()
|
||||
loadedValid = is.readBoolean()
|
||||
}
|
||||
|
||||
assertEquals(message, loadedMessage)
|
||||
assertEquals(length, loadedLength)
|
||||
assertEquals(valid, loadedValid)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingWithObjectOutputStream_thenObjectIsSerializedToFile() {
|
||||
Task task = new Task(description:'Take out the trash', startDate:new Date(), status:0)
|
||||
new File('src/main/resources/ioSerializedObject.txt').withObjectOutputStream { out ->
|
||||
out.writeObject(task)
|
||||
}
|
||||
|
||||
Task taskRead
|
||||
|
||||
new File('src/main/resources/ioSerializedObject.txt').withObjectInputStream { is ->
|
||||
taskRead = is.readObject()
|
||||
}
|
||||
|
||||
assertEquals(task.description, taskRead.description)
|
||||
assertEquals(task.startDate, taskRead.startDate)
|
||||
assertEquals(task.status, taskRead.status)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
package com.baeldung.io
|
||||
|
||||
import static org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ReadExampleUnitTest {
|
||||
|
||||
@Test
|
||||
void whenUsingEachLine_thenCorrectLinesReturned() {
|
||||
def expectedList = [
|
||||
'First line of text',
|
||||
'Second line of text',
|
||||
'Third line of text',
|
||||
'Fourth line of text']
|
||||
|
||||
def lines = []
|
||||
|
||||
new File('src/main/resources/ioInput.txt').eachLine { line ->
|
||||
lines.add(line)
|
||||
}
|
||||
assertEquals(expectedList, lines)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingReadEachLineWithLineNumber_thenCorrectLinesReturned() {
|
||||
def expectedList = [
|
||||
'Second line of text',
|
||||
'Third line of text',
|
||||
'Fourth line of text']
|
||||
|
||||
def lineNoRange = 2..4
|
||||
def lines = []
|
||||
|
||||
new File('src/main/resources/ioInput.txt').eachLine { line, lineNo ->
|
||||
if (lineNoRange.contains(lineNo)) {
|
||||
lines.add(line)
|
||||
}
|
||||
}
|
||||
assertEquals(expectedList, lines)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingReadEachLineWithLineNumberStartAtZero_thenCorrectLinesReturned() {
|
||||
def expectedList = [
|
||||
'Second line of text',
|
||||
'Third line of text',
|
||||
'Fourth line of text']
|
||||
|
||||
def lineNoRange = 1..3
|
||||
def lines = []
|
||||
|
||||
new File('src/main/resources/ioInput.txt').eachLine(0, { line, lineNo ->
|
||||
if (lineNoRange.contains(lineNo)) {
|
||||
lines.add(line)
|
||||
}
|
||||
})
|
||||
assertEquals(expectedList, lines)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingWithReader_thenLineCountReturned() {
|
||||
def expectedCount = 4
|
||||
def actualCount = 0
|
||||
new File('src/main/resources/ioInput.txt').withReader { reader ->
|
||||
while(reader.readLine()) {
|
||||
actualCount++
|
||||
}
|
||||
}
|
||||
assertEquals(expectedCount, actualCount)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingNewReader_thenOutputFileCreated() {
|
||||
def outputPath = 'src/main/resources/ioOut.txt'
|
||||
def reader = new File('src/main/resources/ioInput.txt').newReader()
|
||||
new File(outputPath).append(reader)
|
||||
reader.close()
|
||||
def ioOut = new File(outputPath)
|
||||
assertTrue(ioOut.exists())
|
||||
ioOut.delete()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingWithInputStream_thenCorrectBytesAreReturned() {
|
||||
def expectedLength = 1139
|
||||
byte[] data = []
|
||||
new File("src/main/resources/binaryExample.jpg").withInputStream { stream ->
|
||||
data = stream.getBytes()
|
||||
}
|
||||
assertEquals(expectedLength, data.length)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingNewInputStream_thenOutputFileCreated() {
|
||||
def outputPath = 'src/main/resources/binaryOut.jpg'
|
||||
def is = new File('src/main/resources/binaryExample.jpg').newInputStream()
|
||||
new File(outputPath).append(is)
|
||||
is.close()
|
||||
def ioOut = new File(outputPath)
|
||||
assertTrue(ioOut.exists())
|
||||
ioOut.delete()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingCollect_thenCorrectListIsReturned() {
|
||||
def expectedList = ['First line of text', 'Second line of text', 'Third line of text', 'Fourth line of text']
|
||||
|
||||
def actualList = new File('src/main/resources/ioInput.txt').collect {it}
|
||||
assertEquals(expectedList, actualList)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingAsStringArray_thenCorrectArrayIsReturned() {
|
||||
String[] expectedArray = ['First line of text', 'Second line of text', 'Third line of text', 'Fourth line of text']
|
||||
|
||||
def actualArray = new File('src/main/resources/ioInput.txt') as String[]
|
||||
assertArrayEquals(expectedArray, actualArray)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingText_thenCorrectStringIsReturned() {
|
||||
def ln = System.getProperty('line.separator')
|
||||
def expectedString = "First line of text${ln}Second line of text${ln}Third line of text${ln}Fourth line of text"
|
||||
def actualString = new File('src/main/resources/ioInput.txt').text
|
||||
assertEquals(expectedString.toString(), actualString)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingBytes_thenByteArrayIsReturned() {
|
||||
def expectedLength = 1139
|
||||
def contents = new File('src/main/resources/binaryExample.jpg').bytes
|
||||
assertEquals(expectedLength, contents.length)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package com.baeldung.io
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import groovy.io.FileType
|
||||
import groovy.io.FileVisitResult
|
||||
|
||||
class TraverseFileTreeUnitTest {
|
||||
@Test
|
||||
void whenUsingEachFile_filesAreListed() {
|
||||
new File('src/main/resources').eachFile { file ->
|
||||
println file.name
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException)
|
||||
void whenUsingEachFileOnAFile_anErrorOccurs() {
|
||||
new File('src/main/resources/ioInput.txt').eachFile { file ->
|
||||
println file.name
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachFileMatch_filesAreListed() {
|
||||
new File('src/main/resources').eachFileMatch(~/io.*\.txt/) { file ->
|
||||
println file.name
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachFileRecurse_thenFilesInSubfoldersAreListed() {
|
||||
new File('src/main').eachFileRecurse(FileType.FILES) { file ->
|
||||
println "$file.parent $file.name"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachFileRecurse_thenDirsInSubfoldersAreListed() {
|
||||
new File('src/main').eachFileRecurse(FileType.DIRECTORIES) { file ->
|
||||
println "$file.parent $file.name"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingEachDirRecurse_thenDirsAndSubDirsAreListed() {
|
||||
new File('src/main').eachDirRecurse { dir ->
|
||||
println "$dir.parent $dir.name"
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingTraverse_thenDirectoryIsTraversed() {
|
||||
new File('src/main').traverse { file ->
|
||||
if (file.directory && file.name == 'groovy') {
|
||||
FileVisitResult.SKIP_SUBTREE
|
||||
} else {
|
||||
println "$file.parent - $file.name"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,96 @@
|
|||
package com.baeldung.io
|
||||
|
||||
import static org.junit.Assert.*
|
||||
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
class WriteExampleUnitTest {
|
||||
@Before
|
||||
void clearOutputFile() {
|
||||
new File('src/main/resources/ioOutput.txt').text = ''
|
||||
new File('src/main/resources/ioBinaryOutput.bin').delete()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingWithWriter_thenFileCreated() {
|
||||
def outputLines = [
|
||||
'Line one of output example',
|
||||
'Line two of output example',
|
||||
'Line three of output example'
|
||||
]
|
||||
|
||||
def outputFileName = 'src/main/resources/ioOutput.txt'
|
||||
new File(outputFileName).withWriter { writer ->
|
||||
outputLines.each { line ->
|
||||
writer.writeLine line
|
||||
}
|
||||
}
|
||||
def writtenLines = new File(outputFileName).collect {it}
|
||||
assertEquals(outputLines, writtenLines)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingNewWriter_thenFileCreated() {
|
||||
def outputLines = [
|
||||
'Line one of output example',
|
||||
'Line two of output example',
|
||||
'Line three of output example'
|
||||
]
|
||||
|
||||
def outputFileName = 'src/main/resources/ioOutput.txt'
|
||||
def writer = new File(outputFileName).newWriter()
|
||||
outputLines.forEach {line ->
|
||||
writer.writeLine line
|
||||
}
|
||||
writer.flush()
|
||||
writer.close()
|
||||
|
||||
def writtenLines = new File(outputFileName).collect {it}
|
||||
assertEquals(outputLines, writtenLines)
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingDoubleLessThanOperator_thenFileCreated() {
|
||||
def outputLines = [
|
||||
'Line one of output example',
|
||||
'Line two of output example',
|
||||
'Line three of output example'
|
||||
]
|
||||
|
||||
def ln = System.getProperty('line.separator')
|
||||
def outputFileName = 'src/main/resources/ioOutput.txt'
|
||||
new File(outputFileName) << "Line one of output example${ln}Line two of output example${ln}Line three of output example"
|
||||
def writtenLines = new File(outputFileName).collect {it}
|
||||
assertEquals(outputLines.size(), writtenLines.size())
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingBytes_thenBinaryFileCreated() {
|
||||
def outputFileName = 'src/main/resources/ioBinaryOutput.bin'
|
||||
def outputFile = new File(outputFileName)
|
||||
byte[] outBytes = [44, 88, 22]
|
||||
outputFile.bytes = outBytes
|
||||
assertEquals(3, new File(outputFileName).size())
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingWithOutputStream_thenBinaryFileCreated() {
|
||||
def outputFileName = 'src/main/resources/ioBinaryOutput.bin'
|
||||
byte[] outBytes = [44, 88, 22]
|
||||
new File(outputFileName).withOutputStream { stream ->
|
||||
stream.write(outBytes)
|
||||
}
|
||||
assertEquals(3, new File(outputFileName).size())
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUsingNewOutputStream_thenBinaryFileCreated() {
|
||||
def outputFileName = 'src/main/resources/ioBinaryOutput.bin'
|
||||
byte[] outBytes = [44, 88, 22]
|
||||
def os = new File(outputFileName).newOutputStream()
|
||||
os.write(outBytes)
|
||||
os.close()
|
||||
assertEquals(3, new File(outputFileName).size())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
package com.baeldung.groovy.lists
|
||||
|
||||
import static groovy.test.GroovyAssert.*
|
||||
import org.junit.Test
|
||||
|
||||
class ListTest{
|
||||
|
||||
@Test
|
||||
void testCreateList() {
|
||||
|
||||
def list = [1, 2, 3]
|
||||
assertNotNull(list)
|
||||
|
||||
def listMix = ['A', "b", 1, true]
|
||||
assertTrue(listMix == ['A', "b", 1, true])
|
||||
|
||||
def linkedList = [1, 2, 3] as LinkedList
|
||||
assertTrue(linkedList instanceof LinkedList)
|
||||
|
||||
ArrayList arrList = [1, 2, 3]
|
||||
assertTrue(arrList.class == ArrayList)
|
||||
|
||||
def copyList = new ArrayList(arrList)
|
||||
assertTrue(copyList == arrList)
|
||||
|
||||
def cloneList = arrList.clone()
|
||||
assertTrue(cloneList == arrList)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCreateEmptyList() {
|
||||
|
||||
def emptyList = []
|
||||
assertTrue(emptyList.size() == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCompareTwoLists() {
|
||||
|
||||
def list1 = [5, 6.0, 'p']
|
||||
def list2 = [5, 6.0, 'p']
|
||||
assertTrue(list1 == list2)
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetItemsFromList(){
|
||||
|
||||
def list = ["Hello", "World"]
|
||||
|
||||
assertTrue(list.get(1) == "World")
|
||||
assertTrue(list[1] == "World")
|
||||
assertTrue(list[-1] == "World")
|
||||
assertTrue(list.getAt(1) == "World")
|
||||
assertTrue(list.getAt(-2) == "Hello")
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddItemsToList() {
|
||||
|
||||
def list = []
|
||||
|
||||
list << 1
|
||||
list.add("Apple")
|
||||
assertTrue(list == [1, "Apple"])
|
||||
|
||||
list[2] = "Box"
|
||||
list[4] = true
|
||||
assertTrue(list == [1, "Apple", "Box", null, true])
|
||||
|
||||
list.add(1, 6.0)
|
||||
assertTrue(list == [1, 6.0, "Apple", "Box", null, true])
|
||||
|
||||
def list2 = [1, 2]
|
||||
list += list2
|
||||
list += 12
|
||||
assertTrue(list == [1, 6.0, "Apple", "Box", null, true, 1, 2, 12])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUpdateItemsInList() {
|
||||
|
||||
def list =[1, "Apple", 80, "App"]
|
||||
list[1] = "Box"
|
||||
list.set(2,90)
|
||||
assertTrue(list == [1, "Box", 90, "App"])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoveItemsFromList(){
|
||||
|
||||
def list = [1, 2, 3, 4, 5, 5, 6, 6, 7]
|
||||
|
||||
list.remove(3)
|
||||
assertTrue(list == [1, 2, 3, 5, 5, 6, 6, 7])
|
||||
|
||||
list.removeElement(5)
|
||||
assertTrue(list == [1, 2, 3, 5, 6, 6, 7])
|
||||
|
||||
assertTrue(list - 6 == [1, 2, 3, 5, 7])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIteratingOnAList(){
|
||||
|
||||
def list = [1, "App", 3, 4]
|
||||
list.each{ println it * 2}
|
||||
|
||||
list.eachWithIndex{ it, i -> println "$i : $it" }
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCollectingToAnotherList(){
|
||||
|
||||
def list = ["Kay", "Henry", "Justin", "Tom"]
|
||||
assertTrue(list.collect{"Hi " + it} == ["Hi Kay", "Hi Henry", "Hi Justin", "Hi Tom"])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testJoinItemsInAList(){
|
||||
assertTrue(["One", "Two", "Three"].join(",") == "One,Two,Three")
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFilteringOnLists(){
|
||||
def filterList = [2, 1, 3, 4, 5, 6, 76]
|
||||
|
||||
assertTrue(filterList.find{it > 3} == 4)
|
||||
|
||||
assertTrue(filterList.findAll{it > 3} == [4, 5, 6, 76])
|
||||
|
||||
assertTrue(filterList.findAll{ it instanceof Number} == [2, 1, 3, 4, 5, 6, 76])
|
||||
|
||||
assertTrue(filterList.grep( Number )== [2, 1, 3, 4, 5, 6, 76])
|
||||
|
||||
assertTrue(filterList.grep{ it> 6 }== [76])
|
||||
|
||||
def conditionList = [2, 1, 3, 4, 5, 6, 76]
|
||||
|
||||
assertFalse(conditionList.every{ it < 6})
|
||||
|
||||
assertTrue(conditionList.any{ it%2 == 0})
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetUniqueItemsInAList(){
|
||||
assertTrue([1, 3, 3, 4].toUnique() == [1, 3, 4])
|
||||
|
||||
def uniqueList = [1, 3, 3, 4]
|
||||
uniqueList.unique()
|
||||
assertTrue(uniqueList == [1, 3, 4])
|
||||
|
||||
assertTrue(["A", "B", "Ba", "Bat", "Cat"].toUnique{ it.size()} == ["A", "Ba", "Bat"])
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSorting(){
|
||||
|
||||
assertTrue([1, 2, 1, 0].sort() == [0, 1, 1, 2])
|
||||
Comparator mc = {a,b -> a == b? 0: a < b? 1 : -1}
|
||||
|
||||
def list = [1, 2, 1, 0]
|
||||
list.sort(mc)
|
||||
assertTrue(list == [2, 1, 1, 0])
|
||||
|
||||
def strList = ["na", "ppp", "as"]
|
||||
assertTrue(strList.max() == "ppp")
|
||||
|
||||
Comparator minc = {a,b -> a == b? 0: a < b? -1 : 1}
|
||||
def numberList = [3, 2, 0, 7]
|
||||
assertTrue(numberList.min(minc) == 0)
|
||||
}
|
||||
}
|
|
@ -4,9 +4,9 @@
|
|||
|
||||
### Relevant Articles:
|
||||
- [Java 8 Collectors](http://www.baeldung.com/java-8-collectors)
|
||||
- [Guide to Java 8’s Functional Interfaces](http://www.baeldung.com/java-8-functional-interfaces)
|
||||
- [Functional Interfaces in Java 8](http://www.baeldung.com/java-8-functional-interfaces)
|
||||
- [Java 8 – Powerful Comparison with Lambdas](http://www.baeldung.com/java-8-sort-lambda)
|
||||
- [Java 8 New Features](http://www.baeldung.com/java-8-new-features)
|
||||
- [New Features in Java 8](http://www.baeldung.com/java-8-new-features)
|
||||
- [Lambda Expressions and Functional Interfaces: Tips and Best Practices](http://www.baeldung.com/java-8-lambda-expressions-tips)
|
||||
- [The Double Colon Operator in Java 8](http://www.baeldung.com/java-8-double-colon-operator)
|
||||
- [Guide to Java 8 groupingBy Collector](http://www.baeldung.com/java-groupingby-collector)
|
||||
|
@ -38,3 +38,5 @@
|
|||
- [Java @SafeVarargs Annotation](https://www.baeldung.com/java-safevarargs)
|
||||
- [Java @Deprecated Annotation](https://www.baeldung.com/java-deprecated)
|
||||
- [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain)
|
||||
- [Method References in Java](https://www.baeldung.com/java-method-references)
|
||||
- [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
- [Java 9 Reactive Streams](http://www.baeldung.com/java-9-reactive-streams)
|
||||
- [Java 9 java.util.Objects Additions](http://www.baeldung.com/java-9-objects-new)
|
||||
- [Java 9 Variable Handles Demistyfied](http://www.baeldung.com/java-variable-handles)
|
||||
- [Exploring the New HTTP Client in Java 9](http://www.baeldung.com/java-9-http-client)
|
||||
- [Exploring the New HTTP Client in Java 9 and 11](http://www.baeldung.com/java-9-http-client)
|
||||
- [Method Handles in Java](http://www.baeldung.com/java-method-handles)
|
||||
- [Introduction to Chronicle Queue](http://www.baeldung.com/java-chronicle-queue)
|
||||
- [A Guide to Java 9 Modularity](http://www.baeldung.com/java-9-modularity)
|
||||
|
@ -27,3 +27,5 @@
|
|||
- [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api)
|
||||
- [Guide to java.lang.Process API](https://www.baeldung.com/java-process-api)
|
||||
- [Immutable Set in Java](https://www.baeldung.com/java-immutable-set)
|
||||
- [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar)
|
||||
- [Ahead of Time Compilation (AoT)](https://www.baeldung.com/ahead-of-time-compilation)
|
||||
|
|
|
@ -0,0 +1,182 @@
|
|||
package com.baeldung.processbuilder;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.ProcessBuilder.Redirect;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
public class ProcessBuilderUnitTest {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder tempFolder = new TemporaryFolder();
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenInvokeStart_thenSuccess() throws IOException, InterruptedException, ExecutionException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-version");
|
||||
processBuilder.redirectErrorStream(true);
|
||||
|
||||
Process process = processBuilder.start();
|
||||
|
||||
List<String> results = readOutput(process.getInputStream());
|
||||
assertThat("Results should not be empty", results, is(not(empty())));
|
||||
assertThat("Results should contain java version: ", results, hasItem(containsString("java version")));
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenModifyEnvironment_thenSuccess() throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder();
|
||||
Map<String, String> environment = processBuilder.environment();
|
||||
environment.forEach((key, value) -> System.out.println(key + value));
|
||||
|
||||
environment.put("GREETING", "Hola Mundo");
|
||||
|
||||
List<String> command = getGreetingCommand();
|
||||
processBuilder.command(command);
|
||||
Process process = processBuilder.start();
|
||||
|
||||
List<String> results = readOutput(process.getInputStream());
|
||||
assertThat("Results should not be empty", results, is(not(empty())));
|
||||
assertThat("Results should contain a greeting ", results, hasItem(containsString("Hola Mundo")));
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenModifyWorkingDir_thenSuccess() throws IOException, InterruptedException {
|
||||
List<String> command = getDirectoryListingCommand();
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
|
||||
processBuilder.directory(new File("src"));
|
||||
Process process = processBuilder.start();
|
||||
|
||||
List<String> results = readOutput(process.getInputStream());
|
||||
assertThat("Results should not be empty", results, is(not(empty())));
|
||||
assertThat("Results should contain directory listing: ", results, hasItems(containsString("main"), containsString("test")));
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessWriting() throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-version");
|
||||
|
||||
processBuilder.redirectErrorStream(true);
|
||||
File log = tempFolder.newFile("java-version.log");
|
||||
processBuilder.redirectOutput(log);
|
||||
|
||||
Process process = processBuilder.start();
|
||||
|
||||
assertEquals("If redirected, should be -1 ", -1, process.getInputStream()
|
||||
.read());
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
|
||||
List<String> lines = Files.lines(log.toPath())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat("Results should not be empty", lines, is(not(empty())));
|
||||
assertThat("Results should contain java version: ", lines, hasItem(containsString("java version")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenRedirectStandardOutput_thenSuccessAppending() throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder("java", "-version");
|
||||
|
||||
File log = tempFolder.newFile("java-version-append.log");
|
||||
processBuilder.redirectErrorStream(true);
|
||||
processBuilder.redirectOutput(Redirect.appendTo(log));
|
||||
|
||||
Process process = processBuilder.start();
|
||||
|
||||
assertEquals("If redirected output, should be -1 ", -1, process.getInputStream()
|
||||
.read());
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
|
||||
List<String> lines = Files.lines(log.toPath())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertThat("Results should not be empty", lines, is(not(empty())));
|
||||
assertThat("Results should contain java version: ", lines, hasItem(containsString("java version")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenStartingPipeline_thenSuccess() throws IOException, InterruptedException {
|
||||
if (!isWindows()) {
|
||||
List<ProcessBuilder> builders = Arrays.asList(
|
||||
new ProcessBuilder("find", "src", "-name", "*.java", "-type", "f"),
|
||||
new ProcessBuilder("wc", "-l"));
|
||||
|
||||
List<Process> processes = ProcessBuilder.startPipeline(builders);
|
||||
Process last = processes.get(processes.size() - 1);
|
||||
|
||||
List<String> output = readOutput(last.getInputStream());
|
||||
assertThat("Results should not be empty", output, is(not(empty())));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessBuilder_whenInheritIO_thenSuccess() throws IOException, InterruptedException {
|
||||
List<String> command = getEchoCommand();
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
||||
|
||||
processBuilder.inheritIO();
|
||||
Process process = processBuilder.start();
|
||||
|
||||
int exitCode = process.waitFor();
|
||||
assertEquals("No errors should be detected", 0, exitCode);
|
||||
}
|
||||
|
||||
private List<String> readOutput(InputStream inputStream) throws IOException {
|
||||
try (BufferedReader output = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
return output.lines()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> getDirectoryListingCommand() {
|
||||
return isWindows() ? Arrays.asList("cmd.exe", "/c", "dir") : Arrays.asList("/bin/sh", "-c", "ls");
|
||||
}
|
||||
|
||||
private List<String> getGreetingCommand() {
|
||||
return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo %GREETING%") : Arrays.asList("/bin/bash", "-c", "echo $GREETING");
|
||||
}
|
||||
|
||||
private List<String> getEchoCommand() {
|
||||
return isWindows() ? Arrays.asList("cmd.exe", "/c", "echo hello") : Arrays.asList("/bin/sh", "-c", "echo hello");
|
||||
}
|
||||
|
||||
private boolean isWindows() {
|
||||
return System.getProperty("os.name")
|
||||
.toLowerCase()
|
||||
.startsWith("windows");
|
||||
}
|
||||
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
### Relevant Articles:
|
||||
- [Immutable ArrayList in Java](http://www.baeldung.com/java-immutable-list)
|
||||
- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist)
|
||||
- [Random List Element](http://www.baeldung.com/java-random-list-element)
|
||||
- [Java – Get Random Item/Element From a List](http://www.baeldung.com/java-random-list-element)
|
||||
- [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list)
|
||||
- [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list)
|
||||
- [How to TDD a List Implementation in Java](http://www.baeldung.com/java-test-driven-list)
|
||||
|
@ -28,3 +28,5 @@
|
|||
- [Intersection of Two Lists in Java](https://www.baeldung.com/java-lists-intersection)
|
||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||
- [Determine If All Elements Are the Same in a Java List](https://www.baeldung.com/java-list-all-equal)
|
||||
- [List of Primitive Integer Values in Java](https://www.baeldung.com/java-list-primitive-int)
|
||||
- [Performance Comparison of Primitive Lists in Java](https://www.baeldung.com/java-list-primitive-performance)
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package com.baeldung.collection.filtering;
|
||||
|
||||
/**
|
||||
* Java 8 Collection Filtering by List of Values base class.
|
||||
*
|
||||
* @author Rodolfo Felipe
|
||||
*/
|
||||
public class Employee {
|
||||
|
||||
private Integer employeeNumber;
|
||||
private String name;
|
||||
private Integer departmentId;
|
||||
|
||||
public Employee(Integer employeeNumber, String name, Integer departmentId) {
|
||||
this.employeeNumber = employeeNumber;
|
||||
this.name = name;
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
public Integer getEmployeeNumber() {
|
||||
return employeeNumber;
|
||||
}
|
||||
|
||||
public void setEmployeeNumber(Integer employeeNumber) {
|
||||
this.employeeNumber = employeeNumber;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Integer getDepartmentId() {
|
||||
return departmentId;
|
||||
}
|
||||
|
||||
public void setDepartmentId(Integer departmentId) {
|
||||
this.departmentId = departmentId;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package com.baeldung.collection.filtering;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Various filtering examples.
|
||||
*
|
||||
* @author Rodolfo Felipe
|
||||
*/
|
||||
public class CollectionFilteringUnitTest {
|
||||
|
||||
private List<Employee> buildEmployeeList() {
|
||||
return Arrays.asList(new Employee(1, "Mike", 1), new Employee(2, "John", 1), new Employee(3, "Mary", 1), new Employee(4, "Joe", 2), new Employee(5, "Nicole", 2), new Employee(6, "Alice", 2), new Employee(7, "Bob", 3), new Employee(8, "Scarlett", 3));
|
||||
}
|
||||
|
||||
private List<String> employeeNameFilter() {
|
||||
return Arrays.asList("Alice", "Mike", "Bob");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingForEachLoop() {
|
||||
List<Employee> filteredList = new ArrayList<>();
|
||||
List<Employee> originalList = buildEmployeeList();
|
||||
List<String> nameFilter = employeeNameFilter();
|
||||
|
||||
for (Employee employee : originalList) {
|
||||
for (String name : nameFilter) {
|
||||
if (employee.getName()
|
||||
.equalsIgnoreCase(name)) {
|
||||
filteredList.add(employee);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertThat(filteredList.size(), Matchers.is(nameFilter.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambda() {
|
||||
List<Employee> filteredList;
|
||||
List<Employee> originalList = buildEmployeeList();
|
||||
List<String> nameFilter = employeeNameFilter();
|
||||
|
||||
filteredList = originalList.stream()
|
||||
.filter(employee -> nameFilter.contains(employee.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assert.assertThat(filteredList.size(), Matchers.is(nameFilter.size()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmployeeList_andNameFilterList_thenObtainFilteredEmployeeList_usingLambdaAndHashSet() {
|
||||
List<Employee> filteredList;
|
||||
List<Employee> originalList = buildEmployeeList();
|
||||
Set<String> nameFilterSet = employeeNameFilter().stream()
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
filteredList = originalList.stream()
|
||||
.filter(employee -> nameFilterSet.contains(employee.getName()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
Assert.assertThat(filteredList.size(), Matchers.is(nameFilterSet.size()));
|
||||
}
|
||||
|
||||
}
|
|
@ -32,3 +32,4 @@
|
|||
- [A Guide to Iterator in Java](http://www.baeldung.com/java-iterator)
|
||||
- [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences)
|
||||
- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector)
|
||||
- [Defining a Char Stack in Java](https://www.baeldung.com/java-char-stack)
|
||||
|
|
|
@ -1,17 +1,21 @@
|
|||
package com.baeldung.performance;
|
||||
|
||||
import org.openjdk.jmh.annotations.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.SingleShotTime)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MILLISECONDS)
|
||||
@Measurement(batchSize = 100000, iterations = 10)
|
||||
@Warmup(batchSize = 100000, iterations = 10)
|
||||
|
@ -19,8 +23,8 @@ public class ArraySortBenchmark {
|
|||
|
||||
@State(Scope.Thread)
|
||||
public static class Initialize {
|
||||
Integer[] numbers = {5, 22, 10, 0};
|
||||
int[] primitives = {5, 22, 10, 0};
|
||||
Integer[] numbers = { -769214442, -1283881723, 1504158300, -1260321086, -1800976432, 1278262737, 1863224321, 1895424914, 2062768552, -1051922993, 751605209, -1500919212, 2094856518, -1014488489, -931226326, -1677121986, -2080561705, 562424208, -1233745158, 41308167 };
|
||||
int[] primitives = { -769214442, -1283881723, 1504158300, -1260321086, -1800976432, 1278262737, 1863224321, 1895424914, 2062768552, -1051922993, 751605209, -1500919212, 2094856518, -1014488489, -931226326, -1677121986, -2080561705, 562424208, -1233745158, 41308167 };
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
## Core Java IO Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java - Reading a Large File Efficiently](http://www.baeldung.com/java-read-lines-large-file)
|
||||
- [How to Read a Large File Efficiently with Java](http://www.baeldung.com/java-read-lines-large-file)
|
||||
- [Java InputStream to String](http://www.baeldung.com/convert-input-stream-to-string)
|
||||
- [Java – Write to File](http://www.baeldung.com/java-write-to-file)
|
||||
- [Java - Convert File to InputStream](http://www.baeldung.com/convert-file-to-input-stream)
|
||||
|
@ -11,7 +11,7 @@
|
|||
- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer)
|
||||
- [Java – Directory Size](http://www.baeldung.com/java-folder-size)
|
||||
- [Differences Between the Java WatchService API and the Apache Commons IO Monitor Library](http://www.baeldung.com/java-watchservice-vs-apache-commons-io-monitor-library)
|
||||
- [Calculate the Size of a File in Java](http://www.baeldung.com/java-file-size)
|
||||
- [File Size in Java](http://www.baeldung.com/java-file-size)
|
||||
- [Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java](http://www.baeldung.com/java-path)
|
||||
- [Using Java MappedByteBuffer](http://www.baeldung.com/java-mapped-byte-buffer)
|
||||
- [Copy a File with Java](http://www.baeldung.com/java-copy-file)
|
||||
|
|
|
@ -22,3 +22,4 @@
|
|||
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition)
|
||||
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
|
||||
- [Java equals() and hashCode() Contracts](https://www.baeldung.com/java-equals-hashcode-contracts)
|
||||
- [Marker Interfaces in Java](https://www.baeldung.com/java-marker-interfaces)
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
## Core Java Lang Syntax Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Java Generics](http://www.baeldung.com/java-generics)
|
||||
- [The Basics of Java Generics](http://www.baeldung.com/java-generics)
|
||||
- [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions)
|
||||
- [Java Double Brace Initialization](http://www.baeldung.com/java-double-brace-initialization)
|
||||
- [Guide to the Diamond Operator in Java](http://www.baeldung.com/java-diamond-operator)
|
||||
- [The Java continue and break Keywords](http://www.baeldung.com/java-continue-and-break)
|
||||
- [A Guide to Java Initialization](http://www.baeldung.com/java-initialization)
|
||||
- [A Guide to Creating Objects in Java](http://www.baeldung.com/java-initialization)
|
||||
- [A Guide to Java Loops](http://www.baeldung.com/java-loops)
|
||||
- [Varargs in Java](http://www.baeldung.com/java-varargs)
|
||||
- [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums)
|
||||
|
|
|
@ -41,3 +41,4 @@
|
|||
- [Java Interfaces](https://www.baeldung.com/java-interfaces)
|
||||
- [Attaching Values to Java Enum](https://www.baeldung.com/java-enum-values)
|
||||
- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope)
|
||||
- [Java Classes and Objects](https://www.baeldung.com/java-classes-objects)
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
- [A Guide to the Java URL](http://www.baeldung.com/java-url)
|
||||
- [Working with Network Interfaces in Java](http://www.baeldung.com/java-network-interfaces)
|
||||
- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets)
|
||||
- [URL Encoding and Decoding in Java](http://www.baeldung.com/java-url-encoding-decoding)
|
||||
- [How to Perform a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
||||
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
|
||||
- [Guide to Java URL Encoding/Decoding](http://www.baeldung.com/java-url-encoding-decoding)
|
||||
- [Do a Simple HTTP Request in Java](http://www.baeldung.com/java-http-request)
|
||||
- [Difference between URL and URI](http://www.baeldung.com/java-url-vs-uri)
|
|
@ -8,5 +8,5 @@
|
|||
- [Encrypting and Decrypting Files in Java](http://www.baeldung.com/java-cipher-input-output-stream)
|
||||
- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
|
||||
- [SSL Handshake Failures](https://www.baeldung.com/java-ssl-handshake-failures)
|
||||
- [SHA-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
|
||||
- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
|
||||
- [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12)
|
||||
|
|
|
@ -50,3 +50,4 @@
|
|||
- [Using Curl in Java](https://www.baeldung.com/java-curl)
|
||||
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
|
||||
- [Java Bitwise Operators](https://www.baeldung.com/java-bitwise-operators)
|
||||
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
## Relevant articles:
|
||||
|
||||
- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type)
|
||||
- [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges)
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
- [A guide to the “when{}” block in Kotlin](http://www.baeldung.com/kotlin-when)
|
||||
- [Comprehensive Guide to Null Safety in Kotlin](http://www.baeldung.com/kotlin-null-safety)
|
||||
- [Kotlin Java Interoperability](http://www.baeldung.com/kotlin-java-interoperability)
|
||||
- [Difference Between “==” and “===” in Kotlin](http://www.baeldung.com/kotlin-equality-operators)
|
||||
- [Difference Between “==” and “===” operators in Kotlin](http://www.baeldung.com/kotlin-equality-operators)
|
||||
- [Generics in Kotlin](http://www.baeldung.com/kotlin-generics)
|
||||
- [Introduction to Kotlin Coroutines](http://www.baeldung.com/kotlin-coroutines)
|
||||
- [Destructuring Declarations in Kotlin](http://www.baeldung.com/kotlin-destructuring-declarations)
|
||||
|
@ -52,3 +52,5 @@
|
|||
- [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes)
|
||||
- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final)
|
||||
- [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach)
|
||||
- [Building DSLs in Kotlin](https://www.baeldung.com/kotlin-dsl)
|
||||
- [Static Methods Behavior in Kotlin](https://www.baeldung.com/kotlin-static-methods)
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package com.baeldung.kotlin.delegates
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock
|
||||
import kotlin.concurrent.withLock
|
||||
|
||||
interface Producer {
|
||||
|
||||
fun produce(): String
|
||||
}
|
||||
|
||||
class ProducerImpl : Producer {
|
||||
|
||||
override fun produce() = "ProducerImpl"
|
||||
}
|
||||
|
||||
class EnhancedProducer(private val delegate: Producer) : Producer by delegate {
|
||||
|
||||
override fun produce() = "${delegate.produce()} and EnhancedProducer"
|
||||
}
|
||||
|
||||
interface MessageService {
|
||||
|
||||
fun processMessage(message: String): String
|
||||
}
|
||||
|
||||
class MessageServiceImpl : MessageService {
|
||||
override fun processMessage(message: String): String {
|
||||
return "MessageServiceImpl: $message"
|
||||
}
|
||||
}
|
||||
|
||||
interface UserService {
|
||||
|
||||
fun processUser(userId: String): String
|
||||
}
|
||||
|
||||
class UserServiceImpl : UserService {
|
||||
|
||||
override fun processUser(userId: String): String {
|
||||
return "UserServiceImpl: $userId"
|
||||
}
|
||||
}
|
||||
|
||||
class CompositeService : UserService by UserServiceImpl(), MessageService by MessageServiceImpl()
|
||||
|
||||
interface Service {
|
||||
|
||||
val seed: Int
|
||||
|
||||
fun serve(action: (Int) -> Unit)
|
||||
}
|
||||
|
||||
class ServiceImpl : Service {
|
||||
|
||||
override val seed = 1
|
||||
|
||||
override fun serve(action: (Int) -> Unit) {
|
||||
action(seed)
|
||||
}
|
||||
}
|
||||
|
||||
class ServiceDecorator : Service by ServiceImpl() {
|
||||
override val seed = 2
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.baeldung.kotlin.delegates
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Test
|
||||
|
||||
class InterfaceDelegationTest {
|
||||
|
||||
@Test
|
||||
fun `when delegated implementation is used then it works as expected`() {
|
||||
val producer = EnhancedProducer(ProducerImpl())
|
||||
assertThat(producer.produce()).isEqualTo("ProducerImpl and EnhancedProducer")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when composite delegation is used then it works as expected`() {
|
||||
val service = CompositeService()
|
||||
assertThat(service.processMessage("message")).isEqualTo("MessageServiceImpl: message")
|
||||
assertThat(service.processUser("user")).isEqualTo("UserServiceImpl: user")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `when decoration is used then delegate knows nothing about it`() {
|
||||
val service = ServiceDecorator()
|
||||
service.serve {
|
||||
assertThat(it).isEqualTo(1)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,99 @@
|
|||
package com.baeldung.lambda
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class SplittingTest {
|
||||
private val evenList = listOf(0, "a", 1, "b", 2, "c");
|
||||
|
||||
private val unevenList = listOf(0, "a", 1, "b", 2, "c", 3);
|
||||
|
||||
private fun verifyList(resultList: List<List<Any>>) {
|
||||
assertEquals("[[0, a], [1, b], [2, c]]", resultList.toString())
|
||||
}
|
||||
|
||||
private fun verifyPartialList(resultList: List<List<Any>>) {
|
||||
assertEquals("[[0, a], [1, b], [2, c], [3]]", resultList.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenChunked_thenListIsSplit() {
|
||||
val resultList = evenList.chunked(2)
|
||||
verifyList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenUnevenChunked_thenListIsSplit() {
|
||||
val resultList = unevenList.chunked(2)
|
||||
verifyPartialList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenWindowed_thenListIsSplit() {
|
||||
val resultList = evenList.windowed(2, 2)
|
||||
verifyList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenUnevenPartialWindowed_thenListIsSplit() {
|
||||
val resultList = unevenList.windowed(2, 2, partialWindows = true)
|
||||
verifyPartialList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenUnevenWindowed_thenListIsSplit() {
|
||||
val resultList = unevenList.windowed(2, 2, partialWindows = false)
|
||||
verifyList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGroupByWithAscendingNumbers_thenListIsSplit() {
|
||||
val numberList = listOf(1, 2, 3, 4, 5, 6);
|
||||
val resultList = numberList.groupBy { (it + 1) / 2 }
|
||||
assertEquals("[[1, 2], [3, 4], [5, 6]]", resultList.values.toString())
|
||||
assertEquals("[1, 2, 3]", resultList.keys.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGroupByWithAscendingNumbersUneven_thenListIsSplit() {
|
||||
val numberList = listOf(1, 2, 3, 4, 5, 6, 7);
|
||||
val resultList = numberList.groupBy { (it + 1) / 2 }.values
|
||||
assertEquals("[[1, 2], [3, 4], [5, 6], [7]]", resultList.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenGroupByWithRandomNumbers_thenListIsSplitInWrongWay() {
|
||||
val numberList = listOf(1, 3, 8, 20, 23, 30);
|
||||
val resultList = numberList.groupBy { (it + 1) / 2 }
|
||||
assertEquals("[[1], [3], [8], [20], [23], [30]]", resultList.values.toString())
|
||||
assertEquals("[1, 2, 4, 10, 12, 15]", resultList.keys.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenWithIndexGroupBy_thenListIsSplit() {
|
||||
val resultList = evenList.withIndex()
|
||||
.groupBy { it.index / 2 }
|
||||
.map { it.value.map { it.value } }
|
||||
verifyList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenWithIndexGroupByUneven_thenListIsSplit() {
|
||||
val resultList = unevenList.withIndex()
|
||||
.groupBy { it.index / 2 }
|
||||
.map { it.value.map { it.value } }
|
||||
verifyPartialList(resultList)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun whenFoldIndexed_thenListIsSplit() {
|
||||
val resultList = evenList.foldIndexed(ArrayList<ArrayList<Any>>(evenList.size / 2)) { index, acc, item ->
|
||||
if (index % 2 == 0) {
|
||||
acc.add(ArrayList(2))
|
||||
}
|
||||
acc.last().add(item)
|
||||
acc
|
||||
}
|
||||
verifyList(resultList)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>guava-modules</artifactId>
|
||||
<name>guava-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>guava-18</module>
|
||||
<module>guava-19</module>
|
||||
<module>guava-21</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -2,3 +2,4 @@
|
|||
|
||||
### Relevant Articles
|
||||
- [Guide to Google Guice](http://www.baeldung.com/guice)
|
||||
- [Guice vs Spring – Dependency Injection](https://www.baeldung.com/guice-spring-dependency-injection)
|
||||
|
|
|
@ -14,11 +14,11 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient)
|
||||
- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl)
|
||||
- [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post)
|
||||
- [HttpClient – Set Custom Header](http://www.baeldung.com/httpclient-custom-http-header)
|
||||
- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header)
|
||||
- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication)
|
||||
- [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload)
|
||||
- [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial)
|
||||
- [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide)
|
||||
- [Advanced HttpClient Configuration](http://www.baeldung.com/httpclient-advanced-config)
|
||||
- [HttpClient 4 – Do Not Follow Redirects](http://www.baeldung.com/httpclient-stop-follow-redirect)
|
||||
- [HttpClient 4 – Setting a Custom User-Agent](http://www.baeldung.com/httpclient-user-agent-header)
|
||||
- [Custom User-Agent in HttpClient 4](http://www.baeldung.com/httpclient-user-agent-header)
|
||||
|
|
|
@ -10,14 +10,14 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Jackson – Unmarshall to Collection/Array](http://www.baeldung.com/jackson-collection-array)
|
||||
- [Jackson Unmarshalling json with Unknown Properties](http://www.baeldung.com/jackson-deserialize-json-unknown-properties)
|
||||
- [Jackson – Custom Serializer](http://www.baeldung.com/jackson-custom-serialization)
|
||||
- [Jackson – Custom Deserializer](http://www.baeldung.com/jackson-deserialization)
|
||||
- [Getting Started with Custom Deserialization in Jackson](http://www.baeldung.com/jackson-deserialization)
|
||||
- [Jackson Exceptions – Problems and Solutions](http://www.baeldung.com/jackson-exception)
|
||||
- [Jackson Date](http://www.baeldung.com/jackson-serialize-dates)
|
||||
- [Jackson – Bidirectional Relationships](http://www.baeldung.com/jackson-bidirectional-relationships-and-infinite-recursion)
|
||||
- [Jackson JSON Tutorial](http://www.baeldung.com/jackson)
|
||||
- [Jackson – Working with Maps and nulls](http://www.baeldung.com/jackson-map-null-values-or-null-key)
|
||||
- [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not)
|
||||
- [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations)
|
||||
- [Jackson Annotation Examples](http://www.baeldung.com/jackson-annotations)
|
||||
- [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model)
|
||||
- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson)
|
||||
- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial)
|
||||
|
@ -25,7 +25,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations)
|
||||
- [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance)
|
||||
- [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat)
|
||||
- [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional)
|
||||
- [Using Optional with Jackson](http://www.baeldung.com/jackson-optional)
|
||||
- [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map)
|
||||
- [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api)
|
||||
- [Jackson – JsonMappingException (No serializer found for class)](http://www.baeldung.com/jackson-jsonmappingexception)
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.javastreams2</groupId>
|
||||
<artifactId>javastreams2</artifactId>
|
||||
<version>1.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>1.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.11.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<name>Stream Reduce</name>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,39 @@
|
|||
package com.baeldung.reduce.application;
|
||||
|
||||
import com.baeldung.reduce.entities.User;
|
||||
import com.baeldung.reduce.utilities.NumberUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
int result1 = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
|
||||
System.out.println(result1);
|
||||
|
||||
int result2 = numbers.stream().reduce(0, Integer::sum);
|
||||
System.out.println(result2);
|
||||
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result3 = letters.stream().reduce("", (partialString, element) -> partialString + element);
|
||||
System.out.println(result3);
|
||||
|
||||
String result4 = letters.stream().reduce("", String::concat);
|
||||
System.out.println(result4);
|
||||
|
||||
String result5 = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
|
||||
System.out.println(result5);
|
||||
|
||||
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||
int result6 = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
System.out.println(result6);
|
||||
|
||||
String result7 = letters.parallelStream().reduce("", String::concat);
|
||||
System.out.println(result7);
|
||||
|
||||
int result8 = users.parallelStream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
System.out.println(result8);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.baeldung.reduce.benchmarks;
|
||||
|
||||
import com.baeldung.reduce.entities.User;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.runner.Runner;
|
||||
import org.openjdk.jmh.runner.RunnerException;
|
||||
import org.openjdk.jmh.runner.options.Options;
|
||||
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||
|
||||
@State(Scope.Thread)
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
public class JMHStreamReduceBenchMark {
|
||||
|
||||
private final List<User> userList = createUsers();
|
||||
|
||||
public static void main(String[] args) throws RunnerException {
|
||||
|
||||
Options options = new OptionsBuilder()
|
||||
.include(JMHStreamReduceBenchMark.class.getSimpleName()).threads(1)
|
||||
.forks(1).shouldFailOnError(true).shouldDoGC(true)
|
||||
.jvmArgs("-server").build();
|
||||
new Runner(options).run();
|
||||
}
|
||||
|
||||
private List<User> createUsers() {
|
||||
List<User> users = new ArrayList<>();
|
||||
for (int i = 0; i <= 1000000; i++) {
|
||||
users.add(new User("John" + i, i));
|
||||
}
|
||||
return users;
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public Integer executeReduceOnParallelizedStream() {
|
||||
return this.userList
|
||||
.parallelStream()
|
||||
.reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public Integer executeReduceOnSequentialStream() {
|
||||
return this.userList
|
||||
.stream()
|
||||
.reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.reduce.entities;
|
||||
|
||||
public class User {
|
||||
|
||||
private final String name;
|
||||
private final int age;
|
||||
|
||||
public User(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{" + "name=" + name + ", age=" + age + '}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.baeldung.reduce.utilities;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.BiFunction;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class NumberUtils {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(NumberUtils.class.getName());
|
||||
|
||||
public static int divideListElements(List<Integer> values, Integer divider) {
|
||||
return values.stream()
|
||||
.reduce(0, (a, b) -> {
|
||||
try {
|
||||
return a / divider + b / divider;
|
||||
} catch (ArithmeticException e) {
|
||||
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||
}
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
public static int divideListElementsWithExtractedTryCatchBlock(List<Integer> values, int divider) {
|
||||
return values.stream().reduce(0, (a, b) -> divide(a, divider) + divide(b, divider));
|
||||
}
|
||||
|
||||
public static int divideListElementsWithApplyFunctionMethod(List<Integer> values, int divider) {
|
||||
BiFunction<Integer, Integer, Integer> division = (a, b) -> a / b;
|
||||
return values.stream().reduce(0, (a, b) -> applyFunction(division, a, divider) + applyFunction(division, b, divider));
|
||||
}
|
||||
|
||||
private static int divide(int value, int factor) {
|
||||
int result = 0;
|
||||
try {
|
||||
result = value / factor;
|
||||
} catch (ArithmeticException e) {
|
||||
LOGGER.log(Level.INFO, "Arithmetic Exception: Division by Zero");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int applyFunction(BiFunction<Integer, Integer, Integer> function, int a, int b) {
|
||||
try {
|
||||
return function.apply(a, b);
|
||||
}
|
||||
catch(Exception e) {
|
||||
LOGGER.log(Level.INFO, "Exception thrown!");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package com.baeldung.reduce.tests;
|
||||
|
||||
import com.baeldung.reduce.entities.User;
|
||||
import com.baeldung.reduce.utilities.NumberUtils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class StreamReduceUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenIntegerList_whenReduceWithSumAccumulatorLambda_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
int result = numbers.stream().reduce(0, (subtotal, element) -> subtotal + element);
|
||||
assertThat(result).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenIntegerList_whenReduceWithSumAccumulatorMethodReference_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
int result = numbers.stream().reduce(0, Integer::sum);
|
||||
assertThat(result).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithConcatenatorAccumulatorLambda_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result = letters.stream().reduce("", (partialString, element) -> partialString + element);
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithConcatenatorAccumulatorMethodReference_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result = letters.stream().reduce("", String::concat);
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithUppercaseConcatenatorAccumulator_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result = letters.stream().reduce("", (partialString, element) -> partialString.toUpperCase() + element.toUpperCase());
|
||||
assertThat(result).isEqualTo("ABCDE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUserList_whenReduceWithAgeAccumulatorAndSumCombiner_thenCorrect() {
|
||||
List<User> users = Arrays.asList(new User("John", 30), new User("Julie", 35));
|
||||
int result = users.stream().reduce(0, (partialAgeResult, user) -> partialAgeResult + user.getAge(), Integer::sum);
|
||||
assertThat(result).isEqualTo(65);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStringList_whenReduceWithParallelStream_thenCorrect() {
|
||||
List<String> letters = Arrays.asList("a", "b", "c", "d", "e");
|
||||
String result = letters.parallelStream().reduce("", String::concat);
|
||||
assertThat(result).isEqualTo("abcde");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElements_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
assertThat(NumberUtils.divideListElements(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNumberUtilsClass_whenCalledDivideListElementsWithExtractedTryCatchBlock_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
assertThat(NumberUtils.divideListElementsWithExtractedTryCatchBlock(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenStream_whneCalleddivideListElementsWithApplyFunctionMethod_thenCorrect() {
|
||||
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
assertThat(NumberUtils.divideListElementsWithApplyFunctionMethod(numbers, 1)).isEqualTo(21);
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@
|
|||
## Java Streams Cookbooks and Examples
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java 8 Streams Advanced](http://www.baeldung.com/java-8-streams)
|
||||
- [The Java 8 Stream API Tutorial](http://www.baeldung.com/java-8-streams)
|
||||
- [Introduction to Java 8 Streams](http://www.baeldung.com/java-8-streams-introduction)
|
||||
- [Java 8 and Infinite Streams](http://www.baeldung.com/java-inifinite-streams)
|
||||
- [Java 8 Stream findFirst() vs. findAny()](http://www.baeldung.com/java-stream-findfirst-vs-findany)
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
- [Check if a String is a Palindrome](http://www.baeldung.com/java-palindrome)
|
||||
- [Comparing Strings in Java](http://www.baeldung.com/java-compare-strings)
|
||||
- [Check If a String Is Numeric in Java](http://www.baeldung.com/java-check-string-number)
|
||||
- [Why Use char[] Array Over a String for Storing Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
||||
- [Use char[] Array Over a String for Manipulating Passwords in Java?](http://www.baeldung.com/java-storing-passwords)
|
||||
- [Convert a String to Title Case](http://www.baeldung.com/java-string-title-case)
|
||||
- [Compact Strings in Java 9](http://www.baeldung.com/java-9-compact-string)
|
||||
- [Java Check a String for Lowercase/Uppercase Letter, Special Character and Digit](https://www.baeldung.com/java-lowercase-uppercase-special-character-digit-regex)
|
||||
|
@ -53,3 +53,4 @@
|
|||
- [Java String Interview Questions and Answers](https://www.baeldung.com/java-string-interview-questions)
|
||||
- [Check if a String is a Pangram in Java](https://www.baeldung.com/java-string-pangram)
|
||||
- [Check If a String Contains Multiple Keywords](https://www.baeldung.com/string-contains-multiple-words)
|
||||
- [Common String Operations in Java](https://www.baeldung.com/java-string-operations)
|
||||
|
|
|
@ -3,3 +3,4 @@
|
|||
- [JHipster with a Microservice Architecture](http://www.baeldung.com/jhipster-microservices)
|
||||
- [Intro to JHipster](http://www.baeldung.com/jhipster)
|
||||
- [Building a Basic UAA-Secured JHipster Microservice](https://www.baeldung.com/jhipster-uaa-secured-micro-service)
|
||||
- [Creating New Roles and Authorities in JHipster](https://www.baeldung.com/jhipster-new-roles)
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
## Relevant articles:
|
||||
|
||||
- [Introduction to Jooby Project](http://www.baeldung.com/jooby)
|
||||
- [Introduction to Jooby](http://www.baeldung.com/jooby)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
### Relevant Articles:
|
||||
- [Introduction to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3)
|
||||
- [Guide to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3)
|
||||
- [Introduction to JSF EL 2](http://www.baeldung.com/intro-to-jsf-expression-language)
|
||||
- [JavaServer Faces (JSF) with Spring](http://www.baeldung.com/spring-jsf)
|
||||
- [Introduction to Primefaces](http://www.baeldung.com/jsf-primefaces)
|
||||
|
|
|
@ -11,3 +11,5 @@
|
|||
- [Overview of JSON Pointer](https://www.baeldung.com/json-pointer)
|
||||
- [Introduction to the JSON Binding API (JSR 367) in Java](http://www.baeldung.com/java-json-binding-api)
|
||||
- [Get a Value by Key in a JSONArray](https://www.baeldung.com/java-jsonarray-get-value-by-key)
|
||||
- [Iterating Over an Instance of org.json.JSONObject](https://www.baeldung.com/jsonobject-iteration)
|
||||
- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections)
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
- [Implementing a FTP-Client in Java](http://www.baeldung.com/java-ftp-client)
|
||||
- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library)
|
||||
- [Intro to Derive4J](https://www.baeldung.com/derive4j)
|
||||
- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library)
|
||||
|
||||
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.
|
||||
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>logging-modules</artifactId>
|
||||
<name>logging-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>log4j</module>
|
||||
<module>log4j2</module>
|
||||
<module>logback</module>
|
||||
<module>log-mdc</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
|
@ -14,3 +14,4 @@
|
|||
- [Apache Maven Tutorial](https://www.baeldung.com/maven)
|
||||
- [Use the Latest Version of a Dependency in Maven](https://www.baeldung.com/maven-dependency-latest-version)
|
||||
- [Multi-Module Project with Maven](https://www.baeldung.com/maven-multi-module)
|
||||
- [Maven Enforcer Plugin](https://www.baeldung.com/maven-enforcer-plugin)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<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>compiler-plugin-java-9</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.0</version>
|
||||
<configuration>
|
||||
<source>9</source>
|
||||
<target>9</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,9 @@
|
|||
package com.baeldung.maven.java9;
|
||||
|
||||
import static javax.xml.XMLConstants.XML_NS_PREFIX;
|
||||
|
||||
public class MavenCompilerPlugin {
|
||||
public static void main(String[] args) {
|
||||
System.out.println("The XML namespace prefix is: " + XML_NS_PREFIX);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module com.baeldung.maven.java9 {
|
||||
requires java.xml;
|
||||
}
|
|
@ -29,10 +29,10 @@
|
|||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<spring.version>5.1.2.RELEASE</spring.version>
|
||||
<spring.version>5.1.4.RELEASE</spring.version>
|
||||
<junit.jupiter.version>5.0.2</junit.jupiter.version>
|
||||
<jackson.version>2.9.6</jackson.version>
|
||||
<spring-security.version>5.1.2.RELEASE</spring-security.version>
|
||||
<spring-security.version>5.1.4.RELEASE</spring-security.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,25 @@
|
|||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>design-patterns-2</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
</properties>
|
||||
</project>
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public class JmsRouter implements Router {
|
||||
|
||||
@Override
|
||||
public void route(Message msg) {
|
||||
System.out.println("Routing to a JMS queue. Msg: " + msg);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public class Message {
|
||||
|
||||
private String body;
|
||||
|
||||
private String priority;
|
||||
|
||||
public Message(String body, String priority) {
|
||||
this.body = body;
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public String getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{body='" + body + '\'' +
|
||||
", priority='" + priority + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public class NullRouter implements Router {
|
||||
|
||||
@Override
|
||||
public void route(Message msg) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public interface Router {
|
||||
|
||||
void route(Message msg);
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public class RouterFactory {
|
||||
|
||||
public static Router getRouterForMessage(Message msg) {
|
||||
|
||||
if (msg.getPriority() == null) {
|
||||
return new NullRouter();
|
||||
}
|
||||
|
||||
switch (msg.getPriority()) {
|
||||
case "high":
|
||||
return new SmsRouter();
|
||||
|
||||
case "medium":
|
||||
return new JmsRouter();
|
||||
|
||||
default:
|
||||
return new NullRouter();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RoutingHandler {
|
||||
|
||||
public void handle(Iterable<Message> messages){
|
||||
for (Message msg : messages) {
|
||||
Router router = RouterFactory.getRouterForMessage(msg);
|
||||
router.route(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Message highPriorityMsg = new Message("Alert!", "high");
|
||||
Message mediumPriorityMsg = new Message("Warning!", "medium");
|
||||
Message lowPriorityMsg = new Message("Take a look!", "low");
|
||||
Message nullPriorityMsg = new Message("Take a look!", null);
|
||||
|
||||
List<Message> messages = Arrays.asList(highPriorityMsg,
|
||||
mediumPriorityMsg,
|
||||
lowPriorityMsg,
|
||||
nullPriorityMsg);
|
||||
|
||||
RoutingHandler routingHandler = new RoutingHandler();
|
||||
routingHandler.handle(messages);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.nullobject;
|
||||
|
||||
public class SmsRouter implements Router {
|
||||
|
||||
@Override
|
||||
public void route(Message msg) {
|
||||
System.out.println("Routing to a SMS gateway. Msg: " + msg);
|
||||
}
|
||||
|
||||
}
|
|
@ -17,6 +17,7 @@
|
|||
<module>front-controller</module>
|
||||
<module>intercepting-filter</module>
|
||||
<module>design-patterns</module>
|
||||
<module>design-patterns-2</module>
|
||||
<module>solid</module>
|
||||
</modules>
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.baeldung.jdbc;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Employee {
|
||||
private int id;
|
||||
private String name;
|
||||
|
@ -48,4 +50,21 @@ public class Employee {
|
|||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, name, position, salary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Employee other = (Employee) obj;
|
||||
return id == other.id && Objects.equals(name, other.name) && Objects.equals(position, other.position) && Double.doubleToLongBits(salary) == Double.doubleToLongBits(other.salary);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,359 @@
|
|||
package com.baeldung.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DatabaseMetaData;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class ResultSetLiveTest {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ResultSetLiveTest.class);
|
||||
|
||||
private final Employee expectedEmployee1 = new Employee(1, "John", 1000.0, "Developer");
|
||||
|
||||
private final Employee updatedEmployee1 = new Employee(1, "John", 1100.0, "Developer");
|
||||
|
||||
private final Employee expectedEmployee2 = new Employee(2, "Chris", 925.0, "DBA");
|
||||
|
||||
private final int rowCount = 2;
|
||||
|
||||
private static Connection dbConnection;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() throws ClassNotFoundException, SQLException {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
dbConnection = DriverManager.getConnection("jdbc:mysql://localhost:3306/myDB?noAccessToProcedureBodies=true", "user1", "pass");
|
||||
String tableSql = "CREATE TABLE IF NOT EXISTS employees (emp_id int PRIMARY KEY AUTO_INCREMENT, name varchar(30), position varchar(30), salary double)";
|
||||
try (Statement stmt = dbConnection.createStatement()) {
|
||||
stmt.execute(tableSql);
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("INSERT INTO employees(name, position, salary) values ('John', 'Developer', 1000.0)")) {
|
||||
pstmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionA_whenRetreiveByColumnNames_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
String name = rs.getString("name");
|
||||
Integer empId = rs.getInt("emp_id");
|
||||
Double salary = rs.getDouble("salary");
|
||||
String position = rs.getString("position");
|
||||
employee = new Employee(empId, name, salary, position);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Employee information retreived by column names.", expectedEmployee1, employee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionB_whenRetreiveByColumnIds_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees"); ResultSet rs = pstmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
Integer empId = rs.getInt(1);
|
||||
String name = rs.getString(2);
|
||||
String position = rs.getString(3);
|
||||
Double salary = rs.getDouble(4);
|
||||
employee = new Employee(empId, name, salary, position);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Employee information retreived by column ids.", expectedEmployee1, employee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionD_whenInsertRow_thenCorrect() throws SQLException {
|
||||
int rowCount = 0;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.moveToInsertRow();
|
||||
rs.updateString("name", "Chris");
|
||||
rs.updateString("position", "DBA");
|
||||
rs.updateDouble("salary", 925.0);
|
||||
rs.insertRow();
|
||||
rs.moveToCurrentRow();
|
||||
rs.last();
|
||||
rowCount = rs.getRow();
|
||||
}
|
||||
|
||||
assertEquals("Row Count after inserting a row", 2, rowCount);
|
||||
}
|
||||
|
||||
private Employee populateResultSet(ResultSet rs) throws SQLException {
|
||||
Employee employee;
|
||||
String name = rs.getString("name");
|
||||
Integer empId = rs.getInt("emp_id");
|
||||
Double salary = rs.getDouble("salary");
|
||||
String position = rs.getString("position");
|
||||
employee = new Employee(empId, name, salary, position);
|
||||
return employee;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionE_whenRowCount_thenCorrect() throws SQLException {
|
||||
int numOfRows = 0;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.last();
|
||||
numOfRows = rs.getRow();
|
||||
}
|
||||
|
||||
assertEquals("Num of rows", rowCount, numOfRows);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionG_whenAbsoluteNavigation_thenCorrect() throws SQLException {
|
||||
Employee secondEmployee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.absolute(2);
|
||||
secondEmployee = populateResultSet(rs);
|
||||
}
|
||||
|
||||
assertEquals("Absolute navigation", expectedEmployee2, secondEmployee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionH_whenLastNavigation_thenCorrect() throws SQLException {
|
||||
Employee secondEmployee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.last();
|
||||
secondEmployee = populateResultSet(rs);
|
||||
}
|
||||
|
||||
assertEquals("Using Last", expectedEmployee2, secondEmployee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionI_whenNavigation_thenCorrect() throws SQLException {
|
||||
Employee firstEmployee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
}
|
||||
rs.beforeFirst();
|
||||
while (rs.next()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
}
|
||||
rs.first();
|
||||
while (rs.next()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
}
|
||||
while (rs.previous()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
}
|
||||
rs.afterLast();
|
||||
while (rs.previous()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
}
|
||||
rs.last();
|
||||
while (rs.previous()) {
|
||||
firstEmployee = populateResultSet(rs);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("Several Navigation Options", updatedEmployee1, firstEmployee);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionJ_whenClosedCursor_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
dbConnection.setHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.CLOSE_CURSORS_AT_COMMIT)) {
|
||||
dbConnection.setAutoCommit(false);
|
||||
ResultSet rs = pstmt.executeQuery("select * from employees");
|
||||
while (rs.next()) {
|
||||
if (rs.getString("name")
|
||||
.equalsIgnoreCase("john")) {
|
||||
rs.updateString("position", "Senior Engineer");
|
||||
rs.updateRow();
|
||||
dbConnection.commit();
|
||||
employee = populateResultSet(rs);
|
||||
}
|
||||
}
|
||||
rs.last();
|
||||
}
|
||||
|
||||
assertEquals("Update using closed cursor", "Senior Engineer", employee.getPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionK_whenUpdate_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
dbConnection.setHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
try (Statement pstmt = dbConnection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE, ResultSet.HOLD_CURSORS_OVER_COMMIT)) {
|
||||
dbConnection.setAutoCommit(false);
|
||||
ResultSet rs = pstmt.executeQuery("select * from employees");
|
||||
while (rs.next()) {
|
||||
if (rs.getString("name")
|
||||
.equalsIgnoreCase("john")) {
|
||||
rs.updateString("name", "John Doe");
|
||||
rs.updateRow();
|
||||
dbConnection.commit();
|
||||
employee = populateResultSet(rs);
|
||||
}
|
||||
}
|
||||
rs.last();
|
||||
}
|
||||
|
||||
assertEquals("Update using open cursor", "John Doe", employee.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionM_whenDelete_thenCorrect() throws SQLException {
|
||||
int numOfRows = 0;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.absolute(2);
|
||||
rs.deleteRow();
|
||||
}
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
rs.last();
|
||||
numOfRows = rs.getRow();
|
||||
}
|
||||
assertEquals("Deleted row", 1, numOfRows);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionC_whenUpdate_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
|
||||
Assert.assertEquals(1100.0, rs.getDouble("salary"));
|
||||
|
||||
rs.updateDouble("salary", 1200.0);
|
||||
rs.updateRow();
|
||||
|
||||
Assert.assertEquals(1200.0, rs.getDouble("salary"));
|
||||
|
||||
String name = rs.getString("name");
|
||||
Integer empId = rs.getInt("emp_id");
|
||||
Double salary = rs.getDouble("salary");
|
||||
String position = rs.getString("position");
|
||||
employee = new Employee(empId, name, salary, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionC_whenUpdateByIndex_thenCorrect() throws SQLException {
|
||||
Employee employee = null;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
while (rs.next()) {
|
||||
|
||||
Assert.assertEquals(1000.0, rs.getDouble(4));
|
||||
|
||||
rs.updateDouble(4, 1100.0);
|
||||
rs.updateRow();
|
||||
Assert.assertEquals(1100.0, rs.getDouble(4));
|
||||
|
||||
String name = rs.getString("name");
|
||||
Integer empId = rs.getInt("emp_id");
|
||||
Double salary = rs.getDouble("salary");
|
||||
String position = rs.getString("position");
|
||||
employee = new Employee(empId, name, salary, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionE_whenDBMetaInfo_thenCorrect() throws SQLException {
|
||||
DatabaseMetaData dbmd = dbConnection.getMetaData();
|
||||
boolean supportsTypeForward = dbmd.supportsResultSetType(ResultSet.TYPE_FORWARD_ONLY);
|
||||
boolean supportsTypeScrollSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_SENSITIVE);
|
||||
boolean supportsTypeScrollInSensitive = dbmd.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE);
|
||||
boolean supportsCloseCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.CLOSE_CURSORS_AT_COMMIT);
|
||||
boolean supportsHoldCursorsAtCommit = dbmd.supportsResultSetHoldability(ResultSet.HOLD_CURSORS_OVER_COMMIT);
|
||||
boolean concurrency4TypeFwdNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
boolean concurrency4TypeFwdNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
|
||||
boolean concurrency4TypeScrollInSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
boolean concurrency4TypeScrollInSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
boolean concurrency4TypeScrollSensitiveNConcurUpdatable = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
boolean concurrency4TypeScrollSensitiveNConcurReadOnly = dbmd.supportsResultSetConcurrency(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
|
||||
int rsHoldability = dbmd.getResultSetHoldability();
|
||||
|
||||
assertEquals("checking scroll sensitivity and concur updates : ", true, concurrency4TypeScrollInSensitiveNConcurUpdatable);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionF_whenRSMetaInfo_thenCorrect() throws SQLException {
|
||||
int columnCount = 0;
|
||||
try (PreparedStatement pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); ResultSet rs = pstmt.executeQuery()) {
|
||||
ResultSetMetaData metaData = rs.getMetaData();
|
||||
columnCount = metaData.getColumnCount();
|
||||
for (int i = 1; i <= columnCount; i++) {
|
||||
String catalogName = metaData.getCatalogName(i);
|
||||
String className = metaData.getColumnClassName(i);
|
||||
String label = metaData.getColumnLabel(i);
|
||||
String name = metaData.getColumnName(i);
|
||||
String typeName = metaData.getColumnTypeName(i);
|
||||
Integer type = metaData.getColumnType(i);
|
||||
String tableName = metaData.getTableName(i);
|
||||
String schemaName = metaData.getSchemaName(i);
|
||||
boolean isAutoIncrement = metaData.isAutoIncrement(i);
|
||||
boolean isCaseSensitive = metaData.isCaseSensitive(i);
|
||||
boolean isCurrency = metaData.isCurrency(i);
|
||||
boolean isDefiniteWritable = metaData.isDefinitelyWritable(i);
|
||||
boolean isReadOnly = metaData.isReadOnly(i);
|
||||
boolean isSearchable = metaData.isSearchable(i);
|
||||
boolean isReadable = metaData.isReadOnly(i);
|
||||
boolean isSigned = metaData.isSigned(i);
|
||||
boolean isWritable = metaData.isWritable(i);
|
||||
int nullable = metaData.isNullable(i);
|
||||
}
|
||||
}
|
||||
|
||||
assertEquals("column count", 4, columnCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDbConnectionL_whenFetch_thenCorrect() throws SQLException {
|
||||
PreparedStatement pstmt = null;
|
||||
ResultSet rs = null;
|
||||
List<Employee> listOfEmployees = new ArrayList<Employee>();
|
||||
try {
|
||||
pstmt = dbConnection.prepareStatement("select * from employees", ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
pstmt.setFetchSize(1);
|
||||
rs = pstmt.executeQuery();
|
||||
rs.setFetchSize(1);
|
||||
while (rs.next()) {
|
||||
Employee employee = populateResultSet(rs);
|
||||
listOfEmployees.add(employee);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (rs != null)
|
||||
rs.close();
|
||||
if (pstmt != null)
|
||||
pstmt.close();
|
||||
}
|
||||
|
||||
assertEquals(2, listOfEmployees.size());
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void closeConnection() throws SQLException {
|
||||
PreparedStatement deleteStmt = dbConnection.prepareStatement("drop table employees", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
|
||||
deleteStmt.execute();
|
||||
dbConnection.close();
|
||||
}
|
||||
}
|
|
@ -18,7 +18,7 @@
|
|||
- [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column)
|
||||
- [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy)
|
||||
- [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method)
|
||||
- [Custom Types in Hibernate](https://www.baeldung.com/hibernate-custom-types)
|
||||
- [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types)
|
||||
- [Criteria API – An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions)
|
||||
- [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby)
|
||||
- [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api)
|
||||
|
@ -30,3 +30,5 @@
|
|||
- [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0)
|
||||
- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object)
|
||||
- [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions)
|
||||
- [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions)
|
||||
- [Hibernate Query Plan Cache](https://www.baeldung.com/hibernate-query-plan-cache)
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>persistence-modules</artifactId>
|
||||
<name>persistence-modules</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>activejdbc</module>
|
||||
<module>apache-cayenne</module>
|
||||
<module>core-java-persistence</module>
|
||||
<module>deltaspike</module>
|
||||
<module>flyway</module>
|
||||
<module>hbase</module>
|
||||
<module>hibernate5</module>
|
||||
<module>hibernate-ogm</module>
|
||||
<module>influxdb</module>
|
||||
<module>java-cassandra</module>
|
||||
<module>java-cockroachdb</module>
|
||||
<module>java-jdbi</module>
|
||||
<module>java-jpa</module>
|
||||
<module>java-mongodb</module>
|
||||
<module>jnosql</module>
|
||||
<module>liquibase</module>
|
||||
<module>orientdb</module>
|
||||
<module>querydsl</module>
|
||||
<module>redis</module>
|
||||
<module>solr</module>
|
||||
<module>spring-boot-h2/spring-boot-h2-database</module>
|
||||
<module>spring-boot-persistence</module>
|
||||
<module>spring-boot-persistence-mongodb</module>
|
||||
<module>spring-data-cassandra</module>
|
||||
<module>spring-data-cassandra-reactive</module>
|
||||
<module>spring-data-couchbase-2</module>
|
||||
<module>spring-data-dynamodb</module>
|
||||
<module>spring-data-eclipselink</module>
|
||||
<module>spring-data-elasticsearch</module>
|
||||
<module>spring-data-gemfire</module>
|
||||
<module>spring-data-jpa</module>
|
||||
<module>spring-data-keyvalue</module>
|
||||
<module>spring-data-mongodb</module> <!-- long -->
|
||||
<module>spring-data-neo4j</module>
|
||||
<module>spring-data-redis</module>
|
||||
<module>spring-data-solr</module>
|
||||
<module>spring-hibernate-3</module>
|
||||
<module>spring-hibernate-5</module>
|
||||
<module>spring-hibernate4</module>
|
||||
<module>spring-jpa</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
- [Spring Boot with Multiple SQL Import Files](http://www.baeldung.com/spring-boot-sql-import-files)
|
||||
- [Configuring Separate Spring DataSource for Tests](http://www.baeldung.com/spring-testing-separate-data-source)
|
||||
- [Quick Guide on data.sql and schema.sql Files in Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql)
|
||||
- [Quick Guide on Loading Initial Data with Spring Boot](http://www.baeldung.com/spring-boot-data-sql-and-schema-sql)
|
||||
- [Configuring a Tomcat Connection Pool in Spring Boot](https://www.baeldung.com/spring-boot-tomcat-connection-pool)
|
||||
- [Hibernate Field Naming with Spring Boot](https://www.baeldung.com/hibernate-field-naming-spring-boot)
|
||||
- [Integrating Spring Boot with HSQLDB](https://www.baeldung.com/spring-boot-hsqldb)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## Spring Data Couchbase Tutorial Project
|
||||
|
||||
### Relevant Articles:
|
||||
- [Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
|
||||
- [Intro to Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase)
|
||||
- [Entity Validation, Query Consistency, and Optimistic Locking in Spring Data Couchbase](http://www.baeldung.com/entity-validation-locking-and-query-consistency-in-spring-data-couchbase)
|
||||
- [Multiple Buckets and Spatial View Queries in Spring Data Couchbase](http://www.baeldung.com/spring-data-couchbase-buckets-and-spatial-view-queries)
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
- [INSERT Statement in JPA](https://www.baeldung.com/jpa-insert)
|
||||
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
|
||||
- [Spring Data JPA Query by Example](https://www.baeldung.com/spring-data-query-by-example)
|
||||
- [DB Integration Tests with Spring Boot and Testcontainers](https://www.baeldung.com/spring-boot-testcontainers-integration-test)
|
||||
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
|
||||
|
||||
### Eclipse Config
|
||||
After importing the project into Eclipse, you may see the following error:
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
|
||||
- [Hibernate Many to Many Annotation Tutorial](http://www.baeldung.com/hibernate-many-to-many)
|
||||
- [Programmatic Transactions in the Spring TestContext Framework](http://www.baeldung.com/spring-test-programmatic-transactions)
|
||||
- [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries)
|
||||
- [JPA Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries)
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
## Spring with Hibernate 4 Example Project
|
||||
|
||||
### Relevant Articles:
|
||||
- [Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring)
|
||||
- [The DAO with Spring 3 and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
|
||||
- [Guide to Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring)
|
||||
- [The DAO with Spring and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
|
||||
- [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination)
|
||||
- [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort)
|
||||
- [Stored Procedures with Hibernate](http://www.baeldung.com/stored-procedures-with-hibernate-tutorial)
|
||||
|
|
198
pom.xml
198
pom.xml
|
@ -371,8 +371,7 @@
|
|||
|
||||
<module>bootique</module>
|
||||
|
||||
<module>cas/cas-secured-app</module>
|
||||
<module>cas/cas-server</module>
|
||||
<module>cas</module>
|
||||
<module>cdi</module>
|
||||
<module>checker-plugin</module>
|
||||
<module>core-groovy</module>
|
||||
|
@ -422,9 +421,7 @@
|
|||
<module>gson</module>
|
||||
<module>guava</module>
|
||||
<module>guava-collections</module>
|
||||
<module>guava-modules/guava-18</module>
|
||||
<module>guava-modules/guava-19</module>
|
||||
<module>guava-modules/guava-21</module>
|
||||
<module>guava-modules</module>
|
||||
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
|
||||
<module>guice</module>
|
||||
|
||||
|
@ -475,16 +472,13 @@
|
|||
<module>kotlin-libraries</module>
|
||||
|
||||
<!-- <module>lagom</module> --> <!-- Not a maven project -->
|
||||
<module>libraries</module>
|
||||
<module>libraries</module>
|
||||
<module>libraries-data</module>
|
||||
<module>libraries-apache-commons</module>
|
||||
<module>libraries-security</module>
|
||||
<module>libraries-server</module>
|
||||
<module>linkrest</module>
|
||||
<module>logging-modules/log4j</module>
|
||||
<module>logging-modules/log4j2</module>
|
||||
<module>logging-modules/logback</module>
|
||||
<module>logging-modules/log-mdc</module>
|
||||
<module>logging-modules</module>
|
||||
<module>lombok</module>
|
||||
<module>lucene</module>
|
||||
|
||||
|
@ -515,45 +509,7 @@
|
|||
<!-- <module>play-framework</module> --> <!-- Not a maven project -->
|
||||
<module>protobuffer</module>
|
||||
|
||||
<module>persistence-modules/activejdbc</module>
|
||||
<module>persistence-modules/apache-cayenne</module>
|
||||
<module>persistence-modules/core-java-persistence</module>
|
||||
<module>persistence-modules/deltaspike</module>
|
||||
<module>persistence-modules/flyway</module>
|
||||
<module>persistence-modules/hbase</module>
|
||||
<module>persistence-modules/hibernate5</module>
|
||||
<module>persistence-modules/hibernate-ogm</module>
|
||||
<module>persistence-modules/influxdb</module>
|
||||
<module>persistence-modules/java-cassandra</module>
|
||||
<module>persistence-modules/java-cockroachdb</module>
|
||||
<module>persistence-modules/java-jdbi</module>
|
||||
<module>persistence-modules/java-jpa</module>
|
||||
<module>persistence-modules/jnosql</module>
|
||||
<module>persistence-modules/liquibase</module>
|
||||
<module>persistence-modules/orientdb</module>
|
||||
<module>persistence-modules/querydsl</module>
|
||||
<module>persistence-modules/redis</module>
|
||||
<module>persistence-modules/solr</module>
|
||||
<module>persistence-modules/spring-boot-h2/spring-boot-h2-database</module>
|
||||
<module>persistence-modules/spring-boot-persistence</module>
|
||||
<module>persistence-modules/spring-boot-persistence-mongodb</module>
|
||||
<module>persistence-modules/spring-data-cassandra</module>
|
||||
<module>persistence-modules/spring-data-cassandra-reactive</module>
|
||||
<module>persistence-modules/spring-data-couchbase-2</module>
|
||||
<module>persistence-modules/spring-data-dynamodb</module>
|
||||
<module>persistence-modules/spring-data-eclipselink</module>
|
||||
<module>persistence-modules/spring-data-elasticsearch</module>
|
||||
<module>persistence-modules/spring-data-gemfire</module>
|
||||
<module>persistence-modules/spring-data-jpa</module>
|
||||
<module>persistence-modules/spring-data-keyvalue</module>
|
||||
<module>persistence-modules/spring-data-mongodb</module> <!-- long -->
|
||||
<module>persistence-modules/spring-data-neo4j</module>
|
||||
<module>persistence-modules/spring-data-redis</module>
|
||||
<module>persistence-modules/spring-data-solr</module>
|
||||
<module>persistence-modules/spring-hibernate-3</module>
|
||||
<module>persistence-modules/spring-hibernate-5</module>
|
||||
<module>persistence-modules/spring-hibernate4</module>
|
||||
<module>persistence-modules/spring-jpa</module>
|
||||
<module>persistence-modules</module>
|
||||
|
||||
<module>rabbitmq</module>
|
||||
<!-- <module>raml</module> --> <!-- Not a maven project -->
|
||||
|
@ -563,9 +519,7 @@
|
|||
<module>resteasy</module>
|
||||
<module>restx</module>
|
||||
<!-- <module>rmi</module> --> <!-- Not a maven project -->
|
||||
<module>rule-engines/easy-rules</module>
|
||||
<module>rule-engines/openl-tablets</module>
|
||||
<module>rule-engines/rulebook</module>
|
||||
<module>rule-engines</module>
|
||||
<module>rsocket</module>
|
||||
<module>rxjava</module>
|
||||
<module>rxjava-2</module>
|
||||
|
@ -721,13 +675,7 @@
|
|||
<module>spring-security-angular/server</module>
|
||||
<module>spring-security-cache-control</module>
|
||||
|
||||
<module>spring-security-client/spring-security-jsp-authentication</module>
|
||||
<module>spring-security-client/spring-security-jsp-authorize</module>
|
||||
<module>spring-security-client/spring-security-jsp-config</module>
|
||||
<module>spring-security-client/spring-security-mvc</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authentication</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authorize</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-config</module>
|
||||
<module>spring-security-client</module>
|
||||
|
||||
<module>spring-security-core</module>
|
||||
<module>spring-security-mvc-boot</module>
|
||||
|
@ -773,24 +721,7 @@
|
|||
<module>structurizr</module>
|
||||
<module>struts-2</module>
|
||||
|
||||
<module>testing-modules/gatling</module>
|
||||
<module>testing-modules/groovy-spock</module>
|
||||
<module>testing-modules/junit-5</module>
|
||||
<module>testing-modules/junit5-migration</module>
|
||||
<module>testing-modules/load-testing-comparison</module>
|
||||
<module>testing-modules/mockito</module>
|
||||
<module>testing-modules/mockito-2</module>
|
||||
<module>testing-modules/mocks</module>
|
||||
<module>testing-modules/mockserver</module>
|
||||
<module>testing-modules/parallel-tests-junit</module>
|
||||
<module>testing-modules/rest-assured</module>
|
||||
<module>testing-modules/rest-testing</module>
|
||||
<!-- <module>testing-modules/runjunitfromjava</module> --> <!-- Not a maven project -->
|
||||
<module>testing-modules/selenium-junit-testng</module>
|
||||
<module>testing-modules/spring-testing</module>
|
||||
<module>testing-modules/test-containers</module>
|
||||
<module>testing-modules/testing</module>
|
||||
<module>testing-modules/testng</module>
|
||||
<module>testing-modules</module>
|
||||
|
||||
<module>twilio</module>
|
||||
<module>Twitter4J</module>
|
||||
|
@ -849,8 +780,7 @@
|
|||
<module>spring-apache-camel</module>
|
||||
<module>spring-batch</module>
|
||||
<module>spring-bom</module>
|
||||
<module>spring-boot-admin/spring-boot-admin-client</module>
|
||||
<module>spring-boot-admin/spring-boot-admin-server</module>
|
||||
<module>spring-boot-admin</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-bootstrap</module>
|
||||
<module>spring-boot-camel</module>
|
||||
|
@ -862,22 +792,18 @@
|
|||
<module>spring-boot-jasypt</module>
|
||||
<module>spring-boot-keycloak</module>
|
||||
<module>spring-boot-mvc</module>
|
||||
<module>spring-boot-property-exp/property-exp-custom-config</module>
|
||||
<module>spring-boot-property-exp/property-exp-default-config</module>
|
||||
<module>spring-boot-property-exp</module>
|
||||
<module>spring-boot-vue</module>
|
||||
<module>spring-cloud</module>
|
||||
<module>spring-cloud/spring-cloud-archaius/basic-config</module>
|
||||
<module>spring-cloud/spring-cloud-archaius/extra-configs</module>
|
||||
<module>spring-cloud/spring-cloud-bootstrap/config</module>
|
||||
<module>spring-cloud/spring-cloud-contract/spring-cloud-contract-consumer</module>
|
||||
<module>spring-cloud/spring-cloud-contract/spring-cloud-contract-producer</module>
|
||||
<module>spring-cloud/spring-cloud-contract</module>
|
||||
<module>spring-cloud/spring-cloud-gateway</module>
|
||||
<module>spring-cloud/spring-cloud-kubernetes/demo-backend</module>
|
||||
<module>spring-cloud/spring-cloud-rest/spring-cloud-rest-config-server</module>
|
||||
<module>spring-cloud/spring-cloud-ribbon-client </module>
|
||||
<module>spring-cloud/spring-cloud-security/auth-client</module>
|
||||
<module>spring-cloud/spring-cloud-security/auth-resource</module>
|
||||
<module>spring-cloud/spring-cloud-security/auth-server</module>
|
||||
<module>spring-cloud/spring-cloud-security</module>
|
||||
<module>spring-cloud/spring-cloud-stream/spring-cloud-stream-rabbit</module>
|
||||
<module>spring-cloud/spring-cloud-task/springcloudtasksink</module>
|
||||
<module>spring-cloud/spring-cloud-zookeeper </module>
|
||||
|
@ -925,13 +851,7 @@
|
|||
<module>spring-security-acl</module>
|
||||
<module>spring-security-angular</module>
|
||||
<module>spring-security-cache-control</module>
|
||||
<module>spring-security-client/spring-security-jsp-authentication</module>
|
||||
<module>spring-security-client/spring-security-jsp-authorize</module>
|
||||
<module>spring-security-client/spring-security-jsp-config</module>
|
||||
<module>spring-security-client/spring-security-mvc</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authentication</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authorize</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-config</module>
|
||||
<module>spring-security-client</module>
|
||||
<module>spring-security-core</module>
|
||||
<module>spring-security-mvc-boot</module>
|
||||
<module>spring-security-mvc-custom</module>
|
||||
|
@ -941,14 +861,11 @@
|
|||
<module>spring-security-mvc-session</module>
|
||||
<module>spring-security-mvc-socket</module>
|
||||
<module>spring-security-rest</module>
|
||||
<module>spring-security-sso/spring-security-sso-auth-server</module>
|
||||
<module>spring-security-sso/spring-security-sso-ui</module>
|
||||
<module>spring-security-sso/spring-security-sso-ui-2</module>
|
||||
<module>spring-security-sso</module>
|
||||
<module>spring-security-thymeleaf/spring-security-thymeleaf-authentication</module>
|
||||
<module>spring-security-thymeleaf/spring-security-thymeleaf-authorize</module>
|
||||
<module>spring-security-thymeleaf/spring-security-thymeleaf-config</module>
|
||||
<module>spring-security-x509/spring-security-x509-basic-auth</module>
|
||||
<module>spring-security-x509/spring-security-x509-client-auth</module>
|
||||
<module>spring-security-x509</module>
|
||||
<module>spring-session/spring-session-jdbc</module>
|
||||
<module>spring-sleuth</module>
|
||||
<module>spring-social-login</module>
|
||||
|
@ -1090,8 +1007,7 @@
|
|||
|
||||
<module>bootique</module>
|
||||
|
||||
<module>cas/cas-secured-app</module>
|
||||
<module>cas/cas-server</module>
|
||||
<module>cas</module>
|
||||
<module>cdi</module>
|
||||
<module>checker-plugin</module>
|
||||
<module>core-groovy</module>
|
||||
|
@ -1140,9 +1056,7 @@
|
|||
<module>gson</module>
|
||||
<module>guava</module>
|
||||
<module>guava-collections</module>
|
||||
<module>guava-modules/guava-18</module>
|
||||
<module>guava-modules/guava-19</module>
|
||||
<module>guava-modules/guava-21</module>
|
||||
<module>guava-modules</module>
|
||||
<!-- <module>guest</module> --> <!-- not to be built as its for guest articles -->
|
||||
<module>guice</module>
|
||||
|
||||
|
@ -1199,10 +1113,7 @@
|
|||
<module>libraries-security</module>
|
||||
<module>libraries-server</module>
|
||||
<module>linkrest</module>
|
||||
<module>logging-modules/log4j</module>
|
||||
<module>logging-modules/log4j2</module>
|
||||
<module>logging-modules/logback</module>
|
||||
<module>logging-modules/log-mdc</module>
|
||||
<module>logging-modules</module>
|
||||
<module>lombok</module>
|
||||
<module>lucene</module>
|
||||
|
||||
|
@ -1233,46 +1144,8 @@
|
|||
<!-- <module>play-framework</module> --> <!-- Not a maven project -->
|
||||
<module>protobuffer</module>
|
||||
|
||||
<module>persistence-modules/activejdbc</module>
|
||||
<module>persistence-modules/apache-cayenne</module>
|
||||
<module>persistence-modules/core-java-persistence</module>
|
||||
<module>persistence-modules/deltaspike</module>
|
||||
<module>persistence-modules/flyway</module>
|
||||
<module>persistence-modules/hbase</module>
|
||||
<module>persistence-modules/hibernate5</module>
|
||||
<module>persistence-modules/hibernate-ogm</module>
|
||||
<module>persistence-modules/influxdb</module>
|
||||
<module>persistence-modules/java-cassandra</module>
|
||||
<module>persistence-modules/java-cockroachdb</module>
|
||||
<module>persistence-modules/java-jdbi</module>
|
||||
<module>persistence-modules/java-jpa</module>
|
||||
<module>persistence-modules/jnosql</module>
|
||||
<module>persistence-modules/liquibase</module>
|
||||
<module>persistence-modules/orientdb</module>
|
||||
<module>persistence-modules/querydsl</module>
|
||||
<module>persistence-modules/redis</module>
|
||||
<module>persistence-modules/solr</module>
|
||||
<module>persistence-modules/spring-boot-h2/spring-boot-h2-database</module>
|
||||
<module>persistence-modules/spring-boot-persistence</module>
|
||||
<module>persistence-modules/spring-boot-persistence-mongodb</module>
|
||||
<module>persistence-modules/spring-data-cassandra</module>
|
||||
<module>persistence-modules/spring-data-cassandra-reactive</module>
|
||||
<module>persistence-modules/spring-data-couchbase-2</module>
|
||||
<module>persistence-modules/spring-data-dynamodb</module>
|
||||
<module>persistence-modules/spring-data-eclipselink</module>
|
||||
<module>persistence-modules/spring-data-elasticsearch</module>
|
||||
<module>persistence-modules/spring-data-gemfire</module>
|
||||
<module>persistence-modules/spring-data-jpa</module>
|
||||
<module>persistence-modules/spring-data-keyvalue</module>
|
||||
<module>persistence-modules/spring-data-mongodb</module> <!-- long -->
|
||||
<module>persistence-modules/spring-data-neo4j</module>
|
||||
<module>persistence-modules/spring-data-redis</module>
|
||||
<module>persistence-modules/spring-data-solr</module>
|
||||
<module>persistence-modules/spring-hibernate-3</module>
|
||||
<module>persistence-modules/spring-hibernate-5</module>
|
||||
<module>persistence-modules/spring-hibernate4</module>
|
||||
<module>persistence-modules/spring-jpa</module>
|
||||
|
||||
<module>persistence-modules</module>
|
||||
|
||||
<module>rabbitmq</module>
|
||||
<!-- <module>raml</module> --> <!-- Not a maven project -->
|
||||
<module>ratpack</module>
|
||||
|
@ -1281,9 +1154,7 @@
|
|||
<module>resteasy</module>
|
||||
<module>restx</module>
|
||||
<!-- <module>rmi</module> --> <!-- Not a maven project -->
|
||||
<module>rule-engines/easy-rules</module>
|
||||
<module>rule-engines/openl-tablets</module>
|
||||
<module>rule-engines/rulebook</module>
|
||||
<module>rule-engines</module>
|
||||
<module>rsocket</module>
|
||||
<module>rxjava</module>
|
||||
<module>rxjava-2</module>
|
||||
|
@ -1434,13 +1305,7 @@
|
|||
<module>spring-security-angular/server</module>
|
||||
<module>spring-security-cache-control</module>
|
||||
|
||||
<module>spring-security-client/spring-security-jsp-authentication</module>
|
||||
<module>spring-security-client/spring-security-jsp-authorize</module>
|
||||
<module>spring-security-client/spring-security-jsp-config</module>
|
||||
<module>spring-security-client/spring-security-mvc</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authentication</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-authorize</module>
|
||||
<module>spring-security-client/spring-security-thymeleaf-config</module>
|
||||
<module>spring-security-client</module>
|
||||
|
||||
<module>spring-security-core</module>
|
||||
<module>spring-security-mvc-boot</module>
|
||||
|
@ -1485,24 +1350,7 @@
|
|||
<module>structurizr</module>
|
||||
<module>struts-2</module>
|
||||
|
||||
<module>testing-modules/gatling</module>
|
||||
<module>testing-modules/groovy-spock</module>
|
||||
<module>testing-modules/junit-5</module>
|
||||
<module>testing-modules/junit5-migration</module>
|
||||
<module>testing-modules/load-testing-comparison</module>
|
||||
<module>testing-modules/mockito</module>
|
||||
<module>testing-modules/mockito-2</module>
|
||||
<module>testing-modules/mocks</module>
|
||||
<module>testing-modules/mockserver</module>
|
||||
<module>testing-modules/parallel-tests-junit</module>
|
||||
<module>testing-modules/rest-assured</module>
|
||||
<module>testing-modules/rest-testing</module>
|
||||
<!-- <module>testing-modules/runjunitfromjava</module> --> <!-- Not a maven project -->
|
||||
<module>testing-modules/selenium-junit-testng</module>
|
||||
<module>testing-modules/spring-testing</module>
|
||||
<module>testing-modules/test-containers</module>
|
||||
<module>testing-modules/testing</module>
|
||||
<module>testing-modules/testng</module>
|
||||
<module>testing-modules</module>
|
||||
|
||||
<module>twilio</module>
|
||||
<module>Twitter4J</module>
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
- [Ratpack Integration with Spring Boot](http://www.baeldung.com/ratpack-spring-boot)
|
||||
- [Ratpack with Hystrix](http://www.baeldung.com/ratpack-hystrix)
|
||||
- [Ratpack HTTP Client](https://www.baeldung.com/ratpack-http-client)
|
||||
- [Ratpack with RxJava](https://www.baeldung.com/ratpack-rxjava)
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>rule-engines</artifactId>
|
||||
<name>rule-engines</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<modules>
|
||||
<module>easy-rules</module>
|
||||
<module>openl-tablets</module>
|
||||
<module>rulebook</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue