This commit is contained in:
Gang Wu
2020-02-11 21:59:58 -07:00
107 changed files with 633 additions and 334 deletions
+4
View File
@@ -16,4 +16,8 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Maximum Subarray Problem](https://www.baeldung.com/java-maximum-subarray)
- [How to Merge Two Sorted Arrays](https://www.baeldung.com/java-merge-sorted-arrays)
- [Median of Stream of Integers using Heap](https://www.baeldung.com/java-stream-integers-median-using-heap)
- [Kruskal’s Algorithm for Spanning Trees](https://www.baeldung.com/java-spanning-trees-kruskal)
- [Balanced Brackets Algorithm in Java](https://www.baeldung.com/java-balanced-brackets-algorithm)
- [Efficiently Merge Sorted Java Sequences](https://www.baeldung.com/java-merge-sorted-sequences)
- [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms)
- More articles: [[<-- prev]](/../algorithms-miscellaneous-4)
+3
View File
@@ -0,0 +1,3 @@
### Relevant Articles:
- [Partitioning and Sorting Arrays with Many Repeated Entries](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries)
+3
View File
@@ -6,3 +6,6 @@ This module contains articles about Apache POI
- [Microsoft Word Processing in Java with Apache POI](https://www.baeldung.com/java-microsoft-word-with-apache-poi)
- [Working with Microsoft Excel in Java](https://www.baeldung.com/java-microsoft-excel)
- [Creating a MS PowerPoint Presentation in Java](https://www.baeldung.com/apache-poi-slideshow)
- [Merge Cells in Excel Using Apache POI](https://www.baeldung.com/java-apache-poi-merge-cells)
- [Get String Value of Excel Cell with Apache POI](https://www.baeldung.com/java-apache-poi-cell-string-value)
- [Read Excel Cell Value Rather Than Formula With Apache POI](https://github.com/eugenp/tutorials/tree/master/apache-poi)
+2
View File
@@ -3,3 +3,5 @@
This module contains articles about Apache RocketMQ
### Relevant Articles:
- [Apache RocketMQ with Spring Boot](https://www.baeldung.com/apache-rocketmq-spring-boot)
+1
View File
@@ -1,3 +1,4 @@
### Relevant articles:
- [Java Switch Statement](https://www.baeldung.com/java-switch)
- [New Java 13 Features](https://www.baeldung.com/java-13-new-features)
@@ -13,4 +13,5 @@ This module contains articles about Java arrays
- [Removing an Element from an Array in Java](https://www.baeldung.com/java-array-remove-element)
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)
- [Adding an Element to a Java Array vs an ArrayList](https://www.baeldung.com/java-add-element-to-array-vs-list)
- [Arrays.sort vs Arrays.parallelSort](https://www.baeldung.com/java-arrays-sort-vs-parallelsort)
- [[<-- Prev]](/core-java-modules/core-java-arrays)
@@ -69,7 +69,7 @@ public class SortComparisonUnitTest {
}
@Test
public void givenArrayOfIntegers_whenUsingArraysSortMethodWithRange_thenSortRangeOfArrayInAscendingOrder() {
public void givenArrayOfIntegers_whenUsingArraysSortWithRange_thenSortRangeOfArrayAsc() {
int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
int[] expected = { 10, 4, 1, 2, 6, 7, 8, 9, 3, 5 };
@@ -89,7 +89,7 @@ public class SortComparisonUnitTest {
}
@Test
public void givenArrayOfIntegers_whenUsingArraysParallelSortMethodWithRange_thenSortRangeOfArrayInAscendingOrder() {
public void givenArrayOfIntegers_whenUsingArraysParallelSortWithRange_thenSortRangeOfArrayAsc() {
int[] array = { 10, 4, 6, 2, 1, 9, 7, 8, 3, 5 };
int[] expected = { 10, 4, 1, 2, 6, 7, 8, 9, 3, 5 };
@@ -8,4 +8,6 @@ This module contains articles about advanced topics about multithreading with co
- [Common Concurrency Pitfalls in Java](https://www.baeldung.com/java-common-concurrency-pitfalls)
- [Guide to RejectedExecutionHandler](https://www.baeldung.com/java-rejectedexecutionhandler)
[[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2)
- [Guide to Work Stealing in Java](https://www.baeldung.com/java-work-stealing)
- [Asynchronous Programming in Java](https://www.baeldung.com/java-asynchronous-programming)
- [[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2)
@@ -6,4 +6,5 @@ This module contains articles about date operations in Java.
- [Skipping Weekends While Adding Days to LocalDate in Java 8](https://www.baeldung.com/java-localdate-add-days-skip-weekends)
- [Checking If Two Java Dates Are on the Same Day](https://www.baeldung.com/java-check-two-dates-on-same-day)
- [Converting Java Date to OffsetDateTime](https://www.baeldung.com/java-convert-date-to-offsetdatetime)
- [How to Set the JVM Time Zone](https://www.baeldung.com/java-jvm-time-zone)
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)
@@ -0,0 +1,3 @@
### Relevant Articles:
- [Creating a LocalDate with Values in Java](https://www.baeldung.com/java-creating-localdate-with-values)
@@ -6,3 +6,4 @@ This module contains articles about core java exceptions
- [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice)
- [Wrapping vs Rethrowing Exceptions in Java](https://www.baeldung.com/java-wrapping-vs-rethrowing-exceptions)
- [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception)
@@ -0,0 +1,32 @@
package com.baeldung.socketexception;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public class SocketClient {
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
public void startConnection(String ip, int port) throws IOException {
clientSocket = new Socket(ip, port);
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
}
public String sendMessage(String msg) throws IOException {
out.println(msg);
return in.readLine();
}
public void stopConnection() throws IOException {
in.close();
out.close();
clientSocket.close();
}
}
@@ -0,0 +1,45 @@
package com.baeldung.socketexception;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class SocketServer {
private ServerSocket serverSocket;
private Socket clientSocket;
private PrintWriter out;
private BufferedReader in;
public void start(int port) {
try {
serverSocket = new ServerSocket(port);
clientSocket = serverSocket.accept();
out = new PrintWriter(clientSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String msg = in.readLine();
if (msg.contains("hi"))
out.println("hi");
else
out.println("didn't understand");
close();
stop();
} catch (IOException e) {
}
}
private void close() throws IOException {
in.close();
out.close();
}
private void stop() throws IOException {
clientSocket.close();
serverSocket.close();
}
}
@@ -0,0 +1,31 @@
package com.baeldung.socketexception;
import java.io.IOException;
import java.net.SocketException;
import java.util.concurrent.Executors;
import org.junit.BeforeClass;
import org.junit.Test;
public class SocketExceptionHandlingUnitTest {
@BeforeClass
public static void runServer() throws IOException, InterruptedException {
Executors.newSingleThreadExecutor()
.submit(() -> new SocketServer().start(6699));
Thread.sleep(100);
}
@Test
public void givenRunningServer_whenConnectToClosedSocket_thenHandleException() throws IOException {
SocketClient client = new SocketClient();
client.startConnection("127.0.0.1", 6699);
try {
client.sendMessage("hi");
client.sendMessage("hi again");
} catch (SocketException e) {
client.stopConnection();
}
}
}
@@ -7,4 +7,6 @@ This module contains articles about core features in the Java language
- [Command-Line Arguments in Java](https://www.baeldung.com/java-command-line-arguments)
- [What is a POJO Class?](https://www.baeldung.com/java-pojo-class)
- [Java Default Parameters Using Method Overloading](https://www.baeldung.com/java-default-parameters-method-overloading)
- [How to Return Multiple Values From a Java Method](https://www.baeldung.com/java-method-return-multiple-values)
- [Guide to the Java finally Keyword](https://www.baeldung.com/java-finally-keyword)
- [[<-- Prev]](/core-java-modules/core-java-lang)
@@ -9,3 +9,4 @@
- [The strictfp Keyword in Java](https://www.baeldung.com/java-strictfp)
- [Basic Calculator in Java](https://www.baeldung.com/java-basic-calculator)
- [Overflow and Underflow in Java](https://www.baeldung.com/java-overflow-underflow)
- [Obtaining a Power Set of a Set in Java](https://www.baeldung.com/java-power-set-of-a-set)
@@ -12,4 +12,5 @@ This module contains articles about Java syntax
- [Variable Scope in Java](https://www.baeldung.com/java-variable-scope)
- [Introduction to Basic Syntax in Java](https://www.baeldung.com/java-syntax)
- [Java ‘protected’ Access Modifier](https://www.baeldung.com/java-protected-access-modifier)
- [Using the Not Operator in If Conditions in Java](https://www.baeldung.com/java-using-not-in-if-conditions)
- [[<-- Prev]](/core-java-modules/core-java-lang-syntax)
@@ -13,4 +13,7 @@ This module contains articles about Java syntax
- [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java)
- [Java Switch Statement](https://www.baeldung.com/java-switch)
- [Breaking Out of Nested Loops](https://www.baeldung.com/java-breaking-out-nested-loop)
- [Java Do-While Loop](https://www.baeldung.com/java-do-while-loop)
- [Java While Loop](https://www.baeldung.com/java-while-loop)
- [Java For Loop](https://www.baeldung.com/java-for-loop)
- [[More -->]](/core-java-modules/core-java-lang-syntax-2)
@@ -6,4 +6,5 @@
- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
- [Call Methods at Runtime Using Java Reflection](http://www.baeldung.com/java-method-reflection)
- [Changing Annotation Parameters At Runtime](http://www.baeldung.com/java-reflection-change-annotation-params)
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
- [Dynamic Proxies in Java](http://www.baeldung.com/java-dynamic-proxies)
- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
+3 -1
View File
@@ -5,4 +5,6 @@
### Relevant Articles:
- [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance)
- [A Guide To Java Regular Expressions API](http://www.baeldung.com/regular-expressions-java)
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
- [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char)
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
- [Difference Between Java Matcher find() and matches()](https://www.baeldung.com/java-matcher-find-vs-matches)
@@ -1,7 +0,0 @@
=========
## Core Java 8 Cookbooks and Examples
### Relevant Articles:
- [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance)
- [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile)
+1 -1
View File
@@ -4,5 +4,5 @@ This module contains articles about Kotlin core features.
### Relevant articles:
- [Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates)
- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-conditional-operator)
- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-operator)
- [[<-- Prev]](/core-kotlin-modules/core-kotlin)
+1 -1
View File
@@ -3,7 +3,7 @@
This module contains articles about Kotlin core features.
### Relevant articles:
- [Introduction to the Kotlin Language](https://www.baeldung.com/kotlin)
- [Introduction to the Kotlin Language](https://www.baeldung.com/kotlin-intro)
- [Kotlin Java Interoperability](https://www.baeldung.com/kotlin-java-interoperability)
- [Get a Random Number in Kotlin](https://www.baeldung.com/kotlin-random-number)
- [Create a Java and Kotlin Project with Maven](https://www.baeldung.com/kotlin-maven-java-project)
+1
View File
@@ -8,3 +8,4 @@ This module contains articles about data structures in Java
- [Implementing a Binary Tree in Java](https://www.baeldung.com/java-binary-tree)
- [Circular Linked List Java Implementation](https://www.baeldung.com/java-circular-linked-list)
- [How to Print a Binary Tree Diagram](https://www.baeldung.com/java-print-binary-tree-diagram)
- [Introduction to Big Queue](https://www.baeldung.com/java-big-queue)
+5 -1
View File
@@ -1 +1,5 @@
# Dropwizard
# Dropwizard
### Relevant Articles:
- [Introduction to Dropwizard](https://www.baeldung.com/java-dropwizard)
+4
View File
@@ -0,0 +1,4 @@
### Relevant Articles:
- [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers)
- [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long)
+1
View File
@@ -3,3 +3,4 @@
This module contains articles about JSON.
### Relevant Articles:
- [Introduction to Jsoniter](https://www.baeldung.com/java-jsoniter)
+2
View File
@@ -9,3 +9,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m
### Relevant Articles:
- [Parsing Command-Line Parameters with JCommander](https://www.baeldung.com/jcommander-parsing-command-line-parameters)
- [Guide to the Cactoos Library](https://www.baeldung.com/java-cactoos)
- [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline)
@@ -0,0 +1,90 @@
package com.baeldung.libraries.snakeyaml;
import org.junit.Before;
import org.junit.Test;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.InputStream;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class MultiLineStringsUnitTest {
private Yaml yaml;
@Before
public void setup() {
yaml = new Yaml();
}
@Test
public void whenLiteral_ThenLineBreaksArePresent() {
String key = parseYamlKey("literal.yaml", "key");
assertEquals("Line1\nLine2\nLine3", key);
}
@Test
public void whenLiteral_ThenEndingBreaksAreReducedToOne() {
String key = parseYamlKey("literal2.yaml", "key");
assertEquals("\n\nLine1\n\nLine2\n\nLine3\n", key);
}
@Test
public void whenFolded_ThenLineBreaksAreReplaced() {
String key = parseYamlKey("folded.yaml", "key");
assertEquals("Line1 Line2 Line3", key);
}
@Test
public void whenFolded_ThenEmptyLinesAreReducedToOne() {
String key = parseYamlKey("folded2.yaml", "key");
assertEquals("Line1 Line2\n\nLine3\n", key);
}
@Test
public void whenLiteralKeep_ThenLastEmptyLinesArePresent() {
String key = parseYamlKey("literal_keep.yaml", "key");
assertEquals("Line1\nLine2\nLine3\n\n", key);
}
@Test
public void whenLiteralStrip_ThenLastEmptyLinesAreRemoved() {
String key = parseYamlKey("literal_strip.yaml", "key");
assertEquals("Line1\nLine2\nLine3", key);
}
@Test
public void whenFoldedKeep_ThenLastEmptyLinesArePresent() {
String key = parseYamlKey("folded_keep.yaml", "key");
assertEquals("Line1 Line2 Line3\n\n\n", key);
}
@Test
public void whenFoldedStrip_ThenLastEmptyLinesAreRemoved() {
String key = parseYamlKey("folded_strip.yaml", "key");
assertEquals("Line1 Line2 Line3", key);
}
@Test
public void whenDoubleQuotes_ThenExplicitBreaksArePreserved() {
String key = parseYamlKey("plain_double_quotes.yaml", "key");
assertEquals("Line1\nLine2\nLine3", key);
}
@Test
public void whenSingleQuotes_ThenExplicitBreaksAreIgnored() {
String key = parseYamlKey("plain_single_quotes.yaml", "key");
assertEquals("Line1\\nLine2\nLine3", key);
}
String parseYamlKey(String fileName, String key) {
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream("yaml" + File.separator + "multiline" + File.separator + fileName);
Map<String, String> parsed = yaml.load(inputStream);
return parsed.get(key);
}
}
@@ -0,0 +1,4 @@
key: >
Line1
Line2
Line3

Some files were not shown because too many files have changed in this diff Show More