Merge branch 'master' into BAEL-18235-v4
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,7 +30,7 @@ out/
|
||||
.DS_Store
|
||||
|
||||
# Maven
|
||||
log/
|
||||
log/*
|
||||
target/
|
||||
|
||||
# Gradle
|
||||
|
||||
@@ -14,4 +14,6 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
|
||||
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
|
||||
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
|
||||
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)
|
||||
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)
|
||||
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search)
|
||||
- [The K-Means Clustering Algorithm in Java](https://www.baeldung.com/java-k-means-clustering-algorithm)
|
||||
- More articles: [[<-- prev]](/algorithms-miscellaneous-2) [[next -->]](/algorithms-miscellaneous-4)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.baeldung.algorithms.breadthfirstsearch;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BreadthFirstSearchAlgorithm {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BreadthFirstSearchAlgorithm.class);
|
||||
|
||||
public static <T> Optional<Tree<T>> search(T value, Tree<T> root) {
|
||||
Queue<Tree<T>> queue = new ArrayDeque<>();
|
||||
queue.add(root);
|
||||
|
||||
Tree<T> currentNode;
|
||||
while (!queue.isEmpty()) {
|
||||
currentNode = queue.remove();
|
||||
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||
|
||||
if (currentNode.getValue().equals(value)) {
|
||||
return Optional.of(currentNode);
|
||||
} else {
|
||||
queue.addAll(currentNode.getChildren());
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public static <T> Optional<Node<T>> search(T value, Node<T> start) {
|
||||
Queue<Node<T>> queue = new ArrayDeque<>();
|
||||
queue.add(start);
|
||||
|
||||
Node<T> currentNode;
|
||||
Set<Node<T>> alreadyVisited = new HashSet<>();
|
||||
|
||||
while (!queue.isEmpty()) {
|
||||
currentNode = queue.remove();
|
||||
LOGGER.info("Visited node with value: {}", currentNode.getValue());
|
||||
|
||||
if (currentNode.getValue().equals(value)) {
|
||||
return Optional.of(currentNode);
|
||||
} else {
|
||||
alreadyVisited.add(currentNode);
|
||||
queue.addAll(currentNode.getNeighbors());
|
||||
queue.removeAll(alreadyVisited);
|
||||
}
|
||||
}
|
||||
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.algorithms.breadthfirstsearch;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class Node<T> {
|
||||
|
||||
private T value;
|
||||
private Set<Node<T>> neighbors;
|
||||
|
||||
public Node(T value) {
|
||||
this.value = value;
|
||||
this.neighbors = new HashSet<>();
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Set<Node<T>> getNeighbors() {
|
||||
return Collections.unmodifiableSet(neighbors);
|
||||
}
|
||||
|
||||
public void connect(Node<T> node) {
|
||||
if (this == node) throw new IllegalArgumentException("Can't connect node to itself");
|
||||
this.neighbors.add(node);
|
||||
node.neighbors.add(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.algorithms.breadthfirstsearch;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Tree<T> {
|
||||
|
||||
private T value;
|
||||
private List<Tree<T>> children;
|
||||
|
||||
private Tree(T value) {
|
||||
this.value = value;
|
||||
this.children = new ArrayList<>();
|
||||
}
|
||||
|
||||
public static <T> Tree<T> of(T value) {
|
||||
return new Tree<>(value);
|
||||
}
|
||||
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public List<Tree<T>> getChildren() {
|
||||
return Collections.unmodifiableList(children);
|
||||
}
|
||||
|
||||
public Tree<T> addChild(T value) {
|
||||
Tree<T> newChild = new Tree<>(value);
|
||||
children.add(newChild);
|
||||
return newChild;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.baeldung.algorithms.breadthfirstsearch;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
class BreadthFirstSearchAlgorithmUnitTest {
|
||||
|
||||
private Tree<Integer> root;
|
||||
private Tree<Integer> rootFirstChild;
|
||||
private Tree<Integer> depthMostChild;
|
||||
private Tree<Integer> rootSecondChild;
|
||||
|
||||
private Node<Integer> start;
|
||||
private Node<Integer> firstNeighbor;
|
||||
private Node<Integer> firstNeighborNeighbor;
|
||||
private Node<Integer> secondNeighbor;
|
||||
|
||||
@Test
|
||||
void givenTree_whenSearchTen_thenRoot() {
|
||||
initTree();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(10, root)).isPresent().contains(root);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTree_whenSearchThree_thenDepthMostValue() {
|
||||
initTree();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(3, root)).isPresent().contains(depthMostChild);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTree_whenSearchFour_thenRootSecondChild() {
|
||||
initTree();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(4, root)).isPresent().contains(rootSecondChild);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenTree_whenSearchFive_thenNotFound() {
|
||||
initTree();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(5, root)).isEmpty();
|
||||
}
|
||||
|
||||
private void initTree() {
|
||||
root = Tree.of(10);
|
||||
rootFirstChild = root.addChild(2);
|
||||
depthMostChild = rootFirstChild.addChild(3);
|
||||
rootSecondChild = root.addChild(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNode_whenSearchTen_thenStart() {
|
||||
initNode();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(10, firstNeighborNeighbor)).isPresent().contains(start);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNode_whenSearchThree_thenNeighborNeighbor() {
|
||||
initNode();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(3, firstNeighborNeighbor)).isPresent().contains(firstNeighborNeighbor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNode_whenSearchFour_thenSecondNeighbor() {
|
||||
initNode();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(4, firstNeighborNeighbor)).isPresent().contains(secondNeighbor);
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenNode_whenSearchFive_thenNotFound() {
|
||||
initNode();
|
||||
assertThat(BreadthFirstSearchAlgorithm.search(5, firstNeighborNeighbor)).isEmpty();
|
||||
}
|
||||
|
||||
private void initNode() {
|
||||
start = new Node<>(10);
|
||||
firstNeighbor = new Node<>(2);
|
||||
start.connect(firstNeighbor);
|
||||
|
||||
firstNeighborNeighbor = new Node<>(3);
|
||||
firstNeighbor.connect(firstNeighborNeighbor);
|
||||
firstNeighborNeighbor.connect(start);
|
||||
|
||||
secondNeighbor = new Node<>(4);
|
||||
start.connect(secondNeighbor);
|
||||
}
|
||||
}
|
||||
@@ -12,3 +12,7 @@ This module contains articles about sorting algorithms.
|
||||
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
|
||||
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
|
||||
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
||||
- [How an In-Place Sorting Algorithm Works](https://www.baeldung.com/java-in-place-sorting)
|
||||
- [Selection Sort in Java](https://www.baeldung.com/java-selection-sort)
|
||||
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)
|
||||
- [Radix Sort in Java](https://www.baeldung.com/java-radix-sort)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>animal-sniffer-mvn-plugin</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>animal-sniffer-mvn-plugin</name>
|
||||
|
||||
@@ -14,12 +14,6 @@
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
@@ -46,15 +40,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.avro</groupId>
|
||||
<artifactId>avro-maven-plugin</artifactId>
|
||||
@@ -79,8 +64,6 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<compiler-plugin.version>3.5</compiler-plugin.version>
|
||||
<avro.version>1.8.2</avro.version>
|
||||
<slf4j.version>1.7.25</slf4j.version>
|
||||
</properties>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-fop</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<name>apache-fop</name>
|
||||
|
||||
@@ -19,25 +19,7 @@
|
||||
<artifactId>geode-core</artifactId>
|
||||
<version>${geode.core}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<geode.core>1.6.0</geode.core>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-meecrowave</artifactId>
|
||||
<version>0.0.1</version>
|
||||
<name>apache-meecrowave</name>
|
||||
@@ -38,13 +37,6 @@
|
||||
<version>${meecrowave-junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/junit/junit -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.baeldung.examples.olingo2</groupId>
|
||||
<artifactId>olingo2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>olingo2</name>
|
||||
<description>Sample Olingo 2 Project</description>
|
||||
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<pulsar-client.version>2.1.1-incubating</pulsar-client.version>
|
||||
<pulsar-client.version>2.1.1-incubating</pulsar-client.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
||||
@@ -4,4 +4,6 @@ This module contains articles about Apache Shiro
|
||||
|
||||
### Relevant articles:
|
||||
|
||||
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
||||
- [Introduction to Apache Shiro](https://www.baeldung.com/apache-shiro)
|
||||
- [Permissions-Based Access Control with Apache Shiro](https://www.baeldung.com/apache-shiro-access-control)
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-solrj</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>apache-solrj</name>
|
||||
|
||||
@@ -6,3 +6,5 @@ This module contains articles about Apache Spark
|
||||
|
||||
- [Introduction to Apache Spark](https://www.baeldung.com/apache-spark)
|
||||
- [Building a Data Pipeline with Kafka, Spark Streaming and Cassandra](https://www.baeldung.com/kafka-spark-data-pipeline)
|
||||
- [Machine Learning with Spark MLlib](https://www.baeldung.com/spark-mlib-machine-learning)
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>apache-spark</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>apache-spark</name>
|
||||
@@ -59,15 +58,6 @@
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
@@ -95,7 +85,6 @@
|
||||
<org.apache.spark.spark-streaming-kafka.version>2.3.0</org.apache.spark.spark-streaming-kafka.version>
|
||||
<com.datastax.spark.spark-cassandra-connector.version>2.3.0</com.datastax.spark.spark-cassandra-connector.version>
|
||||
<com.datastax.spark.spark-cassandra-connector-java.version>1.5.2</com.datastax.spark.spark-cassandra-connector-java.version>
|
||||
<maven-compiler-plugin.version>3.2</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<artifactId>apache-velocity</artifactId>
|
||||
<name>apache-velocity</name>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>aws-lambda</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws-lambda</name>
|
||||
@@ -88,7 +87,6 @@
|
||||
|
||||
<properties>
|
||||
<json-simple.version>1.1.1</json-simple.version>
|
||||
<org.json.version>20180130</org.json.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<aws-lambda-java-events.version>1.3.0</aws-lambda-java-events.version>
|
||||
<aws-lambda-java-core.version>1.2.0</aws-lambda-java-core.version>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>aws</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>aws</name>
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
<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>azure</artifactId>
|
||||
<version>0.1</version>
|
||||
<name>azure</name>
|
||||
|
||||
@@ -11,4 +11,5 @@ This module contains articles about core Groovy concepts
|
||||
- [Integrating Groovy into Java Applications](https://www.baeldung.com/groovy-java-applications)
|
||||
- [Concatenate Strings with Groovy](https://www.baeldung.com/groovy-concatenate-strings)
|
||||
- [Metaprogramming in Groovy](https://www.baeldung.com/groovy-metaprogramming)
|
||||
- [[<-- Prev]](/core-groovy)
|
||||
- [A Quick Guide to Working with Web Services in Groovy](https://www.baeldung.com/groovy-web-services)
|
||||
- [[<-- Prev]](/core-groovy)
|
||||
|
||||
@@ -7,4 +7,6 @@ This module contains articles about the Java ArrayList collection
|
||||
- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist)
|
||||
- [Add Multiple Items to an Java ArrayList](http://www.baeldung.com/java-add-items-array-list)
|
||||
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
|
||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||
- [Multi Dimensional ArrayList in Java](https://www.baeldung.com/java-multi-dimensional-arraylist)
|
||||
- [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element)
|
||||
|
||||
|
||||
19
core-java-modules/core-java-concurrency-advanced-2/README.md
Normal file
19
core-java-modules/core-java-concurrency-advanced-2/README.md
Normal file
@@ -0,0 +1,19 @@
|
||||
=========
|
||||
|
||||
## Core Java Concurrency Advanced Examples
|
||||
|
||||
This module contains articles about advanced topics about multithreading with core Java.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Semaphores in Java](https://www.baeldung.com/java-semaphore)
|
||||
- [Daemon Threads in Java](https://www.baeldung.com/java-daemon-thread)
|
||||
- [Priority-based Job Scheduling in Java](https://www.baeldung.com/java-priority-job-schedule)
|
||||
- [Brief Introduction to Java Thread.yield()](https://www.baeldung.com/java-thread-yield)
|
||||
- [Print Even and Odd Numbers Using 2 Threads](https://www.baeldung.com/java-even-odd-numbers-with-2-threads)
|
||||
- [Java CyclicBarrier vs CountDownLatch](https://www.baeldung.com/java-cyclicbarrier-countdownlatch)
|
||||
- [Guide to the Fork/Join Framework in Java](https://www.baeldung.com/java-fork-join)
|
||||
- [Guide to ThreadLocalRandom in Java](https://www.baeldung.com/java-thread-local-random)
|
||||
- [The Thread.join() Method in Java](https://www.baeldung.com/java-thread-join)
|
||||
- [Passing Parameters to Java Threads](https://www.baeldung.com/java-thread-parameters)
|
||||
|
||||
[[<-- previous]](/core-java-modules/core-java-concurrency-advanced)[[next -->]](/core-java-modules/core-java-concurrency-advanced-3)
|
||||
59
core-java-modules/core-java-concurrency-advanced-2/pom.xml
Normal file
59
core-java-modules/core-java-concurrency-advanced-2/pom.xml
Normal file
@@ -0,0 +1,59 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java-concurrency-advanced-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-concurrency-advanced-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-concurrency-advanced-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -4,6 +4,7 @@ import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class CyclicBarrierResetExample {
|
||||
@@ -36,6 +37,11 @@ public class CyclicBarrierResetExample {
|
||||
});
|
||||
}
|
||||
es.shutdown();
|
||||
try {
|
||||
es.awaitTermination(1, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return updateCount.get();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.concurrent.daemon;
|
||||
|
||||
public class NewThread extends Thread {
|
||||
public void run() {
|
||||
long startTime = System.currentTimeMillis();
|
||||
while (true) {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(this.getName() + ": New Thread is running..." + i);
|
||||
try {
|
||||
//Wait for one sec so it doesn't print too fast
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// prevent the Thread to run forever. It will finish it's execution after 2 seconds
|
||||
if (System.currentTimeMillis() - startTime > 2000) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.concurrent.parameter;
|
||||
package com.baeldung.concurrent.parameters;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.concurrent.parameter;
|
||||
package com.baeldung.concurrent.parameters;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.stream.IntStream;
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.baeldung.parameters;
|
||||
package com.baeldung.concurrent.parameters;
|
||||
|
||||
import com.baeldung.concurrent.parameter.AverageCalculator;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ParameterizedThreadUnitTest {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java8;
|
||||
package com.baeldung.forkjoin;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -0,0 +1,9 @@
|
||||
=========
|
||||
|
||||
## Core Java Concurrency Advanced Examples
|
||||
|
||||
This module contains articles about advanced topics about multithreading with core Java.
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
[[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2)
|
||||
33
core-java-modules/core-java-concurrency-advanced-3/pom.xml
Normal file
33
core-java-modules/core-java-concurrency-advanced-3/pom.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>core-java-concurrency-advanced-3</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<name>core-java-concurrency-advanced-3</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-concurrency-advanced-3</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,26 +0,0 @@
|
||||
*.class
|
||||
|
||||
0.*
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/neoDb*
|
||||
/data
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
.resourceCache
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
|
||||
# Files generated by integration tests
|
||||
*.txt
|
||||
backup-pom.xml
|
||||
/bin/
|
||||
/temp
|
||||
|
||||
#IntelliJ specific
|
||||
.idea/
|
||||
*.iml
|
||||
@@ -1,25 +1,16 @@
|
||||
## Core Java Concurrency Advanced Examples
|
||||
|
||||
This module contains articles about advanced concurrency in core Java.
|
||||
This module contains articles about advanced topics about multithreading with core Java.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Introduction to Thread Pools in Java](http://www.baeldung.com/thread-pool-java-and-guava)
|
||||
- [Guide to CountDownLatch in Java](http://www.baeldung.com/java-countdown-latch)
|
||||
- [Guide to java.util.concurrent.Locks](http://www.baeldung.com/java-concurrent-locks)
|
||||
- [An Introduction to ThreadLocal in Java](http://www.baeldung.com/java-threadlocal)
|
||||
- [LongAdder and LongAccumulator in Java](http://www.baeldung.com/java-longadder-and-longaccumulator)
|
||||
- [The Dining Philosophers Problem in Java](http://www.baeldung.com/java-dining-philoshophers)
|
||||
- [Guide to the Java Phaser](http://www.baeldung.com/java-phaser)
|
||||
- [An Introduction to Atomic Variables in Java](http://www.baeldung.com/java-atomic-variables)
|
||||
- [CyclicBarrier in Java](http://www.baeldung.com/java-cyclic-barrier)
|
||||
- [Guide to the Volatile Keyword in Java](http://www.baeldung.com/java-volatile)
|
||||
- [Semaphores in Java](http://www.baeldung.com/java-semaphore)
|
||||
- [Daemon Threads in Java](http://www.baeldung.com/java-daemon-thread)
|
||||
- [Priority-based Job Scheduling in Java](http://www.baeldung.com/java-priority-job-schedule)
|
||||
- [Brief Introduction to Java Thread.yield()](https://www.baeldung.com/java-thread-yield)
|
||||
- [Print Even and Odd Numbers Using 2 Threads](https://www.baeldung.com/java-even-odd-numbers-with-2-threads)
|
||||
- [Java CyclicBarrier vs CountDownLatch](https://www.baeldung.com/java-cyclicbarrier-countdownlatch)
|
||||
- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join)
|
||||
- [Guide to ThreadLocalRandom in Java](http://www.baeldung.com/java-thread-local-random)
|
||||
- [The Thread.join() Method in Java](http://www.baeldung.com/java-thread-join)
|
||||
- [Passing Parameters to Java Threads](https://www.baeldung.com/java-thread-parameters)
|
||||
- [Introduction to Thread Pools in Java](https://www.baeldung.com/thread-pool-java-and-guava)
|
||||
- [Guide to CountDownLatch in Java](https://www.baeldung.com/java-countdown-latch)
|
||||
- [Guide to java.util.concurrent.Locks](https://www.baeldung.com/java-concurrent-locks)
|
||||
- [An Introduction to ThreadLocal in Java](https://www.baeldung.com/java-threadlocal)
|
||||
- [LongAdder and LongAccumulator in Java](https://www.baeldung.com/java-longadder-and-longaccumulator)
|
||||
- [The Dining Philosophers Problem in Java](https://www.baeldung.com/java-dining-philoshophers)
|
||||
- [Guide to the Java Phaser](https://www.baeldung.com/java-phaser)
|
||||
- [An Introduction to Atomic Variables in Java](https://www.baeldung.com/java-atomic-variables)
|
||||
- [CyclicBarrier in Java](https://www.baeldung.com/java-cyclic-barrier)
|
||||
- [Guide to the Volatile Keyword in Java](https://www.baeldung.com/java-volatile)
|
||||
- More Articles: [[next -->]](/core-java-modules/core-java-concurrency-advanced-2)
|
||||
|
||||
@@ -47,16 +47,6 @@
|
||||
<version>${avaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-core</artifactId>
|
||||
<version>${jmh-core.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjdk.jmh</groupId>
|
||||
<artifactId>jmh-generator-annprocess</artifactId>
|
||||
<version>${jmh-generator-annprocess.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -78,8 +68,6 @@
|
||||
<!-- testing -->
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
<avaitility.version>1.7.0</avaitility.version>
|
||||
<jmh-core.version>1.19</jmh-core.version>
|
||||
<jmh-generator-annprocess.version>1.19</jmh-generator-annprocess.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class CyclicBarrierCompletionMethodExample {
|
||||
@@ -35,6 +36,11 @@ public class CyclicBarrierCompletionMethodExample {
|
||||
});
|
||||
}
|
||||
es.shutdown();
|
||||
try {
|
||||
es.awaitTermination(1, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return updateCount.get();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,3 +11,5 @@ This module contains articles about core java exceptions
|
||||
- [Difference Between Throw and Throws in Java](https://www.baeldung.com/java-throw-throws)
|
||||
- [“Sneaky Throws” in Java](https://www.baeldung.com/java-sneaky-throws)
|
||||
- [The StackOverflowError in Java](https://www.baeldung.com/java-stack-overflow-error)
|
||||
- [Checked and Unchecked Exceptions in Java](https://www.baeldung.com/java-checked-unchecked-exceptions)
|
||||
|
||||
|
||||
6
core-java-modules/core-java-io-2/README.md
Normal file
6
core-java-modules/core-java-io-2/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Create a File in a Specific Directory in Java](https://www.baeldung.com/java-create-file-in-directory)
|
||||
- [A Guide to the Java FileReader Class](https://www.baeldung.com/java-filereader)
|
||||
|
||||
@@ -41,4 +41,5 @@ This module contains articles about core Java input and output (IO)
|
||||
- [List Files in a Directory in Java](https://www.baeldung.com/java-list-directory-files)
|
||||
- [Java InputStream to Byte Array and ByteBuffer](https://www.baeldung.com/convert-input-stream-to-array-of-bytes)
|
||||
- [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector)
|
||||
- [How to Avoid the Java FileNotFoundException When Loading Resources](https://www.baeldung.com/java-classpath-resource-cannot-be-opened)
|
||||
- [[More -->]](/core-java-modules/core-java-io-2)
|
||||
|
||||
4
core-java-modules/core-java-jndi/README.md
Normal file
4
core-java-modules/core-java-jndi/README.md
Normal file
@@ -0,0 +1,4 @@
|
||||
|
||||
### Relevant Articles:
|
||||
|
||||
- [Java Naming and Directory Interface Overview](https://www.baeldung.com/jndi)
|
||||
@@ -4,3 +4,5 @@
|
||||
|
||||
### Relevant Articles:
|
||||
- [Method Inlining in the JVM](https://www.baeldung.com/jvm-method-inlining)
|
||||
- [A Guide to System.exit()](https://www.baeldung.com/java-system-exit)
|
||||
- [Guide to System.gc()](https://www.baeldung.com/java-system-gc)
|
||||
|
||||
@@ -4,4 +4,5 @@ This module contains articles about core features in the Java language
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java Primitives versus Objects](https://www.baeldung.com/java-primitives-vs-objects)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang)
|
||||
- [Command-Line Arguments in Java](https://www.baeldung.com/java-command-line-arguments)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang)
|
||||
|
||||
@@ -14,4 +14,5 @@ This module contains articles about Object-oriented programming (OOP) in Java
|
||||
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
|
||||
- [Composition, Aggregation, and Association in Java](https://www.baeldung.com/java-composition-aggregation-association)
|
||||
- [Static and Default Methods in Interfaces in Java](https://www.baeldung.com/java-static-default-methods)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-oop)[[More -->]](/core-java-modules/core-java-lang-oop-3)
|
||||
- [Java Copy Constructor](https://www.baeldung.com/java-copy-constructor)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-lang-oop)[[More -->]](/core-java-modules/core-java-lang-oop-3)
|
||||
|
||||
@@ -25,7 +25,7 @@ public class DeepCopyUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenModifyingOriginalObject_thenConstructorCopyShouldNotChange() {
|
||||
public void whenModifyingOriginalObject_thenCopyShouldNotChange() {
|
||||
Address address = new Address("Downing St 10", "London", "England");
|
||||
User pm = new User("Prime", "Minister", address);
|
||||
User deepCopy = new User(pm);
|
||||
@@ -125,4 +125,13 @@ public class DeepCopyUnitTest {
|
||||
end = System.currentTimeMillis();
|
||||
System.out.println("Cloning with Jackson took " + (end - start) + " milliseconds.");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenModifyingOriginalObject_ThenCopyShouldChange() {
|
||||
Address address = new Address("Downing St 10", "London", "England");
|
||||
User pm = new User("Prime", "Minister", address);
|
||||
User shallowCopy = new User(pm.getFirstName(), pm.getLastName(), pm.getAddress());
|
||||
address.setCountry("Great Britain");
|
||||
assertThat(shallowCopy.getAddress().getCountry()).isEqualTo(pm.getAddress().getCountry());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,3 +5,5 @@
|
||||
- [Java instanceof Operator](https://www.baeldung.com/java-instanceof)
|
||||
- [A Guide to Increment and Decrement Unary Operators in Java](https://www.baeldung.com/java-unary-operators)
|
||||
- [Java Compound Operators](https://www.baeldung.com/java-compound-operators)
|
||||
- [The XOR Operator in Java](https://www.baeldung.com/java-xor-operator)
|
||||
|
||||
|
||||
@@ -35,4 +35,11 @@ public class Generics {
|
||||
return list;
|
||||
}
|
||||
|
||||
public <T> List<T> genericMethod(List<T> list) {
|
||||
return list.stream().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Object> withErasure(List<Object> list) {
|
||||
return list.stream().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -5,3 +5,4 @@ This module contains articles about core Java non-blocking input and output (IO)
|
||||
## Relevant Articles:
|
||||
|
||||
- [Determine File Creation Date in Java](https://www.baeldung.com/java-file-creation-date)
|
||||
- [Find the Number of Lines in a File Using Jav](https://www.baeldung.com/java-file-number-of-lines)
|
||||
|
||||
@@ -14,3 +14,5 @@ This module contains articles about core Java Security
|
||||
- [Enabling TLS v1.2 in Java 7](https://www.baeldung.com/java-7-tls-v12)
|
||||
- [The Java SecureRandom Class](https://www.baeldung.com/java-secure-random)
|
||||
- [An Introduction to Java SASL](https://www.baeldung.com/java-sasl)
|
||||
- [A Guide to Java GSS API](https://www.baeldung.com/java-gss)
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
## Java String Conversions
|
||||
|
||||
This module contains articles about string conversions from/to another type.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Java String Conversions](https://www.baeldung.com/java-string-conversions)
|
||||
- [Convert String to Byte Array and Reverse in Java](https://www.baeldung.com/java-string-to-byte-array)
|
||||
- [Convert Char Array to String](https://www.baeldung.com/java-char-array-to-string)
|
||||
- More articles: [[<-- prev]](/core-java-string-conversions)
|
||||
47
core-java-modules/core-java-string-conversions-2/pom.xml
Normal file
47
core-java-modules/core-java-string-conversions-2/pom.xml
Normal file
@@ -0,0 +1,47 @@
|
||||
<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>core-java-string-conversions-2</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>core-java-string-conversions-2</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-string-conversions-2</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.datetime;
|
||||
package com.baeldung.stringconversions;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string.charArrayToString;
|
||||
package com.baeldung.chararraytostring;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.java.conversion;
|
||||
package com.baeldung.stringconversions;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -13,8 +13,6 @@ import java.util.GregorianCalendar;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.datetime.UseLocalDateTime;
|
||||
|
||||
public class StringConversionUnitTest {
|
||||
|
||||
@Test
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string.conversion;
|
||||
package com.baeldung.stringtobytearray;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string.conversion;
|
||||
package com.baeldung.stringtobytearray;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
16
core-java-modules/core-java-string-conversions/README.md
Normal file
16
core-java-modules/core-java-string-conversions/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
## Java String Conversions
|
||||
|
||||
This module contains articles about string conversions from/to another type.
|
||||
|
||||
### Relevant Articles:
|
||||
- [Converting String to Stream of chars](https://www.baeldung.com/java-string-to-stream)
|
||||
- [Converting Strings to Enums in Java](https://www.baeldung.com/java-string-to-enum)
|
||||
- [Convert a String to Title Case](https://www.baeldung.com/java-string-title-case)
|
||||
- [Convert java.util.Date to String](https://www.baeldung.com/java-util-date-to-string)
|
||||
- [Converting a Stack Trace to a String in Java](https://www.baeldung.com/java-stacktrace-to-string)
|
||||
- [Image to Base64 String Conversion](https://www.baeldung.com/java-base64-image-string)
|
||||
- [Convert a Comma Separated String to a List in Java](https://www.baeldung.com/java-string-with-separator-to-list)
|
||||
- [Converting Java String to Double](https://www.baeldung.com/java-string-to-double)
|
||||
- [Convert Char to String in Java](https://www.baeldung.com/java-convert-char-to-string)
|
||||
- [Convert String to int or Integer in Java](https://www.baeldung.com/java-convert-string-to-int-or-integer)
|
||||
- More articles: [[next -->]](/core-java-string-conversions-2)
|
||||
67
core-java-modules/core-java-string-conversions/pom.xml
Normal file
67
core-java-modules/core-java-string-conversions/pom.xml
Normal file
@@ -0,0 +1,67 @@
|
||||
<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>core-java-string-conversions</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>core-java-string-conversions</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-java</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-java</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.ibm.icu</groupId>
|
||||
<artifactId>icu4j</artifactId>
|
||||
<version>${icu4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>${assertj.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${org.hamcrest.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>core-java-string-conversions</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<icu4j.version>61.1</icu4j.version>
|
||||
<assertj.version>3.6.1</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.enums;
|
||||
package com.baeldung.stringtoenum;
|
||||
|
||||
public enum PizzaStatusEnum {
|
||||
ORDERED(5) {
|
||||
@@ -1,12 +1,11 @@
|
||||
package com.baeldung.string;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
package com.baeldung.titlecase;
|
||||
|
||||
import com.ibm.icu.lang.UCharacter;
|
||||
import com.ibm.icu.text.BreakIterator;
|
||||
import org.apache.commons.lang3.text.WordUtils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TitleCaseConverter {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung;
|
||||
package com.baeldung.chartostring;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.baeldung.string.formatter;
|
||||
package com.baeldung.datetostring;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -13,8 +14,7 @@ import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class DateToStringFormatterUnitTest {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.baeldung.fileToBase64StringConversion;
|
||||
package com.baeldung.filetobase64conversion;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class FileToBase64StringConversionUnitTest {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string.todouble;
|
||||
package com.baeldung.stringtodouble;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.enums;
|
||||
package com.baeldung.stringtoenum;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class PizzaUnitTest {
|
||||
public class StringToEnumUnitTest {
|
||||
|
||||
@Test
|
||||
public void whenConvertedIntoEnum_thenGetsConvertedCorrectly() {
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung;
|
||||
package com.baeldung.stringtoint;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -1,135 +1,134 @@
|
||||
package com.baeldung;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class ConvertStringToListUnitTest {
|
||||
|
||||
private final String countries = "Russia,Germany,England,France,Italy";
|
||||
private final String ranks = "1,2,3,4,5, 6,7";
|
||||
private final String emptyStrings = ",,,,,";
|
||||
private final List<String> expectedCountriesList = Arrays.asList("Russia", "Germany", "England", "France", "Italy");
|
||||
private final List<Integer> expectedRanksList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||
private final List<String> expectedEmptyStringsList = Arrays.asList("", "", "", "", "", "");
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByJava() {
|
||||
List<String> convertedCountriesList = Arrays.asList(countries.split(",", -1));
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByApache() {
|
||||
List<String> convertedCountriesList = Arrays.asList(StringUtils.splitPreserveAllTokens(countries, ","));
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByGuava() {
|
||||
List<String> convertedCountriesList = Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(countries);
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByJava8() {
|
||||
List<String> convertedCountriesList = Stream.of(countries.split(",", -1))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByJava() {
|
||||
String[] convertedRankArray = ranks.split(",");
|
||||
List<Integer> convertedRankList = new ArrayList<Integer>();
|
||||
for (String number : convertedRankArray) {
|
||||
convertedRankList.add(Integer.parseInt(number.trim()));
|
||||
}
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByGuava() {
|
||||
List<Integer> convertedRankList = Lists.transform(Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(ranks), new Function<String, Integer>() {
|
||||
@Override
|
||||
public Integer apply(String input) {
|
||||
return Integer.parseInt(input.trim());
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByJava8() {
|
||||
List<Integer> convertedRankList = Stream.of(ranks.split(","))
|
||||
.map(String::trim)
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByApache() {
|
||||
String[] convertedRankArray = StringUtils.split(ranks, ",");
|
||||
List<Integer> convertedRankList = new ArrayList<Integer>();
|
||||
for (String number : convertedRankArray) {
|
||||
convertedRankList.add(Integer.parseInt(number.trim()));
|
||||
}
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByJava() {
|
||||
List<String> convertedEmptyStringsList = Arrays.asList(emptyStrings.split(",", -1));
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByApache() {
|
||||
List<String> convertedEmptyStringsList = Arrays.asList(StringUtils.splitPreserveAllTokens(emptyStrings, ","));
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByGuava() {
|
||||
List<String> convertedEmptyStringsList = Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(emptyStrings);
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByJava8() {
|
||||
List<String> convertedEmptyStringsList = Stream.of(emptyStrings.split(",", -1))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
}
|
||||
package com.baeldung.stringtolist;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ConvertStringToListUnitTest {
|
||||
|
||||
private final String countries = "Russia,Germany,England,France,Italy";
|
||||
private final String ranks = "1,2,3,4,5, 6,7";
|
||||
private final String emptyStrings = ",,,,,";
|
||||
private final List<String> expectedCountriesList = Arrays.asList("Russia", "Germany", "England", "France", "Italy");
|
||||
private final List<Integer> expectedRanksList = Arrays.asList(1, 2, 3, 4, 5, 6, 7);
|
||||
private final List<String> expectedEmptyStringsList = Arrays.asList("", "", "", "", "", "");
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByJava() {
|
||||
List<String> convertedCountriesList = Arrays.asList(countries.split(",", -1));
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByApache() {
|
||||
List<String> convertedCountriesList = Arrays.asList(StringUtils.splitPreserveAllTokens(countries, ","));
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByGuava() {
|
||||
List<String> convertedCountriesList = Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(countries);
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfStringByJava8() {
|
||||
List<String> convertedCountriesList = Stream.of(countries.split(",", -1))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedCountriesList, convertedCountriesList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByJava() {
|
||||
String[] convertedRankArray = ranks.split(",");
|
||||
List<Integer> convertedRankList = new ArrayList<Integer>();
|
||||
for (String number : convertedRankArray) {
|
||||
convertedRankList.add(Integer.parseInt(number.trim()));
|
||||
}
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByGuava() {
|
||||
List<Integer> convertedRankList = Lists.transform(Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(ranks), new Function<String, Integer>() {
|
||||
@Override
|
||||
public Integer apply(String input) {
|
||||
return Integer.parseInt(input.trim());
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByJava8() {
|
||||
List<Integer> convertedRankList = Stream.of(ranks.split(","))
|
||||
.map(String::trim)
|
||||
.map(Integer::parseInt)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenString_thenGetListOfIntegerByApache() {
|
||||
String[] convertedRankArray = StringUtils.split(ranks, ",");
|
||||
List<Integer> convertedRankList = new ArrayList<Integer>();
|
||||
for (String number : convertedRankArray) {
|
||||
convertedRankList.add(Integer.parseInt(number.trim()));
|
||||
}
|
||||
|
||||
assertEquals(expectedRanksList, convertedRankList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByJava() {
|
||||
List<String> convertedEmptyStringsList = Arrays.asList(emptyStrings.split(",", -1));
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByApache() {
|
||||
List<String> convertedEmptyStringsList = Arrays.asList(StringUtils.splitPreserveAllTokens(emptyStrings, ","));
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByGuava() {
|
||||
List<String> convertedEmptyStringsList = Splitter.on(",")
|
||||
.trimResults()
|
||||
.splitToList(emptyStrings);
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEmptyStrings_thenGetListOfStringByJava8() {
|
||||
List<String> convertedEmptyStringsList = Stream.of(emptyStrings.split(",", -1))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
assertEquals(expectedEmptyStringsList, convertedEmptyStringsList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string;
|
||||
package com.baeldung.stringtostream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.baeldung.string;
|
||||
package com.baeldung.titlecase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 2.8 KiB |
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.builder
|
||||
|
||||
class FoodOrder(
|
||||
class FoodOrder private constructor(
|
||||
val bread: String?,
|
||||
val condiments: String?,
|
||||
val meat: String?,
|
||||
|
||||
@@ -6,9 +6,9 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLPeerUnverifiedException;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
@@ -46,7 +46,7 @@ public class RestClientLiveManualTest {
|
||||
// old httpClient will throw UnsupportedOperationException
|
||||
@Ignore
|
||||
@Test
|
||||
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk_1() throws GeneralSecurityException {
|
||||
public final void givenAcceptingAllCertificates_whenHttpsUrlIsConsumed_thenOk() throws GeneralSecurityException {
|
||||
final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
final CloseableHttpClient httpClient = (CloseableHttpClient) requestFactory.getHttpClient();
|
||||
|
||||
@@ -92,7 +92,7 @@ public class RestClientLiveManualTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void givenAcceptingAllCertificatesUsing4_4_whenHttpsUrlIsConsumedUsingRestTemplate_thenCorrect() throws ClientProtocolException, IOException {
|
||||
public final void givenAcceptingAllCertificatesUsing4_4_whenUsingRestTemplate_thenCorrect() throws ClientProtocolException, IOException {
|
||||
final CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
|
||||
final HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
|
||||
requestFactory.setHttpClient(httpClient);
|
||||
@@ -101,4 +101,12 @@ public class RestClientLiveManualTest {
|
||||
assertThat(response.getStatusCode().value(), equalTo(200));
|
||||
}
|
||||
|
||||
@Test(expected = SSLPeerUnverifiedException.class)
|
||||
public void whenHttpsUrlIsConsumed_thenException() throws ClientProtocolException, IOException {
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
String urlOverHttps = "https://localhost:8082/httpclient-simple";
|
||||
HttpGet getMethod = new HttpGet(urlOverHttps);
|
||||
HttpResponse response = httpClient.execute(getMethod);
|
||||
assertThat(response.getStatusLine().getStatusCode(), equalTo(200));
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user