diff --git a/.gitignore b/.gitignore
index c54117203f..88c5e49808 100644
--- a/.gitignore
+++ b/.gitignore
@@ -85,5 +85,9 @@ transaction.log
*-shell.log
apache-cxf/cxf-aegis/baeldung.xml
+testing-modules/report-*.json
-libraries-2/*.db
\ No newline at end of file
+libraries-2/*.db
+
+# SDKMan
+.sdkmanrc
diff --git a/README.md b/README.md
index b08a93f23e..88750cf654 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-**UPDATE**: The price of "Learn Spring Security OAuth" will permanently change on the 11th of December, along with the upcoming OAuth2 material: http://bit.ly/github-lss
-
The Courses
==============================
diff --git a/akka-http/pom.xml b/akka-http/pom.xml
index c0b460dd8e..c146e58b60 100644
--- a/akka-http/pom.xml
+++ b/akka-http/pom.xml
@@ -38,8 +38,6 @@
- UTF-8
- UTF-810.0.112.5.11
diff --git a/algorithms-genetic/README.md b/algorithms-genetic/README.md
index 1c9e831ac2..eb4e3fb798 100644
--- a/algorithms-genetic/README.md
+++ b/algorithms-genetic/README.md
@@ -5,6 +5,6 @@ This module contains articles about genetic algorithms.
### Relevant articles:
- [Introduction to Jenetics Library](https://www.baeldung.com/jenetics)
-- [Ant Colony Optimization](https://www.baeldung.com/java-ant-colony-optimization)
+- [Ant Colony Optimization with a Java Example](https://www.baeldung.com/java-ant-colony-optimization)
- [Design a Genetic Algorithm in Java](https://www.baeldung.com/java-genetic-algorithm)
- [The Traveling Salesman Problem in Java](https://www.baeldung.com/java-simulated-annealing-for-traveling-salesman)
diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml
index 942acd69c6..4d15464138 100644
--- a/algorithms-genetic/pom.xml
+++ b/algorithms-genetic/pom.xml
@@ -44,18 +44,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.6.13.7.0
diff --git a/algorithms-miscellaneous-1/README.md b/algorithms-miscellaneous-1/README.md
index 25e2733538..02bf874197 100644
--- a/algorithms-miscellaneous-1/README.md
+++ b/algorithms-miscellaneous-1/README.md
@@ -6,8 +6,8 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
### Relevant articles:
- [Validating Input With Finite Automata in Java](https://www.baeldung.com/java-finite-automata)
-- [Example of Hill Climbing Algorithm](https://www.baeldung.com/java-hill-climbing-algorithm)
-- [Introduction to Minimax Algorithm](https://www.baeldung.com/java-minimax-algorithm)
+- [Example of Hill Climbing Algorithm in Java](https://www.baeldung.com/java-hill-climbing-algorithm)
+- [Introduction to Minimax Algorithm with a Java Implementation](https://www.baeldung.com/java-minimax-algorithm)
- [How to Calculate Levenshtein Distance in Java?](https://www.baeldung.com/java-levenshtein-distance)
- [How to Find the Kth Largest Element in Java](https://www.baeldung.com/java-kth-largest-element)
-- More articles: [[next -->]](/../algorithms-miscellaneous-2)
+- More articles: [[next -->]](/algorithms-miscellaneous-2)
diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml
index d9ecbd78e8..00cb4eeda9 100644
--- a/algorithms-miscellaneous-1/pom.xml
+++ b/algorithms-miscellaneous-1/pom.xml
@@ -49,18 +49,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
diff --git a/algorithms-miscellaneous-2/README.md b/algorithms-miscellaneous-2/README.md
index 26737b61f0..265416534e 100644
--- a/algorithms-miscellaneous-2/README.md
+++ b/algorithms-miscellaneous-2/README.md
@@ -14,4 +14,4 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Displaying Money Amounts in Words](https://www.baeldung.com/java-money-into-words)
- [A Collaborative Filtering Recommendation System in Java](https://www.baeldung.com/java-collaborative-filtering-recommendations)
- [Implementing A* Pathfinding in Java](https://www.baeldung.com/java-a-star-pathfinding)
-- More articles: [[<-- prev]](/../algorithms-miscellaneous-1) [[next -->]](/../algorithms-miscellaneous-3)
+- More articles: [[<-- prev]](/algorithms-miscellaneous-1) [[next -->]](/algorithms-miscellaneous-3)
diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml
index 7144a7a391..89d5b3657a 100644
--- a/algorithms-miscellaneous-2/pom.xml
+++ b/algorithms-miscellaneous-2/pom.xml
@@ -54,18 +54,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml
index 877e8bfefa..166a7be623 100644
--- a/algorithms-miscellaneous-3/pom.xml
+++ b/algorithms-miscellaneous-3/pom.xml
@@ -74,25 +74,11 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.9.04.328.0-jre2.6.0
- 1.19
- 1.193.8.11.1.0
diff --git a/algorithms-miscellaneous-4/README.md b/algorithms-miscellaneous-4/README.md
index fd33b58d72..2649df9fc9 100644
--- a/algorithms-miscellaneous-4/README.md
+++ b/algorithms-miscellaneous-4/README.md
@@ -5,8 +5,8 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
### Relevant articles:
- [Multi-Swarm Optimization Algorithm in Java](https://www.baeldung.com/java-multi-swarm-algorithm)
-- [Check If a String Contains All The Letters of The Alphabet](https://www.baeldung.com/java-string-contains-all-letters)
-- [Find the Middle Element of a Linked List](https://www.baeldung.com/java-linked-list-middle-element)
+- [Check If a String Contains All The Letters of The Alphabet with Java](https://www.baeldung.com/java-string-contains-all-letters)
+- [Find the Middle Element of a Linked List in Java](https://www.baeldung.com/java-linked-list-middle-element)
- [Find Substrings That Are Palindromes in Java](https://www.baeldung.com/java-palindrome-substrings)
- [Find the Longest Substring without Repeating Characters](https://www.baeldung.com/java-longest-substring-without-repeated-characters)
- [Permutations of an Array in Java](https://www.baeldung.com/java-array-permutations)
diff --git a/algorithms-miscellaneous-4/pom.xml b/algorithms-miscellaneous-4/pom.xml
index 50fef5ff71..31a6db5354 100644
--- a/algorithms-miscellaneous-4/pom.xml
+++ b/algorithms-miscellaneous-4/pom.xml
@@ -34,18 +34,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.9.027.0.1-jre
diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md
index 3e6eeb4c93..54b936586f 100644
--- a/algorithms-miscellaneous-5/README.md
+++ b/algorithms-miscellaneous-5/README.md
@@ -9,11 +9,11 @@ This module contains articles about algorithms. Some classes of algorithms, e.g.
- [Reversing a Binary Tree in Java](https://www.baeldung.com/java-reversing-a-binary-tree)
- [Find If Two Numbers Are Relatively Prime in Java](https://www.baeldung.com/java-two-relatively-prime-numbers)
- [Knapsack Problem Implementation in Java](https://www.baeldung.com/java-knapsack)
-- [How to Determine if a Binary Tree is Balanced](https://www.baeldung.com/java-balanced-binary-tree)
+- [How to Determine if a Binary Tree is Balanced in Java](https://www.baeldung.com/java-balanced-binary-tree)
- [Overview of Combinatorial Problems in Java](https://www.baeldung.com/java-combinatorial-algorithms)
-- [Prim’s Algorithm](https://www.baeldung.com/java-prim-algorithm)
-- [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)
-- More articles: [[<-- prev]](/../algorithms-miscellaneous-4) [[next -->]](/../algorithms-miscellaneous-6)
+- [Prim’s Algorithm with a Java Implementation](https://www.baeldung.com/java-prim-algorithm)
+- [Maximum Subarray Problem in Java](https://www.baeldung.com/java-maximum-subarray)
+- [How to Merge Two Sorted Arrays in Java](https://www.baeldung.com/java-merge-sorted-arrays)
+- [Median of Stream of Integers using Heap in Java](https://www.baeldung.com/java-stream-integers-median-using-heap)
+- More articles: [[<-- prev]](/algorithms-miscellaneous-4) [[next -->]](/algorithms-miscellaneous-6)
diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml
index 615cf03467..71a5a3d410 100644
--- a/algorithms-miscellaneous-5/pom.xml
+++ b/algorithms-miscellaneous-5/pom.xml
@@ -49,18 +49,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
1.0.13.9.0
diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java
index 0aaa1b6c23..60171220cd 100644
--- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java
+++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithm.java
@@ -13,22 +13,22 @@ public class KadaneAlgorithm {
int start = 0;
int end = 0;
- int maxSoFar = 0, maxEndingHere = 0;
-
+ int maxSoFar = arr[0], maxEndingHere = arr[0];
for (int i = 0; i < size; i++) {
if (arr[i] > maxEndingHere + arr[i]) {
start = i;
maxEndingHere = arr[i];
- } else
+ } else {
maxEndingHere = maxEndingHere + arr[i];
+ }
if (maxSoFar < maxEndingHere) {
maxSoFar = maxEndingHere;
end = i;
}
}
- logger.info("Found Maximum Subarray between {} and {}", start, end);
+ logger.info("Found Maximum Subarray between {} and {}", Math.min(start, end), end);
return maxSoFar;
}
}
diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java
index 9bece56f5b..71531dcf59 100644
--- a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java
+++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/maximumsubarray/KadaneAlgorithmUnitTest.java
@@ -9,11 +9,22 @@ class KadaneAlgorithmUnitTest {
@Test
void givenArrayWithNegativeNumberWhenMaximumSubarrayThenReturns6() {
//given
- int[] arr = new int[]{-3, 1, -8, 4, -1, 2, 1, -5, 5};
+ int[] arr = new int[] { -3, 1, -8, 4, -1, 2, 1, -5, 5 };
//when
KadaneAlgorithm algorithm = new KadaneAlgorithm();
int maxSum = algorithm.maxSubArraySum(arr);
//then
assertEquals(6, maxSum);
}
+
+ @Test
+ void givenArrayWithAllNegativeNumbersWhenMaximumSubarrayThenReturnsExpectedResult() {
+ //given
+ int[] arr = new int[] { -8, -7, -5, -4, -3, -1, -2 };
+ //when
+ KadaneAlgorithm algorithm = new KadaneAlgorithm();
+ int maxSum = algorithm.maxSubArraySum(arr);
+ //then
+ assertEquals(-1, maxSum);
+ }
}
\ No newline at end of file
diff --git a/algorithms-miscellaneous-6/README.md b/algorithms-miscellaneous-6/README.md
index 22ee51530f..f21eddeed8 100644
--- a/algorithms-miscellaneous-6/README.md
+++ b/algorithms-miscellaneous-6/README.md
@@ -1,10 +1,13 @@
### Relevant Articles:
-- [Boruvka’s Algorithm for Minimum Spanning Trees](https://www.baeldung.com/java-boruvka-algorithm)
+- [Boruvka’s Algorithm for Minimum Spanning Trees in Java](https://www.baeldung.com/java-boruvka-algorithm)
- [Gradient Descent in Java](https://www.baeldung.com/java-gradient-descent)
-- [Kruskal’s Algorithm for Spanning Trees](https://www.baeldung.com/java-spanning-trees-kruskal)
+- [Kruskal’s Algorithm for Spanning Trees with a Java Implementation](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)
- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher)
-- More articles: [[<-- prev]](/../algorithms-miscellaneous-5)
+- [Implementing a 2048 Solver in Java](https://www.baeldung.com/2048-java-solver)
+- [Finding Top K Elements in a Java Array](https://www.baeldung.com/java-array-top-elements)
+- [Reversing a Linked List in Java](https://www.baeldung.com/java-reverse-linked-list)
+- More articles: [[<-- prev]](/algorithms-miscellaneous-5)
diff --git a/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/LinkedListReversal.java b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/LinkedListReversal.java
new file mode 100644
index 0000000000..93402133ff
--- /dev/null
+++ b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/LinkedListReversal.java
@@ -0,0 +1,30 @@
+package com.baeldung.algorithms.linkedlist;
+
+public class LinkedListReversal {
+
+ ListNode reverseList(ListNode head) {
+ ListNode previous = null;
+ ListNode current = head;
+ while (current != null) {
+ ListNode nextElement = current.getNext();
+ current.setNext(previous);
+ previous = current;
+ current = nextElement;
+ }
+ return previous;
+ }
+
+ ListNode reverseListRecursive(ListNode head) {
+ if (head == null) {
+ return null;
+ }
+ if (head.getNext() == null) {
+ return head;
+ }
+ ListNode node = reverseListRecursive(head.getNext());
+ head.getNext().setNext(head);
+ head.setNext(null);
+ return node;
+ }
+
+}
diff --git a/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/ListNode.java b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/ListNode.java
new file mode 100644
index 0000000000..de2e93a65c
--- /dev/null
+++ b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/linkedlist/ListNode.java
@@ -0,0 +1,28 @@
+package com.baeldung.algorithms.linkedlist;
+
+public class ListNode {
+
+ private int data;
+ private ListNode next;
+
+ ListNode(int data) {
+ this.data = data;
+ this.next = null;
+ }
+
+ public int getData() {
+ return data;
+ }
+
+ public ListNode getNext() {
+ return next;
+ }
+
+ public void setData(int data) {
+ this.data = data;
+ }
+
+ public void setNext(ListNode next) {
+ this.next = next;
+ }
+}
diff --git a/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/linkedlist/LinkedListReversalUnitTest.java b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/linkedlist/LinkedListReversalUnitTest.java
new file mode 100644
index 0000000000..0940677959
--- /dev/null
+++ b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/linkedlist/LinkedListReversalUnitTest.java
@@ -0,0 +1,59 @@
+package com.baeldung.algorithms.linkedlist;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+public class LinkedListReversalUnitTest {
+ @Test
+ public void givenLinkedList_whenIterativeReverse_thenOutputCorrectResult() {
+ ListNode head = constructLinkedList();
+ ListNode node = head;
+ for (int i = 1; i <= 5; i++) {
+ assertNotNull(node);
+ assertEquals(i, node.getData());
+ node = node.getNext();
+ }
+ LinkedListReversal reversal = new LinkedListReversal();
+ node = reversal.reverseList(head);
+ for (int i = 5; i >= 1; i--) {
+ assertNotNull(node);
+ assertEquals(i, node.getData());
+ node = node.getNext();
+ }
+ }
+
+ @Test
+ public void givenLinkedList_whenRecursiveReverse_thenOutputCorrectResult() {
+ ListNode head = constructLinkedList();
+ ListNode node = head;
+ for (int i = 1; i <= 5; i++) {
+ assertNotNull(node);
+ assertEquals(i, node.getData());
+ node = node.getNext();
+ }
+ LinkedListReversal reversal = new LinkedListReversal();
+ node = reversal.reverseListRecursive(head);
+ for (int i = 5; i >= 1; i--) {
+ assertNotNull(node);
+ assertEquals(i, node.getData());
+ node = node.getNext();
+ }
+ }
+
+ private ListNode constructLinkedList() {
+ ListNode head = null;
+ ListNode tail = null;
+ for (int i = 1; i <= 5; i++) {
+ ListNode node = new ListNode(i);
+ if (head == null) {
+ head = node;
+ } else {
+ tail.setNext(node);
+ }
+ tail = node;
+ }
+ return head;
+ }
+}
diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md
index aed3c7d21f..7d10100832 100644
--- a/algorithms-searching/README.md
+++ b/algorithms-searching/README.md
@@ -3,11 +3,13 @@
This module contains articles about searching algorithms.
### Relevant articles:
+
- [Binary Search Algorithm in Java](https://www.baeldung.com/java-binary-search)
- [Depth First Search in Java](https://www.baeldung.com/java-depth-first-search)
- [Interpolation Search in Java](https://www.baeldung.com/java-interpolation-search)
- [Breadth-First Search Algorithm in Java](https://www.baeldung.com/java-breadth-first-search)
-- [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms)
-- [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search)
+- [String Search Algorithms for Large Texts with Java](https://www.baeldung.com/java-full-text-search-algorithms)
+- [Monte Carlo Tree Search for Tic-Tac-Toe Game in Java](https://www.baeldung.com/java-monte-carlo-tree-search)
- [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search)
-- [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree)
+- [Fast Pattern Matching of Strings Using Suffix Tree in Java](https://www.baeldung.com/java-pattern-matching-suffix-tree)
+- [Find the Kth Smallest Element in Two Sorted Arrays in Java](https://www.baeldung.com/java-kth-smallest-element-in-sorted-arrays)
diff --git a/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java b/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java
new file mode 100644
index 0000000000..2bd1a20ce0
--- /dev/null
+++ b/algorithms-searching/src/main/java/com/baeldung/algorithms/kthsmallest/KthSmallest.java
@@ -0,0 +1,126 @@
+package com.baeldung.algorithms.kthsmallest;
+
+import java.util.Arrays;
+import java.util.NoSuchElementException;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
+public class KthSmallest {
+
+ public static int findKthSmallestElement(int k, int[] list1, int[] list2) throws NoSuchElementException, IllegalArgumentException {
+
+ checkInput(k, list1, list2);
+
+ // we are looking for the minimum value
+ if(k == 1) {
+ return min(list1[0], list2[0]);
+ }
+
+ // we are looking for the maximum value
+ if(list1.length + list2.length == k) {
+ return max(list1[list1.length-1], list2[list2.length-1]);
+ }
+
+ // swap lists if needed to make sure we take at least one element from list1
+ if(k <= list2.length && list2[k-1] < list1[0]) {
+ int[] list1_ = list1;
+ list1 = list2;
+ list2 = list1_;
+ }
+
+ // correct left boundary if k is bigger than the size of list2
+ int left = k < list2.length ? 0 : k - list2.length - 1;
+
+ // the inital right boundary cannot exceed the list1
+ int right = min(k-1, list1.length - 1);
+
+ int nElementsList1, nElementsList2;
+
+ // binary search
+ do {
+ nElementsList1 = ((left + right) / 2) + 1;
+ nElementsList2 = k - nElementsList1;
+
+ if(nElementsList2 > 0) {
+ if (list1[nElementsList1 - 1] > list2[nElementsList2 - 1]) {
+ right = nElementsList1 - 2;
+ } else {
+ left = nElementsList1;
+ }
+ }
+ } while(!kthSmallesElementFound(list1, list2, nElementsList1, nElementsList2));
+
+ return nElementsList2 == 0 ? list1[nElementsList1-1] : max(list1[nElementsList1-1], list2[nElementsList2-1]);
+ }
+
+ private static boolean kthSmallesElementFound(int[] list1, int[] list2, int nElementsList1, int nElementsList2) {
+
+ // we do not take any element from the second list
+ if(nElementsList2 < 1) {
+ return true;
+ }
+
+ if(list1[nElementsList1-1] == list2[nElementsList2-1]) {
+ return true;
+ }
+
+ if(nElementsList1 == list1.length) {
+ return list1[nElementsList1-1] <= list2[nElementsList2];
+ }
+
+ if(nElementsList2 == list2.length) {
+ return list2[nElementsList2-1] <= list1[nElementsList1];
+ }
+
+ return list1[nElementsList1-1] <= list2[nElementsList2] && list2[nElementsList2-1] <= list1[nElementsList1];
+ }
+
+
+ private static void checkInput(int k, int[] list1, int[] list2) throws NoSuchElementException, IllegalArgumentException {
+
+ if(list1 == null || list2 == null || k < 1) {
+ throw new IllegalArgumentException();
+ }
+
+ if(list1.length == 0 || list2.length == 0) {
+ throw new IllegalArgumentException();
+ }
+
+ if(k > list1.length + list2.length) {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public static int getKthElementSorted(int[] list1, int[] list2, int k) {
+
+ int length1 = list1.length, length2 = list2.length;
+ int[] combinedArray = new int[length1 + length2];
+ System.arraycopy(list1, 0, combinedArray, 0, list1.length);
+ System.arraycopy(list2, 0, combinedArray, list1.length, list2.length);
+ Arrays.sort(combinedArray);
+
+ return combinedArray[k-1];
+ }
+
+ public static int getKthElementMerge(int[] list1, int[] list2, int k) {
+
+ int i1 = 0, i2 = 0;
+
+ while(i1 < list1.length && i2 < list2.length && (i1 + i2) < k) {
+ if(list1[i1] < list2[i2]) {
+ i1++;
+ } else {
+ i2++;
+ }
+ }
+
+ if((i1 + i2) < k) {
+ return i1 < list1.length ? list1[k - i2 - 1] : list2[k - i1 - 1];
+ } else if(i1 > 0 && i2 > 0) {
+ return Math.max(list1[i1-1], list2[i2-1]);
+ } else {
+ return i1 == 0 ? list2[i2-1] : list1[i1-1];
+ }
+ }
+}
diff --git a/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java b/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java
new file mode 100644
index 0000000000..740e89d8e7
--- /dev/null
+++ b/algorithms-searching/src/test/java/com/baeldung/algorithms/kthsmallest/KthSmallestUnitTest.java
@@ -0,0 +1,288 @@
+package com.baeldung.algorithms.kthsmallest;
+
+import org.junit.jupiter.api.Nested;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.function.Executable;
+
+import java.util.*;
+
+import static com.baeldung.algorithms.kthsmallest.KthSmallest.*;
+import static org.junit.jupiter.api.Assertions.*;
+
+public class KthSmallestUnitTest {
+
+ @Nested
+ class Exceptions {
+
+ @Test
+ public void when_at_least_one_list_is_null_then_an_exception_is_thrown() {
+
+ Executable executable1 = () -> findKthSmallestElement(1, null, null);
+ Executable executable2 = () -> findKthSmallestElement(1, new int[]{2}, null);
+ Executable executable3 = () -> findKthSmallestElement(1, null, new int[]{2});
+
+ assertThrows(IllegalArgumentException.class, executable1);
+ assertThrows(IllegalArgumentException.class, executable2);
+ assertThrows(IllegalArgumentException.class, executable3);
+ }
+
+ @Test
+ public void when_at_least_one_list_is_empty_then_an_exception_is_thrown() {
+
+ Executable executable1 = () -> findKthSmallestElement(1, new int[]{}, new int[]{2});
+ Executable executable2 = () -> findKthSmallestElement(1, new int[]{2}, new int[]{});
+ Executable executable3 = () -> findKthSmallestElement(1, new int[]{}, new int[]{});
+
+ assertThrows(IllegalArgumentException.class, executable1);
+ assertThrows(IllegalArgumentException.class, executable2);
+ assertThrows(IllegalArgumentException.class, executable3);
+ }
+
+ @Test
+ public void when_k_is_smaller_than_0_then_an_exception_is_thrown() {
+ Executable executable1 = () -> findKthSmallestElement(-1, new int[]{2}, new int[]{2});
+ assertThrows(IllegalArgumentException.class, executable1);
+ }
+
+ @Test
+ public void when_k_is_smaller_than_1_then_an_exception_is_thrown() {
+ Executable executable1 = () -> findKthSmallestElement(0, new int[]{2}, new int[]{2});
+ assertThrows(IllegalArgumentException.class, executable1);
+ }
+
+ @Test
+ public void when_k_bigger_then_the_two_lists_then_an_exception_is_thrown() {
+ Executable executable1 = () -> findKthSmallestElement(6, new int[]{1, 5, 6}, new int[]{2, 5});
+ assertThrows(NoSuchElementException.class, executable1);
+ }
+
+ }
+
+ @Nested
+ class K_is_smaller_than_the_size_of_list1_and_the_size_of_list2 {
+
+ @Test
+ public void when_k_is_1_then_the_smallest_element_is_returned_from_list1() {
+ int result = findKthSmallestElement(1, new int[]{2, 7}, new int[]{3, 5});
+ assertEquals(2, result);
+ }
+
+ @Test
+ public void when_k_is_1_then_the_smallest_element_is_returned_list2() {
+ int result = findKthSmallestElement(1, new int[]{3, 5}, new int[]{2, 7});
+ assertEquals(2, result);
+ }
+
+ @Test
+ public void when_kth_element_is_smallest_element_and_occurs_in_both_lists() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(1, list1, list2);
+ assertEquals(1, result);
+ }
+
+ @Test
+ public void when_kth_element_is_smallest_element_and_occurs_in_both_lists2() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(2, list1, list2);
+ assertEquals(1, result);
+ }
+
+ @Test
+ public void when_kth_element_is_largest_element_and_occurs_in_both_lists_1() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(5, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void when_kth_element_is_largest_element_and_occurs_in_both_lists_2() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(6, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void when_kth_element_and_occurs_in_both_lists() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{0, 2, 3};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(2, result);
+ }
+
+ @Test
+ public void and_kth_element_is_in_first_list() {
+ int[] list1 = new int[]{1,2,3,4};
+ int[] list2 = new int[]{1,3,4,5};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(2, result);
+ }
+
+ @Test
+ public void and_kth_is_in_second_list() {
+ int[] list1 = new int[]{1,3,4,4};
+ int[] list2 = new int[]{1,2,4,5};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(2, result);
+ }
+
+ @Test
+ public void and_elements_in_first_list_are_all_smaller_than_second_list() {
+ int[] list1 = new int[]{1,3,7,9};
+ int[] list2 = new int[]{11,12,14,15};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(7, result);
+ }
+
+ @Test
+ public void and_elements_in_first_list_are_all_smaller_than_second_list2() {
+ int[] list1 = new int[]{1,3,7,9};
+ int[] list2 = new int[]{11,12,14,15};
+ int result = findKthSmallestElement(4, list1, list2);
+ assertEquals(9, result);
+ }
+
+ @Test
+ public void and_only_elements_from_second_list_are_part_of_result() {
+ int[] list1 = new int[]{11,12,14,15};
+ int[] list2 = new int[]{1,3,7,9};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(7, result);
+ }
+
+ @Test
+ public void and_only_elements_from_second_list_are_part_of_result2() {
+ int[] list1 = new int[]{11,12,14,15};
+ int[] list2 = new int[]{1,3,7,9};
+ int result = findKthSmallestElement(4, list1, list2);
+ assertEquals(9, result);
+ }
+ }
+
+ @Nested
+ class K_is_bigger_than_the_size_of_at_least_one_of_the_lists {
+
+ @Test
+ public void k_is_smaller_than_list1_and_bigger_than_list2() {
+ int[] list1 = new int[]{1, 2, 3, 4, 7, 9};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(5, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void k_is_bigger_than_list1_and_smaller_than_list2() {
+ int[] list1 = new int[]{1, 2, 3};
+ int[] list2 = new int[]{1, 2, 3, 4, 7, 9};
+ int result = findKthSmallestElement(5, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void when_k_is_bigger_than_the_size_of_both_lists_and_elements_in_second_list_are_all_smaller_than_first_list() {
+ int[] list1 = new int[]{9, 11, 13, 55};
+ int[] list2 = new int[]{1, 2, 3, 7};
+ int result = findKthSmallestElement(6, list1, list2);
+ assertEquals(11, result);
+ }
+
+ @Test
+ public void when_k_is_bigger_than_the_size_of_both_lists_and_elements_in_second_list_are_all_bigger_than_first_list() {
+ int[] list1 = new int[]{1, 2, 3, 7};
+ int[] list2 = new int[]{9, 11, 13, 55};
+ int result = findKthSmallestElement(6, list1, list2);
+ assertEquals(11, result);
+ }
+
+ @Test
+ public void when_k_is_bigger_than_the_size_of_both_lists() {
+ int[] list1 = new int[]{3, 7, 9, 11, 55};
+ int[] list2 = new int[]{1, 2, 3, 7, 13};
+ int result = findKthSmallestElement(7, list1, list2);
+ assertEquals(9, result);
+ }
+
+ @Test
+ public void when_k_is_bigger_than_the_size_of_both_lists_and_list1_has_more_elements_than_list2() {
+ int[] list1 = new int[]{3, 7, 9, 11, 55, 77, 100, 200};
+ int[] list2 = new int[]{1, 2, 3, 7, 13};
+ int result = findKthSmallestElement(11, list1, list2);
+ assertEquals(77, result);
+ }
+
+ @Test
+ public void max_test() {
+ int[] list1 = new int[]{100, 200};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(4, list1, list2);
+ assertEquals(100, result);
+ }
+
+ @Test
+ public void max_test2() {
+ int[] list1 = new int[]{100, 200};
+ int[] list2 = new int[]{1, 2, 3};
+ int result = findKthSmallestElement(5, list1, list2);
+ assertEquals(200, result);
+ }
+
+ @Test
+ public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_in_list2() {
+ int[] list1 = new int[]{1, 2, 5};
+ int[] list2 = new int[]{1, 3, 4, 7};
+ int result = findKthSmallestElement(4, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_is_smallest_in_list2() {
+ int[] list1 = new int[]{1, 2, 5};
+ int[] list2 = new int[]{3, 4, 7};
+ int result = findKthSmallestElement(3, list1, list2);
+ assertEquals(3, result);
+ }
+
+ @Test
+ public void when_k_is_smaller_than_the_size_of_both_lists_and_kth_element_is_smallest_in_list23() {
+ int[] list1 = new int[]{3, 11, 27, 53, 90};
+ int[] list2 = new int[]{4, 20, 21, 100};
+ int result = findKthSmallestElement(5, list1, list2);
+ assertEquals(21, result);
+ }
+ }
+
+// @Test
+// public void randomTests() {
+// IntStream.range(1, 100000).forEach(i -> random());
+// }
+
+ private void random() {
+
+ Random random = new Random();
+ int length1 = (Math.abs(random.nextInt())) % 1000 + 1;
+ int length2 = (Math.abs(random.nextInt())) % 1000 + 1;
+
+ int[] list1 = sortedRandomIntArrayOfLength(length1);
+ int[] list2 = sortedRandomIntArrayOfLength(length2);
+
+ int k = (Math.abs(random.nextInt()) % (length1 + length2)) + 1 ;
+
+ int result = findKthSmallestElement(k, list1, list2);
+
+ int result2 = getKthElementSorted(list1, list2, k);
+
+ int result3 = getKthElementMerge(list1, list2, k);
+
+ assertEquals(result2, result);
+ assertEquals(result2, result3);
+ }
+
+ private int[] sortedRandomIntArrayOfLength(int length) {
+ int[] intArray = new Random().ints(length).toArray();
+ Arrays.sort(intArray);
+ return intArray;
+ }
+}
\ No newline at end of file
diff --git a/algorithms-sorting-2/README.md b/algorithms-sorting-2/README.md
index 71c9b8f86c..b31cfceb42 100644
--- a/algorithms-sorting-2/README.md
+++ b/algorithms-sorting-2/README.md
@@ -2,6 +2,6 @@
- [Sorting a String Alphabetically in Java](https://www.baeldung.com/java-sort-string-alphabetically)
- [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)
-- [Partitioning and Sorting Arrays with Many Repeated Entries](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries)
+- [Guide to In-Place Sorting Algorithm Works with a Java Implementation](https://www.baeldung.com/java-in-place-sorting)
+- [Partitioning and Sorting Arrays with Many Repeated Entries with Java Examples](https://www.baeldung.com/java-sorting-arrays-with-repeated-entries)
- More articles: [[<-- prev]](/algorithms-sorting)
diff --git a/algorithms-sorting-2/pom.xml b/algorithms-sorting-2/pom.xml
index 529474afda..5ef90b9825 100644
--- a/algorithms-sorting-2/pom.xml
+++ b/algorithms-sorting-2/pom.xml
@@ -44,18 +44,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.6.13.9.0
diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml
index 2de8eed04e..1d0b7718ac 100644
--- a/algorithms-sorting/pom.xml
+++ b/algorithms-sorting/pom.xml
@@ -45,18 +45,6 @@
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.6.13.9.0
diff --git a/apache-cxf/README.md b/apache-cxf/README.md
index bedd19a91a..88edaf4e13 100644
--- a/apache-cxf/README.md
+++ b/apache-cxf/README.md
@@ -7,4 +7,3 @@ This module contains articles about Apache CXF
- [Apache CXF Support for RESTful Web Services](https://www.baeldung.com/apache-cxf-rest-api)
- [A Guide to Apache CXF with Spring](https://www.baeldung.com/apache-cxf-with-spring)
- [Introduction to Apache CXF](https://www.baeldung.com/introduction-to-apache-cxf)
-- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse)
diff --git a/apache-cxf/pom.xml b/apache-cxf/pom.xml
index 3d64000c2e..0975996c06 100644
--- a/apache-cxf/pom.xml
+++ b/apache-cxf/pom.xml
@@ -30,7 +30,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}
diff --git a/apache-cxf/sse-jaxrs/README.md b/apache-cxf/sse-jaxrs/README.md
new file mode 100644
index 0000000000..4d39560b46
--- /dev/null
+++ b/apache-cxf/sse-jaxrs/README.md
@@ -0,0 +1,3 @@
+### Relevant Articles:
+
+- [Server-Sent Events (SSE) In JAX-RS](https://www.baeldung.com/java-ee-jax-rs-sse)
diff --git a/apache-libraries/pom.xml b/apache-libraries/pom.xml
index 9f800f1e0b..15404676cc 100644
--- a/apache-libraries/pom.xml
+++ b/apache-libraries/pom.xml
@@ -129,6 +129,11 @@
zookeeper${zookeeper.version}
+
+ com.fasterxml.jackson.core
+ jackson-core
+ ${jackson.version}
+ com.fasterxml.jackson.corejackson-databind
diff --git a/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerIntegrationTest.java b/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerIntegrationTest.java
new file mode 100644
index 0000000000..3d413e1939
--- /dev/null
+++ b/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerIntegrationTest.java
@@ -0,0 +1,83 @@
+package com.baeldung.avro.util.serealization;
+
+import com.baeldung.avro.util.model.Active;
+import com.baeldung.avro.util.model.AvroHttpRequest;
+import com.baeldung.avro.util.model.ClientIdentifier;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+
+import static org.junit.Assert.*;
+
+public class AvroSerealizerDeSerealizerIntegrationTest {
+
+ AvroSerealizer serealizer;
+ AvroDeSerealizer deSerealizer;
+ AvroHttpRequest request;
+
+ @Before
+ public void setUp() throws Exception {
+ serealizer = new AvroSerealizer();
+ deSerealizer = new AvroDeSerealizer();
+
+ ClientIdentifier clientIdentifier = ClientIdentifier.newBuilder()
+ .setHostName("localhost")
+ .setIpAddress("255.255.255.0")
+ .build();
+
+ List employees = new ArrayList();
+ employees.add("James");
+ employees.add("Alice");
+ employees.add("David");
+ employees.add("Han");
+
+ request = AvroHttpRequest.newBuilder()
+ .setRequestTime(01l)
+ .setActive(Active.YES)
+ .setClientIdentifier(clientIdentifier)
+ .setEmployeeNames(employees)
+ .build();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void WhenSerializedUsingJSONEncoder_thenObjectGetsSerialized() {
+ byte[] data = serealizer.serealizeAvroHttpRequestJSON(request);
+ assertTrue(Objects.nonNull(data));
+ assertTrue(data.length > 0);
+ }
+
+ @Test
+ public void WhenSerializedUsingBinaryEncoder_thenObjectGetsSerialized() {
+ byte[] data = serealizer.serealizeAvroHttpRequestBinary(request);
+ assertTrue(Objects.nonNull(data));
+ assertTrue(data.length > 0);
+ }
+
+ @Test
+ public void WhenDeserializeUsingJSONDecoder_thenActualAndExpectedObjectsAreEqual() {
+ byte[] data = serealizer.serealizeAvroHttpRequestJSON(request);
+ AvroHttpRequest actualRequest = deSerealizer.deSerealizeAvroHttpRequestJSON(data);
+ assertEquals(actualRequest, request);
+ assertTrue(actualRequest.getRequestTime()
+ .equals(request.getRequestTime()));
+ }
+
+ @Test
+ public void WhenDeserializeUsingBinaryecoder_thenActualAndExpectedObjectsAreEqual() {
+ byte[] data = serealizer.serealizeAvroHttpRequestBinary(request);
+ AvroHttpRequest actualRequest = deSerealizer.deSerealizeAvroHttpRequestBinary(data);
+ assertEquals(actualRequest, request);
+ assertTrue(actualRequest.getRequestTime()
+ .equals(request.getRequestTime()));
+ }
+
+}
+
diff --git a/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerUnitTest.java b/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerUnitTest.java
deleted file mode 100644
index 992ea806c3..0000000000
--- a/apache-libraries/src/test/java/com/baeldung/avro/util/serealization/AvroSerealizerDeSerealizerUnitTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-package com.baeldung.avro.util.serealization;
-
-import com.baeldung.avro.util.model.Active;
-import com.baeldung.avro.util.model.AvroHttpRequest;
-import com.baeldung.avro.util.model.ClientIdentifier;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-
-import static org.junit.Assert.*;
-
-public class AvroSerealizerDeSerealizerUnitTest {
-
- AvroSerealizer serealizer;
- AvroDeSerealizer deSerealizer;
- AvroHttpRequest request;
-
- @Before
- public void setUp() throws Exception {
- serealizer = new AvroSerealizer();
- deSerealizer = new AvroDeSerealizer();
-
- ClientIdentifier clientIdentifier = ClientIdentifier.newBuilder()
- .setHostName("localhost")
- .setIpAddress("255.255.255.0")
- .build();
-
- List employees = new ArrayList();
- employees.add("James");
- employees.add("Alice");
- employees.add("David");
- employees.add("Han");
-
- request = AvroHttpRequest.newBuilder()
- .setRequestTime(01l)
- .setActive(Active.YES)
- .setClientIdentifier(clientIdentifier)
- .setEmployeeNames(employees)
- .build();
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void WhenSerializedUsingJSONEncoder_thenObjectGetsSerialized() {
- byte[] data = serealizer.serealizeAvroHttpRequestJSON(request);
- assertTrue(Objects.nonNull(data));
- assertTrue(data.length > 0);
- }
-
- @Test
- public void WhenSerializedUsingBinaryEncoder_thenObjectGetsSerialized() {
- byte[] data = serealizer.serealizeAvroHttpRequestBinary(request);
- assertTrue(Objects.nonNull(data));
- assertTrue(data.length > 0);
- }
-
- @Test
- public void WhenDeserializeUsingJSONDecoder_thenActualAndExpectedObjectsAreEqual() {
- byte[] data = serealizer.serealizeAvroHttpRequestJSON(request);
- AvroHttpRequest actualRequest = deSerealizer.deSerealizeAvroHttpRequestJSON(data);
- assertEquals(actualRequest, request);
- assertTrue(actualRequest.getRequestTime()
- .equals(request.getRequestTime()));
- }
-
- @Test
- public void WhenDeserializeUsingBinaryecoder_thenActualAndExpectedObjectsAreEqual() {
- byte[] data = serealizer.serealizeAvroHttpRequestBinary(request);
- AvroHttpRequest actualRequest = deSerealizer.deSerealizeAvroHttpRequestBinary(data);
- assertEquals(actualRequest, request);
- assertTrue(actualRequest.getRequestTime()
- .equals(request.getRequestTime()));
- }
-
-}
-
diff --git a/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsIntegrationTest.java b/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsIntegrationTest.java
new file mode 100644
index 0000000000..dbd777231c
--- /dev/null
+++ b/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsIntegrationTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.meecrowave;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.junit.MonoMeecrowave;
+import org.apache.meecrowave.testing.ConfigurationInject;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.Response;
+
+@RunWith(MonoMeecrowave.Runner.class)
+public class ArticleEndpointsIntegrationTest {
+
+ @ConfigurationInject
+ private Meecrowave.Builder config;
+ private static OkHttpClient client;
+
+ @BeforeClass
+ public static void setup() {
+ client = new OkHttpClient();
+ }
+
+ @Test
+ public void whenRetunedArticle_thenCorrect() throws IOException {
+ final String base = "http://localhost:"+config.getHttpPort();
+
+ Request request = new Request.Builder()
+ .url(base+"/article")
+ .build();
+ Response response = client.newCall(request).execute();
+ assertEquals(200, response.code());
+ }
+}
diff --git a/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java b/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java
deleted file mode 100644
index f9a06fd7b9..0000000000
--- a/apache-libraries/src/test/java/com/baeldung/meecrowave/ArticleEndpointsUnitTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.baeldung.meecrowave;
-
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-
-import org.apache.meecrowave.Meecrowave;
-import org.apache.meecrowave.junit.MonoMeecrowave;
-import org.apache.meecrowave.testing.ConfigurationInject;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import okhttp3.OkHttpClient;
-import okhttp3.Request;
-import okhttp3.Response;
-
-@RunWith(MonoMeecrowave.Runner.class)
-public class ArticleEndpointsUnitTest {
-
- @ConfigurationInject
- private Meecrowave.Builder config;
- private static OkHttpClient client;
-
- @BeforeClass
- public static void setup() {
- client = new OkHttpClient();
- }
-
- @Test
- public void whenRetunedArticle_thenCorrect() throws IOException {
- final String base = "http://localhost:"+config.getHttpPort();
-
- Request request = new Request.Builder()
- .url(base+"/article")
- .build();
- Response response = client.newCall(request).execute();
- assertEquals(200, response.code());
- }
-}
diff --git a/apache-poi/README.md b/apache-poi/README.md
index b562fefc29..d500787536 100644
--- a/apache-poi/README.md
+++ b/apache-poi/README.md
@@ -3,9 +3,12 @@
This module contains articles about Apache POI
### Relevant Articles:
+
- [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://www.baeldung.com/apache-poi-read-cell-value-formula)
+- [Setting Formulas in Excel with Apache POI](https://www.baeldung.com/java-apache-poi-set-formulas)
+- [Insert a Row in Excel Using Apache POI](https://www.baeldung.com/apache-poi-insert-excel-row)
diff --git a/apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java b/apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java
new file mode 100644
index 0000000000..f5179b19c9
--- /dev/null
+++ b/apache-poi/src/main/java/com/baeldung/poi/excel/setformula/ExcelFormula.java
@@ -0,0 +1,26 @@
+package com.baeldung.poi.excel.setformula;
+
+import org.apache.poi.xssf.usermodel.XSSFCell;
+import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class ExcelFormula {
+ public double setFormula(String fileLocation, XSSFWorkbook wb, String formula) throws IOException {
+ XSSFSheet sheet = wb.getSheetAt(0);
+ int lastCellNum = sheet.getRow(0).getLastCellNum();
+ XSSFCell formulaCell = sheet.getRow(0).createCell(lastCellNum);
+ formulaCell.setCellFormula(formula);
+ XSSFFormulaEvaluator formulaEvaluator = wb.getCreationHelper().createFormulaEvaluator();
+ formulaEvaluator.evaluateFormulaCell(formulaCell);
+ FileOutputStream fileOut = new FileOutputStream(new File(fileLocation));
+ wb.write(fileOut);
+ wb.close();
+ fileOut.close();
+ return formulaCell.getNumericCellValue();
+ }
+}
diff --git a/apache-poi/src/main/resources/com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx b/apache-poi/src/main/resources/com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx
new file mode 100644
index 0000000000..a0fe73f0eb
Binary files /dev/null and b/apache-poi/src/main/resources/com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx differ
diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/insert/ExcelInsertRowUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/insert/ExcelInsertRowUnitTest.java
new file mode 100644
index 0000000000..0f137aa4d2
--- /dev/null
+++ b/apache-poi/src/test/java/com/baeldung/poi/excel/insert/ExcelInsertRowUnitTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.poi.excel.insert;
+
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.jupiter.api.Assertions;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+
+public class ExcelInsertRowUnitTest {
+ private static final String FILE_NAME = "test.xlsx";
+ private static final String NEW_FILE_NAME = "new_test.xlsx";
+ private String fileLocation;
+
+ @Before
+ public void setup() throws URISyntaxException {
+ fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
+ }
+
+ @Test
+ public void givenWorkbook_whenInsertRowBetween_thenRowCreated() throws IOException {
+ int startRow = 2;
+ int rowNumber = 1;
+ Workbook workbook = new XSSFWorkbook(fileLocation);
+ Sheet sheet = workbook.getSheetAt(0);
+ int lastRow = sheet.getLastRowNum();
+ if (lastRow < startRow) {
+ sheet.createRow(startRow);
+ }
+ sheet.shiftRows(startRow, lastRow, rowNumber, true, true);
+ sheet.createRow(startRow);
+ FileOutputStream outputStream = new FileOutputStream(NEW_FILE_NAME);
+ workbook.write(outputStream);
+ File file = new File(NEW_FILE_NAME);
+
+ final int expectedRowResult = 5;
+ Assertions.assertEquals(expectedRowResult, workbook.getSheetAt(0).getLastRowNum());
+
+ outputStream.close();
+ file.delete();
+ workbook.close();
+ }
+
+}
\ No newline at end of file
diff --git a/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java
new file mode 100644
index 0000000000..fa5baa37fa
--- /dev/null
+++ b/apache-poi/src/test/java/com/baeldung/poi/excel/setformula/ExcelFormulaUnitTest.java
@@ -0,0 +1,51 @@
+package com.baeldung.poi.excel.setformula;
+
+import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.junit.Assert;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+
+class ExcelFormulaUnitTest {
+ private static String FILE_NAME = "com/baeldung/poi/excel/setformula/SetFormulaTest.xlsx";
+ private String fileLocation;
+ private ExcelFormula excelFormula;
+
+ @BeforeEach
+ public void setup() throws URISyntaxException {
+ fileLocation = Paths.get(ClassLoader.getSystemResource(FILE_NAME).toURI()).toString();
+ excelFormula = new ExcelFormula();
+ }
+
+ @Test
+ void givenExcelData_whenSetFormula_thenSuccess() throws IOException {
+ FileInputStream inputStream = new FileInputStream(new File(fileLocation));
+ XSSFWorkbook wb = new XSSFWorkbook(inputStream);
+ XSSFSheet sheet = wb.getSheetAt(0);
+ double resultColumnA = 0;
+ double resultColumnB = 0;
+ for (int row = 0; row <= sheet.getLastRowNum(); row++) {
+ resultColumnA += sheet.getRow(row).getCell(0).getNumericCellValue();
+ resultColumnB += sheet.getRow(row).getCell(1).getNumericCellValue();
+ }
+ String colNameA = CellReference.convertNumToColString(0);
+ String colNameB = CellReference.convertNumToColString(1);
+ String startCellA = colNameA + 1;
+ String stopCellA = colNameA + (sheet.getLastRowNum() + 1);
+ String sumFormulaForColumnA = String.format("SUM(%s:%s)", startCellA, stopCellA);
+ String startCellB = colNameB + 1;
+ String stopCellB = colNameB + (sheet.getLastRowNum() + 1);
+ String sumFormulaForColumnB = String.format("SUM(%s:%s)", startCellB, stopCellB);
+
+ double resultValue = excelFormula.setFormula(fileLocation, wb, sumFormulaForColumnA + "-" + sumFormulaForColumnB);
+
+ Assert.assertEquals(resultColumnA - resultColumnB, resultValue, 0d);
+ }
+}
diff --git a/apache-shiro/README.md b/apache-shiro/README.md
index ed63c569da..3a0088072f 100644
--- a/apache-shiro/README.md
+++ b/apache-shiro/README.md
@@ -6,4 +6,4 @@ This module contains articles about 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)
-
+- [Spring Security vs Apache Shiro](https://www.baeldung.com/spring-security-vs-apache-shiro)
diff --git a/apache-spark/README.md b/apache-spark/README.md
index c60b556d51..3a2d2f4e15 100644
--- a/apache-spark/README.md
+++ b/apache-spark/README.md
@@ -8,3 +8,4 @@ This module contains articles about 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)
- [Introduction to Spark Graph Processing with GraphFrames](https://www.baeldung.com/spark-graph-graphframes)
+- [Apache Spark: Differences between Dataframes, Datasets and RDDs](https://www.baeldung.com/java-spark-dataframe-dataset-rdd)
diff --git a/apache-spark/data/Tourist.csv b/apache-spark/data/Tourist.csv
new file mode 100644
index 0000000000..4970e8c2f0
--- /dev/null
+++ b/apache-spark/data/Tourist.csv
@@ -0,0 +1,2247 @@
+Region,Country,Year,Series,Series_Type,Series_Type_Footnote,Value,Footnotes,Source
+4,Afghanistan,2010,Tourism expenditure (millions of US dollars),,,147.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+4,Afghanistan,2016,Tourism expenditure (millions of US dollars),,,62.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+4,Afghanistan,2017,Tourism expenditure (millions of US dollars),,,16.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+4,Afghanistan,2018,Tourism expenditure (millions of US dollars),,,50.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2010,Tourist/visitor arrivals (thousands),TF,,2191.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2016,Tourist/visitor arrivals (thousands),TF,,4070.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2017,Tourist/visitor arrivals (thousands),TF,,4643.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2018,Tourist/visitor arrivals (thousands),TF,,5340.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,1995,Tourism expenditure (millions of US dollars),,,70.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2005,Tourism expenditure (millions of US dollars),,,880.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2010,Tourism expenditure (millions of US dollars),,,1778.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2016,Tourism expenditure (millions of US dollars),,,1821.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2017,Tourism expenditure (millions of US dollars),,,2050.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+8,Albania,2018,Tourism expenditure (millions of US dollars),,,2306.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,1995,Tourist/visitor arrivals (thousands),VF,,520.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2005,Tourist/visitor arrivals (thousands),VF,,1443.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2010,Tourist/visitor arrivals (thousands),VF,,2070.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2016,Tourist/visitor arrivals (thousands),VF,,2039.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2017,Tourist/visitor arrivals (thousands),VF,,2451.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2018,Tourist/visitor arrivals (thousands),VF,,2657.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2005,Tourism expenditure (millions of US dollars),,,477.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2010,Tourism expenditure (millions of US dollars),,,324.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2016,Tourism expenditure (millions of US dollars),,,246.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+12,Algeria,2017,Tourism expenditure (millions of US dollars),,,172.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,1995,Tourist/visitor arrivals (thousands),TF,,34.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2005,Tourist/visitor arrivals (thousands),TF,,24.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2010,Tourist/visitor arrivals (thousands),TF,,23.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2016,Tourist/visitor arrivals (thousands),TF,,20.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2017,Tourist/visitor arrivals (thousands),TF,,20.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2018,Tourist/visitor arrivals (thousands),TF,,20.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2016,Tourism expenditure (millions of US dollars),,,22.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+16,American Samoa,2017,Tourism expenditure (millions of US dollars),,,22.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+20,Andorra,2005,Tourist/visitor arrivals (thousands),TF,,2418.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+20,Andorra,2010,Tourist/visitor arrivals (thousands),TF,,1808.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+20,Andorra,2016,Tourist/visitor arrivals (thousands),TF,,2819.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+20,Andorra,2017,Tourist/visitor arrivals (thousands),TF,,3003.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+20,Andorra,2018,Tourist/visitor arrivals (thousands),TF,,3042.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,1995,Tourist/visitor arrivals (thousands),TF,,9.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2005,Tourist/visitor arrivals (thousands),TF,,210.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2010,Tourist/visitor arrivals (thousands),TF,,425.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2016,Tourist/visitor arrivals (thousands),TF,,397.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2017,Tourist/visitor arrivals (thousands),TF,,261.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2018,Tourist/visitor arrivals (thousands),TF,,218.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,1995,Tourism expenditure (millions of US dollars),,,27.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2005,Tourism expenditure (millions of US dollars),,,103.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2010,Tourism expenditure (millions of US dollars),,,726.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2016,Tourism expenditure (millions of US dollars),,,628.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2017,Tourism expenditure (millions of US dollars),,,884.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+24,Angola,2018,Tourism expenditure (millions of US dollars),,,557.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,1995,Tourist/visitor arrivals (thousands),TF,,39.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2005,Tourist/visitor arrivals (thousands),TF,,62.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2010,Tourist/visitor arrivals (thousands),TF,,62.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2016,Tourist/visitor arrivals (thousands),TF,,79.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2017,Tourist/visitor arrivals (thousands),TF,,68.3000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2018,Tourist/visitor arrivals (thousands),TF,,55.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,1995,Tourism expenditure (millions of US dollars),,,50.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2005,Tourism expenditure (millions of US dollars),,,86.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2010,Tourism expenditure (millions of US dollars),,,99.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2016,Tourism expenditure (millions of US dollars),,,136.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2017,Tourism expenditure (millions of US dollars),,,141.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+660,Anguilla,2018,Tourism expenditure (millions of US dollars),,,102.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,1995,Tourist/visitor arrivals (thousands),TF,,220.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2005,Tourist/visitor arrivals (thousands),TF,,245.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2010,Tourist/visitor arrivals (thousands),TF,,230.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2016,Tourist/visitor arrivals (thousands),TF,,265.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2017,Tourist/visitor arrivals (thousands),TF,,247.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2018,Tourist/visitor arrivals (thousands),TF,,269.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,1995,Tourism expenditure (millions of US dollars),,,247.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2005,Tourism expenditure (millions of US dollars),,,309.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2010,Tourism expenditure (millions of US dollars),,,298.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2016,Tourism expenditure (millions of US dollars),,,753.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2017,Tourism expenditure (millions of US dollars),,,737.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+28,Antigua and Barbuda,2018,Tourism expenditure (millions of US dollars),,,881.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,1995,Tourist/visitor arrivals (thousands),TF,,2289.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2005,Tourist/visitor arrivals (thousands),TF,,3823.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2010,Tourist/visitor arrivals (thousands),TF,,6800.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2016,Tourist/visitor arrivals (thousands),TF,,6668.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2017,Tourist/visitor arrivals (thousands),TF,,6711.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2018,Tourist/visitor arrivals (thousands),TF,,6942.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,1995,Tourism expenditure (millions of US dollars),,,2550.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2005,Tourism expenditure (millions of US dollars),,,3209.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2010,Tourism expenditure (millions of US dollars),,,5605.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2016,Tourism expenditure (millions of US dollars),,,5466.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2017,Tourism expenditure (millions of US dollars),,,5835.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+32,Argentina,2018,Tourism expenditure (millions of US dollars),,,5999.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,1995,Tourist/visitor arrivals (thousands),TF,,12.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2005,Tourist/visitor arrivals (thousands),TF,,319.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2010,Tourist/visitor arrivals (thousands),TF,,684.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2016,Tourist/visitor arrivals (thousands),TF,,1260.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2017,Tourist/visitor arrivals (thousands),TF,,1495.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2018,Tourist/visitor arrivals (thousands),TF,,1652.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,1995,Tourism expenditure (millions of US dollars),,,14.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2005,Tourism expenditure (millions of US dollars),,,243.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2010,Tourism expenditure (millions of US dollars),,,694.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2016,Tourism expenditure (millions of US dollars),,,988.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2017,Tourism expenditure (millions of US dollars),,,1140.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+51,Armenia,2018,Tourism expenditure (millions of US dollars),,,1237.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,1995,Tourist/visitor arrivals (thousands),TF,,619.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2005,Tourist/visitor arrivals (thousands),TF,,733.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2010,Tourist/visitor arrivals (thousands),TF,,824.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2016,Tourist/visitor arrivals (thousands),TF,,1102.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2017,Tourist/visitor arrivals (thousands),TF,,1070.5000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2018,Tourist/visitor arrivals (thousands),TF,,1082.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,1995,Tourism expenditure (millions of US dollars),,,554.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2005,Tourism expenditure (millions of US dollars),,,1097.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2010,Tourism expenditure (millions of US dollars),,,1254.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2016,Tourism expenditure (millions of US dollars),,,1764.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2017,Tourism expenditure (millions of US dollars),,,1857.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+533,Aruba,2018,Tourism expenditure (millions of US dollars),,,2024.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,1995,Tourist/visitor arrivals (thousands),VF,,3726.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2005,Tourist/visitor arrivals (thousands),VF,,5499.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2010,Tourist/visitor arrivals (thousands),VF,,5790.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2016,Tourist/visitor arrivals (thousands),VF,,8269.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2017,Tourist/visitor arrivals (thousands),VF,,8815.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2018,Tourist/visitor arrivals (thousands),VF,,9246.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,1995,Tourism expenditure (millions of US dollars),,,10370.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2005,Tourism expenditure (millions of US dollars),,,19719.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2010,Tourism expenditure (millions of US dollars),,,31064.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2016,Tourism expenditure (millions of US dollars),,,39059.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2017,Tourism expenditure (millions of US dollars),,,43975.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+36,Australia,2018,Tourism expenditure (millions of US dollars),,,47327.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,1995,Tourist/visitor arrivals (thousands),TCE,,17173.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2005,Tourist/visitor arrivals (thousands),TCE,,19952.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2010,Tourist/visitor arrivals (thousands),TCE,,22004.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2016,Tourist/visitor arrivals (thousands),TCE,,28121.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2017,Tourist/visitor arrivals (thousands),TCE,,29460.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2018,Tourist/visitor arrivals (thousands),TCE,,30816.0000,Only paid accommodation; excluding stays at friends and relatives and second homes.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,1995,Tourism expenditure (millions of US dollars),,,13435.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2005,Tourism expenditure (millions of US dollars),,,16243.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2010,Tourism expenditure (millions of US dollars),,,18751.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2016,Tourism expenditure (millions of US dollars),,,19244.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2017,Tourism expenditure (millions of US dollars),,,20333.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+40,Austria,2018,Tourism expenditure (millions of US dollars),,,23233.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2005,Tourist/visitor arrivals (thousands),TF,,693.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2010,Tourist/visitor arrivals (thousands),TF,,1280.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2016,Tourist/visitor arrivals (thousands),TF,,2044.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2017,Tourist/visitor arrivals (thousands),TF,,2454.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2018,Tourist/visitor arrivals (thousands),TF,,2633.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,1995,Tourism expenditure (millions of US dollars),,,87.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2005,Tourism expenditure (millions of US dollars),,,100.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2010,Tourism expenditure (millions of US dollars),,,792.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2016,Tourism expenditure (millions of US dollars),,,2855.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2017,Tourism expenditure (millions of US dollars),,,3214.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+31,Azerbaijan,2018,Tourism expenditure (millions of US dollars),,,2830.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,1995,Tourist/visitor arrivals (thousands),TF,,1598.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2005,Tourist/visitor arrivals (thousands),TF,,1608.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2010,Tourist/visitor arrivals (thousands),TF,,1370.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2016,Tourist/visitor arrivals (thousands),TF,,1500.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2017,Tourist/visitor arrivals (thousands),TF,,1442.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2018,Tourist/visitor arrivals (thousands),TF,,1633.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,1995,Tourism expenditure (millions of US dollars),,,1356.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2005,Tourism expenditure (millions of US dollars),,,2081.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2010,Tourism expenditure (millions of US dollars),,,2159.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2016,Tourism expenditure (millions of US dollars),,,3091.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2017,Tourism expenditure (millions of US dollars),,,3017.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+44,Bahamas,2018,Tourism expenditure (millions of US dollars),,,3383.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,1995,Tourist/visitor arrivals (thousands),VF,,2311.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2005,Tourist/visitor arrivals (thousands),VF,,6313.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2010,Tourist/visitor arrivals (thousands),VF,,11952.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2016,Tourist/visitor arrivals (thousands),VF,,10158.0000,Break in the time series.;Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2017,Tourist/visitor arrivals (thousands),VF,,11374.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2018,Tourist/visitor arrivals (thousands),VF,,12045.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,1995,Tourism expenditure (millions of US dollars),,,593.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2005,Tourism expenditure (millions of US dollars),,,1603.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2010,Tourism expenditure (millions of US dollars),,,2163.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2016,Tourism expenditure (millions of US dollars),,,4021.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2017,Tourism expenditure (millions of US dollars),,,4380.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+48,Bahrain,2018,Tourism expenditure (millions of US dollars),,,3834.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,1995,Tourist/visitor arrivals (thousands),TF,,156.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2005,Tourist/visitor arrivals (thousands),TF,,208.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2010,Tourist/visitor arrivals (thousands),TF,,303.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2016,Tourist/visitor arrivals (thousands),TF,,830.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2017,Tourist/visitor arrivals (thousands),TF,,1026.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2005,Tourism expenditure (millions of US dollars),,,82.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2010,Tourism expenditure (millions of US dollars),,,103.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2016,Tourism expenditure (millions of US dollars),,,214.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2017,Tourism expenditure (millions of US dollars),,,348.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+50,Bangladesh,2018,Tourism expenditure (millions of US dollars),,,357.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,1995,Tourist/visitor arrivals (thousands),TF,,442.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2005,Tourist/visitor arrivals (thousands),TF,,548.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2010,Tourist/visitor arrivals (thousands),TF,,532.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2016,Tourist/visitor arrivals (thousands),TF,,632.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2017,Tourist/visitor arrivals (thousands),TF,,664.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2018,Tourist/visitor arrivals (thousands),TF,,680.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,1995,Tourism expenditure (millions of US dollars),,,630.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2005,Tourism expenditure (millions of US dollars),,,1081.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+52,Barbados,2010,Tourism expenditure (millions of US dollars),,,1074.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,1995,Tourist/visitor arrivals (thousands),TF,,160.6000,Excludes the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2005,Tourist/visitor arrivals (thousands),TF,,91.0000,Excludes the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2010,Tourist/visitor arrivals (thousands),TF,,119.3000,Excludes the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2016,Tourist/visitor arrivals (thousands),TF,,10935.4000,Includes estimation of the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2017,Tourist/visitor arrivals (thousands),TF,,11060.2000,Includes estimation of the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2018,Tourist/visitor arrivals (thousands),TF,,11501.6000,Includes estimation of the Belarusian-Russian border segment.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,1995,Tourism expenditure (millions of US dollars),,,28.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2005,Tourism expenditure (millions of US dollars),,,346.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2010,Tourism expenditure (millions of US dollars),,,665.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2016,Tourism expenditure (millions of US dollars),,,1019.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2017,Tourism expenditure (millions of US dollars),,,1124.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+112,Belarus,2018,Tourism expenditure (millions of US dollars),,,1221.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,1995,Tourist/visitor arrivals (thousands),TCE,,5560.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2005,Tourist/visitor arrivals (thousands),TCE,,6747.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2010,Tourist/visitor arrivals (thousands),TCE,,7186.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2016,Tourist/visitor arrivals (thousands),TCE,,7481.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2017,Tourist/visitor arrivals (thousands),TCE,,8385.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2018,Tourist/visitor arrivals (thousands),TCE,,9119.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2005,Tourism expenditure (millions of US dollars),,,10881.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2010,Tourism expenditure (millions of US dollars),,,12680.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2016,Tourism expenditure (millions of US dollars),,,8784.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2017,Tourism expenditure (millions of US dollars),,,9636.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+56,Belgium,2018,Tourism expenditure (millions of US dollars),,,10381.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,1995,Tourist/visitor arrivals (thousands),TF,,131.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2005,Tourist/visitor arrivals (thousands),TF,,237.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2010,Tourist/visitor arrivals (thousands),TF,,242.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2016,Tourist/visitor arrivals (thousands),TF,,386.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2017,Tourist/visitor arrivals (thousands),TF,,427.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2018,Tourist/visitor arrivals (thousands),TF,,489.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,1995,Tourism expenditure (millions of US dollars),,,78.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2005,Tourism expenditure (millions of US dollars),,,214.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2010,Tourism expenditure (millions of US dollars),,,264.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2016,Tourism expenditure (millions of US dollars),,,391.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2017,Tourism expenditure (millions of US dollars),,,427.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+84,Belize,2018,Tourism expenditure (millions of US dollars),,,487.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,1995,Tourist/visitor arrivals (thousands),TF,,138.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2005,Tourist/visitor arrivals (thousands),TF,,176.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2010,Tourist/visitor arrivals (thousands),TF,,199.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2016,Tourist/visitor arrivals (thousands),TF,,267.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2017,Tourist/visitor arrivals (thousands),TF,,281.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2018,Tourist/visitor arrivals (thousands),TF,,295.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2005,Tourism expenditure (millions of US dollars),,,107.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2010,Tourism expenditure (millions of US dollars),,,149.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2016,Tourism expenditure (millions of US dollars),,,129.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+204,Benin,2017,Tourism expenditure (millions of US dollars),,,160.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,1995,Tourist/visitor arrivals (thousands),TF,,387.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2005,Tourist/visitor arrivals (thousands),TF,,270.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2010,Tourist/visitor arrivals (thousands),TF,,232.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2016,Tourist/visitor arrivals (thousands),TF,,244.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2017,Tourist/visitor arrivals (thousands),TF,,270.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2018,Tourist/visitor arrivals (thousands),TF,,282.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,1995,Tourism expenditure (millions of US dollars),,,488.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2005,Tourism expenditure (millions of US dollars),,,429.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2010,Tourism expenditure (millions of US dollars),,,442.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2016,Tourism expenditure (millions of US dollars),,,441.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2017,Tourism expenditure (millions of US dollars),,,513.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+60,Bermuda,2018,Tourism expenditure (millions of US dollars),,,583.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,1995,Tourist/visitor arrivals (thousands),TF,,4.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2005,Tourist/visitor arrivals (thousands),TF,,13.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2010,Tourist/visitor arrivals (thousands),TF,,41.0000,Break in the time series.;Including regional high end tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2016,Tourist/visitor arrivals (thousands),TF,,210.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2017,Tourist/visitor arrivals (thousands),TF,,255.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2018,Tourist/visitor arrivals (thousands),TF,,274.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,1995,Tourism expenditure (millions of US dollars),,,5.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2005,Tourism expenditure (millions of US dollars),,,19.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2010,Tourism expenditure (millions of US dollars),,,64.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2016,Tourism expenditure (millions of US dollars),,,139.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2017,Tourism expenditure (millions of US dollars),,,153.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+64,Bhutan,2018,Tourism expenditure (millions of US dollars),,,121.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),1995,Tourist/visitor arrivals (thousands),TF,,284.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2005,Tourist/visitor arrivals (thousands),TF,,524.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2010,Tourist/visitor arrivals (thousands),TF,,679.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2016,Tourist/visitor arrivals (thousands),TF,,961.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2017,Tourist/visitor arrivals (thousands),TF,,1109.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2018,Tourist/visitor arrivals (thousands),TF,,1142.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),1995,Tourism expenditure (millions of US dollars),,,92.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2005,Tourism expenditure (millions of US dollars),,,345.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2010,Tourism expenditure (millions of US dollars),,,339.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2016,Tourism expenditure (millions of US dollars),,,827.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2017,Tourism expenditure (millions of US dollars),,,912.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+68,Bolivia (Plurin. State of),2018,Tourism expenditure (millions of US dollars),,,970.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+669,Bonaire,1995,Tourist/visitor arrivals (thousands),TF,,59.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+669,Bonaire,2005,Tourist/visitor arrivals (thousands),TF,,63.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+669,Bonaire,2010,Tourist/visitor arrivals (thousands),TF,,71.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+669,Bonaire,1995,Tourism expenditure (millions of US dollars),,,37.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+669,Bonaire,2005,Tourism expenditure (millions of US dollars),,,87.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2005,Tourist/visitor arrivals (thousands),TCE,,217.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2010,Tourist/visitor arrivals (thousands),TCE,,365.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2016,Tourist/visitor arrivals (thousands),TCE,,778.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2017,Tourist/visitor arrivals (thousands),TCE,,923.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2018,Tourist/visitor arrivals (thousands),TCE,,1053.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2005,Tourism expenditure (millions of US dollars),,,557.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2010,Tourism expenditure (millions of US dollars),,,662.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2016,Tourism expenditure (millions of US dollars),,,876.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2017,Tourism expenditure (millions of US dollars),,,985.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+70,Bosnia and Herzegovina,2018,Tourism expenditure (millions of US dollars),,,1081.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,1995,Tourist/visitor arrivals (thousands),TF,,521.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2005,Tourist/visitor arrivals (thousands),TF,,1474.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2010,Tourist/visitor arrivals (thousands),TF,,1973.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2016,Tourist/visitor arrivals (thousands),TF,,1574.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2017,Tourist/visitor arrivals (thousands),TF,,1623.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,1995,Tourism expenditure (millions of US dollars),,,176.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2005,Tourism expenditure (millions of US dollars),,,563.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2010,Tourism expenditure (millions of US dollars),,,440.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2016,Tourism expenditure (millions of US dollars),,,505.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2017,Tourism expenditure (millions of US dollars),,,541.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+72,Botswana,2018,Tourism expenditure (millions of US dollars),,,575.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,1995,Tourist/visitor arrivals (thousands),TF,,1991.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2005,Tourist/visitor arrivals (thousands),TF,,5358.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2010,Tourist/visitor arrivals (thousands),TF,,5161.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2016,Tourist/visitor arrivals (thousands),TF,,6547.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2017,Tourist/visitor arrivals (thousands),TF,,6589.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2018,Tourist/visitor arrivals (thousands),TF,,6621.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,1995,Tourism expenditure (millions of US dollars),,,1085.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2005,Tourism expenditure (millions of US dollars),,,4168.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2010,Tourism expenditure (millions of US dollars),,,5522.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2016,Tourism expenditure (millions of US dollars),,,6613.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2017,Tourism expenditure (millions of US dollars),,,6175.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+76,Brazil,2018,Tourism expenditure (millions of US dollars),,,6324.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,1995,Tourist/visitor arrivals (thousands),TF,,219.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2005,Tourist/visitor arrivals (thousands),TF,,337.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2010,Tourist/visitor arrivals (thousands),TF,,330.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2016,Tourist/visitor arrivals (thousands),TF,,408.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2017,Tourist/visitor arrivals (thousands),TF,,335.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2018,Tourist/visitor arrivals (thousands),TF,,192.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,1995,Tourism expenditure (millions of US dollars),,,211.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2005,Tourism expenditure (millions of US dollars),,,412.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+92,British Virgin Islands,2010,Tourism expenditure (millions of US dollars),,,389.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2005,Tourist/visitor arrivals (thousands),TF,,126.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2010,Tourist/visitor arrivals (thousands),TF,,214.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2016,Tourist/visitor arrivals (thousands),TF,,219.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2017,Tourist/visitor arrivals (thousands),TF,,259.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2018,Tourist/visitor arrivals (thousands),TF,,278.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2005,Tourism expenditure (millions of US dollars),,,191.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2016,Tourism expenditure (millions of US dollars),,,144.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2017,Tourism expenditure (millions of US dollars),,,177.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+96,Brunei Darussalam,2018,Tourism expenditure (millions of US dollars),,,190.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,1995,Tourist/visitor arrivals (thousands),TF,,3466.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2005,Tourist/visitor arrivals (thousands),TF,,4837.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2010,Tourist/visitor arrivals (thousands),TF,,6047.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2016,Tourist/visitor arrivals (thousands),TF,,8252.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2017,Tourist/visitor arrivals (thousands),TF,,8883.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2018,Tourist/visitor arrivals (thousands),TF,,9273.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,1995,Tourism expenditure (millions of US dollars),,,662.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2005,Tourism expenditure (millions of US dollars),,,3063.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2010,Tourism expenditure (millions of US dollars),,,3807.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2016,Tourism expenditure (millions of US dollars),,,4164.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2017,Tourism expenditure (millions of US dollars),,,4678.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+100,Bulgaria,2018,Tourism expenditure (millions of US dollars),,,5072.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,1995,Tourist/visitor arrivals (thousands),THS,,124.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2005,Tourist/visitor arrivals (thousands),THS,,245.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2010,Tourist/visitor arrivals (thousands),THS,,274.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2016,Tourist/visitor arrivals (thousands),THS,,152.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2017,Tourist/visitor arrivals (thousands),THS,,143.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2018,Tourist/visitor arrivals (thousands),THS,,144.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2005,Tourism expenditure (millions of US dollars),,,46.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2010,Tourism expenditure (millions of US dollars),,,105.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2016,Tourism expenditure (millions of US dollars),,,172.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+854,Burkina Faso,2017,Tourism expenditure (millions of US dollars),,,172.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,1995,Tourist/visitor arrivals (thousands),TF,,34.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2005,Tourist/visitor arrivals (thousands),TF,,148.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2010,Tourist/visitor arrivals (thousands),TF,,142.0000,Break in the time series.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2016,Tourist/visitor arrivals (thousands),TF,,187.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2017,Tourist/visitor arrivals (thousands),TF,,299.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,1995,Tourism expenditure (millions of US dollars),,,2.4250,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2005,Tourism expenditure (millions of US dollars),,,1.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+108,Burundi,2010,Tourism expenditure (millions of US dollars),,,2.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,1995,Tourist/visitor arrivals (thousands),TF,,28.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2005,Tourist/visitor arrivals (thousands),TF,,198.0000,Non-resident tourists staying in hotels and similar establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2010,Tourist/visitor arrivals (thousands),TF,,336.0000,Non-resident tourists staying in hotels and similar establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2016,Tourist/visitor arrivals (thousands),TF,,598.0000,Non-resident tourists staying in hotels and similar establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2017,Tourist/visitor arrivals (thousands),TF,,668.0000,Non-resident tourists staying in hotels and similar establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2018,Tourist/visitor arrivals (thousands),TF,,710.0000,Non-resident tourists staying in hotels and similar establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,1995,Tourism expenditure (millions of US dollars),,,29.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2005,Tourism expenditure (millions of US dollars),,,177.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2010,Tourism expenditure (millions of US dollars),,,387.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2016,Tourism expenditure (millions of US dollars),,,397.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2017,Tourism expenditure (millions of US dollars),,,450.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+132,Cabo Verde,2018,Tourism expenditure (millions of US dollars),,,524.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,1995,Tourist/visitor arrivals (thousands),TF,,220.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2005,Tourist/visitor arrivals (thousands),TF,,1422.0000,Arrivals by all means of transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2010,Tourist/visitor arrivals (thousands),TF,,2508.0000,Arrivals by all means of transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2016,Tourist/visitor arrivals (thousands),TF,,5012.0000,Arrivals by all means of transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2017,Tourist/visitor arrivals (thousands),TF,,5602.0000,Arrivals by all means of transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2018,Tourist/visitor arrivals (thousands),TF,,6201.0000,Arrivals by all means of transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,1995,Tourism expenditure (millions of US dollars),,,71.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2005,Tourism expenditure (millions of US dollars),,,929.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2010,Tourism expenditure (millions of US dollars),,,1671.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2016,Tourism expenditure (millions of US dollars),,,3523.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2017,Tourism expenditure (millions of US dollars),,,4024.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+116,Cambodia,2018,Tourism expenditure (millions of US dollars),,,4832.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2010,Tourist/visitor arrivals (thousands),VF,,573.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2016,Tourist/visitor arrivals (thousands),VF,,994.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2017,Tourist/visitor arrivals (thousands),VF,,1081.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,1995,Tourism expenditure (millions of US dollars),,,75.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2005,Tourism expenditure (millions of US dollars),,,229.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2010,Tourism expenditure (millions of US dollars),,,171.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2016,Tourism expenditure (millions of US dollars),,,508.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2017,Tourism expenditure (millions of US dollars),,,543.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+120,Cameroon,2018,Tourism expenditure (millions of US dollars),,,633.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,1995,Tourist/visitor arrivals (thousands),TF,,16932.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2005,Tourist/visitor arrivals (thousands),TF,,18771.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2010,Tourist/visitor arrivals (thousands),TF,,16219.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2016,Tourist/visitor arrivals (thousands),TF,,19971.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2017,Tourist/visitor arrivals (thousands),TF,,20883.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2018,Tourist/visitor arrivals (thousands),TF,,21134.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,1995,Tourism expenditure (millions of US dollars),,,9176.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2005,Tourism expenditure (millions of US dollars),,,15887.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+124,Canada,2010,Tourism expenditure (millions of US dollars),,,18439.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,1995,Tourist/visitor arrivals (thousands),TF,,361.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2005,Tourist/visitor arrivals (thousands),TF,,168.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2010,Tourist/visitor arrivals (thousands),TF,,288.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2016,Tourist/visitor arrivals (thousands),TF,,385.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2017,Tourist/visitor arrivals (thousands),TF,,418.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2018,Tourist/visitor arrivals (thousands),TF,,463.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,1995,Tourism expenditure (millions of US dollars),,,394.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2005,Tourism expenditure (millions of US dollars),,,356.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2010,Tourism expenditure (millions of US dollars),,,465.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2016,Tourism expenditure (millions of US dollars),,,696.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2017,Tourism expenditure (millions of US dollars),,,782.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+136,Cayman Islands,2018,Tourism expenditure (millions of US dollars),,,880.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,1995,Tourist/visitor arrivals (thousands),TF,,26.0000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2005,Tourist/visitor arrivals (thousands),TF,,12.0000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2010,Tourist/visitor arrivals (thousands),TF,,53.8000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2016,Tourist/visitor arrivals (thousands),TF,,82.0000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2017,Tourist/visitor arrivals (thousands),TF,,107.0000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,1995,Tourism expenditure (millions of US dollars),,,4.0000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2005,Tourism expenditure (millions of US dollars),,,7.2000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+140,Central African Republic,2010,Tourism expenditure (millions of US dollars),,,14.4000,Arrivals by air at Bangui only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+148,Chad,2010,Tourist/visitor arrivals (thousands),TF,,71.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+148,Chad,2016,Tourist/visitor arrivals (thousands),TF,,98.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+148,Chad,2017,Tourist/visitor arrivals (thousands),TF,,87.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+148,Chad,1995,Tourism expenditure (millions of US dollars),,,43.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,1995,Tourist/visitor arrivals (thousands),TF,,1540.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2005,Tourist/visitor arrivals (thousands),TF,,2027.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2010,Tourist/visitor arrivals (thousands),TF,,2801.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2016,Tourist/visitor arrivals (thousands),TF,,5641.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2017,Tourist/visitor arrivals (thousands),TF,,6450.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2018,Tourist/visitor arrivals (thousands),TF,,5723.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,1995,Tourism expenditure (millions of US dollars),,,1186.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2005,Tourism expenditure (millions of US dollars),,,1608.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2010,Tourism expenditure (millions of US dollars),,,2362.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2016,Tourism expenditure (millions of US dollars),,,3744.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2017,Tourism expenditure (millions of US dollars),,,4372.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+152,Chile,2018,Tourism expenditure (millions of US dollars),,,3972.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,1995,Tourist/visitor arrivals (thousands),TF,,20034.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2005,Tourist/visitor arrivals (thousands),TF,,46809.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2010,Tourist/visitor arrivals (thousands),TF,,55664.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2016,Tourist/visitor arrivals (thousands),TF,,59270.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2017,Tourist/visitor arrivals (thousands),TF,,60740.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2018,Tourist/visitor arrivals (thousands),TF,,62900.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,1995,Tourism expenditure (millions of US dollars),,,8730.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2005,Tourism expenditure (millions of US dollars),,,29296.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2010,Tourism expenditure (millions of US dollars),,,45814.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2016,Tourism expenditure (millions of US dollars),,,44432.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2017,Tourism expenditure (millions of US dollars),,,38559.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+156,China,2018,Tourism expenditure (millions of US dollars),,,40386.0000,"For statistical purposes, the data for China do not include those for the Hong Kong Special Administrative Region (Hong Kong SAR), Macao Special Administrative Region (Macao SAR) and Taiwan Province of China.;Excluding passenger transport.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2005,Tourist/visitor arrivals (thousands),TF,,14773.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2010,Tourist/visitor arrivals (thousands),TF,,20085.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2016,Tourist/visitor arrivals (thousands),TF,,26553.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2017,Tourist/visitor arrivals (thousands),TF,,27884.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2018,Tourist/visitor arrivals (thousands),TF,,29263.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2005,Tourism expenditure (millions of US dollars),,,13588.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2010,Tourism expenditure (millions of US dollars),,,27208.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2016,Tourism expenditure (millions of US dollars),,,37838.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2017,Tourism expenditure (millions of US dollars),,,38170.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+344,"China, Hong Kong SAR",2018,Tourism expenditure (millions of US dollars),,,41870.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",1995,Tourist/visitor arrivals (thousands),TF,,4202.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2005,Tourist/visitor arrivals (thousands),TF,,9014.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2010,Tourist/visitor arrivals (thousands),TF,,11926.0000,"Does not include other non-residents namely workers, students, etc.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2016,Tourist/visitor arrivals (thousands),TF,,15703.6000,"Does not include other non-residents namely workers, students, etc.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2017,Tourist/visitor arrivals (thousands),TF,,17255.0000,"Does not include other non-residents namely workers, students, etc.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2018,Tourist/visitor arrivals (thousands),TF,,18493.0000,"Does not include other non-residents namely workers, students, etc.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",1995,Tourism expenditure (millions of US dollars),,,3233.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2005,Tourism expenditure (millions of US dollars),,,7181.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2010,Tourism expenditure (millions of US dollars),,,22688.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2016,Tourism expenditure (millions of US dollars),,,31015.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2017,Tourism expenditure (millions of US dollars),,,36465.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+446,"China, Macao SAR",2018,Tourism expenditure (millions of US dollars),,,40358.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,1995,Tourist/visitor arrivals (thousands),TF,,1399.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2005,Tourist/visitor arrivals (thousands),TF,,933.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2010,Tourist/visitor arrivals (thousands),TF,,1405.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2016,Tourist/visitor arrivals (thousands),TF,,3254.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2017,Tourist/visitor arrivals (thousands),TF,,3631.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2018,Tourist/visitor arrivals (thousands),TF,,3904.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,1995,Tourism expenditure (millions of US dollars),,,887.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2005,Tourism expenditure (millions of US dollars),,,1891.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2010,Tourism expenditure (millions of US dollars),,,3441.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2016,Tourism expenditure (millions of US dollars),,,5584.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2017,Tourism expenditure (millions of US dollars),,,5882.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+170,Colombia,2018,Tourism expenditure (millions of US dollars),,,6617.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,1995,Tourist/visitor arrivals (thousands),TF,,23.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2005,Tourist/visitor arrivals (thousands),TF,,25.9000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2010,Tourist/visitor arrivals (thousands),TF,,15.3000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2016,Tourist/visitor arrivals (thousands),TF,,26.8000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2017,Tourist/visitor arrivals (thousands),TF,,28.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2018,Tourist/visitor arrivals (thousands),TF,,35.9000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,1995,Tourism expenditure (millions of US dollars),,,22.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2005,Tourism expenditure (millions of US dollars),,,24.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2010,Tourism expenditure (millions of US dollars),,,35.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2016,Tourism expenditure (millions of US dollars),,,50.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2017,Tourism expenditure (millions of US dollars),,,60.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+174,Comoros,2018,Tourism expenditure (millions of US dollars),,,76.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2005,Tourist/visitor arrivals (thousands),TF,,35.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2010,Tourist/visitor arrivals (thousands),TF,,194.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2016,Tourist/visitor arrivals (thousands),TF,,211.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2017,Tourist/visitor arrivals (thousands),TF,,149.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2018,Tourist/visitor arrivals (thousands),TF,,156.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,1995,Tourism expenditure (millions of US dollars),,,14.6691,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2010,Tourism expenditure (millions of US dollars),,,39.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+178,Congo,2016,Tourism expenditure (millions of US dollars),,,42.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,1995,Tourist/visitor arrivals (thousands),TF,,48.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2005,Tourist/visitor arrivals (thousands),TF,,88.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2010,Tourist/visitor arrivals (thousands),TF,,104.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2016,Tourist/visitor arrivals (thousands),TF,,146.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2017,Tourist/visitor arrivals (thousands),TF,,161.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2018,Tourist/visitor arrivals (thousands),TF,,169.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,1995,Tourism expenditure (millions of US dollars),,,28.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2005,Tourism expenditure (millions of US dollars),,,91.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2010,Tourism expenditure (millions of US dollars),,,111.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2016,Tourism expenditure (millions of US dollars),,,137.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+184,Cook Islands,2017,Tourism expenditure (millions of US dollars),,,153.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,1995,Tourist/visitor arrivals (thousands),TF,,785.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2005,Tourist/visitor arrivals (thousands),TF,,1679.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2010,Tourist/visitor arrivals (thousands),TF,,2100.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2016,Tourist/visitor arrivals (thousands),TF,,2925.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2017,Tourist/visitor arrivals (thousands),TF,,2960.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2018,Tourist/visitor arrivals (thousands),TF,,3017.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,1995,Tourism expenditure (millions of US dollars),,,763.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2005,Tourism expenditure (millions of US dollars),,,2008.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2010,Tourism expenditure (millions of US dollars),,,2426.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2016,Tourism expenditure (millions of US dollars),,,3776.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2017,Tourism expenditure (millions of US dollars),,,3826.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+188,Costa Rica,2018,Tourism expenditure (millions of US dollars),,,3995.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2010,Tourist/visitor arrivals (thousands),VF,,252.0000,Arrivals to Félix Houphouët Boigny Airport only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2016,Tourist/visitor arrivals (thousands),VF,,1583.0000,Arrivals to Félix Houphouët Boigny Airport only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2017,Tourist/visitor arrivals (thousands),VF,,1800.0000,Arrivals to Félix Houphouët Boigny Airport only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2018,Tourist/visitor arrivals (thousands),VF,,1965.0000,Arrivals to Félix Houphouët Boigny Airport only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,1995,Tourism expenditure (millions of US dollars),,,103.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2005,Tourism expenditure (millions of US dollars),,,93.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2010,Tourism expenditure (millions of US dollars),,,213.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2016,Tourism expenditure (millions of US dollars),,,477.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+384,Côte d’Ivoire,2017,Tourism expenditure (millions of US dollars),,,508.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,1995,Tourist/visitor arrivals (thousands),TCE,,1485.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2005,Tourist/visitor arrivals (thousands),TCE,,7743.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2010,Tourist/visitor arrivals (thousands),TCE,,9111.0000,Excluding arrivals in ports of nautical tourism.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2016,Tourist/visitor arrivals (thousands),TCE,,13809.0000,Excluding arrivals in ports of nautical tourism.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2017,Tourist/visitor arrivals (thousands),TCE,,15593.0000,Excluding arrivals in ports of nautical tourism.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2018,Tourist/visitor arrivals (thousands),TCE,,16645.0000,Excluding arrivals in ports of nautical tourism.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2005,Tourism expenditure (millions of US dollars),,,7625.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2010,Tourism expenditure (millions of US dollars),,,8299.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2016,Tourism expenditure (millions of US dollars),,,9820.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2017,Tourism expenditure (millions of US dollars),,,11128.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+191,Croatia,2018,Tourism expenditure (millions of US dollars),,,12075.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,1995,Tourist/visitor arrivals (thousands),TF,,742.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2005,Tourist/visitor arrivals (thousands),TF,,2261.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2010,Tourist/visitor arrivals (thousands),TF,,2507.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2016,Tourist/visitor arrivals (thousands),TF,,3975.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2017,Tourist/visitor arrivals (thousands),TF,,4594.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2018,Tourist/visitor arrivals (thousands),TF,,4684.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,1995,Tourism expenditure (millions of US dollars),,,1100.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2005,Tourism expenditure (millions of US dollars),,,2591.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2010,Tourism expenditure (millions of US dollars),,,2396.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2016,Tourism expenditure (millions of US dollars),,,3069.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2017,Tourism expenditure (millions of US dollars),,,3302.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+192,Cuba,2018,Tourism expenditure (millions of US dollars),,,2969.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,1995,Tourist/visitor arrivals (thousands),TF,,224.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2005,Tourist/visitor arrivals (thousands),TF,,222.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2010,Tourist/visitor arrivals (thousands),TF,,342.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2016,Tourist/visitor arrivals (thousands),TF,,441.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2017,Tourist/visitor arrivals (thousands),TF,,399.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2018,Tourist/visitor arrivals (thousands),TF,,432.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,1995,Tourism expenditure (millions of US dollars),,,175.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2005,Tourism expenditure (millions of US dollars),,,244.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2010,Tourism expenditure (millions of US dollars),,,438.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2016,Tourism expenditure (millions of US dollars),,,644.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2017,Tourism expenditure (millions of US dollars),,,572.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+531,Curaçao,2018,Tourism expenditure (millions of US dollars),,,605.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,1995,Tourist/visitor arrivals (thousands),TF,,2100.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2005,Tourist/visitor arrivals (thousands),TF,,2470.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2010,Tourist/visitor arrivals (thousands),TF,,2173.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2016,Tourist/visitor arrivals (thousands),TF,,3187.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2017,Tourist/visitor arrivals (thousands),TF,,3652.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2018,Tourist/visitor arrivals (thousands),TF,,3939.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,1995,Tourism expenditure (millions of US dollars),,,2018.0443,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2005,Tourism expenditure (millions of US dollars),,,2644.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2010,Tourism expenditure (millions of US dollars),,,2137.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2016,Tourism expenditure (millions of US dollars),,,2870.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2017,Tourism expenditure (millions of US dollars),,,3274.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+196,Cyprus,2018,Tourism expenditure (millions of US dollars),,,3449.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2005,Tourist/visitor arrivals (thousands),TF,,9404.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2010,Tourist/visitor arrivals (thousands),TF,,8629.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2016,Tourist/visitor arrivals (thousands),TF,,12808.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2017,Tourist/visitor arrivals (thousands),TF,,13665.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2005,Tourism expenditure (millions of US dollars),,,5772.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2010,Tourism expenditure (millions of US dollars),,,8068.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2016,Tourism expenditure (millions of US dollars),,,7041.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2017,Tourism expenditure (millions of US dollars),,,7695.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+203,Czechia,2018,Tourism expenditure (millions of US dollars),,,8291.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,1995,Tourist/visitor arrivals (thousands),TF,,35.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2005,Tourist/visitor arrivals (thousands),TF,,61.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2010,Tourist/visitor arrivals (thousands),TF,,81.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2016,Tourist/visitor arrivals (thousands),TF,,351.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2005,Tourism expenditure (millions of US dollars),,,3.2000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2010,Tourism expenditure (millions of US dollars),,,10.7000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2016,Tourism expenditure (millions of US dollars),,,4.3000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2017,Tourism expenditure (millions of US dollars),,,6.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+180,Dem. Rep. of the Congo,2018,Tourism expenditure (millions of US dollars),,,60.5000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2005,Tourist/visitor arrivals (thousands),TCE,,9587.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2010,Tourist/visitor arrivals (thousands),TCE,,9425.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2016,Tourist/visitor arrivals (thousands),TCE,,10781.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2017,Tourist/visitor arrivals (thousands),TCE,,12426.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2018,Tourist/visitor arrivals (thousands),TCE,,12749.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,1995,Tourism expenditure (millions of US dollars),,,3691.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2005,Tourism expenditure (millions of US dollars),,,5293.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2010,Tourism expenditure (millions of US dollars),,,5704.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2016,Tourism expenditure (millions of US dollars),,,7494.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2017,Tourism expenditure (millions of US dollars),,,8508.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+208,Denmark,2018,Tourism expenditure (millions of US dollars),,,9097.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,1995,Tourist/visitor arrivals (thousands),THS,,21.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2005,Tourist/visitor arrivals (thousands),THS,,30.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2010,Tourist/visitor arrivals (thousands),THS,,51.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,1995,Tourism expenditure (millions of US dollars),,,5.4000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2005,Tourism expenditure (millions of US dollars),,,7.1000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2010,Tourism expenditure (millions of US dollars),,,18.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2016,Tourism expenditure (millions of US dollars),,,33.5000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2017,Tourism expenditure (millions of US dollars),,,36.2000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+262,Djibouti,2018,Tourism expenditure (millions of US dollars),,,57.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,1995,Tourist/visitor arrivals (thousands),TF,,60.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2005,Tourist/visitor arrivals (thousands),TF,,79.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2010,Tourist/visitor arrivals (thousands),TF,,77.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2016,Tourist/visitor arrivals (thousands),TF,,78.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2017,Tourist/visitor arrivals (thousands),TF,,72.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2018,Tourist/visitor arrivals (thousands),TF,,63.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,1995,Tourism expenditure (millions of US dollars),,,42.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2005,Tourism expenditure (millions of US dollars),,,57.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2010,Tourism expenditure (millions of US dollars),,,94.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2016,Tourism expenditure (millions of US dollars),,,198.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2017,Tourism expenditure (millions of US dollars),,,161.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+212,Dominica,2018,Tourism expenditure (millions of US dollars),,,111.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,1995,Tourist/visitor arrivals (thousands),TF,,1776.0000,Including nationals residing abroad.;Arrivals by air.;Excluding the passengers at Herrera airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2005,Tourist/visitor arrivals (thousands),TF,,3691.0000,Including nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2010,Tourist/visitor arrivals (thousands),TF,,4125.0000,Including nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2016,Tourist/visitor arrivals (thousands),TF,,5959.3000,Including nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2017,Tourist/visitor arrivals (thousands),TF,,6188.0000,Including nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2018,Tourist/visitor arrivals (thousands),TF,,6569.0000,Including nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,1995,Tourism expenditure (millions of US dollars),,,1571.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2005,Tourism expenditure (millions of US dollars),,,3518.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2010,Tourism expenditure (millions of US dollars),,,4162.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2016,Tourism expenditure (millions of US dollars),,,6720.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2017,Tourism expenditure (millions of US dollars),,,7184.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+214,Dominican Republic,2018,Tourism expenditure (millions of US dollars),,,7561.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,1995,Tourist/visitor arrivals (thousands),VF,,440.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2005,Tourist/visitor arrivals (thousands),VF,,860.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2010,Tourist/visitor arrivals (thousands),VF,,1047.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2016,Tourist/visitor arrivals (thousands),VF,,1569.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2017,Tourist/visitor arrivals (thousands),VF,,1806.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2018,Tourist/visitor arrivals (thousands),VF,,2535.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,1995,Tourism expenditure (millions of US dollars),,,315.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2005,Tourism expenditure (millions of US dollars),,,488.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2010,Tourism expenditure (millions of US dollars),,,786.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2016,Tourism expenditure (millions of US dollars),,,1450.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2017,Tourism expenditure (millions of US dollars),,,1554.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+218,Ecuador,2018,Tourism expenditure (millions of US dollars),,,1878.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,1995,Tourist/visitor arrivals (thousands),TF,,2871.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2005,Tourist/visitor arrivals (thousands),TF,,8244.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2010,Tourist/visitor arrivals (thousands),TF,,14051.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2016,Tourist/visitor arrivals (thousands),TF,,5258.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2017,Tourist/visitor arrivals (thousands),TF,,8157.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2018,Tourist/visitor arrivals (thousands),TF,,11196.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,1995,Tourism expenditure (millions of US dollars),,,2954.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2005,Tourism expenditure (millions of US dollars),,,7206.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2010,Tourism expenditure (millions of US dollars),,,13633.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2016,Tourism expenditure (millions of US dollars),,,3306.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2017,Tourism expenditure (millions of US dollars),,,8636.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+818,Egypt,2018,Tourism expenditure (millions of US dollars),,,12704.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,1995,Tourist/visitor arrivals (thousands),TF,,235.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2005,Tourist/visitor arrivals (thousands),TF,,1127.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2010,Tourist/visitor arrivals (thousands),TF,,1150.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2016,Tourist/visitor arrivals (thousands),TF,,1434.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2017,Tourist/visitor arrivals (thousands),TF,,1556.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2018,Tourist/visitor arrivals (thousands),TF,,1677.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,1995,Tourism expenditure (millions of US dollars),,,152.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2005,Tourism expenditure (millions of US dollars),,,656.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2010,Tourism expenditure (millions of US dollars),,,646.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2016,Tourism expenditure (millions of US dollars),,,1161.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2017,Tourism expenditure (millions of US dollars),,,1227.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+222,El Salvador,2018,Tourism expenditure (millions of US dollars),,,1370.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+226,Equatorial Guinea,1995,Tourism expenditure (millions of US dollars),,,1.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,1995,Tourist/visitor arrivals (thousands),VF,,315.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,2005,Tourist/visitor arrivals (thousands),VF,,83.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,2010,Tourist/visitor arrivals (thousands),VF,,84.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,2016,Tourist/visitor arrivals (thousands),VF,,142.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,1995,Tourism expenditure (millions of US dollars),,,58.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,2005,Tourism expenditure (millions of US dollars),,,66.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+232,Eritrea,2016,Tourism expenditure (millions of US dollars),,,48.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,1995,Tourist/visitor arrivals (thousands),TF,,530.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2005,Tourist/visitor arrivals (thousands),TF,,1917.0000,"Border statistics are not collected any more, surveys used instead.;Calculated on the basis of accommodation statistics and “Foreign Visitor Survey” carried out by the Statistical Office of Estonia.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2010,Tourist/visitor arrivals (thousands),TF,,2511.0000,"Border statistics are not collected any more, surveys used instead.;Based on mobile positioning data.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2016,Tourist/visitor arrivals (thousands),TF,,3131.0000,"Border statistics are not collected any more, surveys used instead.;Based on mobile positioning data.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2017,Tourist/visitor arrivals (thousands),TF,,3244.0000,"Border statistics are not collected any more, surveys used instead.;Based on mobile positioning data.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2018,Tourist/visitor arrivals (thousands),TF,,3234.0000,"Border statistics are not collected any more, surveys used instead.;Based on mobile positioning data.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,1995,Tourism expenditure (millions of US dollars),,,452.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2005,Tourism expenditure (millions of US dollars),,,1229.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2016,Tourism expenditure (millions of US dollars),,,1916.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2017,Tourism expenditure (millions of US dollars),,,2126.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+233,Estonia,2018,Tourism expenditure (millions of US dollars),,,2332.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,1995,Tourist/visitor arrivals (thousands),TF,,300.0000,Arrivals in hotels only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2005,Tourist/visitor arrivals (thousands),TF,,837.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2010,Tourist/visitor arrivals (thousands),TF,,868.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2016,Tourist/visitor arrivals (thousands),TF,,947.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2017,Tourist/visitor arrivals (thousands),TF,,921.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2018,Tourist/visitor arrivals (thousands),TF,,782.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,1995,Tourism expenditure (millions of US dollars),,,54.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2005,Tourism expenditure (millions of US dollars),,,77.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2010,Tourism expenditure (millions of US dollars),,,51.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2016,Tourism expenditure (millions of US dollars),,,13.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2017,Tourism expenditure (millions of US dollars),,,13.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+748,Eswatini,2018,Tourism expenditure (millions of US dollars),,,16.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,1995,Tourist/visitor arrivals (thousands),TF,,103.0000,Arrivals to Bole airport only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2005,Tourist/visitor arrivals (thousands),TF,,227.0000,Including nationals residing abroad.;Arrivals through all ports of entry.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2010,Tourist/visitor arrivals (thousands),TF,,468.0000,Including nationals residing abroad.;Arrivals through all ports of entry.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2016,Tourist/visitor arrivals (thousands),TF,,871.0000,Including nationals residing abroad.;Arrivals through all ports of entry.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2017,Tourist/visitor arrivals (thousands),TF,,933.0000,Including nationals residing abroad.;Arrivals through all ports of entry.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2018,Tourist/visitor arrivals (thousands),TF,,849.0000,Including nationals residing abroad.;Arrivals through all ports of entry.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,1995,Tourism expenditure (millions of US dollars),,,177.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2005,Tourism expenditure (millions of US dollars),,,533.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2010,Tourism expenditure (millions of US dollars),,,1434.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2016,Tourism expenditure (millions of US dollars),,,2138.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2017,Tourism expenditure (millions of US dollars),,,2505.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+231,Ethiopia,2018,Tourism expenditure (millions of US dollars),,,3548.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,1995,Tourist/visitor arrivals (thousands),TF,,318.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2005,Tourist/visitor arrivals (thousands),TF,,545.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2010,Tourist/visitor arrivals (thousands),TF,,632.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2016,Tourist/visitor arrivals (thousands),TF,,792.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2017,Tourist/visitor arrivals (thousands),TF,,843.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2018,Tourist/visitor arrivals (thousands),TF,,870.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,1995,Tourism expenditure (millions of US dollars),,,369.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2005,Tourism expenditure (millions of US dollars),,,722.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2010,Tourism expenditure (millions of US dollars),,,825.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2016,Tourism expenditure (millions of US dollars),,,1149.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2017,Tourism expenditure (millions of US dollars),,,1243.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+242,Fiji,2018,Tourism expenditure (millions of US dollars),,,1370.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,1995,Tourist/visitor arrivals (thousands),TCE,,1779.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2005,Tourist/visitor arrivals (thousands),TCE,,2080.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2010,Tourist/visitor arrivals (thousands),TCE,,2319.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2016,Tourist/visitor arrivals (thousands),TCE,,2789.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2017,Tourist/visitor arrivals (thousands),TCE,,3180.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2018,Tourist/visitor arrivals (thousands),TCE,,3224.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,1995,Tourism expenditure (millions of US dollars),,,2383.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2005,Tourism expenditure (millions of US dollars),,,3069.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2010,Tourism expenditure (millions of US dollars),,,4497.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2016,Tourism expenditure (millions of US dollars),,,4016.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2017,Tourism expenditure (millions of US dollars),,,5207.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+246,Finland,2018,Tourism expenditure (millions of US dollars),,,5663.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,1995,Tourist/visitor arrivals (thousands),TF,,60033.0000,Estimated based on surveys at national borders.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2005,Tourist/visitor arrivals (thousands),TF,,74988.0000,Arrivals of non-resident visitors.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2010,Tourist/visitor arrivals (thousands),TF,,76647.0000,Arrivals of non-resident visitors.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2016,Tourist/visitor arrivals (thousands),TF,,82682.0000,Arrivals of non-resident visitors.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2017,Tourist/visitor arrivals (thousands),TF,,86758.0000,Arrivals of non-resident visitors.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2018,Tourist/visitor arrivals (thousands),TF,,89322.0000,Estimate.;Arrivals of non-resident visitors.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,1995,Tourism expenditure (millions of US dollars),,,31295.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2005,Tourism expenditure (millions of US dollars),,,52126.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2010,Tourism expenditure (millions of US dollars),,,56178.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2016,Tourism expenditure (millions of US dollars),,,63557.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2017,Tourism expenditure (millions of US dollars),,,67936.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+250,France,2018,Tourism expenditure (millions of US dollars),,,73125.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+254,French Guiana,2005,Tourist/visitor arrivals (thousands),TF,,95.0000,Survey at Cayenne-Rochambeau airport on departure.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+254,French Guiana,2016,Tourist/visitor arrivals (thousands),TF,,96.0000,Survey at Cayenne-Rochambeau airport on departure.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+254,French Guiana,2017,Tourist/visitor arrivals (thousands),TF,,111.0000,Survey at Cayenne-Rochambeau airport on departure.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+254,French Guiana,2005,Tourism expenditure (millions of US dollars),,,44.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,1995,Tourist/visitor arrivals (thousands),TF,,172.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2005,Tourist/visitor arrivals (thousands),TF,,208.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2010,Tourist/visitor arrivals (thousands),TF,,154.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2016,Tourist/visitor arrivals (thousands),TF,,192.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2017,Tourist/visitor arrivals (thousands),TF,,199.0000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2018,Tourist/visitor arrivals (thousands),TF,,216.3000,Excluding nationals residing abroad.;Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,1995,Tourism expenditure (millions of US dollars),,,326.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2005,Tourism expenditure (millions of US dollars),,,759.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2010,Tourism expenditure (millions of US dollars),,,630.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+258,French Polynesia,2016,Tourism expenditure (millions of US dollars),,,782.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,1995,Tourist/visitor arrivals (thousands),TF,,125.0000,Arrivals of non-resident tourists at Libreville airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,2005,Tourist/visitor arrivals (thousands),TF,,269.0000,Arrivals of non-resident tourists at Libreville airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,1995,Tourism expenditure (millions of US dollars),,,94.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,2005,Tourism expenditure (millions of US dollars),,,13.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,2010,Tourism expenditure (millions of US dollars),,,89.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+266,Gabon,2016,Tourism expenditure (millions of US dollars),,,28.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,1995,Tourist/visitor arrivals (thousands),TF,,45.0000,Including nationals residing abroad.;Arrivals by air only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2005,Tourist/visitor arrivals (thousands),TF,,108.0000,Including nationals residing abroad.;Arrivals by air only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2010,Tourist/visitor arrivals (thousands),TF,,91.0000,Including nationals residing abroad.;Arrivals by air only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2016,Tourist/visitor arrivals (thousands),TF,,450.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2017,Tourist/visitor arrivals (thousands),TF,,522.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2018,Tourist/visitor arrivals (thousands),TF,,552.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2005,Tourism expenditure (millions of US dollars),,,59.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2010,Tourism expenditure (millions of US dollars),,,80.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2016,Tourism expenditure (millions of US dollars),,,120.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2017,Tourism expenditure (millions of US dollars),,,116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+270,Gambia,2018,Tourism expenditure (millions of US dollars),,,168.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2010,Tourist/visitor arrivals (thousands),TF,,1067.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2016,Tourist/visitor arrivals (thousands),TF,,3297.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2017,Tourist/visitor arrivals (thousands),TF,,4069.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2018,Tourist/visitor arrivals (thousands),TF,,4757.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2005,Tourism expenditure (millions of US dollars),,,287.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2010,Tourism expenditure (millions of US dollars),,,737.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2016,Tourism expenditure (millions of US dollars),,,2315.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2017,Tourism expenditure (millions of US dollars),,,2971.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+268,Georgia,2018,Tourism expenditure (millions of US dollars),,,3518.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,1995,Tourist/visitor arrivals (thousands),TCE,,14847.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2005,Tourist/visitor arrivals (thousands),TCE,,21500.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2010,Tourist/visitor arrivals (thousands),TCE,,26875.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2016,Tourist/visitor arrivals (thousands),TCE,,35555.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2017,Tourist/visitor arrivals (thousands),TCE,,37452.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2018,Tourist/visitor arrivals (thousands),TCE,,38881.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,1995,Tourism expenditure (millions of US dollars),,,24053.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2005,Tourism expenditure (millions of US dollars),,,40518.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2010,Tourism expenditure (millions of US dollars),,,49116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2016,Tourism expenditure (millions of US dollars),,,52229.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2017,Tourism expenditure (millions of US dollars),,,56330.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+276,Germany,2018,Tourism expenditure (millions of US dollars),,,60260.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,1995,Tourist/visitor arrivals (thousands),TF,,286.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2005,Tourist/visitor arrivals (thousands),TF,,429.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2010,Tourist/visitor arrivals (thousands),TF,,931.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,1995,Tourism expenditure (millions of US dollars),,,30.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2005,Tourism expenditure (millions of US dollars),,,867.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2010,Tourism expenditure (millions of US dollars),,,706.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2016,Tourism expenditure (millions of US dollars),,,952.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2017,Tourism expenditure (millions of US dollars),,,919.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+288,Ghana,2018,Tourism expenditure (millions of US dollars),,,996.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,1995,Tourist/visitor arrivals (thousands),TF,,10130.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2005,Tourist/visitor arrivals (thousands),TF,,14765.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2010,Tourist/visitor arrivals (thousands),TF,,15007.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2016,Tourist/visitor arrivals (thousands),TF,,24799.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2017,Tourist/visitor arrivals (thousands),TF,,27194.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2018,Tourist/visitor arrivals (thousands),TF,,30123.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,1995,Tourism expenditure (millions of US dollars),,,4182.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2005,Tourism expenditure (millions of US dollars),,,13455.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2010,Tourism expenditure (millions of US dollars),,,13857.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2016,Tourism expenditure (millions of US dollars),,,16811.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2017,Tourism expenditure (millions of US dollars),,,19139.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+300,Greece,2018,Tourism expenditure (millions of US dollars),,,21594.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,1995,Tourist/visitor arrivals (thousands),TF,,108.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2005,Tourist/visitor arrivals (thousands),TF,,99.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2010,Tourist/visitor arrivals (thousands),TF,,110.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2016,Tourist/visitor arrivals (thousands),TF,,156.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2017,Tourist/visitor arrivals (thousands),TF,,168.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2018,Tourist/visitor arrivals (thousands),TF,,185.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,1995,Tourism expenditure (millions of US dollars),,,76.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2005,Tourism expenditure (millions of US dollars),,,71.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2010,Tourism expenditure (millions of US dollars),,,112.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2016,Tourism expenditure (millions of US dollars),,,437.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2017,Tourism expenditure (millions of US dollars),,,482.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+308,Grenada,2018,Tourism expenditure (millions of US dollars),,,548.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,1995,Tourist/visitor arrivals (thousands),TF,,640.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).;Non-resident tourists staying in all types of accommodation establishments.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2005,Tourist/visitor arrivals (thousands),TF,,372.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2010,Tourist/visitor arrivals (thousands),TF,,392.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2016,Tourist/visitor arrivals (thousands),TF,,581.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2017,Tourist/visitor arrivals (thousands),TF,,650.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2018,Tourist/visitor arrivals (thousands),TF,,735.0000,"Arrivals by air.;Excluding the north islands, Saint Barthélemy and Saint Martin (French part).","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,1995,Tourism expenditure (millions of US dollars),,,458.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2005,Tourism expenditure (millions of US dollars),,,306.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2010,Tourism expenditure (millions of US dollars),,,510.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+312,Guadeloupe,2018,Tourism expenditure (millions of US dollars),,,860.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,1995,Tourist/visitor arrivals (thousands),TF,,1362.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,2005,Tourist/visitor arrivals (thousands),TF,,1228.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,2010,Tourist/visitor arrivals (thousands),TF,,1197.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,2016,Tourist/visitor arrivals (thousands),TF,,1536.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,2017,Tourist/visitor arrivals (thousands),TF,,1545.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+316,Guam,2018,Tourist/visitor arrivals (thousands),TF,,1549.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2010,Tourist/visitor arrivals (thousands),TF,,1119.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2016,Tourist/visitor arrivals (thousands),TF,,1585.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2017,Tourist/visitor arrivals (thousands),TF,,1660.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2018,Tourist/visitor arrivals (thousands),TF,,1781.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,1995,Tourism expenditure (millions of US dollars),,,213.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2005,Tourism expenditure (millions of US dollars),,,791.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2010,Tourism expenditure (millions of US dollars),,,1378.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2016,Tourism expenditure (millions of US dollars),,,1550.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2017,Tourism expenditure (millions of US dollars),,,1566.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+320,Guatemala,2018,Tourism expenditure (millions of US dollars),,,1549.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2005,Tourist/visitor arrivals (thousands),TF,,45.0000,Arrivals by air at Conakry airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2010,Tourist/visitor arrivals (thousands),TF,,12.4000,Arrivals by air at Conakry airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2016,Tourist/visitor arrivals (thousands),TF,,63.0000,Arrivals by air at Conakry airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2017,Tourist/visitor arrivals (thousands),TF,,99.0000,Arrivals by air at Conakry airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,1995,Tourism expenditure (millions of US dollars),,,0.9110,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2010,Tourism expenditure (millions of US dollars),,,2.0400,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2016,Tourism expenditure (millions of US dollars),,,16.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2017,Tourism expenditure (millions of US dollars),,,16.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+324,Guinea,2018,Tourism expenditure (millions of US dollars),,,7.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2005,Tourist/visitor arrivals (thousands),TF,,5.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2010,Tourist/visitor arrivals (thousands),TF,,22.3000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2016,Tourist/visitor arrivals (thousands),TF,,45.2000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2005,Tourism expenditure (millions of US dollars),,,1.6000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2010,Tourism expenditure (millions of US dollars),,,13.3000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2016,Tourism expenditure (millions of US dollars),,,11.5000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2017,Tourism expenditure (millions of US dollars),,,16.3000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+624,Guinea-Bissau,2018,Tourism expenditure (millions of US dollars),,,19.8000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,1995,Tourist/visitor arrivals (thousands),TF,,106.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2005,Tourist/visitor arrivals (thousands),TF,,117.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2010,Tourist/visitor arrivals (thousands),TF,,152.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2016,Tourist/visitor arrivals (thousands),TF,,235.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2017,Tourist/visitor arrivals (thousands),TF,,247.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2018,Tourist/visitor arrivals (thousands),TF,,287.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,1995,Tourism expenditure (millions of US dollars),,,33.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2005,Tourism expenditure (millions of US dollars),,,35.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2010,Tourism expenditure (millions of US dollars),,,80.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2016,Tourism expenditure (millions of US dollars),,,104.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2017,Tourism expenditure (millions of US dollars),,,95.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+328,Guyana,2018,Tourism expenditure (millions of US dollars),,,28.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,1995,Tourist/visitor arrivals (thousands),TF,,145.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2005,Tourist/visitor arrivals (thousands),TF,,112.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2010,Tourist/visitor arrivals (thousands),TF,,255.0000,Arrivals by air.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2016,Tourist/visitor arrivals (thousands),TF,,445.0000,Arrivals by air.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2017,Tourist/visitor arrivals (thousands),TF,,467.0000,Arrivals by air.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2018,Tourist/visitor arrivals (thousands),TF,,447.0000,Arrivals by air.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,1995,Tourism expenditure (millions of US dollars),,,90.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2005,Tourism expenditure (millions of US dollars),,,80.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2010,Tourism expenditure (millions of US dollars),,,383.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2016,Tourism expenditure (millions of US dollars),,,511.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2017,Tourism expenditure (millions of US dollars),,,460.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+332,Haiti,2018,Tourism expenditure (millions of US dollars),,,620.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,1995,Tourist/visitor arrivals (thousands),TF,,271.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2005,Tourist/visitor arrivals (thousands),TF,,673.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2010,Tourist/visitor arrivals (thousands),TF,,863.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2016,Tourist/visitor arrivals (thousands),TF,,838.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2017,Tourist/visitor arrivals (thousands),TF,,851.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,1995,Tourism expenditure (millions of US dollars),,,85.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2005,Tourism expenditure (millions of US dollars),,,465.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2010,Tourism expenditure (millions of US dollars),,,626.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2016,Tourism expenditure (millions of US dollars),,,700.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2017,Tourism expenditure (millions of US dollars),,,722.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+340,Honduras,2018,Tourism expenditure (millions of US dollars),,,745.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2005,Tourist/visitor arrivals (thousands),TF,,9979.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2010,Tourist/visitor arrivals (thousands),TF,,9510.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2016,Tourist/visitor arrivals (thousands),TF,,15255.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2017,Tourist/visitor arrivals (thousands),TF,,15785.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2018,Tourist/visitor arrivals (thousands),TF,,17552.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,1995,Tourism expenditure (millions of US dollars),,,2938.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2005,Tourism expenditure (millions of US dollars),,,4761.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2010,Tourism expenditure (millions of US dollars),,,6595.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2016,Tourism expenditure (millions of US dollars),,,7481.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2017,Tourism expenditure (millions of US dollars),,,8448.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+348,Hungary,2018,Tourism expenditure (millions of US dollars),,,9595.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,1995,Tourist/visitor arrivals (thousands),TF,,190.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2005,Tourist/visitor arrivals (thousands),TF,,374.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2010,Tourist/visitor arrivals (thousands),TF,,489.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2016,Tourist/visitor arrivals (thousands),TF,,1792.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2017,Tourist/visitor arrivals (thousands),TF,,2225.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2018,Tourist/visitor arrivals (thousands),TF,,2343.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,1995,Tourism expenditure (millions of US dollars),,,186.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2005,Tourism expenditure (millions of US dollars),,,413.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2010,Tourism expenditure (millions of US dollars),,,562.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2016,Tourism expenditure (millions of US dollars),,,2411.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2017,Tourism expenditure (millions of US dollars),,,3024.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+352,Iceland,2018,Tourism expenditure (millions of US dollars),,,3128.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,1995,Tourist/visitor arrivals (thousands),TF,,2124.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2005,Tourist/visitor arrivals (thousands),TF,,3919.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2010,Tourist/visitor arrivals (thousands),TF,,5776.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2016,Tourist/visitor arrivals (thousands),TF,,14570.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2017,Tourist/visitor arrivals (thousands),TF,,15543.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2018,Tourist/visitor arrivals (thousands),TF,,17423.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2005,Tourism expenditure (millions of US dollars),,,7659.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2016,Tourism expenditure (millions of US dollars),,,23111.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2017,Tourism expenditure (millions of US dollars),,,27878.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+356,India,2018,Tourism expenditure (millions of US dollars),,,29143.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,1995,Tourist/visitor arrivals (thousands),VF,,4324.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2005,Tourist/visitor arrivals (thousands),VF,,5002.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2010,Tourist/visitor arrivals (thousands),VF,,7003.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2016,Tourist/visitor arrivals (thousands),VF,,11519.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2017,Tourist/visitor arrivals (thousands),VF,,14040.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2018,Tourist/visitor arrivals (thousands),VF,,15810.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2005,Tourism expenditure (millions of US dollars),,,5094.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2010,Tourism expenditure (millions of US dollars),,,7618.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2016,Tourism expenditure (millions of US dollars),,,12566.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2017,Tourism expenditure (millions of US dollars),,,14691.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+360,Indonesia,2018,Tourism expenditure (millions of US dollars),,,15600.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),1995,Tourist/visitor arrivals (thousands),VF,,568.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2010,Tourist/visitor arrivals (thousands),VF,,2938.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2016,Tourist/visitor arrivals (thousands),VF,,4942.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2017,Tourist/visitor arrivals (thousands),VF,,4867.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2018,Tourist/visitor arrivals (thousands),VF,,7295.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),1995,Tourism expenditure (millions of US dollars),,,205.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2005,Tourism expenditure (millions of US dollars),,,1025.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2010,Tourism expenditure (millions of US dollars),,,2631.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2016,Tourism expenditure (millions of US dollars),,,3914.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+364,Iran (Islamic Republic of),2017,Tourism expenditure (millions of US dollars),,,4632.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,1995,Tourist/visitor arrivals (thousands),VF,,61.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2010,Tourist/visitor arrivals (thousands),VF,,1518.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2005,Tourism expenditure (millions of US dollars),,,186.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2010,Tourism expenditure (millions of US dollars),,,1736.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2016,Tourism expenditure (millions of US dollars),,,3120.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2017,Tourism expenditure (millions of US dollars),,,2959.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+368,Iraq,2018,Tourism expenditure (millions of US dollars),,,1986.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,1995,Tourist/visitor arrivals (thousands),TF,,4818.0000,Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2005,Tourist/visitor arrivals (thousands),TF,,7333.0000,Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2010,Tourist/visitor arrivals (thousands),TF,,7134.0000,Break in the time series.;Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2016,Tourist/visitor arrivals (thousands),TF,,10100.0000,Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2017,Tourist/visitor arrivals (thousands),TF,,10338.0000,Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2018,Tourist/visitor arrivals (thousands),TF,,10926.0000,Including tourists from Northern Ireland.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,1995,Tourism expenditure (millions of US dollars),,,2697.7927,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2005,Tourism expenditure (millions of US dollars),,,6779.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2010,Tourism expenditure (millions of US dollars),,,8185.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2016,Tourism expenditure (millions of US dollars),,,11429.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2017,Tourism expenditure (millions of US dollars),,,14294.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+372,Ireland,2018,Tourism expenditure (millions of US dollars),,,14658.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,1995,Tourist/visitor arrivals (thousands),TF,,2215.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2005,Tourist/visitor arrivals (thousands),TF,,1903.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2010,Tourist/visitor arrivals (thousands),TF,,2803.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2016,Tourist/visitor arrivals (thousands),TF,,2900.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2017,Tourist/visitor arrivals (thousands),TF,,3613.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2018,Tourist/visitor arrivals (thousands),TF,,4121.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,1995,Tourism expenditure (millions of US dollars),,,3491.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2005,Tourism expenditure (millions of US dollars),,,2750.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2010,Tourism expenditure (millions of US dollars),,,5621.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2016,Tourism expenditure (millions of US dollars),,,6587.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2017,Tourism expenditure (millions of US dollars),,,7578.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+376,Israel,2018,Tourism expenditure (millions of US dollars),,,8073.0000,Including the expenditures of foreign workers in Israel.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,1995,Tourist/visitor arrivals (thousands),TF,,31052.0000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2005,Tourist/visitor arrivals (thousands),TF,,36513.0000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2010,Tourist/visitor arrivals (thousands),TF,,43626.0000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2016,Tourist/visitor arrivals (thousands),TF,,52372.0000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2017,Tourist/visitor arrivals (thousands),TF,,58253.0000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2018,Tourist/visitor arrivals (thousands),TF,,61567.2000,Excluding seasonal and border workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,1995,Tourism expenditure (millions of US dollars),,,30411.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2005,Tourism expenditure (millions of US dollars),,,38364.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2016,Tourism expenditure (millions of US dollars),,,42423.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2017,Tourism expenditure (millions of US dollars),,,46719.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+380,Italy,2018,Tourism expenditure (millions of US dollars),,,51602.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,1995,Tourist/visitor arrivals (thousands),TF,,1147.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2005,Tourist/visitor arrivals (thousands),TF,,1479.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2010,Tourist/visitor arrivals (thousands),TF,,1922.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2016,Tourist/visitor arrivals (thousands),TF,,2182.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2017,Tourist/visitor arrivals (thousands),TF,,2353.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2018,Tourist/visitor arrivals (thousands),TF,,2473.0000,Including nationals residing abroad; E/D cards.;Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,1995,Tourism expenditure (millions of US dollars),,,1069.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2005,Tourism expenditure (millions of US dollars),,,1545.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2010,Tourism expenditure (millions of US dollars),,,2001.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2016,Tourism expenditure (millions of US dollars),,,2539.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2017,Tourism expenditure (millions of US dollars),,,2809.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+388,Jamaica,2018,Tourism expenditure (millions of US dollars),,,3099.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,1995,Tourist/visitor arrivals (thousands),VF,,3345.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2005,Tourist/visitor arrivals (thousands),VF,,6728.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2010,Tourist/visitor arrivals (thousands),VF,,8611.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2016,Tourist/visitor arrivals (thousands),VF,,24040.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2017,Tourist/visitor arrivals (thousands),VF,,28691.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2018,Tourist/visitor arrivals (thousands),VF,,31192.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,1995,Tourism expenditure (millions of US dollars),,,4894.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2005,Tourism expenditure (millions of US dollars),,,15554.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2010,Tourism expenditure (millions of US dollars),,,15356.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2016,Tourism expenditure (millions of US dollars),,,33456.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2017,Tourism expenditure (millions of US dollars),,,36978.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+392,Japan,2018,Tourism expenditure (millions of US dollars),,,45276.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,1995,Tourist/visitor arrivals (thousands),TF,,1075.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2005,Tourist/visitor arrivals (thousands),TF,,2987.0000,Break in the time series.;Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2010,Tourist/visitor arrivals (thousands),TF,,4207.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2016,Tourist/visitor arrivals (thousands),TF,,3567.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2017,Tourist/visitor arrivals (thousands),TF,,3843.5000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2018,Tourist/visitor arrivals (thousands),TF,,4150.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,1995,Tourism expenditure (millions of US dollars),,,973.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2005,Tourism expenditure (millions of US dollars),,,1759.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2010,Tourism expenditure (millions of US dollars),,,4390.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2016,Tourism expenditure (millions of US dollars),,,4943.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2017,Tourism expenditure (millions of US dollars),,,5549.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+400,Jordan,2018,Tourism expenditure (millions of US dollars),,,6221.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2005,Tourist/visitor arrivals (thousands),TF,,3143.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2010,Tourist/visitor arrivals (thousands),TF,,2991.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,1995,Tourism expenditure (millions of US dollars),,,155.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2005,Tourism expenditure (millions of US dollars),,,801.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2010,Tourism expenditure (millions of US dollars),,,1236.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2016,Tourism expenditure (millions of US dollars),,,2038.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2017,Tourism expenditure (millions of US dollars),,,2356.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+398,Kazakhstan,2018,Tourism expenditure (millions of US dollars),,,2651.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,1995,Tourist/visitor arrivals (thousands),TF,,918.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2005,Tourist/visitor arrivals (thousands),TF,,1399.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2010,Tourist/visitor arrivals (thousands),TF,,1470.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2016,Tourist/visitor arrivals (thousands),TF,,1268.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2017,Tourist/visitor arrivals (thousands),TF,,1364.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,1995,Tourism expenditure (millions of US dollars),,,785.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2005,Tourism expenditure (millions of US dollars),,,969.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2010,Tourism expenditure (millions of US dollars),,,1620.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2016,Tourism expenditure (millions of US dollars),,,1471.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+404,Kenya,2017,Tourism expenditure (millions of US dollars),,,1564.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,1995,Tourist/visitor arrivals (thousands),TF,,3.9000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2005,Tourist/visitor arrivals (thousands),TF,,4.1000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2010,Tourist/visitor arrivals (thousands),TF,,4.7000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2016,Tourist/visitor arrivals (thousands),TF,,5.7000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2017,Tourist/visitor arrivals (thousands),TF,,5.8000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2018,Tourist/visitor arrivals (thousands),TF,,7.1000,Air arrivals. Tarawa and Christmas Island.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2010,Tourism expenditure (millions of US dollars),,,4.3000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2016,Tourism expenditure (millions of US dollars),,,2.8000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+296,Kiribati,2017,Tourism expenditure (millions of US dollars),,,4.1000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,1995,Tourist/visitor arrivals (thousands),VF,,1443.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2005,Tourist/visitor arrivals (thousands),VF,,3474.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2010,Tourist/visitor arrivals (thousands),VF,,5208.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2016,Tourist/visitor arrivals (thousands),VF,,7055.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2017,Tourist/visitor arrivals (thousands),VF,,7407.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2018,Tourist/visitor arrivals (thousands),VF,,8508.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,1995,Tourism expenditure (millions of US dollars),,,307.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2005,Tourism expenditure (millions of US dollars),,,413.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2010,Tourism expenditure (millions of US dollars),,,574.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2016,Tourism expenditure (millions of US dollars),,,831.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2017,Tourism expenditure (millions of US dollars),,,643.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+414,Kuwait,2018,Tourism expenditure (millions of US dollars),,,919.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2005,Tourist/visitor arrivals (thousands),VF,,319.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2010,Tourist/visitor arrivals (thousands),VF,,1224.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2016,Tourist/visitor arrivals (thousands),VF,,3853.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2017,Tourist/visitor arrivals (thousands),VF,,4568.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2018,Tourist/visitor arrivals (thousands),VF,,6947.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2005,Tourism expenditure (millions of US dollars),,,94.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2010,Tourism expenditure (millions of US dollars),,,212.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2016,Tourism expenditure (millions of US dollars),,,477.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2017,Tourism expenditure (millions of US dollars),,,480.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+417,Kyrgyzstan,2018,Tourism expenditure (millions of US dollars),,,487.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,1995,Tourist/visitor arrivals (thousands),TF,,60.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2005,Tourist/visitor arrivals (thousands),TF,,672.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2010,Tourist/visitor arrivals (thousands),TF,,1670.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2016,Tourist/visitor arrivals (thousands),TF,,3315.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2017,Tourist/visitor arrivals (thousands),TF,,3257.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2018,Tourist/visitor arrivals (thousands),TF,,3770.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,1995,Tourism expenditure (millions of US dollars),,,52.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2005,Tourism expenditure (millions of US dollars),,,143.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2010,Tourism expenditure (millions of US dollars),,,385.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2016,Tourism expenditure (millions of US dollars),,,717.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2017,Tourism expenditure (millions of US dollars),,,655.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+418,Lao People's Dem. Rep.,2018,Tourism expenditure (millions of US dollars),,,757.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,1995,Tourist/visitor arrivals (thousands),TF,,539.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2005,Tourist/visitor arrivals (thousands),TF,,1116.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2010,Tourist/visitor arrivals (thousands),TF,,1373.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2016,Tourist/visitor arrivals (thousands),TF,,1793.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2017,Tourist/visitor arrivals (thousands),TF,,1949.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2018,Tourist/visitor arrivals (thousands),TF,,1946.0000,Non-resident departures. Survey of persons crossing the state border.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,1995,Tourism expenditure (millions of US dollars),,,37.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+428,Latvia,2005,Tourism expenditure (millions of US dollars),,,446.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,1995,Tourist/visitor arrivals (thousands),TF,,450.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2005,Tourist/visitor arrivals (thousands),TF,,1140.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2010,Tourist/visitor arrivals (thousands),TF,,2168.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2016,Tourist/visitor arrivals (thousands),TF,,1688.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2017,Tourist/visitor arrivals (thousands),TF,,1857.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2018,Tourist/visitor arrivals (thousands),TF,,1964.0000,"Excluding the Lebanon, Syria and Palestine nationalities.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,1995,Tourism expenditure (millions of US dollars),,,710.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2005,Tourism expenditure (millions of US dollars),,,5969.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2010,Tourism expenditure (millions of US dollars),,,8026.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2016,Tourism expenditure (millions of US dollars),,,7373.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2017,Tourism expenditure (millions of US dollars),,,8086.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+422,Lebanon,2018,Tourism expenditure (millions of US dollars),,,8694.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,1995,Tourist/visitor arrivals (thousands),VF,,209.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2005,Tourist/visitor arrivals (thousands),VF,,304.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2010,Tourist/visitor arrivals (thousands),VF,,426.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2016,Tourist/visitor arrivals (thousands),VF,,1196.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2017,Tourist/visitor arrivals (thousands),VF,,1137.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2018,Tourist/visitor arrivals (thousands),VF,,1173.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,1995,Tourism expenditure (millions of US dollars),,,27.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2005,Tourism expenditure (millions of US dollars),,,27.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2010,Tourism expenditure (millions of US dollars),,,23.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2016,Tourism expenditure (millions of US dollars),,,48.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2017,Tourism expenditure (millions of US dollars),,,23.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+426,Lesotho,2018,Tourism expenditure (millions of US dollars),,,24.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+430,Liberia,2005,Tourism expenditure (millions of US dollars),,,67.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+434,Libya,2005,Tourist/visitor arrivals (thousands),THS,,81.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+434,Libya,1995,Tourism expenditure (millions of US dollars),,,4.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+434,Libya,2005,Tourism expenditure (millions of US dollars),,,301.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+434,Libya,2010,Tourism expenditure (millions of US dollars),,,170.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+438,Liechtenstein,2010,Tourist/visitor arrivals (thousands),TCE,,64.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+438,Liechtenstein,2016,Tourist/visitor arrivals (thousands),TCE,,69.1000,Excluding long term tourists on campgrounds and in holiday flats.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+438,Liechtenstein,2017,Tourist/visitor arrivals (thousands),TCE,,79.3000,Excluding long term tourists on campgrounds and in holiday flats.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+438,Liechtenstein,2018,Tourist/visitor arrivals (thousands),TCE,,85.3000,Excluding long term tourists on campgrounds and in holiday flats.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,1995,Tourist/visitor arrivals (thousands),TF,,650.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2005,Tourist/visitor arrivals (thousands),TF,,2000.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2010,Tourist/visitor arrivals (thousands),TF,,1507.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2016,Tourist/visitor arrivals (thousands),TF,,2296.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2017,Tourist/visitor arrivals (thousands),TF,,2523.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2018,Tourist/visitor arrivals (thousands),TF,,2825.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,1995,Tourism expenditure (millions of US dollars),,,77.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2005,Tourism expenditure (millions of US dollars),,,920.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2010,Tourism expenditure (millions of US dollars),,,958.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2016,Tourism expenditure (millions of US dollars),,,1210.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2017,Tourism expenditure (millions of US dollars),,,1325.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+440,Lithuania,2018,Tourism expenditure (millions of US dollars),,,1419.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,1995,Tourist/visitor arrivals (thousands),TCE,,768.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2005,Tourist/visitor arrivals (thousands),TCE,,913.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2010,Tourist/visitor arrivals (thousands),TCE,,805.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2016,Tourist/visitor arrivals (thousands),TCE,,1054.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2017,Tourist/visitor arrivals (thousands),TCE,,1046.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2018,Tourist/visitor arrivals (thousands),TCE,,1018.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2005,Tourism expenditure (millions of US dollars),,,3770.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2010,Tourism expenditure (millions of US dollars),,,4519.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2016,Tourism expenditure (millions of US dollars),,,4766.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2017,Tourism expenditure (millions of US dollars),,,4993.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+442,Luxembourg,2018,Tourism expenditure (millions of US dollars),,,5537.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,1995,Tourist/visitor arrivals (thousands),TF,,75.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2005,Tourist/visitor arrivals (thousands),TF,,277.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2010,Tourist/visitor arrivals (thousands),TF,,196.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2016,Tourist/visitor arrivals (thousands),TF,,293.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2017,Tourist/visitor arrivals (thousands),TF,,255.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2018,Tourist/visitor arrivals (thousands),TF,,291.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,1995,Tourism expenditure (millions of US dollars),,,106.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2005,Tourism expenditure (millions of US dollars),,,275.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2010,Tourism expenditure (millions of US dollars),,,425.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2016,Tourism expenditure (millions of US dollars),,,913.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2017,Tourism expenditure (millions of US dollars),,,849.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+450,Madagascar,2018,Tourism expenditure (millions of US dollars),,,879.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,1995,Tourist/visitor arrivals (thousands),TF,,192.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2005,Tourist/visitor arrivals (thousands),TF,,438.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2010,Tourist/visitor arrivals (thousands),TF,,746.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2016,Tourist/visitor arrivals (thousands),TF,,849.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2017,Tourist/visitor arrivals (thousands),TF,,837.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2018,Tourist/visitor arrivals (thousands),TF,,871.0000,Departures.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,1995,Tourism expenditure (millions of US dollars),,,22.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2005,Tourism expenditure (millions of US dollars),,,48.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2010,Tourism expenditure (millions of US dollars),,,45.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2016,Tourism expenditure (millions of US dollars),,,30.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2017,Tourism expenditure (millions of US dollars),,,35.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+454,Malawi,2018,Tourism expenditure (millions of US dollars),,,43.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,1995,Tourist/visitor arrivals (thousands),TF,,7469.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2005,Tourist/visitor arrivals (thousands),TF,,16431.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2010,Tourist/visitor arrivals (thousands),TF,,24577.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2016,Tourist/visitor arrivals (thousands),TF,,26757.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2017,Tourist/visitor arrivals (thousands),TF,,25948.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2018,Tourist/visitor arrivals (thousands),TF,,25832.0000,Including Singapore residents crossing the frontier by road through Johore Causeway.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,1995,Tourism expenditure (millions of US dollars),,,5044.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2005,Tourism expenditure (millions of US dollars),,,10389.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2010,Tourism expenditure (millions of US dollars),,,19619.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2016,Tourism expenditure (millions of US dollars),,,19682.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2017,Tourism expenditure (millions of US dollars),,,20311.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+458,Malaysia,2018,Tourism expenditure (millions of US dollars),,,21774.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,1995,Tourist/visitor arrivals (thousands),TF,,315.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2005,Tourist/visitor arrivals (thousands),TF,,395.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2010,Tourist/visitor arrivals (thousands),TF,,792.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2016,Tourist/visitor arrivals (thousands),TF,,1286.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2017,Tourist/visitor arrivals (thousands),TF,,1390.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2018,Tourist/visitor arrivals (thousands),TF,,1484.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2016,Tourism expenditure (millions of US dollars),,,2640.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2017,Tourism expenditure (millions of US dollars),,,2771.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+462,Maldives,2018,Tourism expenditure (millions of US dollars),,,3054.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2010,Tourist/visitor arrivals (thousands),TF,,169.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2016,Tourist/visitor arrivals (thousands),TF,,173.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2017,Tourist/visitor arrivals (thousands),TF,,193.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,1995,Tourism expenditure (millions of US dollars),,,26.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2005,Tourism expenditure (millions of US dollars),,,149.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2010,Tourism expenditure (millions of US dollars),,,208.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2016,Tourism expenditure (millions of US dollars),,,201.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+466,Mali,2017,Tourism expenditure (millions of US dollars),,,206.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,1995,Tourist/visitor arrivals (thousands),TF,,1116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2005,Tourist/visitor arrivals (thousands),TF,,1171.0000,Departures by air and by sea.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2010,Tourist/visitor arrivals (thousands),TF,,1339.0000,Departures by air and by sea.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2016,Tourist/visitor arrivals (thousands),TF,,1966.0000,Departures by air and by sea.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2017,Tourist/visitor arrivals (thousands),TF,,2274.0000,Departures by air and by sea.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2018,Tourist/visitor arrivals (thousands),TF,,2599.0000,Departures by air and by sea.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,1995,Tourism expenditure (millions of US dollars),,,656.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2005,Tourism expenditure (millions of US dollars),,,755.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2010,Tourism expenditure (millions of US dollars),,,1066.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2016,Tourism expenditure (millions of US dollars),,,1451.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2017,Tourism expenditure (millions of US dollars),,,1746.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+470,Malta,2018,Tourism expenditure (millions of US dollars),,,1845.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,1995,Tourist/visitor arrivals (thousands),TF,,5.5000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2005,Tourist/visitor arrivals (thousands),TF,,9.2000,Air and sea arrivals.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2010,Tourist/visitor arrivals (thousands),TF,,4.6000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2016,Tourist/visitor arrivals (thousands),TF,,5.4000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2017,Tourist/visitor arrivals (thousands),TF,,6.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2018,Tourist/visitor arrivals (thousands),TF,,6.8000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,1995,Tourism expenditure (millions of US dollars),,,2.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2005,Tourism expenditure (millions of US dollars),,,3.6900,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2010,Tourism expenditure (millions of US dollars),,,3.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2016,Tourism expenditure (millions of US dollars),,,30.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2017,Tourism expenditure (millions of US dollars),,,18.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+584,Marshall Islands,2018,Tourism expenditure (millions of US dollars),,,20.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,1995,Tourist/visitor arrivals (thousands),TF,,457.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2005,Tourist/visitor arrivals (thousands),TF,,484.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2010,Tourist/visitor arrivals (thousands),TF,,478.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2016,Tourist/visitor arrivals (thousands),TF,,519.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2017,Tourist/visitor arrivals (thousands),TF,,536.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2018,Tourist/visitor arrivals (thousands),TF,,537.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,1995,Tourism expenditure (millions of US dollars),,,384.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2005,Tourism expenditure (millions of US dollars),,,280.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2010,Tourism expenditure (millions of US dollars),,,472.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2016,Tourism expenditure (millions of US dollars),,,348.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2017,Tourism expenditure (millions of US dollars),,,510.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+474,Martinique,2018,Tourism expenditure (millions of US dollars),,,530.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+478,Mauritania,2016,Tourism expenditure (millions of US dollars),,,33.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+478,Mauritania,2017,Tourism expenditure (millions of US dollars),,,24.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+478,Mauritania,2018,Tourism expenditure (millions of US dollars),,,6.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,1995,Tourist/visitor arrivals (thousands),TF,,422.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2005,Tourist/visitor arrivals (thousands),TF,,761.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2010,Tourist/visitor arrivals (thousands),TF,,935.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2016,Tourist/visitor arrivals (thousands),TF,,1275.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2017,Tourist/visitor arrivals (thousands),TF,,1342.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2018,Tourist/visitor arrivals (thousands),TF,,1399.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,1995,Tourism expenditure (millions of US dollars),,,616.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2005,Tourism expenditure (millions of US dollars),,,1189.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2010,Tourism expenditure (millions of US dollars),,,1585.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2016,Tourism expenditure (millions of US dollars),,,1824.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2017,Tourism expenditure (millions of US dollars),,,2005.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+480,Mauritius,2018,Tourism expenditure (millions of US dollars),,,2161.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,1995,Tourist/visitor arrivals (thousands),TF,,20241.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2005,Tourist/visitor arrivals (thousands),TF,,21915.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2010,Tourist/visitor arrivals (thousands),TF,,23290.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2016,Tourist/visitor arrivals (thousands),TF,,35079.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2017,Tourist/visitor arrivals (thousands),TF,,39291.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2018,Tourist/visitor arrivals (thousands),TF,,41313.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,1995,Tourism expenditure (millions of US dollars),,,6847.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2005,Tourism expenditure (millions of US dollars),,,12801.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2010,Tourism expenditure (millions of US dollars),,,12628.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2016,Tourism expenditure (millions of US dollars),,,20619.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2017,Tourism expenditure (millions of US dollars),,,22467.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+484,Mexico,2018,Tourism expenditure (millions of US dollars),,,23802.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+583,Micronesia (Fed. States of),2005,Tourist/visitor arrivals (thousands),TF,,19.0000,"Arrivals in the States of Kosrae, Chuuk, Pohnpei and Yap; excluding FSM citizens.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+583,Micronesia (Fed. States of),2010,Tourist/visitor arrivals (thousands),TF,,44.7000,"Arrivals in the States of Kosrae, Chuuk, Pohnpei and Yap; excluding FSM citizens.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+583,Micronesia (Fed. States of),2016,Tourist/visitor arrivals (thousands),TF,,29.6000,"Arrivals in the States of Kosrae, Chuuk, Pohnpei and Yap; excluding FSM citizens.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+583,Micronesia (Fed. States of),2018,Tourist/visitor arrivals (thousands),TF,,19.2000,"Arrivals in the States of Kosrae, Chuuk, Pohnpei and Yap; excluding FSM citizens.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+583,Micronesia (Fed. States of),2010,Tourism expenditure (millions of US dollars),,,24.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,1995,Tourist/visitor arrivals (thousands),THS,,233.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,2005,Tourist/visitor arrivals (thousands),THS,,286.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,2010,Tourist/visitor arrivals (thousands),THS,,279.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,2016,Tourist/visitor arrivals (thousands),THS,,336.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,2017,Tourist/visitor arrivals (thousands),THS,,355.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+492,Monaco,2018,Tourist/visitor arrivals (thousands),THS,,347.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2005,Tourist/visitor arrivals (thousands),TF,,339.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2010,Tourist/visitor arrivals (thousands),TF,,456.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2016,Tourist/visitor arrivals (thousands),TF,,404.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2017,Tourist/visitor arrivals (thousands),TF,,469.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2018,Tourist/visitor arrivals (thousands),TF,,529.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,1995,Tourism expenditure (millions of US dollars),,,33.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2005,Tourism expenditure (millions of US dollars),,,203.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2010,Tourism expenditure (millions of US dollars),,,288.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2016,Tourism expenditure (millions of US dollars),,,379.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2017,Tourism expenditure (millions of US dollars),,,462.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+496,Mongolia,2018,Tourism expenditure (millions of US dollars),,,526.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2005,Tourist/visitor arrivals (thousands),TCE,,272.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2010,Tourist/visitor arrivals (thousands),TCE,,1088.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2016,Tourist/visitor arrivals (thousands),TCE,,1662.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2017,Tourist/visitor arrivals (thousands),TCE,,1877.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2018,Tourist/visitor arrivals (thousands),TCE,,2077.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2010,Tourism expenditure (millions of US dollars),,,765.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2016,Tourism expenditure (millions of US dollars),,,978.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2017,Tourism expenditure (millions of US dollars),,,1110.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+499,Montenegro,2018,Tourism expenditure (millions of US dollars),,,1224.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,1995,Tourist/visitor arrivals (thousands),TF,,17.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2005,Tourist/visitor arrivals (thousands),TF,,9.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2010,Tourist/visitor arrivals (thousands),TF,,6.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2016,Tourist/visitor arrivals (thousands),TF,,8.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2017,Tourist/visitor arrivals (thousands),TF,,8.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2018,Tourist/visitor arrivals (thousands),TF,,8.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,1995,Tourism expenditure (millions of US dollars),,,17.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2005,Tourism expenditure (millions of US dollars),,,9.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2010,Tourism expenditure (millions of US dollars),,,5.9000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2016,Tourism expenditure (millions of US dollars),,,8.6000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2017,Tourism expenditure (millions of US dollars),,,8.4000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+500,Montserrat,2018,Tourism expenditure (millions of US dollars),,,11.1000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,1995,Tourist/visitor arrivals (thousands),TF,,2602.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2005,Tourist/visitor arrivals (thousands),TF,,5843.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2010,Tourist/visitor arrivals (thousands),TF,,9288.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2016,Tourist/visitor arrivals (thousands),TF,,10332.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2017,Tourist/visitor arrivals (thousands),TF,,11349.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2018,Tourist/visitor arrivals (thousands),TF,,12289.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,1995,Tourism expenditure (millions of US dollars),,,1469.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2005,Tourism expenditure (millions of US dollars),,,5426.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2010,Tourism expenditure (millions of US dollars),,,8176.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2016,Tourism expenditure (millions of US dollars),,,7922.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2017,Tourism expenditure (millions of US dollars),,,9086.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+504,Morocco,2018,Tourism expenditure (millions of US dollars),,,9523.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2005,Tourist/visitor arrivals (thousands),TF,,578.0000,The data correspond only to 12 border posts.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2010,Tourist/visitor arrivals (thousands),TF,,1718.0000,Break in the time series.;The data of all the border posts of the country are used.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2016,Tourist/visitor arrivals (thousands),TF,,1639.0000,The data of all the border posts of the country are used.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2017,Tourist/visitor arrivals (thousands),TF,,1447.0000,The data of all the border posts of the country are used.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2018,Tourist/visitor arrivals (thousands),TF,,2743.0000,The data of all the border posts of the country are used.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2005,Tourism expenditure (millions of US dollars),,,138.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2010,Tourism expenditure (millions of US dollars),,,135.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2016,Tourism expenditure (millions of US dollars),,,114.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2017,Tourism expenditure (millions of US dollars),,,164.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+508,Mozambique,2018,Tourism expenditure (millions of US dollars),,,331.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,1995,Tourist/visitor arrivals (thousands),TF,,194.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2005,Tourist/visitor arrivals (thousands),TF,,660.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2010,Tourist/visitor arrivals (thousands),TF,,792.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2016,Tourist/visitor arrivals (thousands),TF,,2907.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2017,Tourist/visitor arrivals (thousands),TF,,3443.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2018,Tourist/visitor arrivals (thousands),TF,,3551.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,1995,Tourism expenditure (millions of US dollars),,,169.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2005,Tourism expenditure (millions of US dollars),,,83.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2010,Tourism expenditure (millions of US dollars),,,91.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2016,Tourism expenditure (millions of US dollars),,,2289.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2017,Tourism expenditure (millions of US dollars),,,1988.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+104,Myanmar,2018,Tourism expenditure (millions of US dollars),,,1670.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,1995,Tourist/visitor arrivals (thousands),TF,,272.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2005,Tourist/visitor arrivals (thousands),TF,,778.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2010,Tourist/visitor arrivals (thousands),TF,,984.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2016,Tourist/visitor arrivals (thousands),TF,,1469.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2017,Tourist/visitor arrivals (thousands),TF,,1499.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2005,Tourism expenditure (millions of US dollars),,,363.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2010,Tourism expenditure (millions of US dollars),,,473.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2016,Tourism expenditure (millions of US dollars),,,349.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2017,Tourism expenditure (millions of US dollars),,,449.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+516,Namibia,2018,Tourism expenditure (millions of US dollars),,,488.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+520,Nauru,2010,Tourism expenditure (millions of US dollars),,,0.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+520,Nauru,2016,Tourism expenditure (millions of US dollars),,,3.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+520,Nauru,2017,Tourism expenditure (millions of US dollars),,,3.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+520,Nauru,2018,Tourism expenditure (millions of US dollars),,,1.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,1995,Tourist/visitor arrivals (thousands),TF,,363.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2005,Tourist/visitor arrivals (thousands),TF,,375.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2010,Tourist/visitor arrivals (thousands),TF,,603.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2016,Tourist/visitor arrivals (thousands),TF,,753.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2017,Tourist/visitor arrivals (thousands),TF,,940.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2018,Tourist/visitor arrivals (thousands),TF,,1173.0000,Including arrivals from India.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,1995,Tourism expenditure (millions of US dollars),,,232.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2005,Tourism expenditure (millions of US dollars),,,160.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2010,Tourism expenditure (millions of US dollars),,,378.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2016,Tourism expenditure (millions of US dollars),,,498.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2017,Tourism expenditure (millions of US dollars),,,712.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+524,Nepal,2018,Tourism expenditure (millions of US dollars),,,744.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,1995,Tourist/visitor arrivals (thousands),TCE,,6574.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2005,Tourist/visitor arrivals (thousands),TCE,,10012.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2010,Tourist/visitor arrivals (thousands),TCE,,10883.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2016,Tourist/visitor arrivals (thousands),TCE,,15828.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2017,Tourist/visitor arrivals (thousands),TCE,,17924.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2018,Tourist/visitor arrivals (thousands),TCE,,18780.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,1995,Tourism expenditure (millions of US dollars),,,10611.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2016,Tourism expenditure (millions of US dollars),,,21151.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2017,Tourism expenditure (millions of US dollars),,,23414.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+528,Netherlands,2018,Tourism expenditure (millions of US dollars),,,25850.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,1995,Tourist/visitor arrivals (thousands),TF,,86.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2005,Tourist/visitor arrivals (thousands),TF,,101.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2010,Tourist/visitor arrivals (thousands),TF,,99.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2016,Tourist/visitor arrivals (thousands),TF,,116.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2017,Tourist/visitor arrivals (thousands),TF,,121.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2018,Tourist/visitor arrivals (thousands),TF,,120.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,1995,Tourism expenditure (millions of US dollars),,,108.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2005,Tourism expenditure (millions of US dollars),,,149.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2010,Tourism expenditure (millions of US dollars),,,129.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+540,New Caledonia,2016,Tourism expenditure (millions of US dollars),,,159.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2005,Tourist/visitor arrivals (thousands),TF,,2353.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2010,Tourist/visitor arrivals (thousands),TF,,2435.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2016,Tourist/visitor arrivals (thousands),TF,,3370.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2017,Tourist/visitor arrivals (thousands),TF,,3555.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2018,Tourist/visitor arrivals (thousands),TF,,3686.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,1995,Tourism expenditure (millions of US dollars),,,2318.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2005,Tourism expenditure (millions of US dollars),,,6486.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2010,Tourism expenditure (millions of US dollars),,,6523.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2016,Tourism expenditure (millions of US dollars),,,9773.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2017,Tourism expenditure (millions of US dollars),,,10594.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+554,New Zealand,2018,Tourism expenditure (millions of US dollars),,,10961.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,1995,Tourist/visitor arrivals (thousands),TF,,281.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2005,Tourist/visitor arrivals (thousands),TF,,712.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2010,Tourist/visitor arrivals (thousands),TF,,1011.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2016,Tourist/visitor arrivals (thousands),TF,,1504.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2017,Tourist/visitor arrivals (thousands),TF,,1787.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2018,Tourist/visitor arrivals (thousands),TF,,1256.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,1995,Tourism expenditure (millions of US dollars),,,50.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2005,Tourism expenditure (millions of US dollars),,,206.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2010,Tourism expenditure (millions of US dollars),,,314.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2016,Tourism expenditure (millions of US dollars),,,642.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2017,Tourism expenditure (millions of US dollars),,,841.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+558,Nicaragua,2018,Tourism expenditure (millions of US dollars),,,544.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,1995,Tourist/visitor arrivals (thousands),TF,,35.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2005,Tourist/visitor arrivals (thousands),TF,,58.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2010,Tourist/visitor arrivals (thousands),TF,,74.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2016,Tourist/visitor arrivals (thousands),TF,,152.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2017,Tourist/visitor arrivals (thousands),TF,,164.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2018,Tourist/visitor arrivals (thousands),TF,,157.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2005,Tourism expenditure (millions of US dollars),,,43.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2010,Tourism expenditure (millions of US dollars),,,105.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2016,Tourism expenditure (millions of US dollars),,,84.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+562,Niger,2017,Tourism expenditure (millions of US dollars),,,91.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,1995,Tourist/visitor arrivals (thousands),TF,,656.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2005,Tourist/visitor arrivals (thousands),TF,,1010.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2010,Tourist/visitor arrivals (thousands),TF,,1555.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2016,Tourist/visitor arrivals (thousands),TF,,1889.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,1995,Tourism expenditure (millions of US dollars),,,47.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2005,Tourism expenditure (millions of US dollars),,,139.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2010,Tourism expenditure (millions of US dollars),,,736.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2016,Tourism expenditure (millions of US dollars),,,1088.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2017,Tourism expenditure (millions of US dollars),,,2615.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+566,Nigeria,2018,Tourism expenditure (millions of US dollars),,,1977.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,1995,Tourist/visitor arrivals (thousands),TF,,2.2000,Including Niueans residing usually in New Zealand.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2005,Tourist/visitor arrivals (thousands),TF,,2.8000,Including Niueans residing usually in New Zealand.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2010,Tourist/visitor arrivals (thousands),TF,,6.2000,Including Niueans residing usually in New Zealand.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2016,Tourist/visitor arrivals (thousands),TF,,8.9000,Including Niueans residing usually in New Zealand.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2017,Tourist/visitor arrivals (thousands),TF,,9.8000,Including Niueans residing usually in New Zealand.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,1995,Tourism expenditure (millions of US dollars),,,2.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2005,Tourism expenditure (millions of US dollars),,,1.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+570,Niue,2010,Tourism expenditure (millions of US dollars),,,2.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,1995,Tourist/visitor arrivals (thousands),TCE,,147.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2005,Tourist/visitor arrivals (thousands),TCE,,197.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2010,Tourist/visitor arrivals (thousands),TCE,,262.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2016,Tourist/visitor arrivals (thousands),TCE,,510.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2017,Tourist/visitor arrivals (thousands),TCE,,631.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2018,Tourist/visitor arrivals (thousands),TCE,,707.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2005,Tourism expenditure (millions of US dollars),,,116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2010,Tourism expenditure (millions of US dollars),,,199.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2016,Tourism expenditure (millions of US dollars),,,283.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2017,Tourism expenditure (millions of US dollars),,,331.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+807,North Macedonia,2018,Tourism expenditure (millions of US dollars),,,387.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,1995,Tourist/visitor arrivals (thousands),TF,,669.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,2005,Tourist/visitor arrivals (thousands),TF,,498.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,2010,Tourist/visitor arrivals (thousands),TF,,375.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,2016,Tourist/visitor arrivals (thousands),TF,,526.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,2017,Tourist/visitor arrivals (thousands),TF,,656.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,2018,Tourist/visitor arrivals (thousands),TF,,517.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+580,Northern Mariana Islands,1995,Tourism expenditure (millions of US dollars),,,655.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,1995,Tourist/visitor arrivals (thousands),TF,,2880.0000,Non-resident tourists staying in registered hotels.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2005,Tourist/visitor arrivals (thousands),TF,,3824.0000,Arrivals of non-resident tourists at national borders.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2010,Tourist/visitor arrivals (thousands),TF,,4767.0000,Arrivals of non-resident tourists at national borders.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2016,Tourist/visitor arrivals (thousands),TF,,5960.0000,Non-resident tourists staying in all types of accommodation establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2017,Tourist/visitor arrivals (thousands),TF,,6252.0000,Non-resident tourists staying in all types of accommodation establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2018,Tourist/visitor arrivals (thousands),TF,,5688.0000,Non-resident tourists staying in all types of accommodation establishments.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,1995,Tourism expenditure (millions of US dollars),,,2730.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2005,Tourism expenditure (millions of US dollars),,,4243.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2010,Tourism expenditure (millions of US dollars),,,5299.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2016,Tourism expenditure (millions of US dollars),,,6285.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2017,Tourism expenditure (millions of US dollars),,,6840.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+578,Norway,2018,Tourism expenditure (millions of US dollars),,,7096.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2005,Tourist/visitor arrivals (thousands),TF,,891.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2010,Tourist/visitor arrivals (thousands),TF,,1441.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2016,Tourist/visitor arrivals (thousands),TF,,2335.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2017,Tourist/visitor arrivals (thousands),TF,,2316.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2018,Tourist/visitor arrivals (thousands),TF,,2301.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2005,Tourism expenditure (millions of US dollars),,,627.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2010,Tourism expenditure (millions of US dollars),,,1072.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2016,Tourism expenditure (millions of US dollars),,,2390.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2017,Tourism expenditure (millions of US dollars),,,2717.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+512,Oman,2018,Tourism expenditure (millions of US dollars),,,2975.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,1995,Tourist/visitor arrivals (thousands),VF,,2332.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2005,Tourist/visitor arrivals (thousands),VF,,3378.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2010,Tourist/visitor arrivals (thousands),VF,,5567.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2016,Tourist/visitor arrivals (thousands),VF,,10690.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2017,Tourist/visitor arrivals (thousands),VF,,10740.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2018,Tourist/visitor arrivals (thousands),VF,,11067.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,1995,Tourism expenditure (millions of US dollars),,,3985.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2005,Tourism expenditure (millions of US dollars),,,5740.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2010,Tourism expenditure (millions of US dollars),,,10387.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2016,Tourism expenditure (millions of US dollars),,,15825.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2017,Tourism expenditure (millions of US dollars),,,14847.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+158,Other non-specified areas,2018,Tourism expenditure (millions of US dollars),,,16366.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,1995,Tourist/visitor arrivals (thousands),TF,,378.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2005,Tourist/visitor arrivals (thousands),TF,,798.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2010,Tourist/visitor arrivals (thousands),TF,,907.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,1995,Tourism expenditure (millions of US dollars),,,582.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2005,Tourism expenditure (millions of US dollars),,,828.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2010,Tourism expenditure (millions of US dollars),,,998.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2016,Tourism expenditure (millions of US dollars),,,791.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2017,Tourism expenditure (millions of US dollars),,,866.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+586,Pakistan,2018,Tourism expenditure (millions of US dollars),,,818.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,1995,Tourist/visitor arrivals (thousands),TF,,53.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2005,Tourist/visitor arrivals (thousands),TF,,81.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2010,Tourist/visitor arrivals (thousands),TF,,85.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2016,Tourist/visitor arrivals (thousands),TF,,138.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2017,Tourist/visitor arrivals (thousands),TF,,123.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2018,Tourist/visitor arrivals (thousands),TF,,106.0000,Air arrivals (Palau International Airport).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2005,Tourism expenditure (millions of US dollars),,,63.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2010,Tourism expenditure (millions of US dollars),,,76.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2016,Tourism expenditure (millions of US dollars),,,148.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+585,Palau,2017,Tourism expenditure (millions of US dollars),,,123.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,1995,Tourist/visitor arrivals (thousands),TF,,345.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2005,Tourist/visitor arrivals (thousands),TF,,702.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2010,Tourist/visitor arrivals (thousands),TF,,1324.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2016,Tourist/visitor arrivals (thousands),TF,,1921.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2017,Tourist/visitor arrivals (thousands),TF,,1843.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2018,Tourist/visitor arrivals (thousands),TF,,1785.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,1995,Tourism expenditure (millions of US dollars),,,372.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2005,Tourism expenditure (millions of US dollars),,,1108.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2010,Tourism expenditure (millions of US dollars),,,2621.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2016,Tourism expenditure (millions of US dollars),,,6280.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2017,Tourism expenditure (millions of US dollars),,,6824.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+591,Panama,2018,Tourism expenditure (millions of US dollars),,,5615.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,1995,Tourist/visitor arrivals (thousands),TF,,42.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2005,Tourist/visitor arrivals (thousands),TF,,69.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2010,Tourist/visitor arrivals (thousands),TF,,140.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2016,Tourist/visitor arrivals (thousands),TF,,179.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2017,Tourist/visitor arrivals (thousands),TF,,139.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2018,Tourist/visitor arrivals (thousands),TF,,140.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2005,Tourism expenditure (millions of US dollars),,,9.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2010,Tourism expenditure (millions of US dollars),,,2.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2016,Tourism expenditure (millions of US dollars),,,1.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+598,Papua New Guinea,2017,Tourism expenditure (millions of US dollars),,,15.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,1995,Tourist/visitor arrivals (thousands),TF,,438.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2005,Tourist/visitor arrivals (thousands),TF,,341.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2010,Tourist/visitor arrivals (thousands),TF,,465.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2016,Tourist/visitor arrivals (thousands),TF,,1308.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2017,Tourist/visitor arrivals (thousands),TF,,1584.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2018,Tourist/visitor arrivals (thousands),TF,,1181.0000,Excluding nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,1995,Tourism expenditure (millions of US dollars),,,162.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2005,Tourism expenditure (millions of US dollars),,,96.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2010,Tourism expenditure (millions of US dollars),,,243.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2016,Tourism expenditure (millions of US dollars),,,356.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2017,Tourism expenditure (millions of US dollars),,,399.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+600,Paraguay,2018,Tourism expenditure (millions of US dollars),,,393.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,1995,Tourist/visitor arrivals (thousands),TF,,479.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2005,Tourist/visitor arrivals (thousands),TF,,1571.0000,Including nationals residing abroad.;Including tourists with identity document other than a passport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2010,Tourist/visitor arrivals (thousands),TF,,2299.0000,Including nationals residing abroad.;Including tourists with identity document other than a passport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2016,Tourist/visitor arrivals (thousands),TF,,3744.0000,Including nationals residing abroad.;Including tourists with identity document other than a passport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2017,Tourist/visitor arrivals (thousands),TF,,4032.0000,Including nationals residing abroad.;Including tourists with identity document other than a passport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2018,Tourist/visitor arrivals (thousands),TF,,4419.0000,Including nationals residing abroad.;Including tourists with identity document other than a passport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,1995,Tourism expenditure (millions of US dollars),,,521.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2005,Tourism expenditure (millions of US dollars),,,1438.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2010,Tourism expenditure (millions of US dollars),,,2475.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2016,Tourism expenditure (millions of US dollars),,,4288.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2017,Tourism expenditure (millions of US dollars),,,4573.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+604,Peru,2018,Tourism expenditure (millions of US dollars),,,4894.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,1995,Tourist/visitor arrivals (thousands),TF,,1760.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2005,Tourist/visitor arrivals (thousands),TF,,2623.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2010,Tourist/visitor arrivals (thousands),TF,,3520.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2016,Tourist/visitor arrivals (thousands),TF,,5967.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2017,Tourist/visitor arrivals (thousands),TF,,6621.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2018,Tourist/visitor arrivals (thousands),TF,,7168.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,1995,Tourism expenditure (millions of US dollars),,,1141.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2005,Tourism expenditure (millions of US dollars),,,2863.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2010,Tourism expenditure (millions of US dollars),,,3441.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2016,Tourism expenditure (millions of US dollars),,,6289.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2017,Tourism expenditure (millions of US dollars),,,8349.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+608,Philippines,2018,Tourism expenditure (millions of US dollars),,,9730.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,1995,Tourist/visitor arrivals (thousands),TF,,19215.0000,"Border statistics are not collected any more, surveys used instead.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2005,Tourist/visitor arrivals (thousands),TF,,15200.0000,"Border statistics are not collected any more, surveys used instead.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2010,Tourist/visitor arrivals (thousands),TF,,12470.0000,"Border statistics are not collected any more, surveys used instead.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2016,Tourist/visitor arrivals (thousands),TF,,17471.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2017,Tourist/visitor arrivals (thousands),TF,,18258.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2018,Tourist/visitor arrivals (thousands),TF,,19622.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,1995,Tourism expenditure (millions of US dollars),,,6927.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2005,Tourism expenditure (millions of US dollars),,,7161.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2010,Tourism expenditure (millions of US dollars),,,10036.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2016,Tourism expenditure (millions of US dollars),,,12052.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2017,Tourism expenditure (millions of US dollars),,,14083.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+616,Poland,2018,Tourism expenditure (millions of US dollars),,,15748.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,1995,Tourist/visitor arrivals (thousands),TCE,,4572.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2005,Tourist/visitor arrivals (thousands),TCE,,5769.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2010,Tourist/visitor arrivals (thousands),TCE,,6756.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2016,Tourist/visitor arrivals (thousands),TCE,,13359.0000,"Include hotels, apartment hotels, “pousadas”, tourist apartments, tourist villages, camping sites, recreation centres, tourism in rural areas and local accommodation.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2017,Tourist/visitor arrivals (thousands),TCE,,15432.0000,"Include hotels, apartment hotels, “pousadas”, tourist apartments, tourist villages, camping sites, recreation centres, tourism in rural areas and local accommodation.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2018,Tourist/visitor arrivals (thousands),TCE,,16186.0000,"Include hotels, apartment hotels, “pousadas”, tourist apartments, tourist villages, camping sites, recreation centres, tourism in rural areas and local accommodation.","World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,1995,Tourism expenditure (millions of US dollars),,,5646.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2005,Tourism expenditure (millions of US dollars),,,9038.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2010,Tourism expenditure (millions of US dollars),,,12984.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2016,Tourism expenditure (millions of US dollars),,,17347.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2017,Tourism expenditure (millions of US dollars),,,21586.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+620,Portugal,2018,Tourism expenditure (millions of US dollars),,,24105.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,1995,Tourist/visitor arrivals (thousands),TF,,3131.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2005,Tourist/visitor arrivals (thousands),TF,,3686.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2010,Tourist/visitor arrivals (thousands),TF,,3186.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2016,Tourist/visitor arrivals (thousands),TF,,3736.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2017,Tourist/visitor arrivals (thousands),TF,,3513.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2018,Tourist/visitor arrivals (thousands),TF,,3068.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,1995,Tourism expenditure (millions of US dollars),,,1828.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2005,Tourism expenditure (millions of US dollars),,,3239.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2010,Tourism expenditure (millions of US dollars),,,3211.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2016,Tourism expenditure (millions of US dollars),,,3974.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2017,Tourism expenditure (millions of US dollars),,,3848.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+630,Puerto Rico,2018,Tourism expenditure (millions of US dollars),,,3282.0000,Data refer to fiscal years beginning 1 July.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2010,Tourist/visitor arrivals (thousands),TF,,1699.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2016,Tourist/visitor arrivals (thousands),TF,,2938.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2017,Tourist/visitor arrivals (thousands),TF,,2256.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2018,Tourist/visitor arrivals (thousands),TF,,1819.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2016,Tourism expenditure (millions of US dollars),,,12593.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2017,Tourism expenditure (millions of US dollars),,,15757.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+634,Qatar,2018,Tourism expenditure (millions of US dollars),,,15239.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,1995,Tourist/visitor arrivals (thousands),VF,,3753.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2005,Tourist/visitor arrivals (thousands),VF,,6023.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2010,Tourist/visitor arrivals (thousands),VF,,8798.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2016,Tourist/visitor arrivals (thousands),VF,,17242.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2017,Tourist/visitor arrivals (thousands),VF,,13336.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2018,Tourist/visitor arrivals (thousands),VF,,15347.0000,Including nationals residing abroad and crew members.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,1995,Tourism expenditure (millions of US dollars),,,6670.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2005,Tourism expenditure (millions of US dollars),,,8282.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2010,Tourism expenditure (millions of US dollars),,,14315.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2016,Tourism expenditure (millions of US dollars),,,20924.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2017,Tourism expenditure (millions of US dollars),,,17173.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+410,Republic of Korea,2018,Tourism expenditure (millions of US dollars),,,19856.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2005,Tourist/visitor arrivals (thousands),TCE,,67.0000,Excluding the left side of the river Nistru and the municipality of Bender.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2010,Tourist/visitor arrivals (thousands),TCE,,64.0000,Excluding the left side of the river Nistru and the municipality of Bender.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2016,Tourist/visitor arrivals (thousands),TCE,,121.0000,Excluding the left side of the river Nistru and the municipality of Bender.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2017,Tourist/visitor arrivals (thousands),TCE,,145.0000,Excluding the left side of the river Nistru and the municipality of Bender.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2018,Tourist/visitor arrivals (thousands),TCE,,160.0000,Excluding the left side of the river Nistru and the municipality of Bender.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,1995,Tourism expenditure (millions of US dollars),,,71.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2005,Tourism expenditure (millions of US dollars),,,138.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2010,Tourism expenditure (millions of US dollars),,,222.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2016,Tourism expenditure (millions of US dollars),,,344.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2017,Tourism expenditure (millions of US dollars),,,443.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+498,Republic of Moldova,2018,Tourism expenditure (millions of US dollars),,,500.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,1995,Tourist/visitor arrivals (thousands),TF,,304.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2005,Tourist/visitor arrivals (thousands),TF,,409.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2010,Tourist/visitor arrivals (thousands),TF,,420.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2016,Tourist/visitor arrivals (thousands),TF,,458.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2017,Tourist/visitor arrivals (thousands),TF,,508.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2018,Tourist/visitor arrivals (thousands),TF,,535.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,1995,Tourism expenditure (millions of US dollars),,,216.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2005,Tourism expenditure (millions of US dollars),,,364.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2010,Tourism expenditure (millions of US dollars),,,392.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2016,Tourism expenditure (millions of US dollars),,,343.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2017,Tourism expenditure (millions of US dollars),,,427.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+638,Réunion,2018,Tourism expenditure (millions of US dollars),,,495.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,1995,Tourist/visitor arrivals (thousands),VF,,5445.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2005,Tourist/visitor arrivals (thousands),VF,,5839.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2010,Tourist/visitor arrivals (thousands),VF,,7498.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2016,Tourist/visitor arrivals (thousands),VF,,10223.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2017,Tourist/visitor arrivals (thousands),VF,,10926.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2018,Tourist/visitor arrivals (thousands),VF,,11720.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,1995,Tourism expenditure (millions of US dollars),,,689.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2005,Tourism expenditure (millions of US dollars),,,1324.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2010,Tourism expenditure (millions of US dollars),,,1631.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2016,Tourism expenditure (millions of US dollars),,,2172.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2017,Tourism expenditure (millions of US dollars),,,3008.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+642,Romania,2018,Tourism expenditure (millions of US dollars),,,3261.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,1995,Tourist/visitor arrivals (thousands),VF,,10290.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2005,Tourist/visitor arrivals (thousands),VF,,22201.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2010,Tourist/visitor arrivals (thousands),VF,,22281.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2016,Tourist/visitor arrivals (thousands),VF,,24571.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2017,Tourist/visitor arrivals (thousands),VF,,24390.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2018,Tourist/visitor arrivals (thousands),VF,,24551.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2005,Tourism expenditure (millions of US dollars),,,7805.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2010,Tourism expenditure (millions of US dollars),,,13239.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2016,Tourism expenditure (millions of US dollars),,,12822.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2017,Tourism expenditure (millions of US dollars),,,14983.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+643,Russian Federation,2018,Tourism expenditure (millions of US dollars),,,18670.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2010,Tourist/visitor arrivals (thousands),TF,,504.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2016,Tourist/visitor arrivals (thousands),TF,,932.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,1995,Tourism expenditure (millions of US dollars),,,4.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2005,Tourism expenditure (millions of US dollars),,,67.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2010,Tourism expenditure (millions of US dollars),,,224.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2016,Tourism expenditure (millions of US dollars),,,443.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2017,Tourism expenditure (millions of US dollars),,,548.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+646,Rwanda,2018,Tourism expenditure (millions of US dollars),,,528.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+667,Saba,1995,Tourist/visitor arrivals (thousands),TF,,10.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+667,Saba,2005,Tourist/visitor arrivals (thousands),TF,,11.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+667,Saba,2010,Tourist/visitor arrivals (thousands),TF,,12.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,1995,Tourist/visitor arrivals (thousands),TF,,79.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2005,Tourist/visitor arrivals (thousands),TF,,141.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2010,Tourist/visitor arrivals (thousands),TF,,98.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2016,Tourist/visitor arrivals (thousands),TF,,116.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2017,Tourist/visitor arrivals (thousands),TF,,115.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2018,Tourist/visitor arrivals (thousands),TF,,125.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,1995,Tourism expenditure (millions of US dollars),,,63.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2005,Tourism expenditure (millions of US dollars),,,121.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2010,Tourism expenditure (millions of US dollars),,,90.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2016,Tourism expenditure (millions of US dollars),,,332.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2017,Tourism expenditure (millions of US dollars),,,355.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+659,Saint Kitts and Nevis,2018,Tourism expenditure (millions of US dollars),,,367.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,1995,Tourist/visitor arrivals (thousands),TF,,231.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2005,Tourist/visitor arrivals (thousands),TF,,318.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2010,Tourist/visitor arrivals (thousands),TF,,306.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2016,Tourist/visitor arrivals (thousands),TF,,348.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2017,Tourist/visitor arrivals (thousands),TF,,386.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2018,Tourist/visitor arrivals (thousands),TF,,395.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,1995,Tourism expenditure (millions of US dollars),,,230.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2005,Tourism expenditure (millions of US dollars),,,382.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2010,Tourism expenditure (millions of US dollars),,,309.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2016,Tourism expenditure (millions of US dollars),,,776.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2017,Tourism expenditure (millions of US dollars),,,875.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+662,Saint Lucia,2018,Tourism expenditure (millions of US dollars),,,989.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,1995,Tourist/visitor arrivals (thousands),TF,,60.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2005,Tourist/visitor arrivals (thousands),TF,,96.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2010,Tourist/visitor arrivals (thousands),TF,,72.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2016,Tourist/visitor arrivals (thousands),TF,,79.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2017,Tourist/visitor arrivals (thousands),TF,,76.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2018,Tourist/visitor arrivals (thousands),TF,,80.0000,Arrivals of non-resident tourists by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,1995,Tourism expenditure (millions of US dollars),,,53.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2005,Tourism expenditure (millions of US dollars),,,104.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2010,Tourism expenditure (millions of US dollars),,,86.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2016,Tourism expenditure (millions of US dollars),,,216.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2017,Tourism expenditure (millions of US dollars),,,211.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+670,Saint Vincent & Grenadines,2018,Tourism expenditure (millions of US dollars),,,235.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,1995,Tourist/visitor arrivals (thousands),TF,,68.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2005,Tourist/visitor arrivals (thousands),TF,,102.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2010,Tourist/visitor arrivals (thousands),TF,,122.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2016,Tourist/visitor arrivals (thousands),TF,,134.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2017,Tourist/visitor arrivals (thousands),TF,,146.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2018,Tourist/visitor arrivals (thousands),TF,,164.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,1995,Tourism expenditure (millions of US dollars),,,35.6994,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2005,Tourism expenditure (millions of US dollars),,,73.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2010,Tourism expenditure (millions of US dollars),,,123.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2016,Tourism expenditure (millions of US dollars),,,148.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2017,Tourism expenditure (millions of US dollars),,,167.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+882,Samoa,2018,Tourism expenditure (millions of US dollars),,,191.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,1995,Tourist/visitor arrivals (thousands),THS,,28.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,2005,Tourist/visitor arrivals (thousands),THS,,50.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,2010,Tourist/visitor arrivals (thousands),THS,,120.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,2016,Tourist/visitor arrivals (thousands),THS,,60.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,2017,Tourist/visitor arrivals (thousands),THS,,78.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+674,San Marino,2018,Tourist/visitor arrivals (thousands),THS,,84.0000,Including Italian tourists.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,1995,Tourist/visitor arrivals (thousands),TF,,6.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2005,Tourist/visitor arrivals (thousands),TF,,15.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2010,Tourist/visitor arrivals (thousands),TF,,8.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2016,Tourist/visitor arrivals (thousands),TF,,28.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2017,Tourist/visitor arrivals (thousands),TF,,28.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2018,Tourist/visitor arrivals (thousands),TF,,33.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2016,Tourism expenditure (millions of US dollars),,,69.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2017,Tourism expenditure (millions of US dollars),,,65.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+678,Sao Tome and Principe,2018,Tourism expenditure (millions of US dollars),,,71.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,1995,Tourist/visitor arrivals (thousands),TF,,3325.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2005,Tourist/visitor arrivals (thousands),TF,,8037.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2010,Tourist/visitor arrivals (thousands),TF,,10850.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2016,Tourist/visitor arrivals (thousands),TF,,18044.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2017,Tourist/visitor arrivals (thousands),TF,,16109.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2018,Tourist/visitor arrivals (thousands),TF,,15334.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2010,Tourism expenditure (millions of US dollars),,,7536.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2016,Tourism expenditure (millions of US dollars),,,13438.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2017,Tourism expenditure (millions of US dollars),,,15020.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+682,Saudi Arabia,2018,Tourism expenditure (millions of US dollars),,,16975.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2005,Tourist/visitor arrivals (thousands),TF,,769.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2010,Tourist/visitor arrivals (thousands),TF,,900.0000,Estimate.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2016,Tourist/visitor arrivals (thousands),TF,,1210.0000,Estimate.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2017,Tourist/visitor arrivals (thousands),TF,,1365.0000,Estimate.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,1995,Tourism expenditure (millions of US dollars),,,168.1803,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2005,Tourism expenditure (millions of US dollars),,,334.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2010,Tourism expenditure (millions of US dollars),,,464.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2016,Tourism expenditure (millions of US dollars),,,438.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+686,Senegal,2017,Tourism expenditure (millions of US dollars),,,468.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2005,Tourist/visitor arrivals (thousands),TCE,,453.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2010,Tourist/visitor arrivals (thousands),TCE,,683.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2016,Tourist/visitor arrivals (thousands),TCE,,1281.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2017,Tourist/visitor arrivals (thousands),TCE,,1497.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2018,Tourist/visitor arrivals (thousands),TCE,,1711.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2005,Tourism expenditure (millions of US dollars),,,308.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2010,Tourism expenditure (millions of US dollars),,,950.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2016,Tourism expenditure (millions of US dollars),,,1461.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2017,Tourism expenditure (millions of US dollars),,,1706.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+688,Serbia,2018,Tourism expenditure (millions of US dollars),,,1921.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,1995,Tourist/visitor arrivals (thousands),TF,,121.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2005,Tourist/visitor arrivals (thousands),TF,,129.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2010,Tourist/visitor arrivals (thousands),TF,,175.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2016,Tourist/visitor arrivals (thousands),TF,,303.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2017,Tourist/visitor arrivals (thousands),TF,,350.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2018,Tourist/visitor arrivals (thousands),TF,,362.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,1995,Tourism expenditure (millions of US dollars),,,224.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2005,Tourism expenditure (millions of US dollars),,,269.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2010,Tourism expenditure (millions of US dollars),,,352.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2016,Tourism expenditure (millions of US dollars),,,505.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2017,Tourism expenditure (millions of US dollars),,,585.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+690,Seychelles,2018,Tourism expenditure (millions of US dollars),,,611.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,1995,Tourist/visitor arrivals (thousands),TF,,13.8000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2005,Tourist/visitor arrivals (thousands),TF,,40.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2010,Tourist/visitor arrivals (thousands),TF,,39.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2016,Tourist/visitor arrivals (thousands),TF,,55.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2017,Tourist/visitor arrivals (thousands),TF,,51.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2018,Tourist/visitor arrivals (thousands),TF,,57.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,1995,Tourism expenditure (millions of US dollars),,,57.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2005,Tourism expenditure (millions of US dollars),,,64.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2010,Tourism expenditure (millions of US dollars),,,26.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2016,Tourism expenditure (millions of US dollars),,,41.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2017,Tourism expenditure (millions of US dollars),,,39.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+694,Sierra Leone,2018,Tourism expenditure (millions of US dollars),,,39.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,1995,Tourist/visitor arrivals (thousands),TF,,6070.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2005,Tourist/visitor arrivals (thousands),TF,,7079.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2010,Tourist/visitor arrivals (thousands),TF,,9161.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2016,Tourist/visitor arrivals (thousands),TF,,12913.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2017,Tourist/visitor arrivals (thousands),TF,,13903.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2018,Tourist/visitor arrivals (thousands),TF,,14673.0000,Excluding Malaysian citizens arriving by land.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,1995,Tourism expenditure (millions of US dollars),,,7611.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2005,Tourism expenditure (millions of US dollars),,,6209.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2010,Tourism expenditure (millions of US dollars),,,14178.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2016,Tourism expenditure (millions of US dollars),,,18944.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2017,Tourism expenditure (millions of US dollars),,,19891.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+702,Singapore,2018,Tourism expenditure (millions of US dollars),,,20416.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+668,Sint Eustatius,1995,Tourist/visitor arrivals (thousands),TF,,8.8000,Excluding Netherlands Antillean residents.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+668,Sint Eustatius,2005,Tourist/visitor arrivals (thousands),TF,,10.4000,Excluding Netherlands Antillean residents.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+668,Sint Eustatius,2010,Tourist/visitor arrivals (thousands),TF,,11.4000,Excluding Netherlands Antillean residents.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),1995,Tourist/visitor arrivals (thousands),TF,,460.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2005,Tourist/visitor arrivals (thousands),TF,,468.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2010,Tourist/visitor arrivals (thousands),TF,,443.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2016,Tourist/visitor arrivals (thousands),TF,,528.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2017,Tourist/visitor arrivals (thousands),TF,,402.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2018,Tourist/visitor arrivals (thousands),TF,,178.0000,Arrivals by air. Including arrivals to Saint Martin (French part).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2010,Tourism expenditure (millions of US dollars),,,681.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2016,Tourism expenditure (millions of US dollars),,,871.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2017,Tourism expenditure (millions of US dollars),,,646.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+534,Sint Maarten (Dutch part),2018,Tourism expenditure (millions of US dollars),,,468.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,1995,Tourist/visitor arrivals (thousands),TCE,,903.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2005,Tourist/visitor arrivals (thousands),TCE,,1515.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2010,Tourist/visitor arrivals (thousands),TCE,,1327.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2016,Tourist/visitor arrivals (thousands),TCE,,2027.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2017,Tourist/visitor arrivals (thousands),TCE,,2162.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2018,Tourist/visitor arrivals (thousands),TCE,,2256.0000,Non-resident tourists staying in commercial accommodation only (representing approximately 25% of all tourists).,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,1995,Tourism expenditure (millions of US dollars),,,630.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2005,Tourism expenditure (millions of US dollars),,,1282.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2010,Tourism expenditure (millions of US dollars),,,2334.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2016,Tourism expenditure (millions of US dollars),,,2812.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2017,Tourism expenditure (millions of US dollars),,,3024.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+703,Slovakia,2018,Tourism expenditure (millions of US dollars),,,3318.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,1995,Tourist/visitor arrivals (thousands),TCE,,732.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2005,Tourist/visitor arrivals (thousands),TCE,,1555.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2010,Tourist/visitor arrivals (thousands),TCE,,2049.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2016,Tourist/visitor arrivals (thousands),TCE,,3397.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2017,Tourist/visitor arrivals (thousands),TCE,,3991.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2018,Tourist/visitor arrivals (thousands),TCE,,4425.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,1995,Tourism expenditure (millions of US dollars),,,1128.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2005,Tourism expenditure (millions of US dollars),,,1894.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2010,Tourism expenditure (millions of US dollars),,,2808.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2016,Tourism expenditure (millions of US dollars),,,2717.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2017,Tourism expenditure (millions of US dollars),,,3057.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+705,Slovenia,2018,Tourism expenditure (millions of US dollars),,,3378.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,1995,Tourist/visitor arrivals (thousands),TF,,11.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2005,Tourist/visitor arrivals (thousands),TF,,9.4000,Without first quarter.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2010,Tourist/visitor arrivals (thousands),TF,,20.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2016,Tourist/visitor arrivals (thousands),TF,,23.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2017,Tourist/visitor arrivals (thousands),TF,,25.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2018,Tourist/visitor arrivals (thousands),TF,,27.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,1995,Tourism expenditure (millions of US dollars),,,17.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2005,Tourism expenditure (millions of US dollars),,,6.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2010,Tourism expenditure (millions of US dollars),,,50.8000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2016,Tourism expenditure (millions of US dollars),,,71.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2017,Tourism expenditure (millions of US dollars),,,79.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+90,Solomon Islands,2018,Tourism expenditure (millions of US dollars),,,92.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,1995,Tourist/visitor arrivals (thousands),TF,,4488.0000,Excluding arrivals for work and contract workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2005,Tourist/visitor arrivals (thousands),TF,,7369.0000,Excluding arrivals for work and contract workers.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2010,Tourist/visitor arrivals (thousands),TF,,8074.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2016,Tourist/visitor arrivals (thousands),TF,,10044.0000,Break in the time series.;Excluding transit.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2017,Tourist/visitor arrivals (thousands),TF,,10285.0000,Excluding transit.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2018,Tourist/visitor arrivals (thousands),TF,,10472.0000,Excluding transit.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,1995,Tourism expenditure (millions of US dollars),,,2654.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2005,Tourism expenditure (millions of US dollars),,,8629.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2010,Tourism expenditure (millions of US dollars),,,10309.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2016,Tourism expenditure (millions of US dollars),,,8807.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2017,Tourism expenditure (millions of US dollars),,,9706.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+710,South Africa,2018,Tourism expenditure (millions of US dollars),,,9789.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+728,South Sudan,2016,Tourism expenditure (millions of US dollars),,,23.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+728,South Sudan,2017,Tourism expenditure (millions of US dollars),,,26.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+728,South Sudan,2018,Tourism expenditure (millions of US dollars),,,12.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,1995,Tourist/visitor arrivals (thousands),TF,,32971.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2005,Tourist/visitor arrivals (thousands),TF,,55914.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2010,Tourist/visitor arrivals (thousands),TF,,52677.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2016,Tourist/visitor arrivals (thousands),TF,,75315.0000,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2017,Tourist/visitor arrivals (thousands),TF,,81869.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2018,Tourist/visitor arrivals (thousands),TF,,82773.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,1995,Tourism expenditure (millions of US dollars),,,25368.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2005,Tourism expenditure (millions of US dollars),,,51959.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2010,Tourism expenditure (millions of US dollars),,,58348.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2016,Tourism expenditure (millions of US dollars),,,66982.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2017,Tourism expenditure (millions of US dollars),,,75906.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+724,Spain,2018,Tourism expenditure (millions of US dollars),,,81250.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,1995,Tourist/visitor arrivals (thousands),TF,,403.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2005,Tourist/visitor arrivals (thousands),TF,,549.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2010,Tourist/visitor arrivals (thousands),TF,,654.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2016,Tourist/visitor arrivals (thousands),TF,,2051.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2017,Tourist/visitor arrivals (thousands),TF,,2116.4000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2018,Tourist/visitor arrivals (thousands),TF,,2334.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,1995,Tourism expenditure (millions of US dollars),,,367.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2005,Tourism expenditure (millions of US dollars),,,729.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2010,Tourism expenditure (millions of US dollars),,,1044.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2016,Tourism expenditure (millions of US dollars),,,4591.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2017,Tourism expenditure (millions of US dollars),,,5083.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+144,Sri Lanka,2018,Tourism expenditure (millions of US dollars),,,5608.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2005,Tourist/visitor arrivals (thousands),THS,,88.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2010,Tourist/visitor arrivals (thousands),THS,,522.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2016,Tourist/visitor arrivals (thousands),THS,,400.0000,West Bank only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2017,Tourist/visitor arrivals (thousands),THS,,503.0000,West Bank only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2018,Tourist/visitor arrivals (thousands),THS,,606.0000,West Bank only.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,1995,Tourism expenditure (millions of US dollars),,,255.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2005,Tourism expenditure (millions of US dollars),,,52.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2010,Tourism expenditure (millions of US dollars),,,409.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2016,Tourism expenditure (millions of US dollars),,,235.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2017,Tourism expenditure (millions of US dollars),,,225.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+275,State of Palestine,2018,Tourism expenditure (millions of US dollars),,,245.0000,Excluding passenger transport.;West Bank and Gaza.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,1995,Tourist/visitor arrivals (thousands),TF,,29.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2005,Tourist/visitor arrivals (thousands),TF,,246.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2010,Tourist/visitor arrivals (thousands),TF,,495.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2016,Tourist/visitor arrivals (thousands),TF,,800.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2017,Tourist/visitor arrivals (thousands),TF,,813.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2018,Tourist/visitor arrivals (thousands),TF,,836.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,1995,Tourism expenditure (millions of US dollars),,,8.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2005,Tourism expenditure (millions of US dollars),,,114.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2010,Tourism expenditure (millions of US dollars),,,82.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2016,Tourism expenditure (millions of US dollars),,,1009.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2017,Tourism expenditure (millions of US dollars),,,1029.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+729,Sudan,2018,Tourism expenditure (millions of US dollars),,,1043.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,1995,Tourist/visitor arrivals (thousands),TF,,43.0000,Arrivals at Zanderij Airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2005,Tourist/visitor arrivals (thousands),TF,,161.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2010,Tourist/visitor arrivals (thousands),TF,,205.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2016,Tourist/visitor arrivals (thousands),TF,,256.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2017,Tourist/visitor arrivals (thousands),TF,,278.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,1995,Tourism expenditure (millions of US dollars),,,52.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2005,Tourism expenditure (millions of US dollars),,,96.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2010,Tourism expenditure (millions of US dollars),,,69.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2016,Tourism expenditure (millions of US dollars),,,74.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2017,Tourism expenditure (millions of US dollars),,,61.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+740,Suriname,2018,Tourism expenditure (millions of US dollars),,,73.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,1995,Tourist/visitor arrivals (thousands),TCE,,2310.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2005,Tourist/visitor arrivals (thousands),TCE,,4883.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2010,Tourist/visitor arrivals (thousands),TCE,,5183.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2016,Tourist/visitor arrivals (thousands),TCE,,6782.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2017,Tourist/visitor arrivals (thousands),TCE,,7054.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2018,Tourist/visitor arrivals (thousands),TCE,,7440.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,1995,Tourism expenditure (millions of US dollars),,,3471.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2005,Tourism expenditure (millions of US dollars),,,6554.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2010,Tourism expenditure (millions of US dollars),,,8336.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2016,Tourism expenditure (millions of US dollars),,,12764.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2017,Tourism expenditure (millions of US dollars),,,14168.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+752,Sweden,2018,Tourism expenditure (millions of US dollars),,,14926.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,1995,Tourist/visitor arrivals (thousands),THS,,6946.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2005,Tourist/visitor arrivals (thousands),THS,,7229.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2010,Tourist/visitor arrivals (thousands),THS,,8628.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2016,Tourist/visitor arrivals (thousands),THS,,9205.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2017,Tourist/visitor arrivals (thousands),THS,,9889.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2018,Tourist/visitor arrivals (thousands),THS,,10362.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,1995,Tourism expenditure (millions of US dollars),,,11354.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2005,Tourism expenditure (millions of US dollars),,,11952.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2010,Tourism expenditure (millions of US dollars),,,17614.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2016,Tourism expenditure (millions of US dollars),,,19042.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2017,Tourism expenditure (millions of US dollars),,,19654.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+756,Switzerland,2018,Tourism expenditure (millions of US dollars),,,20276.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+760,Syrian Arab Republic,1995,Tourist/visitor arrivals (thousands),TCE,,815.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+760,Syrian Arab Republic,2005,Tourist/visitor arrivals (thousands),TCE,,3571.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+760,Syrian Arab Republic,2010,Tourist/visitor arrivals (thousands),TCE,,8546.0000,Including nationals residing abroad.;Including Iraqi nationals.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+760,Syrian Arab Republic,2005,Tourism expenditure (millions of US dollars),,,2035.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+760,Syrian Arab Republic,2010,Tourism expenditure (millions of US dollars),,,6308.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2010,Tourist/visitor arrivals (thousands),VF,,160.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2016,Tourist/visitor arrivals (thousands),VF,,344.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2017,Tourist/visitor arrivals (thousands),VF,,431.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2018,Tourist/visitor arrivals (thousands),VF,,1035.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2005,Tourism expenditure (millions of US dollars),,,9.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2010,Tourism expenditure (millions of US dollars),,,141.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2016,Tourism expenditure (millions of US dollars),,,149.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2017,Tourism expenditure (millions of US dollars),,,171.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+762,Tajikistan,2018,Tourism expenditure (millions of US dollars),,,170.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,1995,Tourist/visitor arrivals (thousands),TF,,6952.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2005,Tourist/visitor arrivals (thousands),TF,,11567.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2010,Tourist/visitor arrivals (thousands),TF,,15936.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2016,Tourist/visitor arrivals (thousands),TF,,32530.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2017,Tourist/visitor arrivals (thousands),TF,,35592.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2018,Tourist/visitor arrivals (thousands),TF,,38178.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,1995,Tourism expenditure (millions of US dollars),,,9257.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2005,Tourism expenditure (millions of US dollars),,,12103.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2010,Tourism expenditure (millions of US dollars),,,23796.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2016,Tourism expenditure (millions of US dollars),,,48459.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2017,Tourism expenditure (millions of US dollars),,,57057.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+764,Thailand,2018,Tourism expenditure (millions of US dollars),,,65242.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2010,Tourist/visitor arrivals (thousands),TF,,40.0000,Arrivals by air at Dili Airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2016,Tourist/visitor arrivals (thousands),TF,,66.0000,Arrivals by air at Dili Airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2017,Tourist/visitor arrivals (thousands),TF,,74.0000,Arrivals by air at Dili Airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2018,Tourist/visitor arrivals (thousands),TF,,75.0000,Arrivals by air at Dili Airport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2010,Tourism expenditure (millions of US dollars),,,24.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2016,Tourism expenditure (millions of US dollars),,,58.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2017,Tourism expenditure (millions of US dollars),,,73.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+626,Timor-Leste,2018,Tourism expenditure (millions of US dollars),,,78.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,1995,Tourist/visitor arrivals (thousands),THS,,53.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2005,Tourist/visitor arrivals (thousands),THS,,81.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2010,Tourist/visitor arrivals (thousands),THS,,202.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2016,Tourist/visitor arrivals (thousands),THS,,338.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2017,Tourist/visitor arrivals (thousands),THS,,514.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2018,Tourist/visitor arrivals (thousands),THS,,573.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2005,Tourism expenditure (millions of US dollars),,,27.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2010,Tourism expenditure (millions of US dollars),,,105.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2016,Tourism expenditure (millions of US dollars),,,223.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+768,Togo,2017,Tourism expenditure (millions of US dollars),,,245.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,1995,Tourist/visitor arrivals (thousands),TF,,29.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2005,Tourist/visitor arrivals (thousands),TF,,42.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2010,Tourist/visitor arrivals (thousands),TF,,47.1000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2016,Tourist/visitor arrivals (thousands),TF,,59.1000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2017,Tourist/visitor arrivals (thousands),TF,,62.5000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2018,Tourist/visitor arrivals (thousands),TF,,54.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2005,Tourism expenditure (millions of US dollars),,,15.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2010,Tourism expenditure (millions of US dollars),,,17.3000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2016,Tourism expenditure (millions of US dollars),,,52.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2017,Tourism expenditure (millions of US dollars),,,48.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+776,Tonga,2018,Tourism expenditure (millions of US dollars),,,48.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,1995,Tourist/visitor arrivals (thousands),TF,,260.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2005,Tourist/visitor arrivals (thousands),TF,,463.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2010,Tourist/visitor arrivals (thousands),TF,,388.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2016,Tourist/visitor arrivals (thousands),TF,,409.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2017,Tourist/visitor arrivals (thousands),TF,,395.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2018,Tourist/visitor arrivals (thousands),TF,,375.0000,Arrivals by air.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,1995,Tourism expenditure (millions of US dollars),,,232.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2005,Tourism expenditure (millions of US dollars),,,593.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2010,Tourism expenditure (millions of US dollars),,,630.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2016,Tourism expenditure (millions of US dollars),,,708.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2017,Tourism expenditure (millions of US dollars),,,717.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+780,Trinidad and Tobago,2018,Tourism expenditure (millions of US dollars),,,541.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,1995,Tourist/visitor arrivals (thousands),TF,,4120.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2005,Tourist/visitor arrivals (thousands),TF,,6378.0000,Excluding nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2010,Tourist/visitor arrivals (thousands),TF,,7828.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2016,Tourist/visitor arrivals (thousands),TF,,5724.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2017,Tourist/visitor arrivals (thousands),TF,,7052.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2018,Tourist/visitor arrivals (thousands),TF,,8299.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,1995,Tourism expenditure (millions of US dollars),,,1838.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2005,Tourism expenditure (millions of US dollars),,,2800.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2010,Tourism expenditure (millions of US dollars),,,3477.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2016,Tourism expenditure (millions of US dollars),,,1706.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2017,Tourism expenditure (millions of US dollars),,,1782.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+788,Tunisia,2018,Tourism expenditure (millions of US dollars),,,2320.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,1995,Tourist/visitor arrivals (thousands),TF,,7083.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2005,Tourist/visitor arrivals (thousands),TF,,20273.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2010,Tourist/visitor arrivals (thousands),TF,,31364.0000,Turkish citizens resident abroad are included.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2016,Tourist/visitor arrivals (thousands),TF,,30289.0000,Turkish citizens resident abroad are included.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2017,Tourist/visitor arrivals (thousands),TF,,37601.0000,Turkish citizens resident abroad are included.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2018,Tourist/visitor arrivals (thousands),TF,,45768.0000,Turkish citizens resident abroad are included.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2005,Tourism expenditure (millions of US dollars),,,20760.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2010,Tourism expenditure (millions of US dollars),,,26318.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2016,Tourism expenditure (millions of US dollars),,,26788.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2017,Tourism expenditure (millions of US dollars),,,31870.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+792,Turkey,2018,Tourism expenditure (millions of US dollars),,,37140.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+795,Turkmenistan,1995,Tourist/visitor arrivals (thousands),TF,,218.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+795,Turkmenistan,2005,Tourist/visitor arrivals (thousands),TF,,11.6000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,1995,Tourist/visitor arrivals (thousands),TF,,79.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,2005,Tourist/visitor arrivals (thousands),TF,,176.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,2010,Tourist/visitor arrivals (thousands),TF,,281.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,2016,Tourist/visitor arrivals (thousands),TF,,449.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,2017,Tourist/visitor arrivals (thousands),TF,,416.4000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,2018,Tourist/visitor arrivals (thousands),TF,,441.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+796,Turks and Caicos Islands,1995,Tourism expenditure (millions of US dollars),,,53.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,1995,Tourist/visitor arrivals (thousands),TF,,0.9000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2005,Tourist/visitor arrivals (thousands),TF,,1.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2010,Tourist/visitor arrivals (thousands),TF,,1.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2016,Tourist/visitor arrivals (thousands),TF,,2.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2017,Tourist/visitor arrivals (thousands),TF,,2.5000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2018,Tourist/visitor arrivals (thousands),TF,,2.7000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2005,Tourism expenditure (millions of US dollars),,,1.2000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+798,Tuvalu,2010,Tourism expenditure (millions of US dollars),,,2.4000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,1995,Tourist/visitor arrivals (thousands),TF,,160.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2005,Tourist/visitor arrivals (thousands),TF,,468.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2010,Tourist/visitor arrivals (thousands),TF,,946.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2016,Tourist/visitor arrivals (thousands),TF,,1323.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2017,Tourist/visitor arrivals (thousands),TF,,1402.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2005,Tourism expenditure (millions of US dollars),,,382.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2010,Tourism expenditure (millions of US dollars),,,802.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2016,Tourism expenditure (millions of US dollars),,,1118.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2017,Tourism expenditure (millions of US dollars),,,957.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+800,Uganda,2018,Tourism expenditure (millions of US dollars),,,1044.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,1995,Tourist/visitor arrivals (thousands),TF,,3716.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2005,Tourist/visitor arrivals (thousands),TF,,17631.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2010,Tourist/visitor arrivals (thousands),TF,,21203.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2016,Tourist/visitor arrivals (thousands),TF,,13333.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2017,Tourist/visitor arrivals (thousands),TF,,14230.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2018,Tourist/visitor arrivals (thousands),TF,,14104.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2005,Tourism expenditure (millions of US dollars),,,3542.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2010,Tourism expenditure (millions of US dollars),,,4696.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2016,Tourism expenditure (millions of US dollars),,,1723.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2017,Tourism expenditure (millions of US dollars),,,2019.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+804,Ukraine,2018,Tourism expenditure (millions of US dollars),,,2269.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,1995,Tourist/visitor arrivals (thousands),THS,,2315.0000,Arrivals in hotels only. Including domestic tourism and nationals of the country residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2005,Tourist/visitor arrivals (thousands),THS,,7126.0000,Arrivals in hotels only. Including domestic tourism and nationals of the country residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2016,Tourist/visitor arrivals (thousands),THS,,18967.0000,Arrivals in hotels only. Including domestic tourism and nationals of the country residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2017,Tourist/visitor arrivals (thousands),THS,,20394.0000,Arrivals in hotels only. Including domestic tourism and nationals of the country residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2018,Tourist/visitor arrivals (thousands),THS,,21286.0000,Arrivals in hotels only. Including domestic tourism and nationals of the country residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,1995,Tourism expenditure (millions of US dollars),,,632.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2005,Tourism expenditure (millions of US dollars),,,3218.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2010,Tourism expenditure (millions of US dollars),,,8577.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2016,Tourism expenditure (millions of US dollars),,,19496.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2017,Tourism expenditure (millions of US dollars),,,21048.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+784,United Arab Emirates,2018,Tourism expenditure (millions of US dollars),,,21390.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,1995,Tourist/visitor arrivals (thousands),TF,,21719.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2005,Tourist/visitor arrivals (thousands),TF,,28039.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2010,Tourist/visitor arrivals (thousands),TF,,28295.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2016,Tourist/visitor arrivals (thousands),TF,,35814.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2017,Tourist/visitor arrivals (thousands),TF,,37651.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2018,Tourist/visitor arrivals (thousands),TF,,36316.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,1995,Tourism expenditure (millions of US dollars),,,27577.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2005,Tourism expenditure (millions of US dollars),,,32948.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2010,Tourism expenditure (millions of US dollars),,,34715.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2016,Tourism expenditure (millions of US dollars),,,47777.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2017,Tourism expenditure (millions of US dollars),,,47719.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+826,United Kingdom,2018,Tourism expenditure (millions of US dollars),,,48515.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,1995,Tourist/visitor arrivals (thousands),TF,,285.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2005,Tourist/visitor arrivals (thousands),TF,,590.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2010,Tourist/visitor arrivals (thousands),TF,,754.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2016,Tourist/visitor arrivals (thousands),TF,,1233.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2017,Tourist/visitor arrivals (thousands),TF,,1275.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2018,Tourist/visitor arrivals (thousands),TF,,1378.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2005,Tourism expenditure (millions of US dollars),,,835.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2010,Tourism expenditure (millions of US dollars),,,1279.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2016,Tourism expenditure (millions of US dollars),,,2149.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2017,Tourism expenditure (millions of US dollars),,,2265.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+834,United Rep. of Tanzania,2018,Tourism expenditure (millions of US dollars),,,2465.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,1995,Tourist/visitor arrivals (thousands),TF,,43318.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2005,Tourist/visitor arrivals (thousands),TF,,49206.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2010,Tourist/visitor arrivals (thousands),TF,,60010.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2016,Tourist/visitor arrivals (thousands),TF,,76407.4880,Break in the time series.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2017,Tourist/visitor arrivals (thousands),TF,,77186.7460,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2018,Tourist/visitor arrivals (thousands),TF,,79745.9180,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,1995,Tourism expenditure (millions of US dollars),,,93743.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2005,Tourism expenditure (millions of US dollars),,,122077.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2010,Tourism expenditure (millions of US dollars),,,167996.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2016,Tourism expenditure (millions of US dollars),,,245991.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2017,Tourism expenditure (millions of US dollars),,,251544.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+840,United States of America,2018,Tourism expenditure (millions of US dollars),,,256145.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,1995,Tourist/visitor arrivals (thousands),TF,,454.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2005,Tourist/visitor arrivals (thousands),TF,,594.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2010,Tourist/visitor arrivals (thousands),TF,,572.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2016,Tourist/visitor arrivals (thousands),TF,,667.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2017,Tourist/visitor arrivals (thousands),TF,,535.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2018,Tourist/visitor arrivals (thousands),TF,,381.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,1995,Tourism expenditure (millions of US dollars),,,822.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2005,Tourism expenditure (millions of US dollars),,,1432.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2010,Tourism expenditure (millions of US dollars),,,1223.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2016,Tourism expenditure (millions of US dollars),,,1343.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2017,Tourism expenditure (millions of US dollars),,,1202.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+850,United States Virgin Islands,2018,Tourism expenditure (millions of US dollars),,,1046.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,1995,Tourist/visitor arrivals (thousands),TF,,2022.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2005,Tourist/visitor arrivals (thousands),TF,,1808.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2010,Tourist/visitor arrivals (thousands),TF,,2353.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2016,Tourist/visitor arrivals (thousands),TF,,3037.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2017,Tourist/visitor arrivals (thousands),TF,,3674.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2018,Tourist/visitor arrivals (thousands),TF,,3469.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,1995,Tourism expenditure (millions of US dollars),,,725.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2005,Tourism expenditure (millions of US dollars),,,699.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2010,Tourism expenditure (millions of US dollars),,,1669.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2016,Tourism expenditure (millions of US dollars),,,2182.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2017,Tourism expenditure (millions of US dollars),,,2660.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+858,Uruguay,2018,Tourism expenditure (millions of US dollars),,,2439.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,1995,Tourist/visitor arrivals (thousands),TF,,92.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2005,Tourist/visitor arrivals (thousands),TF,,242.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2010,Tourist/visitor arrivals (thousands),TF,,975.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2016,Tourist/visitor arrivals (thousands),TF,,2027.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2017,Tourist/visitor arrivals (thousands),TF,,2690.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2018,Tourist/visitor arrivals (thousands),TF,,5346.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2005,Tourism expenditure (millions of US dollars),,,28.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2010,Tourism expenditure (millions of US dollars),,,121.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2016,Tourism expenditure (millions of US dollars),,,458.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2017,Tourism expenditure (millions of US dollars),,,689.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+860,Uzbekistan,2018,Tourism expenditure (millions of US dollars),,,1144.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,1995,Tourist/visitor arrivals (thousands),TF,,44.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2005,Tourist/visitor arrivals (thousands),TF,,62.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2010,Tourist/visitor arrivals (thousands),TF,,97.2000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2016,Tourist/visitor arrivals (thousands),TF,,95.1000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2017,Tourist/visitor arrivals (thousands),TF,,109.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2018,Tourist/visitor arrivals (thousands),TF,,116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2005,Tourism expenditure (millions of US dollars),,,104.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2010,Tourism expenditure (millions of US dollars),,,242.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2016,Tourism expenditure (millions of US dollars),,,275.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2017,Tourism expenditure (millions of US dollars),,,289.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+548,Vanuatu,2018,Tourism expenditure (millions of US dollars),,,325.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),1995,Tourist/visitor arrivals (thousands),TF,,700.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2005,Tourist/visitor arrivals (thousands),TF,,706.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2010,Tourist/visitor arrivals (thousands),TF,,526.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2016,Tourist/visitor arrivals (thousands),TF,,601.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2017,Tourist/visitor arrivals (thousands),TF,,427.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),1995,Tourism expenditure (millions of US dollars),,,995.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2005,Tourism expenditure (millions of US dollars),,,722.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2010,Tourism expenditure (millions of US dollars),,,885.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+862,Venezuela (Boliv. Rep. of),2016,Tourism expenditure (millions of US dollars),,,546.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,1995,Tourist/visitor arrivals (thousands),VF,,1351.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2005,Tourist/visitor arrivals (thousands),VF,,3477.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2010,Tourist/visitor arrivals (thousands),VF,,5050.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2016,Tourist/visitor arrivals (thousands),VF,,10013.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2017,Tourist/visitor arrivals (thousands),VF,,12922.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2018,Tourist/visitor arrivals (thousands),VF,,15498.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2005,Tourism expenditure (millions of US dollars),,,2300.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2010,Tourism expenditure (millions of US dollars),,,4450.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2016,Tourism expenditure (millions of US dollars),,,8500.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2017,Tourism expenditure (millions of US dollars),,,8890.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+704,Viet Nam,2018,Tourism expenditure (millions of US dollars),,,10080.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+887,Yemen,1995,Tourist/visitor arrivals (thousands),TF,,61.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+887,Yemen,2005,Tourist/visitor arrivals (thousands),TF,,336.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+887,Yemen,2010,Tourist/visitor arrivals (thousands),TF,,1025.0000,Including nationals residing abroad.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+887,Yemen,2010,Tourism expenditure (millions of US dollars),,,1291.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+887,Yemen,2016,Tourism expenditure (millions of US dollars),,,116.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,1995,Tourist/visitor arrivals (thousands),TF,,163.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2005,Tourist/visitor arrivals (thousands),TF,,669.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2010,Tourist/visitor arrivals (thousands),TF,,815.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2016,Tourist/visitor arrivals (thousands),TF,,956.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2017,Tourist/visitor arrivals (thousands),TF,,1083.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2018,Tourist/visitor arrivals (thousands),TF,,1072.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2005,Tourism expenditure (millions of US dollars),,,447.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2010,Tourism expenditure (millions of US dollars),,,492.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2016,Tourism expenditure (millions of US dollars),,,683.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2017,Tourism expenditure (millions of US dollars),,,653.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+894,Zambia,2018,Tourism expenditure (millions of US dollars),,,742.0000,Excluding passenger transport.,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,1995,Tourist/visitor arrivals (thousands),VF,,1416.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2005,Tourist/visitor arrivals (thousands),VF,,1559.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2010,Tourist/visitor arrivals (thousands),VF,,2239.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2016,Tourist/visitor arrivals (thousands),VF,,2168.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2017,Tourist/visitor arrivals (thousands),VF,,2423.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2018,Tourist/visitor arrivals (thousands),VF,,2580.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,1995,Tourism expenditure (millions of US dollars),,,145.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2005,Tourism expenditure (millions of US dollars),,,99.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2010,Tourism expenditure (millions of US dollars),,,135.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2016,Tourism expenditure (millions of US dollars),,,194.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
+716,Zimbabwe,2017,Tourism expenditure (millions of US dollars),,,158.0000,,"World Tourism Organization (UNWTO), Madrid, the UNWTO Statistics Database, last accessed January 2020."
diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml
index 27768d60fc..e0855155bc 100644
--- a/apache-spark/pom.xml
+++ b/apache-spark/pom.xml
@@ -74,6 +74,7 @@
maven-assembly-plugin
+ 3.3.0package
diff --git a/apache-spark/src/main/java/com/baeldung/differences/dataframe/dataset/rdd/TouristData.java b/apache-spark/src/main/java/com/baeldung/differences/dataframe/dataset/rdd/TouristData.java
new file mode 100644
index 0000000000..fbeef4283a
--- /dev/null
+++ b/apache-spark/src/main/java/com/baeldung/differences/dataframe/dataset/rdd/TouristData.java
@@ -0,0 +1,75 @@
+package com.baeldung.differences.dataframe.dataset.rdd;
+
+
+public class TouristData {
+
+ private String region;
+ private String country;
+ private String year;
+ private String series;
+ private Double value;
+ private String footnotes;
+ private String source;
+
+ public String getRegion() {
+ return region;
+ }
+
+ public void setRegion(String region) {
+ this.region = region;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+ public String getYear() {
+ return year;
+ }
+
+ public void setYear(String year) {
+ this.year = year;
+ }
+
+ public String getSeries() {
+ return series;
+ }
+
+ public void setSeries(String series) {
+ this.series = series;
+ }
+
+ public Double getValue() {
+ return value;
+ }
+
+ public void setValue(Double value) {
+ this.value = value;
+ }
+
+ public String getFootnotes() {
+ return footnotes;
+ }
+
+ public void setFootnotes(String footnotes) {
+ this.footnotes = footnotes;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ @Override
+ public String toString() {
+ return "TouristData [region=" + region + ", country=" + country + ", year=" + year + ", series=" + series + ", value=" + value + ", footnotes=" + footnotes + ", source=" + source + "]";
+ }
+
+}
diff --git a/apache-spark/src/test/java/com/baeldung/differences/rdd/ActionsUnitTest.java b/apache-spark/src/test/java/com/baeldung/differences/rdd/ActionsUnitTest.java
new file mode 100644
index 0000000000..a3e1811e6f
--- /dev/null
+++ b/apache-spark/src/test/java/com/baeldung/differences/rdd/ActionsUnitTest.java
@@ -0,0 +1,67 @@
+package com.baeldung.differences.rdd;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.apache.spark.SparkConf;
+import org.apache.spark.api.java.JavaPairRDD;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import scala.Tuple2;
+
+public class ActionsUnitTest {
+ private static JavaRDD tourists;
+ private static JavaSparkContext sc;
+ public static final String COMMA_DELIMITER = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
+
+ @BeforeClass
+ public static void init() {
+ SparkConf conf = new SparkConf().setAppName("reduce")
+ .setMaster("local[*]");
+ sc = new JavaSparkContext(conf);
+ tourists = sc.textFile("data/Tourist.csv").filter(line -> !line.startsWith("Region"));
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ sc.close();
+ }
+
+ @Test
+ public void whenDistinctCount_thenReturnDistinctNumRecords() {
+ JavaRDD countries = tourists.map(line -> {
+ String[] columns = line.split(COMMA_DELIMITER);
+ return columns[1];
+ })
+ .distinct();
+ Long numberOfCountries = countries.count();
+ System.out.println("Count: " + numberOfCountries);
+
+ assertEquals(Long.valueOf(220), numberOfCountries);
+ }
+
+ @Test
+ public void whenReduceByKeySum_thenTotalValuePerKey() {
+ JavaRDD touristsExpenditure = tourists.filter(line -> line.split(COMMA_DELIMITER)[3].contains("expenditure"));
+
+ JavaPairRDD expenditurePairRdd = touristsExpenditure.mapToPair(line -> {
+ String[] columns = line.split(COMMA_DELIMITER);
+ return new Tuple2<>(columns[1], Double.valueOf(columns[6]));
+ });
+ List> totalByCountry = expenditurePairRdd.reduceByKey((x, y) -> x + y)
+ .collect();
+ System.out.println("Total per Country: " + totalByCountry);
+
+ for(Tuple2 tuple : totalByCountry) {
+ if (tuple._1.equals("Mexico")) {
+ assertEquals(Double.valueOf(99164), tuple._2);
+ }
+ }
+ }
+
+}
diff --git a/apache-spark/src/test/java/com/baeldung/differences/rdd/DataFrameUnitTest.java b/apache-spark/src/test/java/com/baeldung/differences/rdd/DataFrameUnitTest.java
new file mode 100644
index 0000000000..f294e5bc66
--- /dev/null
+++ b/apache-spark/src/test/java/com/baeldung/differences/rdd/DataFrameUnitTest.java
@@ -0,0 +1,74 @@
+package com.baeldung.differences.rdd;
+
+import static org.apache.spark.sql.functions.col;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.spark.sql.DataFrameReader;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class DataFrameUnitTest {
+ private static SparkSession session;
+ private static Dataset data;
+
+ @BeforeClass
+ public static void init() {
+ session = SparkSession.builder()
+ .appName("TouristDataFrameExample")
+ .master("local[*]")
+ .getOrCreate();
+ DataFrameReader dataFrameReader = session.read();
+ data = dataFrameReader.option("header", "true")
+ .csv("data/Tourist.csv");
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ session.stop();
+ }
+
+ @Test
+ public void whenSelectSpecificColumns_thenColumnsFiltered() {
+ Dataset selectedData = data.select(col("country"), col("year"), col("value"));
+ selectedData.show();
+
+ List resultList = Arrays.asList(selectedData.columns());
+ assertTrue(resultList.contains("country"));
+ assertTrue(resultList.contains("year"));
+ assertTrue(resultList.contains("value"));
+ assertFalse(resultList.contains("Series"));
+
+ }
+
+ @Test
+ public void whenFilteringByCountry_thenCountryRecordsSelected() {
+ Dataset filteredData = data.filter(col("country").equalTo("Mexico"));
+ filteredData.show();
+
+ filteredData.foreach(record -> {
+ assertEquals("Mexico", record.get(1));
+ });
+
+ }
+
+ @Test
+ public void whenGroupCountByCountry_thenContryTotalRecords() {
+ Dataset recordsPerCountry = data.groupBy(col("country"))
+ .count();
+ recordsPerCountry.show();
+
+ Dataset filteredData = recordsPerCountry.filter(col("country").equalTo("Sweden"));
+ assertEquals(new Long(12), filteredData.first()
+ .get(1));
+ }
+
+}
diff --git a/apache-spark/src/test/java/com/baeldung/differences/rdd/DatasetUnitTest.java b/apache-spark/src/test/java/com/baeldung/differences/rdd/DatasetUnitTest.java
new file mode 100644
index 0000000000..1d83505812
--- /dev/null
+++ b/apache-spark/src/test/java/com/baeldung/differences/rdd/DatasetUnitTest.java
@@ -0,0 +1,83 @@
+package com.baeldung.differences.rdd;
+
+import static org.apache.spark.sql.functions.col;
+import static org.apache.spark.sql.functions.sum;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.spark.api.java.function.FilterFunction;
+import org.apache.spark.sql.DataFrameReader;
+import org.apache.spark.sql.Dataset;
+import org.apache.spark.sql.Encoders;
+import org.apache.spark.sql.Row;
+import org.apache.spark.sql.SparkSession;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.baeldung.differences.dataframe.dataset.rdd.TouristData;
+
+public class DatasetUnitTest {
+ private static SparkSession session;
+ private static Dataset typedDataset;
+
+ @BeforeClass
+ public static void init() {
+ session = SparkSession.builder()
+ .appName("TouristDatasetExample")
+ .master("local[*]")
+ .getOrCreate();
+ DataFrameReader dataFrameReader = session.read();
+ Dataset data = dataFrameReader.option("header", "true")
+ .csv("data/Tourist.csv");
+ Dataset responseWithSelectedColumns = data.select(col("region"),
+ col("country"), col("year"), col("series"), col("value").cast("double"),
+ col("footnotes"), col("source"));
+ typedDataset = responseWithSelectedColumns.as(Encoders.bean(TouristData.class));
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ session.stop();
+ }
+
+ @Test
+ public void whenFilteringByCountry_thenCountryRecordsSelected() {
+ Dataset selectedData = typedDataset
+ .filter((FilterFunction) record -> record.getCountry()
+ .equals("Norway"));
+ selectedData.show();
+
+ selectedData.foreach(record -> {
+ assertEquals("Norway", record.getCountry());
+ });
+ }
+
+ @Test
+ public void whenGroupCountByCountry_thenContryTotalRecords() {
+ Dataset countriesCount = typedDataset.groupBy(typedDataset.col("country"))
+ .count();
+ countriesCount.show();
+
+ assertEquals(Long.valueOf(220), Long.valueOf(countriesCount.count()));
+ }
+
+ @Test
+ public void whenFilteredByPropertyRange_thenRetreiveValidRecords() {
+ // Filter records with existing data for years between 2010 and 2017
+ typedDataset.filter((FilterFunction) record -> record.getYear() != null
+ && (Long.valueOf(record.getYear()) > 2010 && Long.valueOf(record.getYear()) < 2017))
+ .show();
+ }
+
+ @Test
+ public void whenSumValue_thenRetreiveTotalValue() {
+ // Total tourist expenditure by country
+ typedDataset.filter((FilterFunction) record -> record.getValue() != null
+ && record.getSeries()
+ .contains("expenditure"))
+ .groupBy("country")
+ .agg(sum("value"))
+ .show();
+ }
+
+}
diff --git a/apache-spark/src/test/java/com/baeldung/differences/rdd/TransformationsUnitTest.java b/apache-spark/src/test/java/com/baeldung/differences/rdd/TransformationsUnitTest.java
new file mode 100644
index 0000000000..4b2d9e1127
--- /dev/null
+++ b/apache-spark/src/test/java/com/baeldung/differences/rdd/TransformationsUnitTest.java
@@ -0,0 +1,63 @@
+package com.baeldung.differences.rdd;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.spark.SparkConf;
+import org.apache.spark.api.java.JavaRDD;
+import org.apache.spark.api.java.JavaSparkContext;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TransformationsUnitTest {
+
+ public static final String COMMA_DELIMITER = ",(?=([^\"]*\"[^\"]*\")*[^\"]*$)";
+ private static JavaSparkContext sc;
+ private static JavaRDD tourists;
+
+ @BeforeClass
+ public static void init() {
+ SparkConf conf = new SparkConf().setAppName("uppercaseCountries")
+ .setMaster("local[*]");
+ sc = new JavaSparkContext(conf);
+ tourists = sc.textFile("data/Tourist.csv")
+ .filter(line -> !line.startsWith("Region")); //filter header row
+ }
+
+ @AfterClass
+ public static void cleanup() {
+ sc.close();
+ }
+
+ @Test
+ public void whenMapUpperCase_thenCountryNameUppercased() {
+ JavaRDD upperCaseCountries = tourists.map(line -> {
+ String[] columns = line.split(COMMA_DELIMITER);
+ return columns[1].toUpperCase();
+ })
+ .distinct();
+
+ upperCaseCountries.saveAsTextFile("data/output/uppercase.txt");
+
+ upperCaseCountries.foreach(country -> {
+ //replace non alphanumerical characters
+ country = country.replaceAll("[^a-zA-Z]", "");
+ assertTrue(StringUtils.isAllUpperCase(country));
+ });
+ }
+
+ @Test
+ public void whenFilterByCountry_thenShowRequestedCountryRecords() {
+ JavaRDD touristsInMexico = tourists.filter(line -> line.split(COMMA_DELIMITER)[1].equals("Mexico"));
+
+ touristsInMexico.saveAsTextFile("data/output/touristInMexico.txt");
+
+ touristsInMexico.foreach(record -> {
+ assertEquals("Mexico", record.split(COMMA_DELIMITER)[1]);
+ });
+ }
+
+}
diff --git a/atomikos/pom.xml b/atomikos/pom.xml
index d680a3ca77..8918de7b77 100644
--- a/atomikos/pom.xml
+++ b/atomikos/pom.xml
@@ -51,7 +51,7 @@
org.hibernate
- hibernate-entitymanager
+ hibernate-core${hibernate.version}provided
diff --git a/aws-lambda/README.md b/aws-lambda/README.md
index 2fbdaace10..759c9dd506 100644
--- a/aws-lambda/README.md
+++ b/aws-lambda/README.md
@@ -5,3 +5,4 @@ This module contains articles about AWS Lambda
### Relevant Articles:
- [Using AWS Lambda with API Gateway](https://www.baeldung.com/aws-lambda-api-gateway)
- [Introduction to AWS Serverless Application Model](https://www.baeldung.com/aws-serverless)
+- [How to Implement Hibernate in an AWS Lambda Function in Java](https://www.baeldung.com/java-aws-lambda-hibernate)
diff --git a/aws-lambda/lambda/pom.xml b/aws-lambda/lambda/pom.xml
new file mode 100644
index 0000000000..463d106c77
--- /dev/null
+++ b/aws-lambda/lambda/pom.xml
@@ -0,0 +1,99 @@
+
+
+ 4.0.0
+ lambda
+ 0.1.0-SNAPSHOT
+ lambda
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ../../
+
+
+
+
+ com.amazonaws
+ aws-java-sdk-dynamodb
+ ${aws-java-sdk.version}
+
+
+ com.amazonaws
+ aws-java-sdk-core
+ ${aws-java-sdk.version}
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ ${aws-lambda-java-core.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ ${aws-lambda-java-events.version}
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ com.google.code.gson
+ gson
+ ${gson.version}
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+ com.googlecode.json-simple
+ json-simple
+ ${json-simple.version}
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ ${maven-shade-plugin.version}
+
+ false
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
+
+ 1.1.1
+ 1.3.0
+ 1.2.0
+ 2.8.2
+ 1.11.241
+ 3.0.0
+
+
+
diff --git a/aws-lambda/sam-templates/template-implicit.yaml b/aws-lambda/lambda/sam-templates/template-implicit.yaml
similarity index 100%
rename from aws-lambda/sam-templates/template-implicit.yaml
rename to aws-lambda/lambda/sam-templates/template-implicit.yaml
diff --git a/aws-lambda/sam-templates/template-inline-swagger.yaml b/aws-lambda/lambda/sam-templates/template-inline-swagger.yaml
similarity index 100%
rename from aws-lambda/sam-templates/template-inline-swagger.yaml
rename to aws-lambda/lambda/sam-templates/template-inline-swagger.yaml
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaMethodHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/LambdaRequestStreamHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/APIDemoHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/apigateway/model/Person.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/SavePersonHandler.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonRequest.java
diff --git a/aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java b/aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
similarity index 100%
rename from aws-lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
rename to aws-lambda/lambda/src/main/java/com/baeldung/lambda/dynamodb/bean/PersonResponse.java
diff --git a/aws-lambda/src/main/resources/logback.xml b/aws-lambda/lambda/src/main/resources/logback.xml
similarity index 100%
rename from aws-lambda/src/main/resources/logback.xml
rename to aws-lambda/lambda/src/main/resources/logback.xml
diff --git a/aws-lambda/pom.xml b/aws-lambda/pom.xml
index e1d2c7df27..116fc801aa 100644
--- a/aws-lambda/pom.xml
+++ b/aws-lambda/pom.xml
@@ -5,95 +5,19 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0aws-lambda
- 0.1.0-SNAPSHOTaws-lambda
- jar
+ pomcom.baeldungparent-modules1.0.0-SNAPSHOT
+ ../
-
-
- com.amazonaws
- aws-java-sdk-dynamodb
- ${aws-java-sdk.version}
-
-
- com.amazonaws
- aws-java-sdk-core
- ${aws-java-sdk.version}
-
-
- com.amazonaws
- aws-lambda-java-core
- ${aws-lambda-java-core.version}
-
-
- commons-logging
- commons-logging
-
-
-
-
- com.amazonaws
- aws-lambda-java-events
- ${aws-lambda-java-events.version}
-
-
- commons-logging
- commons-logging
-
-
-
-
- com.google.code.gson
- gson
- ${gson.version}
-
-
- commons-io
- commons-io
- ${commons-io.version}
-
-
- com.googlecode.json-simple
- json-simple
- ${json-simple.version}
-
-
+
+ lambda
+ shipping-tracker/ShippingFunction
+
-
-
-
- org.apache.maven.plugins
- maven-shade-plugin
- ${maven-shade-plugin.version}
-
- false
-
-
-
- package
-
- shade
-
-
-
-
-
-
-
-
- 1.1.1
- 2.5
- 1.3.0
- 1.2.0
- 2.8.2
- 1.11.241
- 3.0.0
-
-
-
\ No newline at end of file
+
diff --git a/aws-lambda/shipping-tracker/.gitignore b/aws-lambda/shipping-tracker/.gitignore
new file mode 100644
index 0000000000..9984c2e554
--- /dev/null
+++ b/aws-lambda/shipping-tracker/.gitignore
@@ -0,0 +1 @@
+.aws-sam/
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/pom.xml b/aws-lambda/shipping-tracker/ShippingFunction/pom.xml
new file mode 100644
index 0000000000..2c8224e6d5
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/pom.xml
@@ -0,0 +1,73 @@
+
+ 4.0.0
+ com.baeldung
+ ShippingFunction
+ 1.0
+ jar
+ ShippingFunction
+
+ 1.8
+ 1.8
+ 5.4.21.Final
+
+
+
+
+ com.amazonaws
+ aws-lambda-java-core
+ 1.2.0
+
+
+ com.amazonaws
+ aws-lambda-java-events
+ 3.1.0
+
+
+ com.fasterxml.jackson.core
+ jackson-databind
+ 2.11.2
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ org.hibernate
+ hibernate-core
+ ${hibernate.version}
+
+
+ org.hibernate
+ hibernate-hikaricp
+ ${hibernate.version}
+
+
+ org.postgresql
+ postgresql
+ 42.2.16
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-shade-plugin
+ 3.1.1
+
+
+
+
+ package
+
+ shade
+
+
+
+
+
+
+
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java
new file mode 100644
index 0000000000..95fd058667
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/App.java
@@ -0,0 +1,121 @@
+package com.baeldung.lambda.shipping;
+
+import com.amazonaws.services.lambda.runtime.Context;
+import com.amazonaws.services.lambda.runtime.RequestHandler;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
+import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.zaxxer.hikari.HikariDataSource;
+import org.hibernate.SessionFactory;
+import org.hibernate.boot.MetadataSources;
+import org.hibernate.boot.registry.StandardServiceRegistry;
+import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
+import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.hibernate.cfg.AvailableSettings.*;
+import static org.hibernate.cfg.AvailableSettings.PASS;
+
+/**
+ * Handler for requests to Lambda function.
+ */
+public class App implements RequestHandler {
+private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+ private SessionFactory sessionFactory = createSessionFactory();
+
+ public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
+ try {
+ ShippingService service = new ShippingService(sessionFactory, new ShippingDao());
+ return routeRequest(input, service);
+ } finally {
+ flushConnectionPool();
+ }
+ }
+
+ private APIGatewayProxyResponseEvent routeRequest(APIGatewayProxyRequestEvent input, ShippingService service) {
+ Map headers = new HashMap<>();
+ headers.put("Content-Type", "application/json");
+ headers.put("X-Custom-Header", "application/json");
+
+ Object result = "OK";
+
+ switch (input.getResource()) {
+ case "/consignment":
+ result = service.createConsignment(
+ fromJson(input.getBody(), Consignment.class));
+ break;
+ case "/consignment/{id}":
+ result = service.view(input.getPathParameters().get("id"));
+ break;
+ case "/consignment/{id}/item":
+ service.addItem(input.getPathParameters().get("id"),
+ fromJson(input.getBody(), Item.class));
+ break;
+ case "/consignment/{id}/checkin":
+ service.checkIn(input.getPathParameters().get("id"),
+ fromJson(input.getBody(), Checkin.class));
+ break;
+ }
+
+ return new APIGatewayProxyResponseEvent()
+ .withHeaders(headers)
+ .withStatusCode(200)
+ .withBody(toJson(result));
+ }
+
+ private static String toJson(T object) {
+ try {
+ return OBJECT_MAPPER.writeValueAsString(object);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static T fromJson(String json, Class type) {
+ try {
+ return OBJECT_MAPPER.readValue(json, type);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private static SessionFactory createSessionFactory() {
+ Map settings = new HashMap<>();
+ settings.put(URL, System.getenv("DB_URL"));
+ settings.put(DIALECT, "org.hibernate.dialect.PostgreSQLDialect");
+ settings.put(DEFAULT_SCHEMA, "shipping");
+ settings.put(DRIVER, "org.postgresql.Driver");
+ settings.put(USER, System.getenv("DB_USER"));
+ settings.put(PASS, System.getenv("DB_PASSWORD"));
+ settings.put("hibernate.hikari.connectionTimeout", "20000");
+ settings.put("hibernate.hikari.minimumIdle", "1");
+ settings.put("hibernate.hikari.maximumPoolSize", "2");
+ settings.put("hibernate.hikari.idleTimeout", "30000");
+
+// commented out as we only need them on first use
+// settings.put(HBM2DDL_AUTO, "create-only");
+// settings.put(HBM2DDL_DATABASE_ACTION, "create");
+
+ StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
+ .applySettings(settings)
+ .build();
+
+ return new MetadataSources(registry)
+ .addAnnotatedClass(Consignment.class)
+ .addAnnotatedClass(Item.class)
+ .addAnnotatedClass(Checkin.class)
+ .buildMetadata()
+ .buildSessionFactory();
+ }
+
+ private void flushConnectionPool() {
+ ConnectionProvider connectionProvider = sessionFactory.getSessionFactoryOptions()
+ .getServiceRegistry()
+ .getService(ConnectionProvider.class);
+ HikariDataSource hikariDataSource = connectionProvider.unwrap(HikariDataSource.class);
+ hikariDataSource.getHikariPoolMXBean().softEvictConnections();
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java
new file mode 100644
index 0000000000..93e6404749
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Checkin.java
@@ -0,0 +1,28 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Checkin {
+ private String timeStamp;
+ private String location;
+
+ @Column(name = "timestamp")
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+
+ @Column(name = "location")
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java
new file mode 100644
index 0000000000..1a2371b37f
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Consignment.java
@@ -0,0 +1,77 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.*;
+import java.util.ArrayList;
+import java.util.List;
+
+import static javax.persistence.FetchType.EAGER;
+
+@Entity(name = "consignment")
+@Table(name = "consignment")
+public class Consignment {
+ private String id;
+ private String source;
+ private String destination;
+ private boolean isDelivered;
+ private List items = new ArrayList<>();
+ private List checkins = new ArrayList<>();
+
+ @Id
+ @Column(name = "consignment_id")
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Column(name = "source")
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ @Column(name = "destination")
+ public String getDestination() {
+ return destination;
+ }
+
+ public void setDestination(String destination) {
+ this.destination = destination;
+ }
+
+ @Column(name = "delivered", columnDefinition = "boolean")
+ public boolean isDelivered() {
+ return isDelivered;
+ }
+
+ public void setDelivered(boolean delivered) {
+ isDelivered = delivered;
+ }
+
+ @ElementCollection(fetch = EAGER)
+ @CollectionTable(name = "consignment_item", joinColumns = @JoinColumn(name = "consignment_id"))
+ @OrderColumn(name = "item_index")
+ public List getItems() {
+ return items;
+ }
+
+ public void setItems(List items) {
+ this.items = items;
+ }
+
+ @ElementCollection(fetch = EAGER)
+ @CollectionTable(name = "consignment_checkin", joinColumns = @JoinColumn(name = "consignment_id"))
+ @OrderColumn(name = "checkin_index")
+ public List getCheckins() {
+ return checkins;
+ }
+
+ public void setCheckins(List checkins) {
+ this.checkins = checkins;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java
new file mode 100644
index 0000000000..de6194e180
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/Item.java
@@ -0,0 +1,38 @@
+package com.baeldung.lambda.shipping;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class Item {
+ private String location;
+ private String description;
+ private String timeStamp;
+
+ @Column(name = "location")
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ @Column(name = "description")
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ @Column(name = "timestamp")
+ public String getTimeStamp() {
+ return timeStamp;
+ }
+
+ public void setTimeStamp(String timeStamp) {
+ this.timeStamp = timeStamp;
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java
new file mode 100644
index 0000000000..369dc33935
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingDao.java
@@ -0,0 +1,25 @@
+package com.baeldung.lambda.shipping;
+
+import org.hibernate.Session;
+import org.hibernate.Transaction;
+
+import java.util.Optional;
+
+public class ShippingDao {
+ /**
+ * Save a consignment to the database
+ * @param consignment the consignment to save
+ */
+ public void save(Session session, Consignment consignment) {
+ Transaction transaction = session.beginTransaction();
+ session.save(consignment);
+ transaction.commit();
+ }
+
+ /**
+ * Find a consignment in the database by id
+ */
+ public Optional find(Session session, String id) {
+ return Optional.ofNullable(session.get(Consignment.class, id));
+ }
+}
diff --git a/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java
new file mode 100644
index 0000000000..4c951068ea
--- /dev/null
+++ b/aws-lambda/shipping-tracker/ShippingFunction/src/main/java/com/baeldung/lambda/shipping/ShippingService.java
@@ -0,0 +1,62 @@
+package com.baeldung.lambda.shipping;
+
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+
+import java.util.Comparator;
+import java.util.UUID;
+
+public class ShippingService {
+ private SessionFactory sessionFactory;
+ private ShippingDao shippingDao;
+
+ public ShippingService(SessionFactory sessionFactory, ShippingDao shippingDao) {
+ this.sessionFactory = sessionFactory;
+ this.shippingDao = shippingDao;
+ }
+
+ public String createConsignment(Consignment consignment) {
+ try (Session session = sessionFactory.openSession()) {
+ consignment.setDelivered(false);
+ consignment.setId(UUID.randomUUID().toString());
+ shippingDao.save(session, consignment);
+ return consignment.getId();
+ }
+ }
+
+ public void addItem(String consignmentId, Item item) {
+ try (Session session = sessionFactory.openSession()) {
+ shippingDao.find(session, consignmentId)
+ .ifPresent(consignment -> addItem(session, consignment, item));
+ }
+ }
+
+ private void addItem(Session session, Consignment consignment, Item item) {
+ consignment.getItems()
+ .add(item);
+ shippingDao.save(session, consignment);
+ }
+
+ public void checkIn(String consignmentId, Checkin checkin) {
+ try (Session session = sessionFactory.openSession()) {
+ shippingDao.find(session, consignmentId)
+ .ifPresent(consignment -> checkIn(session, consignment, checkin));
+ }
+ }
+
+ private void checkIn(Session session, Consignment consignment, Checkin checkin) {
+ consignment.getCheckins().add(checkin);
+ consignment.getCheckins().sort(Comparator.comparing(Checkin::getTimeStamp));
+ if (checkin.getLocation().equals(consignment.getDestination())) {
+ consignment.setDelivered(true);
+ }
+ shippingDao.save(session, consignment);
+ }
+
+ public Consignment view(String consignmentId) {
+ try (Session session = sessionFactory.openSession()) {
+ return shippingDao.find(session, consignmentId)
+ .orElseGet(Consignment::new);
+ }
+ }
+}
diff --git a/aws-lambda/shipping-tracker/template.yaml b/aws-lambda/shipping-tracker/template.yaml
new file mode 100644
index 0000000000..ec75c51ba1
--- /dev/null
+++ b/aws-lambda/shipping-tracker/template.yaml
@@ -0,0 +1,47 @@
+AWSTemplateFormatVersion: '2010-09-09'
+Transform: AWS::Serverless-2016-10-31
+Description: >
+ shipping-tracker
+
+ Sample SAM Template for shipping-tracker
+
+# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
+Globals:
+ Function:
+ Timeout: 20
+
+Resources:
+ ShippingFunction:
+ Type: AWS::Serverless::Function
+ Properties:
+ CodeUri: ShippingFunction
+ Handler: com.baeldung.lambda.shipping.App::handleRequest
+ Runtime: java8
+ MemorySize: 512
+ Environment:
+ Variables:
+ DB_URL: jdbc:postgresql://postgres/postgres
+ DB_USER: postgres
+ DB_PASSWORD: password
+ Events:
+ CreateConsignment:
+ Type: Api
+ Properties:
+ Path: /consignment
+ Method: post
+ AddItem:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}/item
+ Method: post
+ CheckIn:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}/checkin
+ Method: post
+ ViewConsignment:
+ Type: Api
+ Properties:
+ Path: /consignment/{id}
+ Method: get
+
diff --git a/aws-reactive/pom.xml b/aws-reactive/pom.xml
index d4f0e5e231..6224ccbb99 100644
--- a/aws-reactive/pom.xml
+++ b/aws-reactive/pom.xml
@@ -100,7 +100,6 @@
- 1.82.2.1.RELEASE2.10.27
diff --git a/axon/pom.xml b/axon/pom.xml
index f6c43c7cbd..f2cdc34fd1 100644
--- a/axon/pom.xml
+++ b/axon/pom.xml
@@ -53,7 +53,7 @@
- 4.1.2
+ 4.4.7
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/commandmodel/OrderAggregate.java b/axon/src/main/java/com/baeldung/axon/commandmodel/OrderAggregate.java
deleted file mode 100644
index 4ef02e6b54..0000000000
--- a/axon/src/main/java/com/baeldung/axon/commandmodel/OrderAggregate.java
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.baeldung.axon.commandmodel;
-
-import static org.axonframework.modelling.command.AggregateLifecycle.apply;
-
-import org.axonframework.commandhandling.CommandHandler;
-import org.axonframework.eventsourcing.EventSourcingHandler;
-import org.axonframework.modelling.command.AggregateIdentifier;
-import org.axonframework.spring.stereotype.Aggregate;
-
-import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
-import com.baeldung.axon.coreapi.commands.PlaceOrderCommand;
-import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
-import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
-import com.baeldung.axon.coreapi.events.OrderPlacedEvent;
-import com.baeldung.axon.coreapi.events.OrderShippedEvent;
-import com.baeldung.axon.coreapi.exceptions.UnconfirmedOrderException;
-
-@Aggregate
-public class OrderAggregate {
-
- @AggregateIdentifier
- private String orderId;
- private boolean orderConfirmed;
-
- @CommandHandler
- public OrderAggregate(PlaceOrderCommand command) {
- apply(new OrderPlacedEvent(command.getOrderId(), command.getProduct()));
- }
-
- @CommandHandler
- public void handle(ConfirmOrderCommand command) {
- apply(new OrderConfirmedEvent(orderId));
- }
-
- @CommandHandler
- public void handle(ShipOrderCommand command) {
- if (!orderConfirmed) {
- throw new UnconfirmedOrderException();
- }
-
- apply(new OrderShippedEvent(orderId));
- }
-
- @EventSourcingHandler
- public void on(OrderPlacedEvent event) {
- this.orderId = event.getOrderId();
- this.orderConfirmed = false;
- }
-
- @EventSourcingHandler
- public void on(OrderConfirmedEvent event) {
- this.orderConfirmed = true;
- }
-
- protected OrderAggregate() {
- // Required by Axon to build a default Aggregate prior to Event Sourcing
- }
-
-}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java
new file mode 100644
index 0000000000..97342bdb3a
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderAggregate.java
@@ -0,0 +1,98 @@
+package com.baeldung.axon.commandmodel.order;
+
+import com.baeldung.axon.coreapi.commands.AddProductCommand;
+import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
+import com.baeldung.axon.coreapi.commands.CreateOrderCommand;
+import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
+import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
+import com.baeldung.axon.coreapi.events.OrderCreatedEvent;
+import com.baeldung.axon.coreapi.events.OrderShippedEvent;
+import com.baeldung.axon.coreapi.events.ProductAddedEvent;
+import com.baeldung.axon.coreapi.events.ProductRemovedEvent;
+import com.baeldung.axon.coreapi.exceptions.DuplicateOrderLineException;
+import com.baeldung.axon.coreapi.exceptions.OrderAlreadyConfirmedException;
+import com.baeldung.axon.coreapi.exceptions.UnconfirmedOrderException;
+import org.axonframework.commandhandling.CommandHandler;
+import org.axonframework.eventsourcing.EventSourcingHandler;
+import org.axonframework.modelling.command.AggregateIdentifier;
+import org.axonframework.modelling.command.AggregateMember;
+import org.axonframework.spring.stereotype.Aggregate;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.axonframework.modelling.command.AggregateLifecycle.apply;
+
+@Aggregate
+public class OrderAggregate {
+
+ @AggregateIdentifier
+ private String orderId;
+ private boolean orderConfirmed;
+
+ @AggregateMember
+ private Map orderLines;
+
+ @CommandHandler
+ public OrderAggregate(CreateOrderCommand command) {
+ apply(new OrderCreatedEvent(command.getOrderId()));
+ }
+
+ @CommandHandler
+ public void handle(AddProductCommand command) {
+ if (orderConfirmed) {
+ throw new OrderAlreadyConfirmedException(orderId);
+ }
+
+ String productId = command.getProductId();
+ if (orderLines.containsKey(productId)) {
+ throw new DuplicateOrderLineException(productId);
+ }
+ apply(new ProductAddedEvent(orderId, productId));
+ }
+
+ @CommandHandler
+ public void handle(ConfirmOrderCommand command) {
+ if (orderConfirmed) {
+ return;
+ }
+
+ apply(new OrderConfirmedEvent(orderId));
+ }
+
+ @CommandHandler
+ public void handle(ShipOrderCommand command) {
+ if (!orderConfirmed) {
+ throw new UnconfirmedOrderException();
+ }
+
+ apply(new OrderShippedEvent(orderId));
+ }
+
+ @EventSourcingHandler
+ public void on(OrderCreatedEvent event) {
+ this.orderId = event.getOrderId();
+ this.orderConfirmed = false;
+ this.orderLines = new HashMap<>();
+ }
+
+ @EventSourcingHandler
+ public void on(OrderConfirmedEvent event) {
+ this.orderConfirmed = true;
+ }
+
+ @EventSourcingHandler
+ public void on(ProductAddedEvent event) {
+ String productId = event.getProductId();
+ this.orderLines.put(productId, new OrderLine(productId));
+ }
+
+ @EventSourcingHandler
+ public void on(ProductRemovedEvent event) {
+ this.orderLines.remove(event.getProductId());
+ }
+
+ protected OrderAggregate() {
+ // Required by Axon to build a default Aggregate prior to Event Sourcing
+ }
+}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderLine.java b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderLine.java
new file mode 100644
index 0000000000..e471ecbfe0
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/commandmodel/order/OrderLine.java
@@ -0,0 +1,83 @@
+package com.baeldung.axon.commandmodel.order;
+
+import com.baeldung.axon.coreapi.commands.DecrementProductCountCommand;
+import com.baeldung.axon.coreapi.commands.IncrementProductCountCommand;
+import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountIncrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductRemovedEvent;
+import com.baeldung.axon.coreapi.exceptions.OrderAlreadyConfirmedException;
+import org.axonframework.commandhandling.CommandHandler;
+import org.axonframework.eventsourcing.EventSourcingHandler;
+import org.axonframework.modelling.command.EntityId;
+
+import java.util.Objects;
+
+import static org.axonframework.modelling.command.AggregateLifecycle.apply;
+
+public class OrderLine {
+
+ @EntityId
+ private final String productId;
+ private Integer count;
+ private boolean orderConfirmed;
+
+ public OrderLine(String productId) {
+ this.productId = productId;
+ this.count = 1;
+ }
+
+ @CommandHandler
+ public void handle(IncrementProductCountCommand command) {
+ if (orderConfirmed) {
+ throw new OrderAlreadyConfirmedException(command.getOrderId());
+ }
+
+ apply(new ProductCountIncrementedEvent(command.getOrderId(), productId));
+ }
+
+ @CommandHandler
+ public void handle(DecrementProductCountCommand command) {
+ if (orderConfirmed) {
+ throw new OrderAlreadyConfirmedException(command.getOrderId());
+ }
+
+ if (count <= 1) {
+ apply(new ProductRemovedEvent(command.getOrderId(), productId));
+ } else {
+ apply(new ProductCountDecrementedEvent(command.getOrderId(), productId));
+ }
+ }
+
+ @EventSourcingHandler
+ public void on(ProductCountIncrementedEvent event) {
+ this.count++;
+ }
+
+ @EventSourcingHandler
+ public void on(ProductCountDecrementedEvent event) {
+ this.count--;
+ }
+
+ @EventSourcingHandler
+ public void on(OrderConfirmedEvent event) {
+ this.orderConfirmed = true;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ OrderLine orderLine = (OrderLine) o;
+ return Objects.equals(productId, orderLine.productId) && Objects.equals(count, orderLine.count);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(productId, count);
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/AddProductCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/AddProductCommand.java
new file mode 100644
index 0000000000..28736aaadc
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/commands/AddProductCommand.java
@@ -0,0 +1,50 @@
+package com.baeldung.axon.coreapi.commands;
+
+import org.axonframework.modelling.command.TargetAggregateIdentifier;
+
+import java.util.Objects;
+
+public class AddProductCommand {
+
+ @TargetAggregateIdentifier
+ private final String orderId;
+ private final String productId;
+
+ public AddProductCommand(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ AddProductCommand that = (AddProductCommand) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "AddProductCommand{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java
new file mode 100644
index 0000000000..ceb7fd6a08
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/commands/CreateOrderCommand.java
@@ -0,0 +1,43 @@
+package com.baeldung.axon.coreapi.commands;
+
+import org.axonframework.modelling.command.TargetAggregateIdentifier;
+
+import java.util.Objects;
+
+public class CreateOrderCommand {
+
+ @TargetAggregateIdentifier
+ private final String orderId;
+
+ public CreateOrderCommand(String orderId) {
+ this.orderId = orderId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ CreateOrderCommand that = (CreateOrderCommand) o;
+ return Objects.equals(orderId, that.orderId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId);
+ }
+
+ @Override
+ public String toString() {
+ return "CreateOrderCommand{" +
+ "orderId='" + orderId + '\'' +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/DecrementProductCountCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/DecrementProductCountCommand.java
new file mode 100644
index 0000000000..f6f4db00fc
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/commands/DecrementProductCountCommand.java
@@ -0,0 +1,50 @@
+package com.baeldung.axon.coreapi.commands;
+
+import org.axonframework.modelling.command.TargetAggregateIdentifier;
+
+import java.util.Objects;
+
+public class DecrementProductCountCommand {
+
+ @TargetAggregateIdentifier
+ private final String orderId;
+ private final String productId;
+
+ public DecrementProductCountCommand(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ DecrementProductCountCommand that = (DecrementProductCountCommand) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "DecrementProductCountCommand{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/IncrementProductCountCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/IncrementProductCountCommand.java
new file mode 100644
index 0000000000..548faabe37
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/commands/IncrementProductCountCommand.java
@@ -0,0 +1,50 @@
+package com.baeldung.axon.coreapi.commands;
+
+import org.axonframework.modelling.command.TargetAggregateIdentifier;
+
+import java.util.Objects;
+
+public class IncrementProductCountCommand {
+
+ @TargetAggregateIdentifier
+ private final String orderId;
+ private final String productId;
+
+ public IncrementProductCountCommand(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ IncrementProductCountCommand that = (IncrementProductCountCommand) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "IncrementProductCountCommand{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java b/axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java
deleted file mode 100644
index c70d503050..0000000000
--- a/axon/src/main/java/com/baeldung/axon/coreapi/commands/PlaceOrderCommand.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.baeldung.axon.coreapi.commands;
-
-import java.util.Objects;
-
-import org.axonframework.modelling.command.TargetAggregateIdentifier;
-
-public class PlaceOrderCommand {
-
- @TargetAggregateIdentifier
- private final String orderId;
- private final String product;
-
- public PlaceOrderCommand(String orderId, String product) {
- this.orderId = orderId;
- this.product = product;
- }
-
- public String getOrderId() {
- return orderId;
- }
-
- public String getProduct() {
- return product;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(orderId, product);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- final PlaceOrderCommand other = (PlaceOrderCommand) obj;
- return Objects.equals(this.orderId, other.orderId)
- && Objects.equals(this.product, other.product);
- }
-
- @Override
- public String toString() {
- return "PlaceOrderCommand{" +
- "orderId='" + orderId + '\'' +
- ", product='" + product + '\'' +
- '}';
- }
-}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java
new file mode 100644
index 0000000000..5d2d8b7f55
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderCreatedEvent.java
@@ -0,0 +1,40 @@
+package com.baeldung.axon.coreapi.events;
+
+import java.util.Objects;
+
+public class OrderCreatedEvent {
+
+ private final String orderId;
+
+ public OrderCreatedEvent(String orderId) {
+ this.orderId = orderId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ OrderCreatedEvent that = (OrderCreatedEvent) o;
+ return Objects.equals(orderId, that.orderId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId);
+ }
+
+ @Override
+ public String toString() {
+ return "OrderCreatedEvent{" +
+ "orderId='" + orderId + '\'' +
+ '}';
+ }
+}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java
deleted file mode 100644
index 06de4c5f9f..0000000000
--- a/axon/src/main/java/com/baeldung/axon/coreapi/events/OrderPlacedEvent.java
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.axon.coreapi.events;
-
-import java.util.Objects;
-
-public class OrderPlacedEvent {
-
- private final String orderId;
- private final String product;
-
- public OrderPlacedEvent(String orderId, String product) {
- this.orderId = orderId;
- this.product = product;
- }
-
- public String getOrderId() {
- return orderId;
- }
-
- public String getProduct() {
- return product;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(orderId, product);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- final OrderPlacedEvent other = (OrderPlacedEvent) obj;
- return Objects.equals(this.orderId, other.orderId)
- && Objects.equals(this.product, other.product);
- }
-
- @Override
- public String toString() {
- return "OrderPlacedEvent{" +
- "orderId='" + orderId + '\'' +
- ", product='" + product + '\'' +
- '}';
- }
-}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductAddedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductAddedEvent.java
new file mode 100644
index 0000000000..091ef2a570
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductAddedEvent.java
@@ -0,0 +1,47 @@
+package com.baeldung.axon.coreapi.events;
+
+import java.util.Objects;
+
+public class ProductAddedEvent {
+
+ private final String orderId;
+ private final String productId;
+
+ public ProductAddedEvent(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProductAddedEvent that = (ProductAddedEvent) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "ProductAddedEvent{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountDecrementedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountDecrementedEvent.java
new file mode 100644
index 0000000000..4017916791
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountDecrementedEvent.java
@@ -0,0 +1,47 @@
+package com.baeldung.axon.coreapi.events;
+
+import java.util.Objects;
+
+public class ProductCountDecrementedEvent {
+
+ private final String orderId;
+ private final String productId;
+
+ public ProductCountDecrementedEvent(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProductCountDecrementedEvent that = (ProductCountDecrementedEvent) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "ProductCountDecrementedEvent{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountIncrementedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountIncrementedEvent.java
new file mode 100644
index 0000000000..2910a9ea6f
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductCountIncrementedEvent.java
@@ -0,0 +1,47 @@
+package com.baeldung.axon.coreapi.events;
+
+import java.util.Objects;
+
+public class ProductCountIncrementedEvent {
+
+ private final String orderId;
+ private final String productId;
+
+ public ProductCountIncrementedEvent(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProductCountIncrementedEvent that = (ProductCountIncrementedEvent) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "ProductCountIncrementedEvent{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductRemovedEvent.java b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductRemovedEvent.java
new file mode 100644
index 0000000000..7f89ccd1cc
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/events/ProductRemovedEvent.java
@@ -0,0 +1,47 @@
+package com.baeldung.axon.coreapi.events;
+
+import java.util.Objects;
+
+public class ProductRemovedEvent {
+
+ private final String orderId;
+ private final String productId;
+
+ public ProductRemovedEvent(String orderId, String productId) {
+ this.orderId = orderId;
+ this.productId = productId;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public String getProductId() {
+ return productId;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ ProductRemovedEvent that = (ProductRemovedEvent) o;
+ return Objects.equals(orderId, that.orderId) && Objects.equals(productId, that.productId);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, productId);
+ }
+
+ @Override
+ public String toString() {
+ return "ProductRemovedEvent{" +
+ "orderId='" + orderId + '\'' +
+ ", productId='" + productId + '\'' +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/DuplicateOrderLineException.java b/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/DuplicateOrderLineException.java
new file mode 100644
index 0000000000..c8a62a6cf0
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/DuplicateOrderLineException.java
@@ -0,0 +1,8 @@
+package com.baeldung.axon.coreapi.exceptions;
+
+public class DuplicateOrderLineException extends IllegalStateException {
+
+ public DuplicateOrderLineException(String productId) {
+ super("Cannot duplicate order line for product identifier [" + productId + "]");
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/OrderAlreadyConfirmedException.java b/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/OrderAlreadyConfirmedException.java
new file mode 100644
index 0000000000..5a4d1cdaec
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/exceptions/OrderAlreadyConfirmedException.java
@@ -0,0 +1,8 @@
+package com.baeldung.axon.coreapi.exceptions;
+
+public class OrderAlreadyConfirmedException extends IllegalStateException {
+
+ public OrderAlreadyConfirmedException(String orderId) {
+ super("Cannot perform operation because order [" + orderId + "] is already confirmed.");
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java b/axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java
new file mode 100644
index 0000000000..1810a053d3
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/queries/Order.java
@@ -0,0 +1,83 @@
+package com.baeldung.axon.coreapi.queries;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+
+public class Order {
+
+ private final String orderId;
+ private final Map products;
+ private OrderStatus orderStatus;
+
+ public Order(String orderId) {
+ this.orderId = orderId;
+ this.products = new HashMap<>();
+ orderStatus = OrderStatus.CREATED;
+ }
+
+ public String getOrderId() {
+ return orderId;
+ }
+
+ public Map getProducts() {
+ return products;
+ }
+
+ public OrderStatus getOrderStatus() {
+ return orderStatus;
+ }
+
+ public void addProduct(String productId) {
+ products.putIfAbsent(productId, 1);
+ }
+
+ public void incrementProductInstance(String productId) {
+ products.computeIfPresent(productId, (id, count) -> ++count);
+ }
+
+ public void decrementProductInstance(String productId) {
+ products.computeIfPresent(productId, (id, count) -> --count);
+ }
+
+
+ public void removeProduct(String productId) {
+ products.remove(productId);
+ }
+
+ public void setOrderConfirmed() {
+ this.orderStatus = OrderStatus.CONFIRMED;
+ }
+
+ public void setOrderShipped() {
+ this.orderStatus = OrderStatus.SHIPPED;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ Order that = (Order) o;
+ return Objects.equals(orderId, that.orderId)
+ && Objects.equals(products, that.products)
+ && orderStatus == that.orderStatus;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(orderId, products, orderStatus);
+ }
+
+ @Override
+ public String toString() {
+ return "Order{" +
+ "orderId='" + orderId + '\'' +
+ ", products=" + products +
+ ", orderStatus=" + orderStatus +
+ '}';
+ }
+}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java b/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java
index d215c5fc32..fc5da5d77e 100644
--- a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java
+++ b/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderStatus.java
@@ -2,6 +2,5 @@ package com.baeldung.axon.coreapi.queries;
public enum OrderStatus {
- PLACED, CONFIRMED, SHIPPED
-
+ CREATED, CONFIRMED, SHIPPED
}
diff --git a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java b/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java
deleted file mode 100644
index d847bb2a98..0000000000
--- a/axon/src/main/java/com/baeldung/axon/coreapi/queries/OrderedProduct.java
+++ /dev/null
@@ -1,64 +0,0 @@
-package com.baeldung.axon.coreapi.queries;
-
-import java.util.Objects;
-
-public class OrderedProduct {
-
- private final String orderId;
- private final String product;
- private OrderStatus orderStatus;
-
- public OrderedProduct(String orderId, String product) {
- this.orderId = orderId;
- this.product = product;
- orderStatus = OrderStatus.PLACED;
- }
-
- public String getOrderId() {
- return orderId;
- }
-
- public String getProduct() {
- return product;
- }
-
- public OrderStatus getOrderStatus() {
- return orderStatus;
- }
-
- public void setOrderConfirmed() {
- this.orderStatus = OrderStatus.CONFIRMED;
- }
-
- public void setOrderShipped() {
- this.orderStatus = OrderStatus.SHIPPED;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(orderId, product, orderStatus);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null || getClass() != obj.getClass()) {
- return false;
- }
- final OrderedProduct other = (OrderedProduct) obj;
- return Objects.equals(this.orderId, other.orderId)
- && Objects.equals(this.product, other.product)
- && Objects.equals(this.orderStatus, other.orderStatus);
- }
-
- @Override
- public String toString() {
- return "OrderedProduct{" +
- "orderId='" + orderId + '\'' +
- ", product='" + product + '\'' +
- ", orderStatus=" + orderStatus +
- '}';
- }
-}
diff --git a/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java b/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java
index a9f34cc691..11e03bf6a5 100644
--- a/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java
+++ b/axon/src/main/java/com/baeldung/axon/gui/OrderRestEndpoint.java
@@ -1,20 +1,24 @@
package com.baeldung.axon.gui;
-import java.util.List;
-import java.util.UUID;
-
+import com.baeldung.axon.coreapi.commands.AddProductCommand;
+import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
+import com.baeldung.axon.coreapi.commands.CreateOrderCommand;
+import com.baeldung.axon.coreapi.commands.DecrementProductCountCommand;
+import com.baeldung.axon.coreapi.commands.IncrementProductCountCommand;
+import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
+import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery;
+import com.baeldung.axon.coreapi.queries.Order;
import org.axonframework.commandhandling.gateway.CommandGateway;
import org.axonframework.messaging.responsetypes.ResponseTypes;
import org.axonframework.queryhandling.QueryGateway;
import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
-import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
-import com.baeldung.axon.coreapi.commands.PlaceOrderCommand;
-import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
-import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery;
-import com.baeldung.axon.coreapi.queries.OrderedProduct;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
@RestController
public class OrderRestEndpoint {
@@ -28,25 +32,63 @@ public class OrderRestEndpoint {
}
@PostMapping("/ship-order")
- public void shipOrder() {
+ public CompletableFuture shipOrder() {
String orderId = UUID.randomUUID().toString();
- commandGateway.send(new PlaceOrderCommand(orderId, "Deluxe Chair"));
- commandGateway.send(new ConfirmOrderCommand(orderId));
- commandGateway.send(new ShipOrderCommand(orderId));
+ return commandGateway.send(new CreateOrderCommand(orderId))
+ .thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
+ .thenCompose(result -> commandGateway.send(new ConfirmOrderCommand(orderId)))
+ .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
}
@PostMapping("/ship-unconfirmed-order")
- public void shipUnconfirmedOrder() {
+ public CompletableFuture shipUnconfirmedOrder() {
String orderId = UUID.randomUUID().toString();
- commandGateway.send(new PlaceOrderCommand(orderId, "Deluxe Chair"));
- // This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
- commandGateway.send(new ShipOrderCommand(orderId));
+ return commandGateway.send(new CreateOrderCommand(orderId))
+ .thenCompose(result -> commandGateway.send(new AddProductCommand(orderId, "Deluxe Chair")))
+ // This throws an exception, as an Order cannot be shipped if it has not been confirmed yet.
+ .thenCompose(result -> commandGateway.send(new ShipOrderCommand(orderId)));
+ }
+
+ @PostMapping("/order")
+ public CompletableFuture createOrder() {
+ return createOrder(UUID.randomUUID().toString());
+ }
+
+ @PostMapping("/order/{order-id}")
+ public CompletableFuture createOrder(@PathVariable("order-id") String orderId) {
+ return commandGateway.send(new CreateOrderCommand(orderId));
+ }
+
+ @PostMapping("/order/{order-id}/product/{product-id}")
+ public CompletableFuture addProduct(@PathVariable("order-id") String orderId,
+ @PathVariable("product-id") String productId) {
+ return commandGateway.send(new AddProductCommand(orderId, productId));
+ }
+
+ @PostMapping("/order/{order-id}/product/{product-id}/increment")
+ public CompletableFuture incrementProduct(@PathVariable("order-id") String orderId,
+ @PathVariable("product-id") String productId) {
+ return commandGateway.send(new IncrementProductCountCommand(orderId, productId));
+ }
+
+ @PostMapping("/order/{order-id}/product/{product-id}/decrement")
+ public CompletableFuture decrementProduct(@PathVariable("order-id") String orderId,
+ @PathVariable("product-id") String productId) {
+ return commandGateway.send(new DecrementProductCountCommand(orderId, productId));
+ }
+
+ @PostMapping("/order/{order-id}/confirm")
+ public CompletableFuture confirmOrder(@PathVariable("order-id") String orderId) {
+ return commandGateway.send(new ConfirmOrderCommand(orderId));
+ }
+
+ @PostMapping("/order/{order-id}/ship")
+ public CompletableFuture shipOrder(@PathVariable("order-id") String orderId) {
+ return commandGateway.send(new ShipOrderCommand(orderId));
}
@GetMapping("/all-orders")
- public List findAllOrderedProducts() {
- return queryGateway.query(new FindAllOrderedProductsQuery(), ResponseTypes.multipleInstancesOf(OrderedProduct.class))
- .join();
+ public CompletableFuture> findAllOrders() {
+ return queryGateway.query(new FindAllOrderedProductsQuery(), ResponseTypes.multipleInstancesOf(Order.class));
}
-
}
diff --git a/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java b/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java
deleted file mode 100644
index a37f0111ed..0000000000
--- a/axon/src/main/java/com/baeldung/axon/querymodel/OrderedProductsEventHandler.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.baeldung.axon.querymodel;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.axonframework.config.ProcessingGroup;
-import org.axonframework.eventhandling.EventHandler;
-import org.axonframework.queryhandling.QueryHandler;
-import org.springframework.stereotype.Service;
-
-import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
-import com.baeldung.axon.coreapi.events.OrderPlacedEvent;
-import com.baeldung.axon.coreapi.events.OrderShippedEvent;
-import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery;
-import com.baeldung.axon.coreapi.queries.OrderedProduct;
-
-@Service
-@ProcessingGroup("ordered-products")
-public class OrderedProductsEventHandler {
-
- private final Map orderedProducts = new HashMap<>();
-
- @EventHandler
- public void on(OrderPlacedEvent event) {
- String orderId = event.getOrderId();
- orderedProducts.put(orderId, new OrderedProduct(orderId, event.getProduct()));
- }
-
- @EventHandler
- public void on(OrderConfirmedEvent event) {
- orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {
- orderedProduct.setOrderConfirmed();
- return orderedProduct;
- });
- }
-
- @EventHandler
- public void on(OrderShippedEvent event) {
- orderedProducts.computeIfPresent(event.getOrderId(), (orderId, orderedProduct) -> {
- orderedProduct.setOrderShipped();
- return orderedProduct;
- });
- }
-
- @QueryHandler
- public List handle(FindAllOrderedProductsQuery query) {
- return new ArrayList<>(orderedProducts.values());
- }
-
-}
\ No newline at end of file
diff --git a/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java b/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java
new file mode 100644
index 0000000000..25666b0bf3
--- /dev/null
+++ b/axon/src/main/java/com/baeldung/axon/querymodel/OrdersEventHandler.java
@@ -0,0 +1,86 @@
+package com.baeldung.axon.querymodel;
+
+import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
+import com.baeldung.axon.coreapi.events.OrderCreatedEvent;
+import com.baeldung.axon.coreapi.events.OrderShippedEvent;
+import com.baeldung.axon.coreapi.events.ProductAddedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountIncrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductRemovedEvent;
+import com.baeldung.axon.coreapi.queries.FindAllOrderedProductsQuery;
+import com.baeldung.axon.coreapi.queries.Order;
+import org.axonframework.config.ProcessingGroup;
+import org.axonframework.eventhandling.EventHandler;
+import org.axonframework.queryhandling.QueryHandler;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Service
+@ProcessingGroup("orders")
+public class OrdersEventHandler {
+
+ private final Map orders = new HashMap<>();
+
+ @EventHandler
+ public void on(OrderCreatedEvent event) {
+ String orderId = event.getOrderId();
+ orders.put(orderId, new Order(orderId));
+ }
+
+ @EventHandler
+ public void on(ProductAddedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.addProduct(event.getProductId());
+ return order;
+ });
+ }
+
+ @EventHandler
+ public void on(ProductCountIncrementedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.incrementProductInstance(event.getProductId());
+ return order;
+ });
+ }
+
+ @EventHandler
+ public void on(ProductCountDecrementedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.decrementProductInstance(event.getProductId());
+ return order;
+ });
+ }
+
+ @EventHandler
+ public void on(ProductRemovedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.removeProduct(event.getProductId());
+ return order;
+ });
+ }
+
+ @EventHandler
+ public void on(OrderConfirmedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.setOrderConfirmed();
+ return order;
+ });
+ }
+
+ @EventHandler
+ public void on(OrderShippedEvent event) {
+ orders.computeIfPresent(event.getOrderId(), (orderId, order) -> {
+ order.setOrderShipped();
+ return order;
+ });
+ }
+
+ @QueryHandler
+ public List handle(FindAllOrderedProductsQuery query) {
+ return new ArrayList<>(orders.values());
+ }
+}
\ No newline at end of file
diff --git a/axon/src/main/resources/order-api.http b/axon/src/main/resources/order-api.http
index a3c69c72bc..6c06c48989 100644
--- a/axon/src/main/resources/order-api.http
+++ b/axon/src/main/resources/order-api.http
@@ -1,11 +1,37 @@
+### Create Order, Add Product, Confirm and Ship Order
+
POST http://localhost:8080/ship-order
-###
+### Create Order, Add Product and Ship Order
POST http://localhost:8080/ship-unconfirmed-order
-###
+### Retrieve all existing Orders
GET http://localhost:8080/all-orders
+### Create Order with id 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768
+
+### Add Product a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3 to Order 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768/product/a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3
+
+### Increment Product a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3 to Order 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768/product/a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3/increment
+
+### Decrement Product a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3 to Order 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768/product/a6aa01eb-4e38-4dfb-b53b-b5b82961fbf3/decrement
+
+### Confirm Order 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768/confirm
+
+### Ship Order 666a1661-474d-4046-8b12-8b5896312768
+
+POST http://localhost:8080/order/666a1661-474d-4046-8b12-8b5896312768/ship
+
###
diff --git a/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java b/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java
index aaefe49fb1..c1d6bdccc2 100644
--- a/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java
+++ b/axon/src/test/java/com/baeldung/axon/commandmodel/OrderAggregateUnitTest.java
@@ -1,62 +1,139 @@
package com.baeldung.axon.commandmodel;
-import java.util.UUID;
-
+import com.baeldung.axon.commandmodel.order.OrderAggregate;
+import com.baeldung.axon.coreapi.commands.AddProductCommand;
+import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
+import com.baeldung.axon.coreapi.commands.CreateOrderCommand;
+import com.baeldung.axon.coreapi.commands.DecrementProductCountCommand;
+import com.baeldung.axon.coreapi.commands.IncrementProductCountCommand;
+import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
+import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
+import com.baeldung.axon.coreapi.events.OrderCreatedEvent;
+import com.baeldung.axon.coreapi.events.OrderShippedEvent;
+import com.baeldung.axon.coreapi.events.ProductAddedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountDecrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductCountIncrementedEvent;
+import com.baeldung.axon.coreapi.events.ProductRemovedEvent;
+import com.baeldung.axon.coreapi.exceptions.DuplicateOrderLineException;
+import com.baeldung.axon.coreapi.exceptions.OrderAlreadyConfirmedException;
import com.baeldung.axon.coreapi.exceptions.UnconfirmedOrderException;
import org.axonframework.test.aggregate.AggregateTestFixture;
import org.axonframework.test.aggregate.FixtureConfiguration;
-import org.junit.*;
+import org.axonframework.test.matchers.Matchers;
+import org.junit.jupiter.api.*;
-import com.baeldung.axon.coreapi.commands.ConfirmOrderCommand;
-import com.baeldung.axon.coreapi.commands.PlaceOrderCommand;
-import com.baeldung.axon.coreapi.commands.ShipOrderCommand;
-import com.baeldung.axon.coreapi.events.OrderConfirmedEvent;
-import com.baeldung.axon.coreapi.events.OrderPlacedEvent;
-import com.baeldung.axon.coreapi.events.OrderShippedEvent;
+import java.util.UUID;
-public class OrderAggregateUnitTest {
+class OrderAggregateUnitTest {
+
+ private static final String ORDER_ID = UUID.randomUUID().toString();
+ private static final String PRODUCT_ID = UUID.randomUUID().toString();
private FixtureConfiguration fixture;
- @Before
- public void setUp() {
+ @BeforeEach
+ void setUp() {
fixture = new AggregateTestFixture<>(OrderAggregate.class);
}
@Test
- public void giveNoPriorActivity_whenPlaceOrderCommand_thenShouldPublishOrderPlacedEvent() {
- String orderId = UUID.randomUUID().toString();
- String product = "Deluxe Chair";
+ void giveNoPriorActivity_whenCreateOrderCommand_thenShouldPublishOrderCreatedEvent() {
fixture.givenNoPriorActivity()
- .when(new PlaceOrderCommand(orderId, product))
- .expectEvents(new OrderPlacedEvent(orderId, product));
+ .when(new CreateOrderCommand(ORDER_ID))
+ .expectEvents(new OrderCreatedEvent(ORDER_ID));
}
@Test
- public void givenOrderPlacedEvent_whenConfirmOrderCommand_thenShouldPublishOrderConfirmedEvent() {
- String orderId = UUID.randomUUID().toString();
- String product = "Deluxe Chair";
- fixture.given(new OrderPlacedEvent(orderId, product))
- .when(new ConfirmOrderCommand(orderId))
- .expectEvents(new OrderConfirmedEvent(orderId));
+ void givenOrderCreatedEvent_whenAddProductCommand_thenShouldPublishProductAddedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID))
+ .when(new AddProductCommand(ORDER_ID, PRODUCT_ID))
+ .expectEvents(new ProductAddedEvent(ORDER_ID, PRODUCT_ID));
}
@Test
- public void givenOrderPlacedEvent_whenShipOrderCommand_thenShouldThrowUnconfirmedOrderException() {
- String orderId = UUID.randomUUID().toString();
- String product = "Deluxe Chair";
- fixture.given(new OrderPlacedEvent(orderId, product))
- .when(new ShipOrderCommand(orderId))
+ void givenOrderCreatedEventAndProductAddedEvent_whenAddProductCommandForSameProductId_thenShouldThrowDuplicateOrderLineException() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID))
+ .when(new AddProductCommand(ORDER_ID, PRODUCT_ID))
+ .expectException(DuplicateOrderLineException.class)
+ .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(PRODUCT_ID)));
+ }
+
+ @Test
+ void givenOrderCreatedEventAndProductAddedEvent_whenIncrementProductCountCommand_thenShouldPublishProductCountIncrementedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID))
+ .when(new IncrementProductCountCommand(ORDER_ID, PRODUCT_ID))
+ .expectEvents(new ProductCountIncrementedEvent(ORDER_ID, PRODUCT_ID));
+ }
+
+ @Test
+ void givenOrderCreatedEventProductAddedEventAndProductCountIncrementedEvent_whenDecrementProductCountCommand_thenShouldPublishProductCountDecrementedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID),
+ new ProductAddedEvent(ORDER_ID, PRODUCT_ID),
+ new ProductCountIncrementedEvent(ORDER_ID, PRODUCT_ID))
+ .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID))
+ .expectEvents(new ProductCountDecrementedEvent(ORDER_ID, PRODUCT_ID));
+ }
+
+ @Test
+ void givenOrderCreatedEventAndProductAddedEvent_whenDecrementProductCountCommand_thenShouldPublishProductRemovedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new ProductAddedEvent(ORDER_ID, PRODUCT_ID))
+ .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID))
+ .expectEvents(new ProductRemovedEvent(ORDER_ID, PRODUCT_ID));
+ }
+
+ @Test
+ void givenOrderCreatedEvent_whenConfirmOrderCommand_thenShouldPublishOrderConfirmedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID))
+ .when(new ConfirmOrderCommand(ORDER_ID))
+ .expectEvents(new OrderConfirmedEvent(ORDER_ID));
+ }
+
+ @Test
+ void givenOrderCreatedEventAndOrderConfirmedEvent_whenConfirmOrderCommand_thenExpectNoEvents() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID))
+ .when(new ConfirmOrderCommand(ORDER_ID))
+ .expectNoEvents();
+ }
+
+ @Test
+ void givenOrderCreatedEvent_whenShipOrderCommand_thenShouldThrowUnconfirmedOrderException() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID))
+ .when(new ShipOrderCommand(ORDER_ID))
.expectException(UnconfirmedOrderException.class);
}
@Test
- public void givenOrderPlacedEventAndOrderConfirmedEvent_whenShipOrderCommand_thenShouldPublishOrderShippedEvent() {
- String orderId = UUID.randomUUID().toString();
- String product = "Deluxe Chair";
- fixture.given(new OrderPlacedEvent(orderId, product), new OrderConfirmedEvent(orderId))
- .when(new ShipOrderCommand(orderId))
- .expectEvents(new OrderShippedEvent(orderId));
+ void givenOrderCreatedEventAndOrderConfirmedEvent_whenShipOrderCommand_thenShouldPublishOrderShippedEvent() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID))
+ .when(new ShipOrderCommand(ORDER_ID))
+ .expectEvents(new OrderShippedEvent(ORDER_ID));
}
+ @Test
+ void givenOrderCreatedEventProductAndOrderConfirmedEvent_whenAddProductCommand_thenShouldThrowOrderAlreadyConfirmedException() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID), new OrderConfirmedEvent(ORDER_ID))
+ .when(new AddProductCommand(ORDER_ID, PRODUCT_ID))
+ .expectException(OrderAlreadyConfirmedException.class)
+ .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(ORDER_ID)));
+ }
+
+ @Test
+ void givenOrderCreatedEventProductAddedEventAndOrderConfirmedEvent_whenIncrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID),
+ new ProductAddedEvent(ORDER_ID, PRODUCT_ID),
+ new OrderConfirmedEvent(ORDER_ID))
+ .when(new IncrementProductCountCommand(ORDER_ID, PRODUCT_ID))
+ .expectException(OrderAlreadyConfirmedException.class)
+ .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(ORDER_ID)));
+ }
+
+ @Test
+ void givenOrderCreatedEventProductAddedEventAndOrderConfirmedEvent_whenDecrementProductCountCommand_thenShouldThrowOrderAlreadyConfirmedException() {
+ fixture.given(new OrderCreatedEvent(ORDER_ID),
+ new ProductAddedEvent(ORDER_ID, PRODUCT_ID),
+ new OrderConfirmedEvent(ORDER_ID))
+ .when(new DecrementProductCountCommand(ORDER_ID, PRODUCT_ID))
+ .expectException(OrderAlreadyConfirmedException.class)
+ .expectExceptionMessage(Matchers.predicate(message -> ((String) message).contains(ORDER_ID)));
+ }
}
\ No newline at end of file
diff --git a/blade/pom.xml b/blade/pom.xml
index 178d1afb52..458ec40051 100644
--- a/blade/pom.xml
+++ b/blade/pom.xml
@@ -154,7 +154,6 @@
2.0.14.RELEASE4.2.1
- 3.8.11.18.44.5.64.5.6
diff --git a/cdi/pom.xml b/cdi/pom.xml
index fec12a9b16..226ca529e1 100644
--- a/cdi/pom.xml
+++ b/cdi/pom.xml
@@ -1,8 +1,8 @@
+ 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">
4.0.0cdi1.0-SNAPSHOT
@@ -10,9 +10,9 @@
com.baeldung
- parent-spring-4
+ parent-spring-50.0.1-SNAPSHOT
- ../parent-spring-4
+ ../parent-spring-5
@@ -26,28 +26,22 @@
weld-se-core${weld-se-core.version}
-
- org.hamcrest
- hamcrest
- ${hamcrest.version}
- test
- org.assertjassertj-core${assertj-core.version}test
-
- org.springframework
- spring-context
- ${spring.version}
- org.aspectjaspectjweaver${aspectjweaver.version}
+
+ org.springframework
+ spring-context
+ ${spring.version}
+ org.springframeworkspring-test
@@ -61,7 +55,6 @@
3.0.5.Final1.9.23.10.0
- 5.1.2.RELEASE
diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml
index b1bfa19771..207c090615 100644
--- a/core-groovy-2/pom.xml
+++ b/core-groovy-2/pom.xml
@@ -115,7 +115,6 @@
maven-surefire-plugin
- ${surefire.plugin.version}false
@@ -186,7 +185,6 @@
1.2.32.5.73.1.0
- 2.20.13.8.03.3.0-01
diff --git a/core-groovy-collections/pom.xml b/core-groovy-collections/pom.xml
index 125dfca4c1..770bcc57d6 100644
--- a/core-groovy-collections/pom.xml
+++ b/core-groovy-collections/pom.xml
@@ -101,7 +101,6 @@
maven-surefire-plugin
- ${surefire.plugin.version}false
@@ -128,7 +127,6 @@
2.4.01.1-groovy-2.41.6
- 2.20.1
diff --git a/core-groovy-strings/README.md b/core-groovy-strings/README.md
new file mode 100644
index 0000000000..2f49f47cf9
--- /dev/null
+++ b/core-groovy-strings/README.md
@@ -0,0 +1,3 @@
+### Relevant Articles:
+
+- [How to Remove a Prefix From Strings in Groovy](https://www.baeldung.com/groovy-remove-string-prefix)
diff --git a/core-groovy-strings/pom.xml b/core-groovy-strings/pom.xml
new file mode 100644
index 0000000000..1144d748ee
--- /dev/null
+++ b/core-groovy-strings/pom.xml
@@ -0,0 +1,122 @@
+
+
+ 4.0.0
+ core-groovy-strings
+ 1.0-SNAPSHOT
+ core-groovy-strings
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+
+ org.codehaus.groovy
+ groovy
+ ${groovy.version}
+
+
+ org.codehaus.groovy
+ groovy-all
+ ${groovy-all.version}
+ pom
+
+
+ org.codehaus.groovy
+ groovy-dateutil
+ ${groovy.version}
+
+
+ org.codehaus.groovy
+ groovy-sql
+ ${groovy-sql.version}
+
+
+ org.junit.platform
+ junit-platform-runner
+ ${junit.platform.version}
+ test
+
+
+ org.hsqldb
+ hsqldb
+ ${hsqldb.version}
+ test
+
+
+ org.spockframework
+ spock-core
+ ${spock-core.version}
+ test
+
+
+
+
+
+
+ org.codehaus.gmavenplus
+ gmavenplus-plugin
+ ${gmavenplus-plugin.version}
+
+
+
+ addSources
+ addTestSources
+ compile
+ compileTests
+
+
+
+
+
+ maven-failsafe-plugin
+ ${maven-failsafe-plugin.version}
+
+
+ org.junit.platform
+ junit-platform-surefire-provider
+ ${junit.platform.version}
+
+
+
+
+ junit5
+
+ integration-test
+ verify
+
+
+
+ **/*Test5.java
+
+
+
+
+
+
+
+
+
+
+ central
+ https://jcenter.bintray.com
+
+
+
+
+ 1.0.0
+ 2.5.6
+ 2.5.6
+ 2.5.6
+ 2.4.0
+ 1.1-groovy-2.4
+ 1.6
+
+
+
\ No newline at end of file
diff --git a/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy
new file mode 100644
index 0000000000..61b81fe1b2
--- /dev/null
+++ b/core-groovy-strings/src/test/groovy/com/baeldung/removeprefix/RemovePrefixTest.groovy
@@ -0,0 +1,70 @@
+package com.baeldung.removeprefix
+
+import org.junit.Assert
+import org.junit.Test
+
+class RemovePrefixTest {
+
+
+ @Test
+ public void whenCasePrefixIsRemoved_thenReturnTrue() {
+ def trimPrefix = {
+ it.startsWith('Groovy-') ? it.minus('Groovy-') : it
+ }
+
+ def actual = trimPrefix("Groovy-Tutorials at Baeldung")
+ def expected = "Tutorials at Baeldung"
+
+ Assert.assertEquals(expected, actual)
+ }
+
+ @Test
+ public void whenPrefixIsRemoved_thenReturnTrue() {
+
+ String prefix = "groovy-"
+ String trimPrefix = "Groovy-Tutorials at Baeldung"
+ def actual;
+ if(trimPrefix.startsWithIgnoreCase(prefix)) {
+ actual = trimPrefix.substring(prefix.length())
+ }
+
+ def expected = "Tutorials at Baeldung"
+
+ Assert.assertEquals(expected, actual)
+ }
+
+ @Test
+ public void whenPrefixIsRemovedUsingRegex_thenReturnTrue() {
+
+ def regex = ~"^([Gg])roovy-"
+ String trimPrefix = "Groovy-Tutorials at Baeldung"
+ String actual = trimPrefix - regex
+
+ def expected = "Tutorials at Baeldung"
+
+ Assert.assertEquals(expected, actual)
+ }
+
+ @Test
+ public void whenPrefixIsRemovedUsingReplaceFirst_thenReturnTrue() {
+ def regex = ~"^groovy"
+ String trimPrefix = "groovyTutorials at Baeldung's groovy page"
+ String actual = trimPrefix.replaceFirst(regex, "")
+
+ def expected = "Tutorials at Baeldung's groovy page"
+
+ Assert.assertEquals(expected, actual)
+ }
+
+ @Test
+ public void whenPrefixIsRemovedUsingReplaceAll_thenReturnTrue() {
+
+ String trimPrefix = "groovyTutorials at Baeldung groovy"
+ String actual = trimPrefix.replaceAll(/^groovy/, "")
+
+ def expected = "Tutorials at Baeldung groovy"
+
+ Assert.assertEquals(expected, actual)
+ }
+
+}
\ No newline at end of file
diff --git a/core-groovy/README.md b/core-groovy/README.md
index f852b3ccf2..70e8d262ce 100644
--- a/core-groovy/README.md
+++ b/core-groovy/README.md
@@ -13,4 +13,5 @@ This module contains articles about core Groovy concepts
- [Converting a String to a Date in Groovy](https://www.baeldung.com/groovy-string-to-date)
- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
- [Convert String to Integer in Groovy](https://www.baeldung.com/groovy-convert-string-to-integer)
+- [Groovy Variable Scope](https://www.baeldung.com/groovy/variable-scope)
- [[More -->]](/core-groovy-2)
diff --git a/core-java-modules/core-java-10/README.md b/core-java-modules/core-java-10/README.md
index 2b57ec9064..9a110449bc 100644
--- a/core-java-modules/core-java-10/README.md
+++ b/core-java-modules/core-java-10/README.md
@@ -5,7 +5,10 @@ This module contains articles about Java 10 core features
### Relevant Articles:
- [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference)
-- [Guide to Java 10](http://www.baeldung.com/java-10-overview)
+- [New Features in Java 10](https://www.baeldung.com/java-10-overview)
- [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another)
- [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler)
- [Copying Sets in Java](https://www.baeldung.com/java-copy-sets)
+- [Converting between a List and a Set in Java](https://www.baeldung.com/convert-list-to-set-and-set-to-list)
+- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception)
+- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
diff --git a/core-java-modules/core-java-10/pom.xml b/core-java-modules/core-java-10/pom.xml
index a9b991852f..b293eb6c2f 100644
--- a/core-java-modules/core-java-10/pom.xml
+++ b/core-java-modules/core-java-10/pom.xml
@@ -1,22 +1,29 @@
+ 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">
4.0.0core-java-100.1.0-SNAPSHOTcore-java-10jar
- http://maven.apache.org
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
- ../../
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+ org.apache.commons
+ commons-collections4
+ ${commons-collections4.version}
+
+
+
@@ -34,6 +41,7 @@
1010
+ 4.1
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java
deleted file mode 100644
index c9f61455bd..0000000000
--- a/core-java-modules/core-java-10/src/test/java/com/baeldung/AppTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-/**
- * Unit test for simple App.
- */
-public class AppTest
- extends TestCase
-{
- /**
- * Create the test case
- *
- * @param testName name of the test case
- */
- public AppTest( String testName )
- {
- super( testName );
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite( AppTest.class );
- }
-
- /**
- * Rigourous Test :-)
- */
- public void testApp()
- {
- assertTrue( true );
- }
-}
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java
new file mode 100644
index 0000000000..73eb8e661a
--- /dev/null
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/AppUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppUnitTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppUnitTest(String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppUnitTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/collections/conversion/ListSetConversionUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/collections/conversion/ListSetConversionUnitTest.java
new file mode 100644
index 0000000000..1526d1ae7f
--- /dev/null
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/collections/conversion/ListSetConversionUnitTest.java
@@ -0,0 +1,68 @@
+package com.baeldung.java10.collections.conversion;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+import org.apache.commons.collections4.CollectionUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class ListSetConversionUnitTest {
+
+ // Set -> List; List -> Set
+
+ @Test
+ public final void givenUsingCoreJava_whenSetConvertedToList_thenCorrect() {
+ final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
+ final List targetList = new ArrayList<>(sourceSet);
+ }
+
+ @Test
+ public final void givenUsingCoreJava_whenListConvertedToSet_thenCorrect() {
+ final List sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
+ final Set targetSet = new HashSet<>(sourceList);
+ }
+
+ @Test
+ public void givenUsingJava10_whenSetConvertedToList_thenCorrect() {
+ final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
+ final List targetList = List.copyOf(sourceSet);
+ }
+
+ @Test
+ public void givenUsingJava10_whenListConvertedToSet_thenCorrect() {
+ final List sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
+ final Set targetSet = Set.copyOf(sourceList);
+ }
+
+ @Test
+ public final void givenUsingGuava_whenSetConvertedToList_thenCorrect() {
+ final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
+ final List targetList = Lists.newArrayList(sourceSet);
+ }
+
+ @Test
+ public final void givenUsingGuava_whenListConvertedToSet_thenCorrect() {
+ final List sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
+ final Set targetSet = Sets.newHashSet(sourceList);
+ }
+
+ @Test
+ public final void givenUsingCommonsCollections_whenListConvertedToSet_thenCorrect() {
+ final List sourceList = Lists.newArrayList(0, 1, 2, 3, 4, 5);
+
+ final Set targetSet = new HashSet<>(6);
+ CollectionUtils.addAll(targetSet, sourceList);
+ }
+
+ @Test
+ public final void givenUsingCommonsCollections_whenSetConvertedToList_thenCorrect() {
+ final Set sourceSet = Sets.newHashSet(0, 1, 2, 3, 4, 5);
+
+ final List targetList = new ArrayList<>(6);
+ CollectionUtils.addAll(targetList, sourceSet);
+ }
+}
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
index f529e219a6..0b70516146 100644
--- a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/list/CopyListServiceUnitTest.java
@@ -10,5 +10,6 @@ public class CopyListServiceUnitTest {
@Test(expected = UnsupportedOperationException.class)
public void whenModifyCopyOfList_thenThrowsException() {
List copyList = List.copyOf(Arrays.asList(1, 2, 3, 4));
+ copyList.add(4);
}
}
diff --git a/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java
new file mode 100644
index 0000000000..8b1ef54fd2
--- /dev/null
+++ b/core-java-modules/core-java-10/src/test/java/com/baeldung/java10/streams/StreamToImmutableJava10UnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.java10.streams;
+
+import static java.util.stream.Collectors.toUnmodifiableList;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+public class StreamToImmutableJava10UnitTest {
+
+ @Test
+ public void whenUsingCollectorsToUnmodifiableList_thenSuccess() {
+ List givenList = Arrays.asList("a", "b", "c");
+ List result = givenList.stream()
+ .collect(toUnmodifiableList());
+
+ System.out.println(result.getClass());
+ }
+}
diff --git a/core-java-modules/core-java-11-2/README.md b/core-java-modules/core-java-11-2/README.md
new file mode 100644
index 0000000000..c87936b07d
--- /dev/null
+++ b/core-java-modules/core-java-11-2/README.md
@@ -0,0 +1,9 @@
+## Core Java 11
+
+This module contains articles about Java 11 core features
+
+### Relevant articles
+- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
+- [Guide to Java Reflection](http://www.baeldung.com/java-reflection)
+- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
+- [New Features in Java 11](https://www.baeldung.com/java-11-new-features)
diff --git a/core-java-modules/core-java-11-2/pom.xml b/core-java-modules/core-java-11-2/pom.xml
new file mode 100644
index 0000000000..b92963a5c8
--- /dev/null
+++ b/core-java-modules/core-java-11-2/pom.xml
@@ -0,0 +1,79 @@
+
+
+ 4.0.0
+ core-java-11-2
+ 0.1.0-SNAPSHOT
+ core-java-11-2
+ jar
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ../..
+
+
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.mock-server
+ mockserver-junit-jupiter
+ ${mockserver.version}
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit.jupiter.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-params
+ ${junit.jupiter.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit.jupiter.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.source.version}
+ ${maven.compiler.target.version}
+
+
+
+
+
+
+ 11
+ 11
+ 29.0-jre
+ 5.7.0
+ 3.17.2
+ 5.11.1
+
+
+
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java
new file mode 100644
index 0000000000..b00c56fcd7
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/features/MainClass.java
@@ -0,0 +1,17 @@
+package com.baeldung.features;
+
+public class MainClass {
+
+ private static boolean mainPrivateMethod() {
+ return true;
+ }
+
+ public static class NestedClass {
+
+ boolean nestedPublicMethod() {
+ return mainPrivateMethod();
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Modem.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/optional/Modem.java
similarity index 100%
rename from core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Modem.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/optional/Modem.java
diff --git a/core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/optional/Person.java
similarity index 100%
rename from core-java-modules/core-java-optional/src/main/java/com/baeldung/optional/Person.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/optional/Person.java
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java
new file mode 100644
index 0000000000..364246ae64
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Animal.java
@@ -0,0 +1,23 @@
+package com.baeldung.reflection;
+
+public abstract class Animal implements Eating {
+
+ public static final String CATEGORY = "domestic";
+
+ private String name;
+
+ public Animal(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ protected abstract String getSound();
+
+}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
similarity index 93%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
index bd6f13094c..f5bb0f9b19 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Bird.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Bird.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Bird extends Animal {
private boolean walks;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
similarity index 91%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
index 3776ef82e2..b7ff083daf 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/DynamicGreeter.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/DynamicGreeter.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Annotation;
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java
new file mode 100644
index 0000000000..c959becf00
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Eating.java
@@ -0,0 +1,5 @@
+package com.baeldung.reflection;
+
+public interface Eating {
+ String eats();
+}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
similarity index 90%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
index 503717ae5e..086d09d543 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Goat.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Goat.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Goat extends Animal implements Locomotion {
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
similarity index 83%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
index 57aefdd169..d06a719312 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greeter.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greeter.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
similarity index 98%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
index 601306f5d2..f23c407c52 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/GreetingAnnotation.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/GreetingAnnotation.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java
new file mode 100644
index 0000000000..fc6dfe949b
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Greetings.java
@@ -0,0 +1,6 @@
+package com.baeldung.reflection;
+
+@Greeter(greet="Good morning")
+public class Greetings {
+
+}
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java
new file mode 100644
index 0000000000..230fd9a466
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Locomotion.java
@@ -0,0 +1,5 @@
+package com.baeldung.reflection;
+
+public interface Locomotion {
+ String getLocomotion();
+}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
similarity index 90%
rename from core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java
rename to core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
index da4b479b02..5264378524 100644
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Operations.java
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Operations.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
public class Operations {
diff --git a/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java
new file mode 100644
index 0000000000..1a1fafef93
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/main/java/com/baeldung/reflection/Person.java
@@ -0,0 +1,6 @@
+package com.baeldung.reflection;
+
+public class Person {
+ private String name;
+ private int age;
+}
diff --git a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
similarity index 87%
rename from core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
index 6afc9f4182..7990b1fdb7 100644
--- a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/collectors/Java8CollectorsUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/collectors/Java8CollectorsUnitTest.java
@@ -1,18 +1,11 @@
-package com.baeldung.streams.collectors;
+package com.baeldung.collectors;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.junit.Test;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.DoubleSummaryStatistics;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
+import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
@@ -20,19 +13,7 @@ import java.util.function.Supplier;
import java.util.stream.Collector;
import static com.google.common.collect.Sets.newHashSet;
-import static java.util.stream.Collectors.averagingDouble;
-import static java.util.stream.Collectors.collectingAndThen;
-import static java.util.stream.Collectors.counting;
-import static java.util.stream.Collectors.groupingBy;
-import static java.util.stream.Collectors.joining;
-import static java.util.stream.Collectors.maxBy;
-import static java.util.stream.Collectors.partitioningBy;
-import static java.util.stream.Collectors.summarizingDouble;
-import static java.util.stream.Collectors.summingDouble;
-import static java.util.stream.Collectors.toCollection;
-import static java.util.stream.Collectors.toList;
-import static java.util.stream.Collectors.toMap;
-import static java.util.stream.Collectors.toSet;
+import static java.util.stream.Collectors.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@@ -48,6 +29,14 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsAll(givenList);
}
+ @Test
+ public void whenCollectingToUnmodifiableList_shouldCollectToUnmodifiableList() {
+ final List result = givenList.stream().collect(toUnmodifiableList());
+
+ assertThatThrownBy(() -> result.add("foo"))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void whenCollectingToSet_shouldCollectToSet() throws Exception {
final Set result = givenList.stream().collect(toSet());
@@ -55,6 +44,14 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsAll(givenList);
}
+ @Test
+ public void whenCollectingToUnmodifiableSet_shouldCollectToUnmodifiableSet() {
+ final Set result = givenList.stream().collect(toUnmodifiableSet());
+
+ assertThatThrownBy(() -> result.add("foo"))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void givenContainsDuplicateElements_whenCollectingToSet_shouldAddDuplicateElementsOnlyOnce() throws Exception {
final Set result = listWithDuplicates.stream().collect(toSet());
@@ -84,6 +81,15 @@ public class Java8CollectorsUnitTest {
assertThat(result).containsEntry("a", 1).containsEntry("bb", 2).containsEntry("ccc", 3).containsEntry("dd", 2);
}
+ @Test
+ public void whenCollectingToUnmodifiableMap_shouldCollectToUnmodifiableMap() {
+ final Map result = givenList.stream()
+ .collect(toUnmodifiableMap(Function.identity(), String::length));
+
+ assertThatThrownBy(() -> result.put("foo", 3))
+ .isInstanceOf(UnsupportedOperationException.class);
+ }
+
@Test
public void whenCollectingToMapwWithDuplicates_shouldCollectToMapMergingTheIdenticalItems() throws Exception {
final Map result = listWithDuplicates.stream().collect(
diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java
new file mode 100644
index 0000000000..1d49f5dbd1
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/HttpClientIntegrationTest.java
@@ -0,0 +1,54 @@
+package com.baeldung.features;
+
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockserver.integration.ClientAndServer;
+import org.mockserver.model.HttpStatusCode;
+import org.mockserver.socket.PortFactory;
+
+import java.io.IOException;
+import java.net.URI;
+import java.net.http.HttpClient;
+import java.net.http.HttpRequest;
+import java.net.http.HttpResponse;
+import java.time.Duration;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockserver.integration.ClientAndServer.startClientAndServer;
+
+class HttpClientIntegrationTest {
+
+ private static ClientAndServer mockServer;
+ private static int port;
+
+ @BeforeAll
+ static void startServer() {
+ port = PortFactory.findFreePort();
+ mockServer = startClientAndServer(port);
+ mockServer.when(new org.mockserver.model.HttpRequest().withMethod("GET"))
+ .respond(new org.mockserver.model.HttpResponse()
+ .withStatusCode(HttpStatusCode.OK_200.code())
+ .withBody("Hello from the server!"));
+ }
+
+ @AfterAll
+ static void stopServer() {
+ mockServer.stop();
+ }
+
+ @Test
+ void givenSampleHttpRequest_whenRequestIsSent_thenServerResponseIsReceived() throws IOException, InterruptedException {
+ HttpClient httpClient = HttpClient.newBuilder()
+ .version(HttpClient.Version.HTTP_2)
+ .connectTimeout(Duration.ofSeconds(20))
+ .build();
+ HttpRequest httpRequest = HttpRequest.newBuilder()
+ .GET()
+ .uri(URI.create("http://localhost:" + port))
+ .build();
+ HttpResponse httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofString());
+ assertThat(httpResponse.body()).isEqualTo("Hello from the server!");
+ }
+
+}
diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java
new file mode 100644
index 0000000000..61ce9c7c13
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/JavaElevenFeaturesUnitTest.java
@@ -0,0 +1,61 @@
+package com.baeldung.features;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import javax.annotation.Nonnull;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.List;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class JavaElevenFeaturesUnitTest {
+
+ @Test
+ void givenMultilineString_whenExtractingNonBlankStrippedLines_thenLinesAreReturned() {
+ String multilineString = "Baeldung helps \n \n developers \n explore Java.";
+ List lines = multilineString.lines()
+ .filter(line -> !line.isBlank())
+ .map(String::strip)
+ .collect(Collectors.toList());
+ assertThat(lines).containsExactly("Baeldung helps", "developers", "explore Java.");
+ }
+
+ @Test
+ void givenTemporaryFile_whenReadingStringContent_thenContentIsReturned(@TempDir Path tempDir) throws IOException {
+ Path filePath = Files.writeString(Files.createTempFile(tempDir, "demo", ".txt"), "Sample text");
+ String fileContent = Files.readString(filePath);
+ assertThat(fileContent).isEqualTo("Sample text");
+ }
+
+ @Test
+ void givenSampleList_whenConvertingToArray_thenItemsRemainUnchanged() {
+ List sampleList = Arrays.asList("Java", "Kotlin");
+ String[] sampleArray = sampleList.toArray(String[]::new);
+ assertThat(sampleArray).containsExactly("Java", "Kotlin");
+ }
+
+ @Test
+ void givenSampleList_whenConvertingToUppercaseString_thenUppercaseIsReturned() {
+ List sampleList = Arrays.asList("Java", "Kotlin");
+ String resultString = sampleList.stream()
+ .map((@Nonnull var x) -> x.toUpperCase())
+ .collect(Collectors.joining(", "));
+ assertThat(resultString).isEqualTo("JAVA, KOTLIN");
+ }
+
+ @Test
+ void givenSampleList_whenExtractingNonBlankValues_thenOnlyNonBlanksAreReturned() {
+ List sampleList = Arrays.asList("Java", "\n \n", "Kotlin", " ");
+ List withoutBlanks = sampleList.stream()
+ .filter(Predicate.not(String::isBlank))
+ .collect(Collectors.toList());
+ assertThat(withoutBlanks).containsExactly("Java", "Kotlin");
+ }
+
+}
diff --git a/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java
new file mode 100644
index 0000000000..902ad9c6f8
--- /dev/null
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/features/NestedClassesUnitTest.java
@@ -0,0 +1,37 @@
+package com.baeldung.features;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class NestedClassesUnitTest {
+
+ @Test
+ public void giveNestedClass_whenCallingMainClassPrivateMethod_thenNoExceptionIsThrown() {
+ MainClass.NestedClass nestedInstance = new MainClass.NestedClass();
+ assertThat(nestedInstance.nestedPublicMethod()).isTrue();
+ }
+
+ @Test
+ public void giveNestedClass_whenCheckingNestmate_thenNestedClassIsReturned() {
+ assertThat(MainClass.class.isNestmateOf(MainClass.NestedClass.class)).isTrue();
+ }
+
+ @Test
+ public void giveNestedClass_whenCheckingNestHost_thenMainClassIsReturned() {
+ assertThat(MainClass.NestedClass.class.getNestHost()).isEqualTo(MainClass.class);
+ }
+
+ @Test
+ public void giveNestedClass_whenCheckingNestMembers_thenNestMembersAreReturned() {
+ Set nestedMembers = Arrays.stream(MainClass.NestedClass.class.getNestMembers())
+ .map(Class::getName)
+ .collect(Collectors.toSet());
+ assertThat(nestedMembers).contains(MainClass.class.getName(), MainClass.NestedClass.class.getName());
+ }
+
+}
diff --git a/core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java
similarity index 96%
rename from core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java
index 9ef156501b..65b9e22f44 100644
--- a/core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalChainingUnitTest.java
@@ -7,7 +7,9 @@ import java.util.Optional;
import java.util.function.Supplier;
import java.util.stream.Stream;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
public class OptionalChainingUnitTest {
diff --git a/core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalUnitTest.java
similarity index 96%
rename from core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalUnitTest.java
index de16e9b635..1b0a2d4445 100644
--- a/core-java-modules/core-java-optional/src/test/java/com/baeldung/optional/OptionalUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/optional/OptionalUnitTest.java
@@ -9,7 +9,9 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
public class OptionalUnitTest {
@@ -262,6 +264,12 @@ public class OptionalUnitTest {
.orElseThrow(IllegalArgumentException::new);
}
+ @Test(expected = NoSuchElementException.class)
+ public void whenNoArgOrElseThrowWorks_thenCorrect() {
+ String nullName = null;
+ String name = Optional.ofNullable(nullName).orElseThrow();
+ }
+
public String getMyDefault() {
LOG.debug("Getting default value...");
return "Default Value";
diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
similarity index 98%
rename from core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
index 217910bffd..7584d5da94 100644
--- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/OperationsUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/OperationsUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertFalse;
diff --git a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
similarity index 77%
rename from core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java
rename to core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
index a791d64874..c73fa5f8e0 100644
--- a/core-java-modules/core-java-reflection/src/test/java/com/baeldung/reflection/java/reflection/ReflectionUnitTest.java
+++ b/core-java-modules/core-java-11-2/src/test/java/com/baeldung/reflection/ReflectionUnitTest.java
@@ -1,4 +1,4 @@
-package com.baeldung.java.reflection;
+package com.baeldung.reflection;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -32,23 +32,23 @@ public class ReflectionUnitTest {
final Class> clazz = goat.getClass();
assertEquals("Goat", clazz.getSimpleName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
}
@Test
public void givenClassName_whenCreatesObject_thenCorrect() throws ClassNotFoundException {
- final Class> clazz = Class.forName("com.baeldung.java.reflection.Goat");
+ final Class> clazz = Class.forName("com.baeldung.reflection.Goat");
assertEquals("Goat", clazz.getSimpleName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
- assertEquals("com.baeldung.java.reflection.Goat", clazz.getCanonicalName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getName());
+ assertEquals("com.baeldung.reflection.Goat", clazz.getCanonicalName());
}
@Test
public void givenClass_whenRecognisesModifiers_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final int goatMods = goatClass.getModifiers();
final int animalMods = animalClass.getModifiers();
@@ -63,7 +63,7 @@ public class ReflectionUnitTest {
final Class> goatClass = goat.getClass();
final Package pkg = goatClass.getPackage();
- assertEquals("com.baeldung.java.reflection", pkg.getName());
+ assertEquals("com.baeldung.reflection", pkg.getName());
}
@Test
@@ -81,8 +81,8 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsImplementedInterfaces_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Class>[] goatInterfaces = goatClass.getInterfaces();
final Class>[] animalInterfaces = animalClass.getInterfaces();
@@ -94,16 +94,16 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsConstructor_thenCorrect() throws ClassNotFoundException {
- final Class> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
+ final Class> goatClass = Class.forName("com.baeldung.reflection.Goat");
final Constructor>[] constructors = goatClass.getConstructors();
assertEquals(1, constructors.length);
- assertEquals("com.baeldung.java.reflection.Goat", constructors[0].getName());
+ assertEquals("com.baeldung.reflection.Goat", constructors[0].getName());
}
@Test
public void givenClass_whenGetsFields_thenCorrect() throws ClassNotFoundException {
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Field[] fields = animalClass.getDeclaredFields();
final List actualFields = getFieldNames(fields);
@@ -114,7 +114,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsMethods_thenCorrect() throws ClassNotFoundException {
- final Class> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
+ final Class> animalClass = Class.forName("com.baeldung.reflection.Animal");
final Method[] methods = animalClass.getDeclaredMethods();
final List actualMethods = getMethodNames(methods);
@@ -124,7 +124,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsAllConstructors_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Constructor>[] constructors = birdClass.getConstructors();
assertEquals(3, constructors.length);
@@ -132,7 +132,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsEachConstructorByParamTypes_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
birdClass.getConstructor();
birdClass.getConstructor(String.class);
birdClass.getConstructor(String.class, boolean.class);
@@ -140,7 +140,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenInstantiatesObjectsAtRuntime_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Constructor> cons1 = birdClass.getConstructor();
final Constructor> cons2 = birdClass.getConstructor(String.class);
@@ -159,7 +159,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsPublicFields_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field[] fields = birdClass.getFields();
assertEquals(1, fields.length);
assertEquals("CATEGORY", fields[0].getName());
@@ -168,7 +168,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsPublicFieldByName_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getField("CATEGORY");
assertEquals("CATEGORY", field.getName());
@@ -176,7 +176,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsDeclaredFields_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field[] fields = birdClass.getDeclaredFields();
assertEquals(1, fields.length);
assertEquals("walks", fields[0].getName());
@@ -184,7 +184,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsFieldsByName_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getDeclaredField("walks");
assertEquals("walks", field.getName());
@@ -192,14 +192,14 @@ public class ReflectionUnitTest {
@Test
public void givenClassField_whenGetsType_thenCorrect() throws Exception {
- final Field field = Class.forName("com.baeldung.java.reflection.Bird").getDeclaredField("walks");
+ final Field field = Class.forName("com.baeldung.reflection.Bird").getDeclaredField("walks");
final Class> fieldClass = field.getType();
assertEquals("boolean", fieldClass.getSimpleName());
}
@Test
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Field field = birdClass.getDeclaredField("walks");
field.setAccessible(true);
@@ -216,7 +216,7 @@ public class ReflectionUnitTest {
@Test
public void givenClassField_whenGetsAndSetsWithNull_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Field field = birdClass.getField("CATEGORY");
field.setAccessible(true);
@@ -225,7 +225,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsAllPublicMethods_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Method[] methods = birdClass.getMethods();
final List methodNames = getMethodNames(methods);
@@ -235,7 +235,7 @@ public class ReflectionUnitTest {
@Test
public void givenClass_whenGetsOnlyDeclaredMethods_thenCorrect() throws ClassNotFoundException {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final List actualMethodNames = getMethodNames(birdClass.getDeclaredMethods());
final List expectedMethodNames = Arrays.asList("setWalks", "walks", "getSound", "eats");
@@ -248,24 +248,17 @@ public class ReflectionUnitTest {
@Test
public void givenMethodName_whenGetsMethod_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
- final Method walksMethod = birdClass.getDeclaredMethod("walks");
- final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
-
- assertFalse(walksMethod.isAccessible());
- assertFalse(setWalksMethod.isAccessible());
-
- walksMethod.setAccessible(true);
- setWalksMethod.setAccessible(true);
-
- assertTrue(walksMethod.isAccessible());
- assertTrue(setWalksMethod.isAccessible());
+ final Bird bird = new Bird();
+ final Method walksMethod = bird.getClass().getDeclaredMethod("walks");
+ final Method setWalksMethod = bird.getClass().getDeclaredMethod("setWalks", boolean.class);
+ assertTrue(walksMethod.canAccess(bird));
+ assertTrue(setWalksMethod.canAccess(bird));
}
@Test
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
- final Class> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
+ final Class> birdClass = Class.forName("com.baeldung.reflection.Bird");
final Bird bird = (Bird) birdClass.getConstructor().newInstance();
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
final Method walksMethod = birdClass.getDeclaredMethod("walks");
diff --git a/core-java-modules/core-java-11/README.md b/core-java-modules/core-java-11/README.md
index 70e2e66737..a3601c8339 100644
--- a/core-java-modules/core-java-11/README.md
+++ b/core-java-modules/core-java-11/README.md
@@ -8,7 +8,7 @@ This module contains articles about Java 11 core features
- [Java 11 Local Variable Syntax for Lambda Parameters](https://www.baeldung.com/java-var-lambda-params)
- [Java 11 String API Additions](https://www.baeldung.com/java-11-string-api)
- [Java 11 Nest Based Access Control](https://www.baeldung.com/java-nest-based-access-control)
-- [Exploring the New HTTP Client in Java 9 and 11](https://www.baeldung.com/java-9-http-client)
+- [Exploring the New HTTP Client in Java](https://www.baeldung.com/java-9-http-client)
- [An Introduction to Epsilon GC: A No-Op Experimental Garbage Collector](https://www.baeldung.com/jvm-epsilon-gc-garbage-collector)
- [Guide to jlink](https://www.baeldung.com/jlink)
- [Negate a Predicate Method Reference with Java 11](https://www.baeldung.com/java-negate-predicate-method-reference)
diff --git a/core-java-modules/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml
index bbc4219eaa..cdb3aab2c7 100644
--- a/core-java-modules/core-java-11/pom.xml
+++ b/core-java-modules/core-java-11/pom.xml
@@ -32,12 +32,12 @@
org.openjdk.jmhjmh-core
- ${jmh.version}
+ ${jmh-core.version}org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}provided
@@ -105,9 +105,8 @@
27.1-jre3.11.1benchmarks
- 1.2210.0.0
- 10.0.0
+ 3.2.4
diff --git a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java
index 42f56838c4..2a2540a517 100644
--- a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java
+++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpClientUnitTest.java
@@ -64,7 +64,7 @@ public class HttpClientUnitTest {
.send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode(), equalTo(HttpURLConnection.HTTP_MOVED_PERM));
- assertThat(response.body(), containsString("https://stackoverflow.com/"));
+ assertTrue(response.headers().map().get("location").stream().anyMatch("https://stackoverflow.com/"::equals));
}
@Test
diff --git a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java
index b87e6b3c6e..a3a5592cd9 100644
--- a/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java
+++ b/core-java-modules/core-java-11/src/test/java/com/baeldung/java11/httpclient/test/HttpRequestUnitTest.java
@@ -18,6 +18,7 @@ import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import org.junit.Test;
+import org.junit.jupiter.api.Disabled;
public class HttpRequestUnitTest {
@@ -48,7 +49,12 @@ public class HttpRequestUnitTest {
assertThat(response.version(), equalTo(HttpClient.Version.HTTP_2));
}
- @Test
+ /*
+ * This test will fail as soon as the given URL returns a HTTP 2 response.
+ * Therefore, let's leave it commented out.
+ * */
+ @Test
+ @Disabled
public void shouldFallbackToHttp1_1WhenWebsiteDoesNotUseHttp2() throws IOException, InterruptedException, URISyntaxException, NoSuchAlgorithmException {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("https://postman-echo.com/get"))
diff --git a/core-java-modules/core-java-12/README.md b/core-java-modules/core-java-12/README.md
index 6c603e4dea..b509be876c 100644
--- a/core-java-modules/core-java-12/README.md
+++ b/core-java-modules/core-java-12/README.md
@@ -1,4 +1,4 @@
## Relevant Articles:
-
- [String API Updates in Java 12](https://www.baeldung.com/java12-string-api)
+- [New Features in Java 12](https://www.baeldung.com/java-12-new-features)
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java
new file mode 100644
index 0000000000..08a6d58d72
--- /dev/null
+++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/CompactNumbersUnitTest.java
@@ -0,0 +1,21 @@
+package java.com.baeldung.newfeatures;
+
+import org.junit.Test;
+
+import java.text.NumberFormat;
+import java.util.Locale;
+
+import static org.junit.Assert.assertEquals;
+
+public class CompactNumbersUnitTest {
+
+ @Test
+ public void givenNumber_thenCompactValues() {
+ NumberFormat likesShort = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.SHORT);
+ likesShort.setMaximumFractionDigits(2);
+ assertEquals("2.59K", likesShort.format(2592));
+ NumberFormat likesLong = NumberFormat.getCompactNumberInstance(new Locale("en", "US"), NumberFormat.Style.LONG);
+ likesLong.setMaximumFractionDigits(2);
+ assertEquals("2.59 thousand", likesShort.format(2592));
+ }
+}
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java
new file mode 100644
index 0000000000..7f081fe399
--- /dev/null
+++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/FileMismatchUnitTest.java
@@ -0,0 +1,32 @@
+package java.com.baeldung.newfeatures;
+
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import static org.junit.Assert.assertEquals;
+
+public class FileMismatchUnitTest {
+
+ @Test
+ public void givenIdenticalFiles_thenShouldNotFindMismatch() throws IOException {
+ Path filePath1 = Files.createTempFile("file1", ".txt");
+ Path filePath2 = Files.createTempFile("file2", ".txt");
+ Files.writeString(filePath1, "Java 12 Article");
+ Files.writeString(filePath2, "Java 12 Article");
+ long mismatch = Files.mismatch(filePath1, filePath2);
+ assertEquals(-1, mismatch);
+ }
+
+ @Test
+ public void givenDifferentFiles_thenShouldFindMismatch() throws IOException {
+ Path filePath3 = Files.createTempFile("file3", ".txt");
+ Path filePath4 = Files.createTempFile("file4", ".txt");
+ Files.writeString(filePath3, "Java 12 Article");
+ Files.writeString(filePath4, "Java 12 Tutorial");
+ long mismatch = Files.mismatch(filePath3, filePath4);
+ assertEquals(8, mismatch);
+ }
+}
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java
new file mode 100644
index 0000000000..5ae51bd960
--- /dev/null
+++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/StringUnitTest.java
@@ -0,0 +1,15 @@
+package java.com.baeldung.newfeatures;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class StringUnitTest {
+
+ @Test
+ public void givenString_thenRevertValue() {
+ String text = "Baeldung";
+ String transformed = text.transform(value -> new StringBuilder(value).reverse().toString());
+ assertEquals("gnudleaB", transformed);
+ }
+}
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java
new file mode 100644
index 0000000000..30a5cb40a7
--- /dev/null
+++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/newfeatures/TeeingCollectorUnitTest.java
@@ -0,0 +1,18 @@
+package java.com.baeldung.newfeatures;
+
+import org.junit.Test;
+
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+
+public class TeeingCollectorUnitTest {
+
+ @Test
+ public void givenSetOfNumbers_thenCalculateAverage() {
+ double mean = Stream.of(1, 2, 3, 4, 5)
+ .collect(Collectors.teeing(Collectors.summingDouble(i -> i), Collectors.counting(), (sum, count) -> sum / count));
+ assertEquals(3.0, mean);
+ }
+}
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java
deleted file mode 100644
index 3d80a36bf6..0000000000
--- a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPITest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.string;
-
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.MatcherAssert.assertThat;
-
-import org.junit.Test;
-
-public class StringAPITest {
-
- @Test
- public void whenPositiveArgument_thenReturnIndentedString() {
- String multilineStr = "This is\na multiline\nstring.";
- String outputStr = " This is\n a multiline\n string.\n";
-
- String postIndent = multilineStr.indent(3);
-
- assertThat(postIndent, equalTo(outputStr));
- }
-
- @Test
- public void whenNegativeArgument_thenReturnReducedIndentedString() {
- String multilineStr = " This is\n a multiline\n string.";
- String outputStr = " This is\n a multiline\n string.\n";
-
- String postIndent = multilineStr.indent(-2);
-
- assertThat(postIndent, equalTo(outputStr));
- }
-
- @Test
- public void whenTransformUsingLamda_thenReturnTransformedString() {
- String result = "hello".transform(input -> input + " world!");
-
- assertThat(result, equalTo("hello world!"));
- }
-
- @Test
- public void whenTransformUsingParseInt_thenReturnInt() {
- int result = "42".transform(Integer::parseInt);
-
- assertThat(result, equalTo(42));
- }
-}
diff --git a/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java
new file mode 100644
index 0000000000..e5f21bb25f
--- /dev/null
+++ b/core-java-modules/core-java-12/src/test/java/com/baeldung/string/StringAPIUnitTest.java
@@ -0,0 +1,43 @@
+package com.baeldung.string;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+
+import org.junit.Test;
+
+public class StringAPIUnitTest {
+
+ @Test
+ public void whenPositiveArgument_thenReturnIndentedString() {
+ String multilineStr = "This is\na multiline\nstring.";
+ String outputStr = " This is\n a multiline\n string.\n";
+
+ String postIndent = multilineStr.indent(3);
+
+ assertThat(postIndent, equalTo(outputStr));
+ }
+
+ @Test
+ public void whenNegativeArgument_thenReturnReducedIndentedString() {
+ String multilineStr = " This is\n a multiline\n string.";
+ String outputStr = " This is\n a multiline\n string.\n";
+
+ String postIndent = multilineStr.indent(-2);
+
+ assertThat(postIndent, equalTo(outputStr));
+ }
+
+ @Test
+ public void whenTransformUsingLamda_thenReturnTransformedString() {
+ String result = "hello".transform(input -> input + " world!");
+
+ assertThat(result, equalTo("hello world!"));
+ }
+
+ @Test
+ public void whenTransformUsingParseInt_thenReturnInt() {
+ int result = "42".transform(Integer::parseInt);
+
+ assertThat(result, equalTo(42));
+ }
+}
diff --git a/core-java-modules/core-java-13/README.md b/core-java-modules/core-java-13/README.md
index 697f89c362..9215139dd4 100644
--- a/core-java-modules/core-java-13/README.md
+++ b/core-java-modules/core-java-13/README.md
@@ -1,4 +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)
+- [New Features in Java 13](https://www.baeldung.com/java-13-new-features)
diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md
index d382c4814a..07cdf9859c 100644
--- a/core-java-modules/core-java-14/README.md
+++ b/core-java-modules/core-java-14/README.md
@@ -10,3 +10,4 @@ This module contains articles about Java 14.
- [Helpful NullPointerExceptions in Java 14](https://www.baeldung.com/java-14-nullpointerexception)
- [Foreign Memory Access API in Java 14](https://www.baeldung.com/java-foreign-memory-access)
- [Java 14 Record Keyword](https://www.baeldung.com/java-record-keyword)
+- [New Features in Java 14](https://www.baeldung.com/java-14-new-features)
diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml
index 96cb6b37e7..e977f39e9d 100644
--- a/core-java-modules/core-java-14/pom.xml
+++ b/core-java-modules/core-java-14/pom.xml
@@ -44,6 +44,8 @@
${maven.compiler.release}--enable-preview
+ 14
+ 14
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java
new file mode 100644
index 0000000000..44c712a17f
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/character/IsLetterOrAlphabetUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.java14.character;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class IsLetterOrAlphabetUnitTest {
+
+ @Test
+ public void givenACharacter_whenLetter_thenAssertIsLetterTrue() {
+ assertTrue(Character.isLetter(65));
+ }
+
+ @Test
+ public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic(65));
+ }
+
+ @Test
+ public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() {
+ assertFalse(Character.isLetter(837));
+ }
+
+ @Test
+ public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic(837));
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java
new file mode 100644
index 0000000000..4efd1ff362
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/MultilineUnitTest.java
@@ -0,0 +1,26 @@
+package com.baeldung.java14.newfeatues;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class MultilineUnitTest {
+
+ @SuppressWarnings("preview")
+ String multiline = """
+ A quick brown fox jumps over a lazy dog; \
+ the lazy dog howls loudly.""";
+
+ @SuppressWarnings("preview")
+ String anotherMultiline = """
+ A quick brown fox jumps over a lazy dog;
+ the lazy dog howls loudly.""";
+
+ @Test
+ public void givenMultilineString_whenSlashUsed_thenNoNewLine() {
+ assertFalse(multiline.contains("\n"));
+ assertTrue(anotherMultiline.contains("\n"));
+ }
+
+}
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java
new file mode 100644
index 0000000000..3d7a55d3e6
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/RecordUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.java14.newfeatues;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class RecordUnitTest {
+
+ @SuppressWarnings("preview")
+ public record User(int id, String password) {
+ };
+
+ private User user1 = new User(0, "UserOne");
+
+ @Test
+ public void givenRecord_whenObjInitialized_thenValuesCanBeFetchedWithGetters() {
+
+ assertEquals(0, user1.id());
+ assertEquals("UserOne", user1.password());
+ }
+
+ @Test
+ public void whenRecord_thenEqualsImplemented() {
+
+ User user2 = user1;
+
+ assertEquals(user1, user2);
+ }
+
+ @Test
+ public void whenRecord_thenToStringImplemented() {
+
+ assertTrue(user1.toString()
+ .contains("UserOne"));
+ }
+
+}
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java
new file mode 100644
index 0000000000..896b3ec7de
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/newfeatues/SwitchExprUnitTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.java14.newfeatues;
+
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class SwitchExprUnitTest {
+
+ @Test
+ public void givenDay_whenSunday_thenWeekend() {
+ assertTrue(isTodayHolidayInJava8("SUNDAY"));
+
+ assertTrue(isTodayHolidayInJava14("SUNDAY"));
+
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> isTodayHolidayInJava8("SOMEDAY"));
+
+ assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> isTodayHolidayInJava14("SOMEDAY"));
+ }
+
+ private boolean isTodayHolidayInJava8(String day) {
+
+ boolean isTodayHoliday;
+ switch (day) {
+ case "MONDAY":
+ case "TUESDAY":
+ case "WEDNESDAY":
+ case "THURSDAY":
+ case "FRIDAY":
+ isTodayHoliday = false;
+ break;
+ case "SATURDAY":
+ case "SUNDAY":
+ isTodayHoliday = true;
+ break;
+ default:
+ throw new IllegalArgumentException("What's a " + day);
+ }
+ return isTodayHoliday;
+ }
+
+ private boolean isTodayHolidayInJava14(String day) {
+ return switch (day) {
+ case "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY" -> false;
+ case "SATURDAY", "SUNDAY" -> true;
+ default -> throw new IllegalArgumentException("What's a " + day);
+ };
+ }
+
+}
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java
deleted file mode 100644
index 9bed3dab8f..0000000000
--- a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-package com.baeldung.java14.record;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class PersonTest {
-
- @Test
- public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() {
-
- String name = "John Doe";
- String address = "100 Linda Ln.";
-
- Person person1 = new Person(name, address);
- Person person2 = new Person(name, address);
-
- assertTrue(person1.equals(person2));
- }
-
- @Test
- public void givenDifferentObject_whenEquals_thenNotEqual() {
-
- Person person = new Person("John Doe", "100 Linda Ln.");
-
- assertFalse(person.equals(new Object()));
- }
-
- @Test
- public void givenDifferentName_whenEquals_thenPersonsNotEqual() {
-
- String address = "100 Linda Ln.";
-
- Person person1 = new Person("Jane Doe", address);
- Person person2 = new Person("John Doe", address);
-
- assertFalse(person1.equals(person2));
- }
-
- @Test
- public void givenDifferentAddress_whenEquals_thenPersonsNotEqual() {
-
- String name = "John Doe";
-
- Person person1 = new Person(name, "100 Linda Ln.");
- Person person2 = new Person(name, "200 London Ave.");
-
- assertFalse(person1.equals(person2));
- }
-
- @Test
- public void givenSameNameAndAddress_whenHashCode_thenPersonsEqual() {
-
- String name = "John Doe";
- String address = "100 Linda Ln.";
-
- Person person1 = new Person(name, address);
- Person person2 = new Person(name, address);
-
- assertEquals(person1.hashCode(), person2.hashCode());
- }
-
- @Test
- public void givenDifferentObject_whenHashCode_thenNotEqual() {
-
- Person person = new Person("John Doe", "100 Linda Ln.");
-
- assertNotEquals(person.hashCode(), new Object().hashCode());
- }
-
- @Test
- public void givenDifferentName_whenHashCode_thenPersonsNotEqual() {
-
- String address = "100 Linda Ln.";
-
- Person person1 = new Person("Jane Doe", address);
- Person person2 = new Person("John Doe", address);
-
- assertNotEquals(person1.hashCode(), person2.hashCode());
- }
-
- @Test
- public void givenDifferentAddress_whenHashCode_thenPersonsNotEqual() {
-
- String name = "John Doe";
-
- Person person1 = new Person(name, "100 Linda Ln.");
- Person person2 = new Person(name, "200 London Ave.");
-
- assertNotEquals(person1.hashCode(), person2.hashCode());
- }
-
- @Test
- public void givenValidNameAndAddress_whenGetNameAndAddress_thenExpectedValuesReturned() {
-
- String name = "John Doe";
- String address = "100 Linda Ln.";
-
- Person person = new Person(name, address);
-
- assertEquals(name, person.name());
- assertEquals(address, person.address());
- }
-
- @Test
- public void givenValidNameAndAddress_whenToString_thenCorrectStringReturned() {
-
- String name = "John Doe";
- String address = "100 Linda Ln.";
-
- Person person = new Person(name, address);
-
- assertEquals("Person[name=" + name + ", address=" + address + "]", person.toString());
- }
-
- @Test(expected = NullPointerException.class)
- public void givenNullName_whenConstruct_thenErrorThrown() {
- new Person(null, "100 Linda Ln.");
- }
-
- @Test(expected = NullPointerException.class)
- public void givenNullAddress_whenConstruct_thenErrorThrown() {
- new Person("John Doe", null);
- }
-
- @Test
- public void givenUnknownAddress_whenConstructing_thenAddressPopulated() {
-
- String name = "John Doe";
-
- Person person = new Person(name);
-
- assertEquals(name, person.name());
- assertEquals(Person.UNKNOWN_ADDRESS, person.address());
- }
-
- @Test
- public void givenUnnamed_whenConstructingThroughFactory_thenNamePopulated() {
-
- String address = "100 Linda Ln.";
-
- Person person = Person.unnamed(address);
-
- assertEquals(Person.UNNAMED, person.name());
- assertEquals(address, person.address());
- }
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java
new file mode 100644
index 0000000000..594ced56cd
--- /dev/null
+++ b/core-java-modules/core-java-14/src/test/java/com/baeldung/java14/record/PersonUnitTest.java
@@ -0,0 +1,150 @@
+package com.baeldung.java14.record;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class PersonUnitTest {
+
+ @Test
+ public void givenSameNameAndAddress_whenEquals_thenPersonsEqual() {
+
+ String name = "John Doe";
+ String address = "100 Linda Ln.";
+
+ Person person1 = new Person(name, address);
+ Person person2 = new Person(name, address);
+
+ assertTrue(person1.equals(person2));
+ }
+
+ @Test
+ public void givenDifferentObject_whenEquals_thenNotEqual() {
+
+ Person person = new Person("John Doe", "100 Linda Ln.");
+
+ assertFalse(person.equals(new Object()));
+ }
+
+ @Test
+ public void givenDifferentName_whenEquals_thenPersonsNotEqual() {
+
+ String address = "100 Linda Ln.";
+
+ Person person1 = new Person("Jane Doe", address);
+ Person person2 = new Person("John Doe", address);
+
+ assertFalse(person1.equals(person2));
+ }
+
+ @Test
+ public void givenDifferentAddress_whenEquals_thenPersonsNotEqual() {
+
+ String name = "John Doe";
+
+ Person person1 = new Person(name, "100 Linda Ln.");
+ Person person2 = new Person(name, "200 London Ave.");
+
+ assertFalse(person1.equals(person2));
+ }
+
+ @Test
+ public void givenSameNameAndAddress_whenHashCode_thenPersonsEqual() {
+
+ String name = "John Doe";
+ String address = "100 Linda Ln.";
+
+ Person person1 = new Person(name, address);
+ Person person2 = new Person(name, address);
+
+ assertEquals(person1.hashCode(), person2.hashCode());
+ }
+
+ @Test
+ public void givenDifferentObject_whenHashCode_thenNotEqual() {
+
+ Person person = new Person("John Doe", "100 Linda Ln.");
+
+ assertNotEquals(person.hashCode(), new Object().hashCode());
+ }
+
+ @Test
+ public void givenDifferentName_whenHashCode_thenPersonsNotEqual() {
+
+ String address = "100 Linda Ln.";
+
+ Person person1 = new Person("Jane Doe", address);
+ Person person2 = new Person("John Doe", address);
+
+ assertNotEquals(person1.hashCode(), person2.hashCode());
+ }
+
+ @Test
+ public void givenDifferentAddress_whenHashCode_thenPersonsNotEqual() {
+
+ String name = "John Doe";
+
+ Person person1 = new Person(name, "100 Linda Ln.");
+ Person person2 = new Person(name, "200 London Ave.");
+
+ assertNotEquals(person1.hashCode(), person2.hashCode());
+ }
+
+ @Test
+ public void givenValidNameAndAddress_whenGetNameAndAddress_thenExpectedValuesReturned() {
+
+ String name = "John Doe";
+ String address = "100 Linda Ln.";
+
+ Person person = new Person(name, address);
+
+ assertEquals(name, person.name());
+ assertEquals(address, person.address());
+ }
+
+ @Test
+ public void givenValidNameAndAddress_whenToString_thenCorrectStringReturned() {
+
+ String name = "John Doe";
+ String address = "100 Linda Ln.";
+
+ Person person = new Person(name, address);
+
+ assertEquals("Person[name=" + name + ", address=" + address + "]", person.toString());
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void givenNullName_whenConstruct_thenErrorThrown() {
+ new Person(null, "100 Linda Ln.");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void givenNullAddress_whenConstruct_thenErrorThrown() {
+ new Person("John Doe", null);
+ }
+
+ @Test
+ public void givenUnknownAddress_whenConstructing_thenAddressPopulated() {
+
+ String name = "John Doe";
+
+ Person person = new Person(name);
+
+ assertEquals(name, person.name());
+ assertEquals(Person.UNKNOWN_ADDRESS, person.address());
+ }
+
+ @Test
+ public void givenUnnamed_whenConstructingThroughFactory_thenNamePopulated() {
+
+ String address = "100 Linda Ln.";
+
+ Person person = Person.unnamed(address);
+
+ assertEquals(Person.UNNAMED, person.name());
+ assertEquals(address, person.address());
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-15/.mvn/jvm.config b/core-java-modules/core-java-15/.mvn/jvm.config
new file mode 100644
index 0000000000..50f549be0a
--- /dev/null
+++ b/core-java-modules/core-java-15/.mvn/jvm.config
@@ -0,0 +1 @@
+--enable-preview
\ No newline at end of file
diff --git a/core-java-modules/core-java-15/README.md b/core-java-modules/core-java-15/README.md
new file mode 100644
index 0000000000..de503fbb31
--- /dev/null
+++ b/core-java-modules/core-java-15/README.md
@@ -0,0 +1,7 @@
+## Core Java 15
+
+This module contains articles about Java 15.
+
+### Relevant articles
+
+- [Sealed Classes and Interfaces in Java 15](https://www.baeldung.com/java-sealed-classes-interfaces)
diff --git a/core-java-modules/core-java-15/pom.xml b/core-java-modules/core-java-15/pom.xml
new file mode 100644
index 0000000000..3b0d324d10
--- /dev/null
+++ b/core-java-modules/core-java-15/pom.xml
@@ -0,0 +1,76 @@
+
+
+ 4.0.0
+ core-java-15
+ core-java-15
+ jar
+ http://maven.apache.org
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+ ../../pom.xml
+
+
+
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-engine
+ ${junit-jupiter.version}
+ test
+
+
+ org.junit.jupiter
+ junit-jupiter-api
+ ${junit-jupiter.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ ${maven.compiler.release}
+ --enable-preview
+ 14
+ 14
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${surefire.plugin.version}
+
+ --enable-preview
+
+
+
+
+
+
+ 15
+ 3.17.2
+ 3.8.1
+ 3.0.0-M3
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java
new file mode 100644
index 0000000000..091c5841bf
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/alternative/Vehicles.java
@@ -0,0 +1,49 @@
+package com.baeldung.sealed.alternative;
+
+public class Vehicles {
+
+ abstract static class Vehicle {
+
+ private final String registrationNumber;
+
+ public Vehicle(String registrationNumber) {
+ this.registrationNumber = registrationNumber;
+ }
+
+ public String getRegistrationNumber() {
+ return registrationNumber;
+ }
+
+ }
+
+ public static final class Car extends Vehicle {
+
+ private final int numberOfSeats;
+
+ public Car(int numberOfSeats, String registrationNumber) {
+ super(registrationNumber);
+ this.numberOfSeats = numberOfSeats;
+ }
+
+ public int getNumberOfSeats() {
+ return numberOfSeats;
+ }
+
+ }
+
+ public static final class Truck extends Vehicle {
+
+ private final int loadCapacity;
+
+ public Truck(int loadCapacity, String registrationNumber) {
+ super(registrationNumber);
+ this.loadCapacity = loadCapacity;
+ }
+
+ public int getLoadCapacity() {
+ return loadCapacity;
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java
new file mode 100644
index 0000000000..7dce266da7
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Car.java
@@ -0,0 +1,21 @@
+package com.baeldung.sealed.classes;
+
+public non-sealed class Car extends Vehicle implements Service {
+
+ private final int numberOfSeats;
+
+ public Car(int numberOfSeats, String registrationNumber) {
+ super(registrationNumber);
+ this.numberOfSeats = numberOfSeats;
+ }
+
+ public int getNumberOfSeats() {
+ return numberOfSeats;
+ }
+
+ @Override
+ public int getMaxServiceIntervalInMonths() {
+ return 12;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java
new file mode 100644
index 0000000000..9486b302f1
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Service.java
@@ -0,0 +1,11 @@
+package com.baeldung.sealed.classes;
+
+public sealed interface Service permits Car, Truck {
+
+ int getMaxServiceIntervalInMonths();
+
+ default int getMaxDistanceBetweenServicesInKilometers() {
+ return 100000;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java
new file mode 100644
index 0000000000..8d5234342b
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Truck.java
@@ -0,0 +1,21 @@
+package com.baeldung.sealed.classes;
+
+public final class Truck extends Vehicle implements Service {
+
+ private final int loadCapacity;
+
+ public Truck(int loadCapacity, String registrationNumber) {
+ super(registrationNumber);
+ this.loadCapacity = loadCapacity;
+ }
+
+ public int getLoadCapacity() {
+ return loadCapacity;
+ }
+
+ @Override
+ public int getMaxServiceIntervalInMonths() {
+ return 18;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java
new file mode 100644
index 0000000000..79eda0c790
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/classes/Vehicle.java
@@ -0,0 +1,15 @@
+package com.baeldung.sealed.classes;
+
+public abstract sealed class Vehicle permits Car, Truck {
+
+ protected final String registrationNumber;
+
+ public Vehicle(String registrationNumber) {
+ this.registrationNumber = registrationNumber;
+ }
+
+ public String getRegistrationNumber() {
+ return registrationNumber;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java
new file mode 100644
index 0000000000..74b6ed1405
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Car.java
@@ -0,0 +1,14 @@
+package com.baeldung.sealed.records;
+
+public record Car(int numberOfSeats, String registrationNumber) implements Vehicle {
+
+ @Override
+ public String getRegistrationNumber() {
+ return registrationNumber;
+ }
+
+ public int getNumberOfSeats() {
+ return numberOfSeats;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java
new file mode 100644
index 0000000000..1b887ae014
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Truck.java
@@ -0,0 +1,14 @@
+package com.baeldung.sealed.records;
+
+public record Truck(int loadCapacity, String registrationNumber) implements Vehicle {
+
+ @Override
+ public String getRegistrationNumber() {
+ return registrationNumber;
+ }
+
+ public int getLoadCapacity() {
+ return loadCapacity;
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java
new file mode 100644
index 0000000000..c51f8e97c6
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/sealed/records/Vehicle.java
@@ -0,0 +1,7 @@
+package com.baeldung.sealed.records;
+
+public sealed interface Vehicle permits Car, Truck {
+
+ String getRegistrationNumber();
+
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java
new file mode 100644
index 0000000000..74cf5edf9c
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/records/Person.java
@@ -0,0 +1,15 @@
+package com.baeldung.whatsnew.records;
+
+/**
+ * Java record with a header indicating 2 fields.
+ */
+public record Person(String name, int age) {
+ /**
+ * Public constructor that does some basic validation.
+ */
+ public Person {
+ if (age < 0) {
+ throw new IllegalArgumentException("Age cannot be negative");
+ }
+ }
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java
new file mode 100644
index 0000000000..ec85c371b7
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Employee.java
@@ -0,0 +1,9 @@
+package com.baeldung.whatsnew.sealedclasses;
+
+import java.util.Date;
+
+public non-sealed class Employee extends Person {
+ public Date getHiredDate() {
+ return new Date();
+ }
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java
new file mode 100644
index 0000000000..79c50b057e
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Manager.java
@@ -0,0 +1,4 @@
+package com.baeldung.whatsnew.sealedclasses;
+
+public final class Manager extends Person {
+}
diff --git a/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java
new file mode 100644
index 0000000000..2a52bc1a73
--- /dev/null
+++ b/core-java-modules/core-java-15/src/main/java/com/baeldung/whatsnew/sealedclasses/Person.java
@@ -0,0 +1,21 @@
+package com.baeldung.whatsnew.sealedclasses;
+
+import java.util.Date;
+
+public sealed class Person permits Employee, Manager {
+ /**
+ * Demonstration of pattern matching for instanceof
+ *
+ * @param person A Person object
+ * @return
+ */
+ public static void patternMatchingDemo(Person person) {
+ if(person instanceof Employee employee) {
+ Date hiredDate = employee.getHiredDate();
+ }
+
+ if(person instanceof Employee employee && employee.getHiredDate() != null) {
+ Date hiredDate = employee.getHiredDate();
+ }
+ }
+}
diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
new file mode 100644
index 0000000000..b614981a43
--- /dev/null
+++ b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/classes/VehicleUnitTest.java
@@ -0,0 +1,76 @@
+package com.baeldung.sealed.classes;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.lang.constant.ClassDesc;
+
+public class VehicleUnitTest {
+
+ private static Vehicle car;
+ private static Vehicle truck;
+
+ @BeforeAll
+ public static void createInstances() {
+ car = new Car(5, "VZ500DA");
+ truck = new Truck(19000, "VZ600TA");
+ }
+
+ @Test
+ public void givenCar_whenUsingReflectionAPI_thenSuperClassIsSealed() {
+ Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
+ Assertions.assertThat(car.getClass().getSuperclass().isSealed()).isEqualTo(true);
+ Assertions.assertThat(car.getClass().getSuperclass().permittedSubclasses())
+ .contains(ClassDesc.of(car.getClass().getCanonicalName()));
+ }
+
+ @Test
+ public void givenTruck_whenUsingReflectionAPI_thenSuperClassIsSealed() {
+ Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
+ Assertions.assertThat(truck.getClass().getSuperclass().isSealed()).isEqualTo(true);
+ Assertions.assertThat(truck.getClass().getSuperclass().permittedSubclasses())
+ .contains(ClassDesc.of(truck.getClass().getCanonicalName()));
+ }
+
+ @Test
+ public void givenCar_whenGettingPropertyTraditionalWay_thenNumberOfSeatsPropertyIsReturned() {
+ Assertions.assertThat(getPropertyTraditionalWay(car)).isEqualTo(5);
+ }
+
+ @Test
+ public void givenCar_whenGettingPropertyViaPatternMatching_thenNumberOfSeatsPropertyIsReturned() {
+ Assertions.assertThat(getPropertyViaPatternMatching(car)).isEqualTo(5);
+ }
+
+ @Test
+ public void givenTruck_whenGettingPropertyTraditionalWay_thenLoadCapacityIsReturned() {
+ Assertions.assertThat(getPropertyTraditionalWay(truck)).isEqualTo(19000);
+ }
+
+ @Test
+ public void givenTruck_whenGettingPropertyViaPatternMatching_thenLoadCapacityIsReturned() {
+ Assertions.assertThat(getPropertyViaPatternMatching(truck)).isEqualTo(19000);
+ }
+
+ private int getPropertyTraditionalWay(Vehicle vehicle) {
+ if (vehicle instanceof Car) {
+ return ((Car) vehicle).getNumberOfSeats();
+ } else if (vehicle instanceof Truck) {
+ return ((Truck) vehicle).getLoadCapacity();
+ } else {
+ throw new RuntimeException("Unknown instance of Vehicle");
+ }
+ }
+
+ private int getPropertyViaPatternMatching(Vehicle vehicle) {
+ if (vehicle instanceof Car car) {
+ return car.getNumberOfSeats();
+ } else if (vehicle instanceof Truck truck) {
+ return truck.getLoadCapacity();
+ } else {
+ throw new RuntimeException("Unknown instance of Vehicle");
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java
new file mode 100644
index 0000000000..ac8a8c953c
--- /dev/null
+++ b/core-java-modules/core-java-15/src/test/java/com/baeldung/sealed/records/VehicleUnitTest.java
@@ -0,0 +1,76 @@
+package com.baeldung.sealed.records;
+
+import org.assertj.core.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.lang.constant.ClassDesc;
+
+public class VehicleUnitTest {
+
+ private static Vehicle car;
+ private static Vehicle truck;
+
+ @BeforeAll
+ public static void createInstances() {
+ car = new Car(4, "VZ500DA");
+ truck = new Truck(16000, "VZ600TA");
+ }
+
+ @Test
+ public void givenCar_whenUsingReflectionAPI_thenInterfaceIsSealed() {
+ Assertions.assertThat(car.getClass().isSealed()).isEqualTo(false);
+ Assertions.assertThat(car.getClass().getInterfaces()[0].isSealed()).isEqualTo(true);
+ Assertions.assertThat(car.getClass().getInterfaces()[0].permittedSubclasses())
+ .contains(ClassDesc.of(car.getClass().getCanonicalName()));
+ }
+
+ @Test
+ public void givenTruck_whenUsingReflectionAPI_thenInterfaceIsSealed() {
+ Assertions.assertThat(truck.getClass().isSealed()).isEqualTo(false);
+ Assertions.assertThat(truck.getClass().getInterfaces()[0].isSealed()).isEqualTo(true);
+ Assertions.assertThat(truck.getClass().getInterfaces()[0].permittedSubclasses())
+ .contains(ClassDesc.of(truck.getClass().getCanonicalName()));
+ }
+
+ @Test
+ public void givenCar_whenGettingPropertyTraditionalWay_thenNumberOfSeatsPropertyIsReturned() {
+ Assertions.assertThat(getPropertyTraditionalWay(car)).isEqualTo(4);
+ }
+
+ @Test
+ public void givenCar_whenGettingPropertyViaPatternMatching_thenNumberOfSeatsPropertyIsReturned() {
+ Assertions.assertThat(getPropertyViaPatternMatching(car)).isEqualTo(4);
+ }
+
+ @Test
+ public void givenTruck_whenGettingPropertyTraditionalWay_thenLoadCapacityIsReturned() {
+ Assertions.assertThat(getPropertyTraditionalWay(truck)).isEqualTo(16000);
+ }
+
+ @Test
+ public void givenTruck_whenGettingPropertyViaPatternMatching_thenLoadCapacityIsReturned() {
+ Assertions.assertThat(getPropertyViaPatternMatching(truck)).isEqualTo(16000);
+ }
+
+ private int getPropertyTraditionalWay(Vehicle vehicle) {
+ if (vehicle instanceof Car) {
+ return ((Car) vehicle).getNumberOfSeats();
+ } else if (vehicle instanceof Truck) {
+ return ((Truck) vehicle).getLoadCapacity();
+ } else {
+ throw new RuntimeException("Unknown instance of Vehicle");
+ }
+ }
+
+ private int getPropertyViaPatternMatching(Vehicle vehicle) {
+ if (vehicle instanceof Car car) {
+ return car.getNumberOfSeats();
+ } else if (vehicle instanceof Truck truck) {
+ return truck.getLoadCapacity();
+ } else {
+ throw new RuntimeException("Unknown instance of Vehicle");
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java
index 797e0b954a..8ca0066a0d 100644
--- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java
+++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseDateTimeFormatterUnitTest.java
@@ -31,6 +31,6 @@ public class UseDateTimeFormatterUnitTest {
public void givenALocalDate_whenFormattingWithStyleAndLocale_thenPass() {
String result = subject.formatWithStyleAndLocale(localDateTime, FormatStyle.MEDIUM, Locale.UK);
- assertThat(result).isEqualTo("25 Jan 2015, 06:30:00");
+ assertThat(result).isEqualTo("25-Jan-2015 06:30:00");
}
}
\ No newline at end of file
diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java
index 78d9a647fe..cb6e804284 100644
--- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java
+++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseToInstantUnitTest.java
@@ -3,6 +3,7 @@ package com.baeldung.datetime;
import static org.assertj.core.api.Assertions.assertThat;
import java.time.LocalDateTime;
+import java.time.ZoneId;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -24,10 +25,11 @@ public class UseToInstantUnitTest {
@Test
public void givenADate_whenConvertingToLocalDate_thenAsExpected() {
- Date givenDate = new Date(1465817690000L);
+ LocalDateTime currentDateTime = LocalDateTime.now();
+ Date givenDate = Date.from(currentDateTime.atZone(ZoneId.systemDefault()).toInstant());
LocalDateTime localDateTime = subject.convertDateToLocalDate(givenDate);
- assertThat(localDateTime).isEqualTo("2016-06-13T13:34:50");
+ assertThat(localDateTime).isEqualTo(currentDateTime);
}
}
\ No newline at end of file
diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java
index 4a39f6056e..0ee0f72d78 100644
--- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java
+++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/datetime/UseZonedDateTimeUnitTest.java
@@ -54,7 +54,7 @@ public class UseZonedDateTimeUnitTest {
@Test
public void givenAStringWithTimeZone_whenParsing_thenEqualsExpected() {
ZonedDateTime resultFromString = zonedDateTime.getZonedDateTimeUsingParseMethod("2015-05-03T10:15:30+01:00[Europe/Paris]");
- ZonedDateTime resultFromLocalDateTime = ZonedDateTime.of(2015, 5, 3, 11, 15, 30, 0, ZoneId.of("Europe/Paris"));
+ ZonedDateTime resultFromLocalDateTime = ZonedDateTime.of(2015, 5, 3, 10, 15, 30, 0, ZoneId.of("Europe/Paris"));
assertThat(resultFromString.getZone()).isEqualTo(ZoneId.of("Europe/Paris"));
assertThat(resultFromLocalDateTime.getZone()).isEqualTo(ZoneId.of("Europe/Paris"));
diff --git a/core-java-modules/core-java-9-jigsaw/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java b/core-java-modules/core-java-9-jigsaw/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java
index 2519da085b..617a0a7e70 100644
--- a/core-java-modules/core-java-9-jigsaw/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java
+++ b/core-java-modules/core-java-9-jigsaw/src/modules/com.baeldung.student.service.dbimpl/com/baeldung/student/service/dbimpl/StudentDbService.java
@@ -19,12 +19,12 @@ public class StudentDbService implements StudentService {
}
public Student update(Student student) {
- logger.log(Level.INFO, "Updating sutdent in DB...");
+ logger.log(Level.INFO, "Updating student in DB...");
return student;
}
public String delete(String registrationId) {
- logger.log(Level.INFO, "Deleteing sutdent in DB...");
+ logger.log(Level.INFO, "Deleting student in DB...");
return registrationId;
}
}
\ No newline at end of file
diff --git a/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java b/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java
index aa2fb34753..b909636b56 100644
--- a/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java
+++ b/core-java-modules/core-java-9-jigsaw/src/test/java/com/baeldung/java9/modules/ModuleAPIUnitTest.java
@@ -2,8 +2,7 @@ package com.baeldung.java9.modules;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.hamcrest.Matchers.*;
import static org.hamcrest.collection.IsEmptyCollection.empty;
import static org.junit.Assert.*;
@@ -74,7 +73,6 @@ public class ModuleAPIUnitTest {
ModuleLayer javaBaseModuleLayer = javaBaseModule.getLayer();
assertTrue(javaBaseModuleLayer.configuration().findModule(JAVA_BASE_MODULE_NAME).isPresent());
- assertThat(javaBaseModuleLayer.configuration().modules().size(), is(78));
assertTrue(javaBaseModuleLayer.parents().get(0).configuration().parents().isEmpty());
}
@@ -108,8 +106,7 @@ public class ModuleAPIUnitTest {
.collect(Collectors.toSet());
assertThat(javaBaseRequires, empty());
- assertThat(javaSqlRequires.size(), is(3));
- assertThat(javaSqlRequiresNames, containsInAnyOrder("java.base", "java.xml", "java.logging"));
+ assertThat(javaSqlRequiresNames, hasItems("java.base", "java.xml", "java.logging"));
}
@Test
@@ -127,16 +124,13 @@ public class ModuleAPIUnitTest {
@Test
public void givenModules_whenAccessingModuleDescriptorExports_thenExportsAreReturned() {
- Set javaBaseExports = javaBaseModule.getDescriptor().exports();
Set javaSqlExports = javaSqlModule.getDescriptor().exports();
Set javaSqlExportsSource = javaSqlExports.stream()
.map(Exports::source)
.collect(Collectors.toSet());
- assertThat(javaBaseExports.size(), is(108));
- assertThat(javaSqlExports.size(), is(3));
- assertThat(javaSqlExportsSource, containsInAnyOrder("java.sql", "javax.transaction.xa", "javax.sql"));
+ assertThat(javaSqlExportsSource, hasItems("java.sql", "javax.sql"));
}
@Test
@@ -144,7 +138,6 @@ public class ModuleAPIUnitTest {
Set javaBaseUses = javaBaseModule.getDescriptor().uses();
Set javaSqlUses = javaSqlModule.getDescriptor().uses();
- assertThat(javaBaseUses.size(), is(34));
assertThat(javaSqlUses, contains("java.sql.Driver"));
}
diff --git a/core-java-modules/core-java-9-new-features/README.md b/core-java-modules/core-java-9-new-features/README.md
index c2ef63a530..4045a37d9d 100644
--- a/core-java-modules/core-java-9-new-features/README.md
+++ b/core-java-modules/core-java-9-new-features/README.md
@@ -4,7 +4,7 @@ This module contains articles about core Java features that have been introduced
### Relevant Articles:
-- [Java 9 New Features](https://www.baeldung.com/new-java-9)
+- [New Features in Java 9](https://www.baeldung.com/new-java-9)
- [Java 9 Variable Handles Demystified](http://www.baeldung.com/java-variable-handles)
- [Exploring the New HTTP Client in Java 9 and 11](http://www.baeldung.com/java-9-http-client)
- [Multi-Release Jar Files](https://www.baeldung.com/java-multi-release-jar)
@@ -13,3 +13,5 @@ This module contains articles about core Java features that have been introduced
- [Java 9 Platform Logging API](https://www.baeldung.com/java-9-logging-api)
- [Java 9 Reactive Streams](https://www.baeldung.com/java-9-reactive-streams)
- [Multi-Release JAR Files with Maven](https://www.baeldung.com/maven-multi-release-jars)
+- [The Difference between RxJava API and the Java 9 Flow API](https://www.baeldung.com/rxjava-vs-java-flow-api)
+- [How to Get a Name of a Method Being Executed?](https://www.baeldung.com/java-name-of-executing-method)
diff --git a/core-java-modules/core-java-9/README.md b/core-java-modules/core-java-9/README.md
index 0a9bf76ac4..cab02369cc 100644
--- a/core-java-modules/core-java-9/README.md
+++ b/core-java-modules/core-java-9/README.md
@@ -9,3 +9,4 @@ This module contains articles about Java 9 core features
- [Iterate Through a Range of Dates in Java](https://www.baeldung.com/java-iterate-date-range)
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
- [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list)
+- [Easy Ways to Write a Java InputStream to an OutputStream](https://www.baeldung.com/java-inputstream-to-outputstream)
diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml
index 0669d6f597..001faf88cb 100644
--- a/core-java-modules/core-java-9/pom.xml
+++ b/core-java-modules/core-java-9/pom.xml
@@ -44,6 +44,16 @@
commons-collections4${commons-collections4.version}
+
+ org.apache.commons
+ commons-lang3
+ ${commons-lang3.version}
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
@@ -77,6 +87,7 @@
1.925.1-jre4.1
+ 3.2.2
diff --git a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java
deleted file mode 100644
index 7646755358..0000000000
--- a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesTest.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package com.baeldung.java9.methodhandles;
-
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.*;
-
-import java.lang.invoke.MethodHandle;
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.MethodType;
-import java.lang.invoke.WrongMethodTypeException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.List;
-
-import org.junit.Test;
-
-/**
- * Test case for the {@link MethodHandles} API
- */
-public class MethodHandlesTest {
-
- @Test
- public void givenConcatMethodHandle_whenInvoked_thenCorrectlyConcatenated() throws Throwable {
-
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(String.class, String.class);
- MethodHandle concatMH = publicLookup.findVirtual(String.class, "concat", mt);
-
- String output = (String) concatMH.invoke("Effective ", "Java");
-
- assertEquals("Effective Java", output);
- }
-
- @Test
- public void givenAsListMethodHandle_whenInvokingWithArguments_thenCorrectlyInvoked() throws Throwable {
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(List.class, Object[].class);
- MethodHandle asListMH = publicLookup.findStatic(Arrays.class, "asList", mt);
-
- List list = (List) asListMH.invokeWithArguments(1, 2);
-
- assertThat(Arrays.asList(1, 2), is(list));
- }
-
- @Test
- public void givenConstructorMethodHandle_whenInvoked_thenObjectCreatedCorrectly() throws Throwable {
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(void.class, String.class);
- MethodHandle newIntegerMH = publicLookup.findConstructor(Integer.class, mt);
-
- Integer integer = (Integer) newIntegerMH.invoke("1");
-
- assertEquals(1, integer.intValue());
- }
-
- @Test
- public void givenAFieldWithoutGetter_whenCreatingAGetter_thenCorrectlyInvoked() throws Throwable {
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- MethodHandle getTitleMH = lookup.findGetter(Book.class, "title", String.class);
-
- Book book = new Book("ISBN-1234", "Effective Java");
-
- assertEquals("Effective Java", getTitleMH.invoke(book));
- }
-
- @Test
- public void givenPrivateMethod_whenCreatingItsMethodHandle_thenCorrectlyInvoked() throws Throwable {
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- Method formatBookMethod = Book.class.getDeclaredMethod("formatBook");
- formatBookMethod.setAccessible(true);
-
- MethodHandle formatBookMH = lookup.unreflect(formatBookMethod);
-
- Book book = new Book("ISBN-123", "Java in Action");
-
- assertEquals("ISBN-123 > Java in Action", formatBookMH.invoke(book));
- }
-
- @Test
- public void givenReplaceMethod_whenUsingReflectionAndInvoked_thenCorrectlyReplaced() throws Throwable {
- Method replaceMethod = String.class.getMethod("replace", char.class, char.class);
-
- String string = (String) replaceMethod.invoke("jovo", 'o', 'a');
-
- assertEquals("java", string);
- }
-
- @Test
- public void givenReplaceMethodHandle_whenInvoked_thenCorrectlyReplaced() throws Throwable {
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(String.class, char.class, char.class);
- MethodHandle replaceMH = publicLookup.findVirtual(String.class, "replace", mt);
-
- String replacedString = (String) replaceMH.invoke("jovo", Character.valueOf('o'), 'a');
-
- assertEquals("java", replacedString);
- }
-
- @Test
- public void givenReplaceMethodHandle_whenInvokingExact_thenCorrectlyReplaced() throws Throwable {
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- MethodType mt = MethodType.methodType(String.class, char.class, char.class);
- MethodHandle replaceMH = lookup.findVirtual(String.class, "replace", mt);
-
- String s = (String) replaceMH.invokeExact("jovo", 'o', 'a');
-
- assertEquals("java", s);
- }
-
- @Test
- public void givenSumMethodHandle_whenInvokingExact_thenSumIsCorrect() throws Throwable {
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- MethodType mt = MethodType.methodType(int.class, int.class, int.class);
- MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt);
-
- int sum = (int) sumMH.invokeExact(1, 11);
-
- assertEquals(12, sum);
- }
-
- @Test(expected = WrongMethodTypeException.class)
- public void givenSumMethodHandleAndIncompatibleArguments_whenInvokingExact_thenException() throws Throwable {
- MethodHandles.Lookup lookup = MethodHandles.lookup();
- MethodType mt = MethodType.methodType(int.class, int.class, int.class);
- MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt);
-
- sumMH.invokeExact(Integer.valueOf(1), 11);
- }
-
- @Test
- public void givenSpreadedEqualsMethodHandle_whenInvokedOnArray_thenCorrectlyEvaluated() throws Throwable {
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(boolean.class, Object.class);
- MethodHandle equalsMH = publicLookup.findVirtual(String.class, "equals", mt);
-
- MethodHandle methodHandle = equalsMH.asSpreader(Object[].class, 2);
-
- assertTrue((boolean) methodHandle.invoke(new Object[] { "java", "java" }));
- assertFalse((boolean) methodHandle.invoke(new Object[] { "java", "jova" }));
- }
-
- @Test
- public void givenConcatMethodHandle_whenBindToAString_thenCorrectlyConcatenated() throws Throwable {
- MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
- MethodType mt = MethodType.methodType(String.class, String.class);
- MethodHandle concatMH = publicLookup.findVirtual(String.class, "concat", mt);
-
- MethodHandle bindedConcatMH = concatMH.bindTo("Hello ");
-
- assertEquals("Hello World!", bindedConcatMH.invoke("World!"));
- }
-}
diff --git a/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java
new file mode 100644
index 0000000000..7aa74a490f
--- /dev/null
+++ b/core-java-modules/core-java-9/src/test/java/com/baeldung/java9/methodhandles/MethodHandlesUnitTest.java
@@ -0,0 +1,152 @@
+package com.baeldung.java9.methodhandles;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
+
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.WrongMethodTypeException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.Test;
+
+/**
+ * Test case for the {@link MethodHandles} API
+ */
+public class MethodHandlesUnitTest {
+
+ @Test
+ public void givenConcatMethodHandle_whenInvoked_thenCorrectlyConcatenated() throws Throwable {
+
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(String.class, String.class);
+ MethodHandle concatMH = publicLookup.findVirtual(String.class, "concat", mt);
+
+ String output = (String) concatMH.invoke("Effective ", "Java");
+
+ assertEquals("Effective Java", output);
+ }
+
+ @Test
+ public void givenAsListMethodHandle_whenInvokingWithArguments_thenCorrectlyInvoked() throws Throwable {
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(List.class, Object[].class);
+ MethodHandle asListMH = publicLookup.findStatic(Arrays.class, "asList", mt);
+
+ List list = (List) asListMH.invokeWithArguments(1, 2);
+
+ assertThat(Arrays.asList(1, 2), is(list));
+ }
+
+ @Test
+ public void givenConstructorMethodHandle_whenInvoked_thenObjectCreatedCorrectly() throws Throwable {
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(void.class, String.class);
+ MethodHandle newIntegerMH = publicLookup.findConstructor(Integer.class, mt);
+
+ Integer integer = (Integer) newIntegerMH.invoke("1");
+
+ assertEquals(1, integer.intValue());
+ }
+
+ @Test
+ public void givenAFieldWithoutGetter_whenCreatingAGetter_thenCorrectlyInvoked() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodHandle getTitleMH = lookup.findGetter(Book.class, "title", String.class);
+
+ Book book = new Book("ISBN-1234", "Effective Java");
+
+ assertEquals("Effective Java", getTitleMH.invoke(book));
+ }
+
+ @Test
+ public void givenPrivateMethod_whenCreatingItsMethodHandle_thenCorrectlyInvoked() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ Method formatBookMethod = Book.class.getDeclaredMethod("formatBook");
+ formatBookMethod.setAccessible(true);
+
+ MethodHandle formatBookMH = lookup.unreflect(formatBookMethod);
+
+ Book book = new Book("ISBN-123", "Java in Action");
+
+ assertEquals("ISBN-123 > Java in Action", formatBookMH.invoke(book));
+ }
+
+ @Test
+ public void givenReplaceMethod_whenUsingReflectionAndInvoked_thenCorrectlyReplaced() throws Throwable {
+ Method replaceMethod = String.class.getMethod("replace", char.class, char.class);
+
+ String string = (String) replaceMethod.invoke("jovo", 'o', 'a');
+
+ assertEquals("java", string);
+ }
+
+ @Test
+ public void givenReplaceMethodHandle_whenInvoked_thenCorrectlyReplaced() throws Throwable {
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(String.class, char.class, char.class);
+ MethodHandle replaceMH = publicLookup.findVirtual(String.class, "replace", mt);
+
+ String replacedString = (String) replaceMH.invoke("jovo", Character.valueOf('o'), 'a');
+
+ assertEquals("java", replacedString);
+ }
+
+ @Test
+ public void givenReplaceMethodHandle_whenInvokingExact_thenCorrectlyReplaced() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodType mt = MethodType.methodType(String.class, char.class, char.class);
+ MethodHandle replaceMH = lookup.findVirtual(String.class, "replace", mt);
+
+ String s = (String) replaceMH.invokeExact("jovo", 'o', 'a');
+
+ assertEquals("java", s);
+ }
+
+ @Test
+ public void givenSumMethodHandle_whenInvokingExact_thenSumIsCorrect() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodType mt = MethodType.methodType(int.class, int.class, int.class);
+ MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt);
+
+ int sum = (int) sumMH.invokeExact(1, 11);
+
+ assertEquals(12, sum);
+ }
+
+ @Test(expected = WrongMethodTypeException.class)
+ public void givenSumMethodHandleAndIncompatibleArguments_whenInvokingExact_thenException() throws Throwable {
+ MethodHandles.Lookup lookup = MethodHandles.lookup();
+ MethodType mt = MethodType.methodType(int.class, int.class, int.class);
+ MethodHandle sumMH = lookup.findStatic(Integer.class, "sum", mt);
+
+ sumMH.invokeExact(Integer.valueOf(1), 11);
+ }
+
+ @Test
+ public void givenSpreadedEqualsMethodHandle_whenInvokedOnArray_thenCorrectlyEvaluated() throws Throwable {
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(boolean.class, Object.class);
+ MethodHandle equalsMH = publicLookup.findVirtual(String.class, "equals", mt);
+
+ MethodHandle methodHandle = equalsMH.asSpreader(Object[].class, 2);
+
+ assertTrue((boolean) methodHandle.invoke(new Object[] { "java", "java" }));
+ assertFalse((boolean) methodHandle.invoke(new Object[] { "java", "jova" }));
+ }
+
+ @Test
+ public void givenConcatMethodHandle_whenBindToAString_thenCorrectlyConcatenated() throws Throwable {
+ MethodHandles.Lookup publicLookup = MethodHandles.publicLookup();
+ MethodType mt = MethodType.methodType(String.class, String.class);
+ MethodHandle concatMH = publicLookup.findVirtual(String.class, "concat", mt);
+
+ MethodHandle bindedConcatMH = concatMH.bindTo("Hello ");
+
+ assertEquals("Hello World!", bindedConcatMH.invoke("World!"));
+ }
+}
diff --git a/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/AnnotatedClass.java b/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/AnnotatedClass.java
new file mode 100644
index 0000000000..d5d9c88388
--- /dev/null
+++ b/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/AnnotatedClass.java
@@ -0,0 +1,8 @@
+package com.baeldung.annotations;
+
+import javax.annotation.Generated;
+
+@RetentionAnnotation
+@Generated("Available only on source code")
+public class AnnotatedClass {
+}
diff --git a/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/RetentionAnnotation.java b/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/RetentionAnnotation.java
new file mode 100644
index 0000000000..4591334dde
--- /dev/null
+++ b/core-java-modules/core-java-annotations/src/main/java/com/baeldung/annotations/RetentionAnnotation.java
@@ -0,0 +1,12 @@
+package com.baeldung.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.TYPE;
+
+@Target(TYPE)
+@Retention(RetentionPolicy.RUNTIME)
+public @interface RetentionAnnotation {
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-annotations/src/test/java/com/baeldung/annotations/AnnotatedClassUnitTest.java b/core-java-modules/core-java-annotations/src/test/java/com/baeldung/annotations/AnnotatedClassUnitTest.java
new file mode 100644
index 0000000000..9bf0b78cbb
--- /dev/null
+++ b/core-java-modules/core-java-annotations/src/test/java/com/baeldung/annotations/AnnotatedClassUnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.annotations;
+
+import org.junit.Test;
+
+import java.lang.annotation.Annotation;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+public class AnnotatedClassUnitTest {
+
+ @Test
+ public void whenAnnotationRetentionPolicyRuntime_shouldAccess() {
+ AnnotatedClass anAnnotatedClass = new AnnotatedClass();
+ Annotation[] annotations = anAnnotatedClass.getClass().getAnnotations();
+ assertThat(annotations.length, is(1));
+ }
+}
diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md
index 56c0c716d8..7338ff9523 100644
--- a/core-java-modules/core-java-arrays-guides/README.md
+++ b/core-java-modules/core-java-arrays-guides/README.md
@@ -5,4 +5,6 @@ This module contains complete guides about arrays in Java
### Relevant Articles:
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
- [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays)
-- [What is [Ljava.lang.Object;?]](https://www.baeldung.com/java-tostring-array)
+- [What is \[Ljava.lang.Object;?](https://www.baeldung.com/java-tostring-array)
+- [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception)
+- [Creating a Generic Array in Java](https://www.baeldung.com/java-generic-array)
diff --git a/core-java-modules/core-java-arrays-guides/pom.xml b/core-java-modules/core-java-arrays-guides/pom.xml
index df8639820d..a7c996cf7e 100644
--- a/core-java-modules/core-java-arrays-guides/pom.xml
+++ b/core-java-modules/core-java-arrays-guides/pom.xml
@@ -17,16 +17,18 @@
org.openjdk.jmhjmh-core
- ${jmh.version}
+ ${jmh-core.version}org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}
+
+
+ org.assertj
+ assertj-core
+ 3.19.0
+ test
-
-
- 1.19
-
\ No newline at end of file
diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java
new file mode 100644
index 0000000000..7c81142949
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExampleCE.java
@@ -0,0 +1,11 @@
+package com.baeldung.array.arraystoreexception;
+
+public class ArrayStoreExampleCE {
+
+ public static void main(String[] args) {
+
+ //String array[] = new String[5]; //This will lead to compile-time error at line-8 when uncommented
+ //array[0] = 2;
+ }
+
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java
new file mode 100644
index 0000000000..ce63fd6605
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/array/arraystoreexception/ArrayStoreExceptionExample.java
@@ -0,0 +1,16 @@
+package com.baeldung.array.arraystoreexception;
+
+public class ArrayStoreExceptionExample {
+
+ public static void main(String[] args) {
+
+ try {
+ Object array[] = new String[5];
+ array[0] = 2;
+ } catch (ArrayStoreException e) {
+ // handle the exception
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java
new file mode 100644
index 0000000000..02659f13bc
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/main/java/com/baeldung/genericarrays/MyStack.java
@@ -0,0 +1,30 @@
+package com.baeldung.genericarrays;
+
+import java.lang.reflect.Array;
+
+public class MyStack {
+ private E[] elements;
+ private int size = 0;
+
+ public MyStack(Class clazz, int capacity) {
+ elements = (E[]) Array.newInstance(clazz, capacity);
+ }
+
+ public void push(E item) {
+ if (size == elements.length) {
+ throw new RuntimeException();
+ }
+ elements[size++] = item;
+ }
+
+ public E pop() {
+ if (size == 0) {
+ throw new RuntimeException();
+ }
+ return elements[--size];
+ }
+
+ public E[] getAllElements() {
+ return elements;
+ }
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java
new file mode 100644
index 0000000000..df7e0566ed
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/ListToArrayUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.genericarrays;
+
+import org.junit.Test;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+
+public class ListToArrayUnitTest {
+
+ @Test
+ public void givenListOfItems_whenToArray_thenReturnArrayOfItems() {
+ List items = new LinkedList<>();
+ items.add("first item");
+ items.add("second item");
+
+ String[] itemsAsArray = items.toArray(new String[0]);
+
+ assertEquals("first item", itemsAsArray[0]);
+ assertEquals("second item", itemsAsArray[1]);
+ }
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java
new file mode 100644
index 0000000000..e36c5169a5
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/MyStackUnitTest.java
@@ -0,0 +1,44 @@
+package com.baeldung.genericarrays;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class MyStackUnitTest {
+
+ @Test
+ public void givenStackWithTwoItems_whenPop_thenReturnLastAdded() {
+ MyStack myStack = new MyStack<>(String.class, 2);
+ myStack.push("hello");
+ myStack.push("example");
+
+ assertEquals("example", myStack.pop());
+ }
+
+ @Test (expected = RuntimeException.class)
+ public void givenStackWithFixedCapacity_whenExceedCapacity_thenThrowException() {
+ MyStack myStack = new MyStack<>(Integer.class, 2);
+ myStack.push(100);
+ myStack.push(200);
+ myStack.push(300);
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void givenStack_whenPopOnEmptyStack_thenThrowException() {
+ MyStack myStack = new MyStack<>(Integer.class, 1);
+ myStack.push(100);
+ myStack.pop();
+ myStack.pop();
+ }
+
+ @Test
+ public void givenStackWithItems_whenGetAllElements_thenSizeShouldEqualTotal() {
+ MyStack myStack = new MyStack<>(String.class, 2);
+ myStack.push("hello");
+ myStack.push("example");
+
+ String[] items = myStack.getAllElements();
+
+ assertEquals(2, items.length);
+ }
+}
diff --git a/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/StreamToArrayUnitTest.java b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/StreamToArrayUnitTest.java
new file mode 100644
index 0000000000..5dea901b25
--- /dev/null
+++ b/core-java-modules/core-java-arrays-guides/src/test/java/com/baeldung/genericarrays/StreamToArrayUnitTest.java
@@ -0,0 +1,77 @@
+package com.baeldung.genericarrays;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.IntFunction;
+import java.util.stream.Stream;
+
+import static java.util.Collections.singletonList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+public class StreamToArrayUnitTest {
+
+ @Test
+ public void givenAStream_thenCanGetArrayOfObject() {
+ Object[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
+ .filter(string -> string.startsWith("A"))
+ .toArray();
+
+ assertThat(strings).containsExactly("A", "AAA", "AAB");
+ assertThat(strings).isNotInstanceOf(String[].class);
+ }
+
+ @Test
+ public void givenAStream_thenCanGetArrayOfString() {
+ String[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
+ .filter(string -> string.startsWith("A"))
+ .toArray(String[]::new);
+
+ assertThat(strings).containsExactly("A", "AAA", "AAB");
+ assertThat(strings).isInstanceOf(String[].class);
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void givenAStream_whenConvertToOptional_thenCanGetArrayOfOptional() {
+ Stream> stream = Stream.of("A", "AAA", "B", "AAB", "C")
+ .filter(string -> string.startsWith("A"))
+ .map(Optional::of);
+ Optional[] strings = stream
+ .toArray(Optional[]::new);
+
+ assertThat(strings).containsExactly(Optional.of("A"),
+ Optional.of("AAA"),
+ Optional.of("AAB"));
+ assertThat(strings).isInstanceOf(Optional[].class);
+ }
+
+ @Test
+ public void givenAStream_whenConvertToOptional_thenCanGetArrayOfOptionalWithHelper() {
+ Optional[] strings = Stream.of("A", "AAA", "B", "AAB", "C")
+ .filter(string -> string.startsWith("A"))
+ .map(Optional::of)
+ .toArray(genericArray(Optional[]::new));
+
+ assertThat(strings).containsExactly(Optional.of("A"),
+ Optional.of("AAA"),
+ Optional.of("AAB"));
+ assertThat(strings).isInstanceOf(Optional[].class);
+ }
+
+ @Test
+ public void whenInvalidUseOfGenericArray_thenIllegalCast() {
+ assertThatThrownBy(() -> {
+ ArrayList[] lists = Stream.of(singletonList("A"))
+ .toArray(genericArray(List[]::new));
+ }).isInstanceOf(ClassCastException.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ private static IntFunction genericArray(IntFunction arrayCreator) {
+ return size -> (R[])arrayCreator.apply(size);
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-advanced/README.md b/core-java-modules/core-java-arrays-operations-advanced/README.md
index af0c00641a..c8ec3e74bc 100644
--- a/core-java-modules/core-java-arrays-operations-advanced/README.md
+++ b/core-java-modules/core-java-arrays-operations-advanced/README.md
@@ -3,7 +3,9 @@
This module contains articles about advanced operations on arrays in Java. They assume some background knowledge with arrays in Java.
### Relevant Articles:
+
- [How to Copy an Array in Java](https://www.baeldung.com/java-array-copy)
- [Arrays.deepEquals](https://www.baeldung.com/java-arrays-deepequals)
- [Find Sum and Average in a Java Array](https://www.baeldung.com/java-array-sum-average)
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)
+- [Comparing Arrays in Java](https://www.baeldung.com/java-comparing-arrays)
diff --git a/core-java-modules/core-java-arrays-operations-advanced/pom.xml b/core-java-modules/core-java-arrays-operations-advanced/pom.xml
index d73fdcee28..c7ea09c616 100644
--- a/core-java-modules/core-java-arrays-operations-advanced/pom.xml
+++ b/core-java-modules/core-java-arrays-operations-advanced/pom.xml
@@ -29,8 +29,6 @@
- 3.9
-
3.10.0
\ No newline at end of file
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java
new file mode 100644
index 0000000000..1731578b76
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/main/java/com/baeldung/arraycompare/Plane.java
@@ -0,0 +1,39 @@
+package com.baeldung.arraycompare;
+
+import java.util.Objects;
+
+public class Plane {
+
+ private final String name;
+
+ private final String model;
+
+ public Plane(String name, String model) {
+
+ this.name = name;
+ this.model = model;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getModel() {
+ return model;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Plane plane = (Plane) o;
+ return Objects.equals(name, plane.name) && Objects.equals(model, plane.model);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(name, model);
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java
new file mode 100644
index 0000000000..c8ebafb26b
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/DeepEqualsCompareUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.arraycompare;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DeepEqualsCompareUnitTest {
+
+ @Test
+ public void givenSameContents_whenDeepEquals_thenTrue() {
+ final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") },
+ new Plane[] { new Plane("Plane 2", "B738") } };
+ final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") },
+ new Plane[] { new Plane("Plane 2", "B738") } };
+
+ assertThat(Arrays.deepEquals(planes1, planes2)).isTrue();
+ }
+
+ @Test
+ public void givenSameContentsWithDifferentOrder_whenDeepEquals_thenFalse() {
+ final Plane[][] planes1 = new Plane[][] { new Plane[] { new Plane("Plane 1", "A320") },
+ new Plane[] { new Plane("Plane 2", "B738") } };
+ final Plane[][] planes2 = new Plane[][] { new Plane[] { new Plane("Plane 2", "B738") },
+ new Plane[] { new Plane("Plane 1", "A320") } };
+
+ assertThat(Arrays.deepEquals(planes1, planes2)).isFalse();
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java
new file mode 100644
index 0000000000..a022bf7082
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/EqualsCompareUnitTest.java
@@ -0,0 +1,26 @@
+package com.baeldung.arraycompare;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class EqualsCompareUnitTest {
+
+ @Test
+ public void givenSameContents_whenEquals_thenTrue() {
+ final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+ final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+
+ assertThat(Arrays.equals(planes1, planes2)).isTrue();
+ }
+
+ @Test
+ public void givenSameContentsDifferentOrder_whenEquals_thenFalse() {
+ final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+ final String[] planes2 = new String[] { "B738", "A320", "A321", "A319", "B77W", "B737", "A333", "A332" };
+
+ assertThat(Arrays.equals(planes1, planes2)).isFalse();
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java
new file mode 100644
index 0000000000..23187b827c
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/LengthsCompareUnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.arraycompare;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LengthsCompareUnitTest {
+
+ @Test
+ public void givenSameContent_whenSizeCompare_thenTrue() {
+ final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+ final Integer[] quantities = new Integer[] { 10, 12, 34, 45, 12, 43, 5, 2 };
+
+ assertThat(planes1).hasSize(8);
+ assertThat(quantities).hasSize(8);
+ }
+}
+
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java
new file mode 100644
index 0000000000..4dd7964020
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/OrderCompareUnitTest.java
@@ -0,0 +1,33 @@
+package com.baeldung.arraycompare;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Comparator;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertTrue;
+
+public class OrderCompareUnitTest {
+ @Test
+ public void givenSameContentDifferentOrder_whenSortedAndDeepEquals_thenTrue() {
+ final Plane[][] planes1 = new Plane[][] {
+ new Plane[] { new Plane("Plane 1", "A320"), new Plane("Plane 2", "B738") } };
+ final Plane[][] planes2 = new Plane[][] {
+ new Plane[] { new Plane("Plane 2", "B738"), new Plane("Plane 1", "A320") } };
+
+ Comparator planeComparator = (o1, o2) -> {
+ if (o1.getName()
+ .equals(o2.getName())) {
+ return o2.getModel()
+ .compareTo(o1.getModel());
+ }
+ return o2.getName()
+ .compareTo(o1.getName());
+ };
+ Arrays.sort(planes1[0], planeComparator);
+ Arrays.sort(planes2[0], planeComparator);
+
+ assertThat(Arrays.deepEquals(planes1, planes2)).isTrue();
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java
new file mode 100644
index 0000000000..d8072a98e3
--- /dev/null
+++ b/core-java-modules/core-java-arrays-operations-advanced/src/test/java/com/baeldung/arraycompare/ReferenceCompareUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.arraycompare;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ReferenceCompareUnitTest {
+
+ @Test
+ public void givenSameReferences_whenSame_thenTrue() {
+ final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+ final String[] planes2 = planes1;
+
+ assertThat(planes1).isSameAs(planes2);
+
+ planes2[0] = "747";
+
+ assertThat(planes1).isSameAs(planes2);
+ assertThat(planes2[0]).isEqualTo("747");
+ assertThat(planes1[0]).isEqualTo("747");
+ }
+
+ @Test
+ public void givenSameContentDifferentReferences_whenSame_thenFalse() {
+ final String[] planes1 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+ final String[] planes2 = new String[] { "A320", "B738", "A321", "A319", "B77W", "B737", "A333", "A332" };
+
+ assertThat(planes1).isNotSameAs(planes2);
+ }
+}
diff --git a/core-java-modules/core-java-arrays-operations-basic/pom.xml b/core-java-modules/core-java-arrays-operations-basic/pom.xml
index 64856d9b39..9157d9deb9 100644
--- a/core-java-modules/core-java-arrays-operations-basic/pom.xml
+++ b/core-java-modules/core-java-arrays-operations-basic/pom.xml
@@ -24,12 +24,12 @@
org.openjdk.jmhjmh-core
- ${jmh.version}
+ ${jmh-core.version}org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}
@@ -68,11 +68,6 @@
3.2.0
-
- 3.9
-
- 1.19
-
3.10.0
\ No newline at end of file
diff --git a/core-java-modules/core-java-arrays-sorting/pom.xml b/core-java-modules/core-java-arrays-sorting/pom.xml
index 9b307870a1..610582260b 100644
--- a/core-java-modules/core-java-arrays-sorting/pom.xml
+++ b/core-java-modules/core-java-arrays-sorting/pom.xml
@@ -31,12 +31,12 @@
org.openjdk.jmhjmh-core
- ${jmh.version}
+ ${jmh-core.version}org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}
@@ -76,12 +76,7 @@
3.2.0
-
- 3.928.2-jre
-
- 1.19
-
3.10.0
\ No newline at end of file
diff --git a/core-java-modules/core-java-char/README.md b/core-java-modules/core-java-char/README.md
new file mode 100644
index 0000000000..5f33aa6914
--- /dev/null
+++ b/core-java-modules/core-java-char/README.md
@@ -0,0 +1,6 @@
+## Core Java Character
+
+This module contains articles about Java Character Class
+
+### Relevant Articles:
+- [Character#isAlphabetic vs. Character#isLetter](https://www.baeldung.com/java-character-isletter-isalphabetic)
diff --git a/core-java-modules/core-java-char/pom.xml b/core-java-modules/core-java-char/pom.xml
new file mode 100644
index 0000000000..078a829e00
--- /dev/null
+++ b/core-java-modules/core-java-char/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+ core-java-char
+ 0.1.0-SNAPSHOT
+ core-java-char
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${jmh-core.version}
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${jmh-generator.version}
+
+
+
+
+ 3.11.1
+
+
+
diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java
new file mode 100644
index 0000000000..9fab13df45
--- /dev/null
+++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/CharacterGeneralCategoryTypeUnitTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.character;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+public class CharacterGeneralCategoryTypeUnitTest {
+ @Test
+ public void givenACharacter_whenUpperCaseLetter_thenAssertTrue() {
+ assertEquals(Character.UPPERCASE_LETTER, Character.getType('U'));
+ }
+
+ @Test
+ public void givenACharacter_whenLowerCaseLetter_thenAssertTrue() {
+ assertEquals(Character.LOWERCASE_LETTER, Character.getType('u'));
+ }
+
+ @Test
+ public void givenACharacter_whenTitleCaseLetter_thenAssertTrue() {
+ assertEquals(Character.TITLECASE_LETTER, Character.getType('\u01f2'));
+ }
+
+ @Test
+ public void givenACharacter_whenModifierLetter_thenAssertTrue() {
+ assertEquals(Character.MODIFIER_LETTER, Character.getType('\u02b0'));
+ }
+
+ @Test
+ public void givenACharacter_whenOtherLetter_thenAssertTrue() {
+ assertEquals(Character.OTHER_LETTER, Character.getType('\u05d0'));
+ }
+
+ @Test
+ public void givenACharacter_whenLetterNumber_thenAssertTrue() {
+ assertEquals(Character.LETTER_NUMBER, Character.getType('\u2164'));
+ }
+}
diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java
new file mode 100644
index 0000000000..3de3a16e6a
--- /dev/null
+++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/character/IsLetterOrAlphabetUnitTest.java
@@ -0,0 +1,49 @@
+package com.baeldung.character;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+
+public class IsLetterOrAlphabetUnitTest {
+
+ @Test
+ public void givenACharacter_whenUpperCaseLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic('A'));
+ }
+
+ @Test
+ public void givenACharacter_whenTitleCaseLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic('\u01f2'));
+ }
+
+ @Test
+ public void givenACharacter_whenLowerCaseLetter_thenAssertIsLetterTrue() {
+ assertTrue(Character.isAlphabetic('a'));
+ }
+
+ @Test
+ public void givenACharacter_whenModifierLetter_thenAssertIsLetterTrue() {
+ assertTrue(Character.isAlphabetic('\u02b0'));
+ }
+
+ @Test
+ public void givenACharacter_whenLetter_thenAssertIsLetterTrue() {
+ assertTrue(Character.isLetter('a'));
+ }
+
+ @Test
+ public void givenACharacter_whenLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic('a'));
+ }
+
+ @Test
+ public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsLetterFalse() {
+ assertFalse(Character.isLetter('\u2164'));
+ }
+
+ @Test
+ public void givenACharacter_whenAlphabeticAndNotLetter_thenAssertIsAlphabeticTrue() {
+ assertTrue(Character.isAlphabetic('\u2164'));
+ }
+}
diff --git a/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java b/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java
index 2505adcea7..d474e95cb2 100644
--- a/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java
+++ b/core-java-modules/core-java-collections-2/src/test/java/com/baeldung/collections/sorting/JavaSortingUnitTest.java
@@ -5,7 +5,16 @@ import org.apache.commons.lang3.ArrayUtils;
import org.junit.Before;
import org.junit.Test;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Map.Entry;
import static org.junit.Assert.assertTrue;
@@ -138,7 +147,7 @@ public class JavaSortingUnitTest {
HashSet descSortedIntegersSet = new LinkedHashSet<>(Arrays.asList(255, 200, 123, 89, 88, 66, 7, 5, 1));
ArrayList list = new ArrayList<>(integersSet);
- list.sort((i1, i2) -> i2 - i1);
+ list.sort(Comparator.reverseOrder());
integersSet = new LinkedHashSet<>(list);
assertTrue(Arrays.equals(integersSet.toArray(), descSortedIntegersSet.toArray()));
diff --git a/core-java-modules/core-java-collections-3/README.md b/core-java-modules/core-java-collections-3/README.md
index fb983d9abc..6bc9139856 100644
--- a/core-java-modules/core-java-collections-3/README.md
+++ b/core-java-modules/core-java-collections-3/README.md
@@ -3,6 +3,7 @@
## Core Java Collections Cookbooks and Examples
### Relevant Articles:
+
- [Time Comparison of Arrays.sort(Object[]) and Arrays.sort(int[])](https://www.baeldung.com/arrays-sortobject-vs-sortint)
- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector)
- [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences)
@@ -10,3 +11,7 @@
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
- [Fail-Safe Iterator vs Fail-Fast Iterator](https://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
- [Quick Guide to the Java Stack](https://www.baeldung.com/java-stack)
+- [Convert an Array of Primitives to a List](https://www.baeldung.com/java-primitive-array-to-list)
+- [A Guide to BitSet in Java](https://www.baeldung.com/java-bitset)
+- [Get the First Key and Value From a HashMap](https://www.baeldung.com/java-hashmap-get-first-entry)
+- [Performance of removeAll() in a HashSet](https://www.baeldung.com/java-hashset-removeall-performance)
diff --git a/core-java-modules/core-java-collections-3/pom.xml b/core-java-modules/core-java-collections-3/pom.xml
index b206cd61d2..aa04d1cb24 100644
--- a/core-java-modules/core-java-collections-3/pom.xml
+++ b/core-java-modules/core-java-collections-3/pom.xml
@@ -16,10 +16,15 @@
+
+ org.openjdk.jol
+ jol-core
+ ${jol-core.version}
+ org.openjdk.jmhjmh-core
- ${openjdk.jmh.version}
+ ${jmh-core.version}org.assertj
@@ -30,13 +35,13 @@
org.apache.commonscommons-lang3
- 3.10
+ ${commons-lang3.version}
- 1.193.11.1
+ 0.10
diff --git a/core-java-modules/core-java-collections-3/src/main/java/com/baeldung/collections/removeallperformance/HashSetBenchmark.java b/core-java-modules/core-java-collections-3/src/main/java/com/baeldung/collections/removeallperformance/HashSetBenchmark.java
new file mode 100644
index 0000000000..8f784de26d
--- /dev/null
+++ b/core-java-modules/core-java-collections-3/src/main/java/com/baeldung/collections/removeallperformance/HashSetBenchmark.java
@@ -0,0 +1,103 @@
+package com.baeldung.collections.removeallperformance;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.RandomStringUtils;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Level;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+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 com.baeldung.collections.containsperformance.Employee;
+
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Warmup(iterations = 5)
+public class HashSetBenchmark {
+
+ @State(Scope.Thread)
+ public static class MyState {
+ private Set employeeSet1 = new HashSet<>();
+ private List employeeList1 = new ArrayList<>();
+ private Set employeeSet2 = new HashSet<>();
+ private List employeeList2 = new ArrayList<>();
+ private Set employeeSet3 = new HashSet<>();
+ private Set employeeSet4 = new HashSet<>();
+
+ private long set1Size = 60000;
+ private long list1Size = 50000;
+ private long set2Size = 50000;
+ private long list2Size = 60000;
+ private long set3Size = 50000;
+ private long set4Size = 60000;
+
+ @Setup(Level.Trial)
+ public void setUp() {
+
+ for (long i = 0; i < set1Size; i++) {
+ employeeSet1.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ for (long i = 0; i < list1Size; i++) {
+ employeeList1.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ for (long i = 0; i < set2Size; i++) {
+ employeeSet2.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ for (long i = 0; i < list2Size; i++) {
+ employeeList2.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ for (long i = 0; i < set3Size; i++) {
+ employeeSet3.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ for (long i = 0; i < set4Size; i++) {
+ employeeSet4.add(new Employee(i, RandomStringUtils.random(7, true, false)));
+ }
+
+ }
+
+ }
+
+ @Benchmark
+ public boolean given_SizeOfHashsetGreaterThanSizeOfCollection_When_RemoveAllFromHashSet_Then_GoodPerformance(MyState state) {
+ return state.employeeSet1.removeAll(state.employeeList1);
+ }
+
+ @Benchmark
+ public boolean given_SizeOfHashsetSmallerThanSizeOfCollection_When_RemoveAllFromHashSet_Then_BadPerformance(MyState state) {
+ return state.employeeSet2.removeAll(state.employeeList2);
+ }
+
+ @Benchmark
+ public boolean given_SizeOfHashsetSmallerThanSizeOfAnotherHashSet_When_RemoveAllFromHashSet_Then_GoodPerformance(MyState state) {
+ return state.employeeSet3.removeAll(state.employeeSet4);
+ }
+
+ public static void main(String[] args) throws Exception {
+ Options options = new OptionsBuilder().include(HashSetBenchmark.class.getSimpleName())
+ .threads(1)
+ .forks(1)
+ .shouldFailOnError(true)
+ .shouldDoGC(true)
+ .jvmArgs("-server")
+ .build();
+ new Runner(options).run();
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java
new file mode 100644
index 0000000000..d9340f45c1
--- /dev/null
+++ b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/bitset/BitSetUnitTest.java
@@ -0,0 +1,178 @@
+package com.baeldung.collections.bitset;
+
+import org.junit.Test;
+import org.openjdk.jol.info.ClassLayout;
+import org.openjdk.jol.info.GraphLayout;
+
+import java.util.BitSet;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BitSetUnitTest {
+
+ @Test
+ public void givenBoolArray_whenMemoryLayout_thenConsumeMoreThanOneBit() {
+ boolean[] bits = new boolean[1024 * 1024];
+
+ System.out.println(ClassLayout.parseInstance(bits).toPrintable());
+ }
+
+ @Test
+ public void givenBitSet_whenMemoryLayout_thenConsumeOneBitPerFlag() {
+ BitSet bitSet = new BitSet(1024 * 1024);
+
+ System.out.println(GraphLayout.parseInstance(bitSet).toPrintable());
+ }
+
+ @Test
+ public void givenBitSet_whenSetting_thenShouldBeTrue() {
+ BitSet bitSet = new BitSet();
+
+ bitSet.set(10);
+ assertThat(bitSet.get(10)).isTrue();
+
+ bitSet.set(20, 30);
+ for (int i = 20; i <= 29; i++) {
+ assertThat(bitSet.get(i)).isTrue();
+ }
+ assertThat(bitSet.get(30)).isFalse();
+
+ bitSet.set(10, false);
+ assertThat(bitSet.get(10)).isFalse();
+
+ bitSet.set(20, 30, false);
+ for (int i = 20; i <= 30; i++) {
+ assertThat(bitSet.get(i)).isFalse();
+ }
+ }
+
+ @Test
+ public void givenBitSet_whenClearing_thenShouldBeFalse() {
+ BitSet bitSet = new BitSet();
+ bitSet.set(42);
+ assertThat(bitSet.get(42)).isTrue();
+
+ bitSet.clear(42);
+ assertThat(bitSet.get(42)).isFalse();
+
+ bitSet.set(10, 20);
+ for (int i = 10; i < 20; i++) {
+ assertThat(bitSet.get(i)).isTrue();
+ }
+
+ bitSet.clear(10, 20);
+ for (int i = 10; i < 20; i++) {
+ assertThat(bitSet.get(i)).isFalse();
+ }
+
+ bitSet.set(10, 20);
+ bitSet.clear();
+ for (int i = 0; i < 100; i++) {
+ assertThat(bitSet.get(i)).isFalse();
+ }
+ }
+
+ @Test
+ public void givenBitSet_whenGettingElements_thenShouldReturnRequestedBits() {
+ BitSet bitSet = new BitSet();
+ bitSet.set(42);
+
+ assertThat(bitSet.get(42)).isTrue();
+ assertThat(bitSet.get(43)).isFalse();
+
+ bitSet.set(10, 20);
+ BitSet newBitSet = bitSet.get(10, 20);
+ for (int i = 0; i < 10; i++) {
+ assertThat(newBitSet.get(i)).isTrue();
+ }
+ }
+
+ @Test
+ public void givenBitSet_whenFlip_thenTogglesTrueToFalseAndViceVersa() {
+ BitSet bitSet = new BitSet();
+ bitSet.set(42);
+ bitSet.flip(42);
+ assertThat(bitSet.get(42)).isFalse();
+
+ bitSet.flip(12);
+ assertThat(bitSet.get(12)).isTrue();
+
+ bitSet.flip(30, 40);
+ for (int i = 30; i < 40; i++) {
+ assertThat(bitSet.get(i)).isTrue();
+ }
+ }
+
+ @Test
+ public void givenBitSet_whenGettingTheSize_thenReturnsTheSize() {
+ BitSet defaultBitSet = new BitSet();
+ assertThat(defaultBitSet.size()).isEqualTo(64);
+
+ BitSet bitSet = new BitSet(1024);
+ assertThat(bitSet.size()).isEqualTo(1024);
+
+ assertThat(bitSet.cardinality()).isEqualTo(0);
+ bitSet.set(10, 30);
+ assertThat(bitSet.cardinality()).isEqualTo(30 - 10);
+
+ assertThat(bitSet.length()).isEqualTo(30);
+ bitSet.set(100);
+ assertThat(bitSet.length()).isEqualTo(101);
+
+ assertThat(bitSet.isEmpty()).isFalse();
+ bitSet.clear();
+ assertThat(bitSet.isEmpty()).isTrue();
+ }
+
+ @Test
+ public void givenBitSet_whenSetOperations_thenShouldReturnAnotherBitSet() {
+ BitSet first = new BitSet();
+ first.set(5, 10);
+
+ BitSet second = new BitSet();
+ second.set(7, 15);
+
+ assertThat(first.intersects(second)).isTrue();
+
+ first.and(second);
+ assertThat(first.get(7)).isTrue();
+ assertThat(first.get(8)).isTrue();
+ assertThat(first.get(9)).isTrue();
+ assertThat(first.get(10)).isFalse();
+
+ first.clear();
+ first.set(5, 10);
+
+ first.xor(second);
+ for (int i = 5; i < 7; i++) {
+ assertThat(first.get(i)).isTrue();
+ }
+ for (int i = 10; i < 15; i++) {
+ assertThat(first.get(i)).isTrue();
+ }
+ }
+
+ @Test
+ public void givenBitSet_whenStream_thenStreamsAllSetBits() {
+ BitSet bitSet = new BitSet();
+ bitSet.set(15, 25);
+
+ bitSet.stream().forEach(System.out::println);
+ assertThat(bitSet.stream().count()).isEqualTo(10);
+ }
+
+ @Test
+ public void givenBitSet_whenNextOrPrev_thenReturnsTheNextOrPrevClearOrSetBit() {
+ BitSet bitSet = new BitSet();
+ bitSet.set(15, 25);
+
+ assertThat(bitSet.nextSetBit(13)).isEqualTo(15);
+ assertThat(bitSet.nextSetBit(25)).isEqualTo(-1);
+
+ assertThat(bitSet.nextClearBit(23)).isEqualTo(25);
+
+ assertThat(bitSet.previousClearBit(24)).isEqualTo(14);
+ assertThat(bitSet.previousSetBit(29)).isEqualTo(24);
+ assertThat(bitSet.previousSetBit(14)).isEqualTo(-1);
+ }
+}
diff --git a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/hashset/HashSetUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/hashset/HashSetUnitTest.java
new file mode 100644
index 0000000000..1c23538675
--- /dev/null
+++ b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/hashset/HashSetUnitTest.java
@@ -0,0 +1,33 @@
+package com.baeldung.collections.hashset;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+
+class HashSetUnitTest {
+
+ @Test
+ void whenRemoveAllFromHashset_thenRemovesAllElementsFromHashsetThatArePresentInCollection() {
+ Set set = new HashSet<>();
+ Collection collection = new ArrayList<>();
+ set.add(1);
+ set.add(2);
+ set.add(3);
+ set.add(4);
+ collection.add(1);
+ collection.add(3);
+
+ set.removeAll(collection);
+
+ assertEquals(2, set.size());
+ Integer[] actualElements = new Integer[set.size()];
+ Integer[] expectedElements = new Integer[] { 2, 4 };
+ assertArrayEquals(expectedElements, set.toArray(actualElements));
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java
new file mode 100644
index 0000000000..8272e7323a
--- /dev/null
+++ b/core-java-modules/core-java-collections-3/src/test/java/com/baeldung/collections/mapfirstpair/MapFirstPairUnitTest.java
@@ -0,0 +1,146 @@
+package com.baeldung.collections.mapfirstpair;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.AbstractMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.Test;
+
+public class MapFirstPairUnitTest {
+
+ private Map.Entry getFirstPairUsingIterator(Map map) {
+ if (map == null || map.size() == 0) {
+ return null;
+ }
+
+ Iterator> iterator = map.entrySet()
+ .iterator();
+
+ if (iterator.hasNext()) {
+ return iterator.next();
+ }
+
+ return null;
+ }
+
+ private Map.Entry getFirstPairUsingStream(Map map) {
+ if (map == null || map.size() == 0) {
+ return null;
+ }
+
+ Set> entrySet = map.entrySet();
+
+ return entrySet.stream()
+ .findFirst()
+ .get();
+ }
+
+ private Map populateMapValues(Map map) {
+ if (map != null) {
+ map.put(5, "A");
+ map.put(1, "B");
+ map.put(2, "C");
+ }
+ return map;
+ }
+
+ @Test
+ public void whenUsingIteratorForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ Map.Entry actualValue = getFirstPairUsingIterator(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(1, "B");
+ Map.Entry pairInsertedFirst = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ assertNotEquals(pairInsertedFirst, actualValue);
+ }
+
+ @Test
+ public void whenUsingStreamForHashMap_thenFirstPairWhichWasNotInsertedFirst() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+ Map.Entry actualValue = getFirstPairUsingStream(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(1, "B");
+ Map.Entry pairInsertedFirst = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ assertNotEquals(pairInsertedFirst, actualValue);
+ }
+
+ @Test
+ public void whenUsingIteratorForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+ Map.Entry actualValue = getFirstPairUsingIterator(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenUsingStreamForLinkedHashMap_thenFirstPairWhichWasInsertedFirst() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ Map.Entry actualValue = getFirstPairUsingStream(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingIterator() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ hashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingIterator(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(0, "D");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInHashMap_thenFirstPairChangedUsingStream() {
+ Map hashMap = new HashMap<>();
+ hashMap = populateMapValues(hashMap);
+
+ hashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingStream(hashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(0, "D");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingIterator() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ linkedHashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingIterator(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+
+ @Test
+ public void whenAddedAnElementInLinkedHashMap_thenFirstPairRemainUnchangedUsingStream() {
+ Map linkedHashMap = new LinkedHashMap<>();
+ linkedHashMap = populateMapValues(linkedHashMap);
+
+ linkedHashMap.put(0, "D");
+ Map.Entry actualValue = getFirstPairUsingStream(linkedHashMap);
+ Map.Entry expectedValue = new AbstractMap.SimpleEntry(5, "A");
+
+ assertEquals(expectedValue, actualValue);
+ }
+}
diff --git a/core-java-modules/core-java-collections-4/README.md b/core-java-modules/core-java-collections-4/README.md
new file mode 100644
index 0000000000..4fd77473d4
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/README.md
@@ -0,0 +1,8 @@
+=========
+
+## Core Java Collections Cookbooks and Examples
+
+### Relevant Articles:
+
+- [ArrayList vs. LinkedList vs. HashMap in Java](https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap)
+- [Java Deque vs. Stack](https://www.baeldung.com/java-deque-vs-stack)
diff --git a/core-java-modules/core-java-collections-4/pom.xml b/core-java-modules/core-java-collections-4/pom.xml
new file mode 100644
index 0000000000..b4f8aa6320
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/pom.xml
@@ -0,0 +1,31 @@
+
+
+ 4.0.0
+ core-java-collections-4
+ 0.1.0-SNAPSHOT
+ core-java-collections-4
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../pom.xml
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+ 3.19.0
+
+
+
diff --git a/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/ArrayLifoStack.java b/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/ArrayLifoStack.java
new file mode 100644
index 0000000000..16fdec5b77
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/ArrayLifoStack.java
@@ -0,0 +1,91 @@
+package com.baeldung.collections.dequestack;
+
+import java.util.ArrayDeque;
+import java.util.Collection;
+import java.util.Deque;
+import java.util.Iterator;
+
+public class ArrayLifoStack implements LifoStack {
+ private final Deque deque = new ArrayDeque<>();
+
+ @Override
+ public void push(E item) {
+ deque.addFirst(item);
+ }
+
+ @Override
+ public E pop() {
+ return deque.removeFirst();
+ }
+
+ @Override
+ public E peek() {
+ return deque.peekFirst();
+ }
+
+ // implementing methods from the Collection interface
+ @Override
+ public int size() {
+ return deque.size();
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return deque.isEmpty();
+ }
+
+ @Override
+ public boolean contains(Object o) {
+ return deque.contains(o);
+ }
+
+ @Override
+ public Iterator iterator() {
+ return deque.iterator();
+ }
+
+ @Override
+ public Object[] toArray() {
+ return deque.toArray();
+ }
+
+ @Override
+ public T[] toArray(T[] a) {
+ return deque.toArray(a);
+ }
+
+ @Override
+ public boolean add(E e) {
+ return deque.add(e);
+ }
+
+ @Override
+ public boolean remove(Object o) {
+ return deque.remove(o);
+ }
+
+ @Override
+ public boolean containsAll(Collection> c) {
+ return deque.containsAll(c);
+ }
+
+ @Override
+ public boolean addAll(Collection extends E> c) {
+ return deque.addAll(c);
+ }
+
+ @Override
+ public boolean removeAll(Collection> c) {
+ return deque.removeAll(c);
+ }
+
+ @Override
+ public boolean retainAll(Collection> c) {
+ return deque.retainAll(c);
+ }
+
+ @Override
+ public void clear() {
+ deque.clear();
+ }
+}
diff --git a/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/LifoStack.java b/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/LifoStack.java
new file mode 100644
index 0000000000..11e07e3555
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/main/java/com/baeldung/collections/dequestack/LifoStack.java
@@ -0,0 +1,12 @@
+package com.baeldung.collections.dequestack;
+
+import java.util.Collection;
+
+public interface LifoStack extends Collection {
+
+ E peek();
+
+ E pop();
+
+ void push(E item);
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java
new file mode 100644
index 0000000000..bc6a07d274
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ArrayListUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.collections.comparation;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ArrayListUnitTest {
+
+ @Test
+ void givenArrayList_whenItemAddedToSpecificIndex_thenItCanBeRetrieved() {
+ List list = new ArrayList<>();
+ list.add("Daniel");
+ list.add(0, "Marko");
+ assertThat(list).hasSize(2);
+ assertThat(list.get(0)).isEqualTo("Marko");
+ }
+
+ @Test
+ void givenArrayList_whenItemRemovedViaIndex_thenListSizeIsReduced() {
+ List list = new ArrayList<>(Arrays.asList("Daniel", "Marko"));
+ list.remove(1);
+ assertThat(list).hasSize(1);
+ assertThat(list).doesNotContain("Marko");
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java
new file mode 100644
index 0000000000..3b595472e0
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/HashMapUnitTest.java
@@ -0,0 +1,31 @@
+package com.baeldung.collections.comparation;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class HashMapUnitTest {
+
+ @Test
+ void givenHashMap_whenItemAddedByKey_thenItCanBeRetrieved() {
+ Map map = new HashMap<>();
+ map.put("123456", "Daniel");
+ map.put("654321", "Marko");
+ assertThat(map.get("654321")).isEqualTo("Marko");
+ }
+
+ @Test
+ void givenHashMap_whenItemRemovedByKey_thenMapSizeIsReduced() {
+ Map map = new HashMap<>();
+ map.put("123456", "Daniel");
+ map.put("654321", "Marko");
+ map.remove("654321");
+ assertThat(map).hasSize(1);
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java
new file mode 100644
index 0000000000..aa6b7fa923
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/LinkedListUnitTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.collections.comparation;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LinkedListUnitTest {
+
+ @Test
+ void givenLinkedList_whenItemIsAppended_thenItCanBeRetrieved() {
+ LinkedList list = new LinkedList<>();
+ list.addLast("Daniel");
+ list.addFirst("Marko");
+ assertThat(list).hasSize(2);
+ assertThat(list.getLast()).isEqualTo("Daniel");
+ }
+
+ @Test
+ void givenLinkedList_whenItemIsRemoved_thenListSizeIsReduced() {
+ LinkedList list = new LinkedList<>(Arrays.asList("Daniel", "Marko", "David"));
+ list.removeFirst();
+ list.removeLast();
+ assertThat(list).hasSize(1);
+ assertThat(list).containsExactly("Marko");
+ }
+
+ @Test
+ void givenLinkedList_whenItemInserted_thenItCanBeRetrievedAndDeleted() {
+ LinkedList list = new LinkedList<>();
+ list.push("Daniel");
+ list.push("Marko");
+ assertThat(list.poll()).isEqualTo("Marko");
+ assertThat(list).hasSize(1);
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java
new file mode 100644
index 0000000000..dd6bf760fd
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/comparation/ListVsMapUnitTest.java
@@ -0,0 +1,32 @@
+package com.baeldung.collections.comparation;
+
+import static org.assertj.core.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+
+import java.util.*;
+
+class ListVsMapUnitTest {
+
+ @Test
+ void givenList_whenIteratingTroughValues_thenEachValueIsPresent() {
+ List list = new ArrayList<>();
+ list.add("Daniel");
+ list.add("Marko");
+ for (String name : list) {
+ assertThat(name).isIn(list);
+ }
+ assertThat(list).containsExactly("Daniel", "Marko");
+ }
+
+ @Test
+ void givenMap_whenIteratingTroughValues_thenEachValueIsPresent() {
+ Map map = new HashMap<>();
+ map.put(1, "Daniel");
+ map.put(2, "Marko");
+ for (String name : map.values()) {
+ assertThat(name).isIn(map.values());
+ }
+ assertThat(map.values()).containsExactlyInAnyOrder("Daniel", "Marko");
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/dequestack/StackVsDequeUnitTest.java b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/dequestack/StackVsDequeUnitTest.java
new file mode 100644
index 0000000000..ca3b0e8d54
--- /dev/null
+++ b/core-java-modules/core-java-collections-4/src/test/java/com/baeldung/collections/dequestack/StackVsDequeUnitTest.java
@@ -0,0 +1,90 @@
+package com.baeldung.collections.dequestack;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayDeque;
+import java.util.Deque;
+import java.util.Iterator;
+import java.util.Stack;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class StackVsDequeUnitTest {
+
+ @Test
+ void givenAStack_whenAccessByIndex_thenElementCanBeRead() {
+ Stack myStack = new Stack<>();
+ myStack.push("I am the 1st element."); //index 0
+ myStack.push("I am the 2nd element."); //index 1
+ myStack.push("I am the 3rd element."); //index 2
+ //access by index
+ assertThat(myStack.get(0)).isEqualTo("I am the 1st element.");
+ }
+
+ @Test
+ void givenAStack_whenIterate_thenFromBottomToTop() {
+ Stack myStack = new Stack<>();
+ myStack.push("I am at the bottom.");
+ myStack.push("I am in the middle.");
+ myStack.push("I am at the top.");
+
+ Iterator it = myStack.iterator();
+
+ assertThat(it).toIterable().containsExactly(
+ "I am at the bottom.",
+ "I am in the middle.",
+ "I am at the top.");
+ }
+
+ @Test
+ void givenAStack_whenAddOrRemoveByIndex_thenElementCanBeAddedOrRemoved() {
+ Stack myStack = new Stack<>();
+ myStack.push("I am the 1st element.");
+ myStack.push("I am the 3rd element.");
+
+ assertThat(myStack.size()).isEqualTo(2);
+
+ //insert by index
+ myStack.add(1, "I am the 2nd element.");
+ assertThat(myStack.size()).isEqualTo(3);
+ assertThat(myStack.get(1)).isEqualTo("I am the 2nd element.");
+ //remove by index
+ myStack.remove(1);
+ assertThat(myStack.size()).isEqualTo(2);
+ }
+
+ @Test
+ void givenADeque_whenAddOrRemoveLastElement_thenTheLastElementCanBeAddedOrRemoved() {
+ Deque myStack = new ArrayDeque<>();
+ myStack.push("I am the 1st element.");
+ myStack.push("I am the 2nd element.");
+ myStack.push("I am the 3rd element.");
+
+ assertThat(myStack.size()).isEqualTo(3);
+
+ //insert element to the bottom of the stack
+ myStack.addLast("I am the NEW element.");
+ assertThat(myStack.size()).isEqualTo(4);
+ assertThat(myStack.peek()).isEqualTo("I am the 3rd element.");
+
+ //remove element from the bottom of the stack
+ String removedStr = myStack.removeLast();
+ assertThat(myStack.size()).isEqualTo(3);
+ assertThat(removedStr).isEqualTo("I am the NEW element.");
+ }
+
+ @Test
+ void givenADeque_whenIterate_thenFromTopToBottom() {
+ Deque myStack = new ArrayDeque<>();
+ myStack.push("I am at the bottom.");
+ myStack.push("I am in the middle.");
+ myStack.push("I am at the top.");
+
+ Iterator it = myStack.iterator();
+
+ assertThat(it).toIterable().containsExactly(
+ "I am at the top.",
+ "I am in the middle.",
+ "I am at the bottom.");
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-array-list/README.md b/core-java-modules/core-java-collections-array-list/README.md
index 3637f835cf..d24f7492bb 100644
--- a/core-java-modules/core-java-collections-array-list/README.md
+++ b/core-java-modules/core-java-collections-array-list/README.md
@@ -8,4 +8,4 @@ This module contains articles about the Java ArrayList collection
- [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)
- [Removing an Element From an ArrayList](https://www.baeldung.com/java-arraylist-remove-element)
-
+- [The Capacity of an ArrayList vs the Size of an Array in Java](https://www.baeldung.com/java-list-capacity-array-size)
diff --git a/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java
new file mode 100644
index 0000000000..74c8b93872
--- /dev/null
+++ b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayCreatorUnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.listcapacityvsarraysize;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class ArrayCreatorUnitTest {
+
+ @Test
+ void whenSizeOfAnArrayIsNonZero_thenReturnNewArrayOfGivenSize() {
+ Integer[] array = new Integer[10];
+ assertEquals(10, array.length);
+ }
+
+ @Test
+ void whenSizeOfAnArrayIsLessThanZero_thenThrowException() {
+ assertThrows(NegativeArraySizeException.class, () -> { Integer[] array = new Integer[-1]; });
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java
new file mode 100644
index 0000000000..62efe43af4
--- /dev/null
+++ b/core-java-modules/core-java-collections-array-list/src/test/java/com/baeldung/listcapacityvsarraysize/ArrayListCreatorUnitTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.listcapacityvsarraysize;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.ArrayList;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class ArrayListCreatorUnitTest {
+
+ @Test
+ void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithGivenCapacity() {
+ ArrayList list = new ArrayList<>(100);
+
+ assertNotNull(list);
+ }
+
+ @Test
+ void givenInvalidCapacityOfList_whenCreateListInvoked_thenThrowException() {
+ assertThrows(IllegalArgumentException.class, () -> new ArrayList<>(-1));
+ }
+
+ @Test
+ void givenValidCapacityOfList_whenCreateListInvoked_thenCreateNewArrayListWithSizeZero() {
+ assertEquals(0, new ArrayList(100).size());
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-collections-list-3/README.md b/core-java-modules/core-java-collections-list-3/README.md
index 65c377bd99..967e148a99 100644
--- a/core-java-modules/core-java-collections-list-3/README.md
+++ b/core-java-modules/core-java-collections-list-3/README.md
@@ -10,4 +10,5 @@ This module contains articles about the Java List collection
- [Performance Comparison of Primitive Lists in Java](https://www.baeldung.com/java-list-primitive-performance)
- [Filtering a Java Collection by a List](https://www.baeldung.com/java-filter-collection-by-list)
- [How to Count Duplicate Elements in Arraylist](https://www.baeldung.com/java-count-duplicate-elements-arraylist)
+- [Finding the Differences Between Two Lists in Java](https://www.baeldung.com/java-lists-difference)
- [[<-- Prev]](/core-java-modules/core-java-collections-list-2)
diff --git a/core-java-modules/core-java-collections-list-3/pom.xml b/core-java-modules/core-java-collections-list-3/pom.xml
index 373190a130..d1d199ec3f 100644
--- a/core-java-modules/core-java-collections-list-3/pom.xml
+++ b/core-java-modules/core-java-collections-list-3/pom.xml
@@ -21,6 +21,12 @@
commons-collections4${commons-collections4.version}
+
+ com.google.guava
+ guava
+ ${guava.version}
+ compile
+ org.assertjassertj-core
@@ -52,7 +58,7 @@
org.openjdk.jmhjmh-generator-annprocess
- ${jmh-core.version}
+ ${jmh-generator.version}
diff --git a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java
index bd37e5e74e..5dd1eaef09 100644
--- a/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java
+++ b/core-java-modules/core-java-collections-list-3/src/main/java/com/baeldung/list/primitive/PrimitivesListPerformance.java
@@ -8,6 +8,7 @@ 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.List;
import java.util.concurrent.TimeUnit;
@@ -18,12 +19,12 @@ import java.util.concurrent.TimeUnit;
@State(Scope.Thread)
public class PrimitivesListPerformance {
- private List arrayList = new ArrayList<>();
- private TIntArrayList tList = new TIntArrayList();
- private cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList();
- private IntArrayList fastUtilList = new IntArrayList();
+ private List arrayList = new ArrayList<>(Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9));
+ private TIntArrayList tList = new TIntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
+ private cern.colt.list.IntArrayList coltList = new cern.colt.list.IntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
+ private IntArrayList fastUtilList = new IntArrayList(new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
- private int getValue = 10;
+ private int getValue = 4;
@Benchmark
public boolean addArrayList() {
diff --git a/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java
new file mode 100644
index 0000000000..ceeff5e442
--- /dev/null
+++ b/core-java-modules/core-java-collections-list-3/src/test/java/com/baeldung/list/difference/FindDifferencesBetweenListsUnitTest.java
@@ -0,0 +1,96 @@
+package com.baeldung.list.difference;
+
+import com.google.common.collect.Sets;
+import org.apache.commons.collections4.CollectionUtils;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.assertj.core.api.Assertions.*;
+
+public class FindDifferencesBetweenListsUnitTest {
+
+ private static final List listOne = Arrays.asList("Jack", "Tom", "Sam", "John", "James", "Jack");
+ private static final List listTwo = Arrays.asList("Jack", "Daniel", "Sam", "Alan", "James", "George");
+
+ @Test
+ public void givenLists_whenUsingPlainJavaImpl_thenDifferencesAreFound() {
+ List differences = new ArrayList<>(listOne);
+ differences.removeAll(listTwo);
+ assertEquals(2, differences.size());
+ assertThat(differences).containsExactly("Tom", "John");
+ }
+
+ @Test
+ public void givenReverseLists_whenUsingPlainJavaImpl_thenDifferencesAreFound() {
+ List differences = new ArrayList<>(listTwo);
+ differences.removeAll(listOne);
+ assertEquals(3, differences.size());
+ assertThat(differences).containsExactly("Daniel", "Alan", "George");
+ }
+
+ @Test
+ public void givenLists_whenUsingJavaStreams_thenDifferencesAreFound() {
+ List differences = listOne.stream()
+ .filter(element -> !listTwo.contains(element))
+ .collect(Collectors.toList());
+ assertEquals(2, differences.size());
+ assertThat(differences).containsExactly("Tom", "John");
+ }
+
+ @Test
+ public void givenReverseLists_whenUsingJavaStreams_thenDifferencesAreFound() {
+ List differences = listTwo.stream()
+ .filter(element -> !listOne.contains(element))
+ .collect(Collectors.toList());
+ assertEquals(3, differences.size());
+ assertThat(differences).containsExactly("Daniel", "Alan", "George");
+ }
+
+ @Test
+ public void givenLists_whenUsingGoogleGuava_thenDifferencesAreFound() {
+ List differences = new ArrayList<>(Sets.difference(Sets.newHashSet(listOne), Sets.newHashSet(listTwo)));
+ assertEquals(2, differences.size());
+ assertThat(differences).containsExactlyInAnyOrder("Tom", "John");
+ }
+
+ @Test
+ public void givenReverseLists_whenUsingGoogleGuava_thenDifferencesAreFound() {
+ List differences = new ArrayList<>(Sets.difference(Sets.newHashSet(listTwo), Sets.newHashSet(listOne)));
+ assertEquals(3, differences.size());
+ assertThat(differences).containsExactlyInAnyOrder("Daniel", "Alan", "George");
+ }
+
+ @Test
+ public void givenLists_whenUsingApacheCommons_thenDifferencesAreFound() {
+ List differences = new ArrayList<>((CollectionUtils.removeAll(listOne, listTwo)));
+ assertEquals(2, differences.size());
+ assertThat(differences).containsExactly("Tom", "John");
+ }
+
+ @Test
+ public void givenReverseLists_whenUsingApacheCommons_thenDifferencesAreFound() {
+ List differences = new ArrayList<>((CollectionUtils.removeAll(listTwo, listOne)));
+ assertEquals(3, differences.size());
+ assertThat(differences).containsExactly("Daniel", "Alan", "George");
+ }
+
+ @Test
+ public void givenLists_whenUsingPlainJavaImpl_thenDifferencesWithDuplicatesAreFound() {
+ List differences = new ArrayList<>(listOne);
+ listTwo.forEach(differences::remove);
+ assertThat(differences).containsExactly("Tom", "John", "Jack");
+ }
+
+ @Test
+ public void givenLists_whenUsingApacheCommons_thenDifferencesWithDuplicatesAreFound() {
+ List differences = new ArrayList<>(CollectionUtils.subtract(listOne, listTwo));
+ assertEquals(3, differences.size());
+ assertThat(differences).containsExactly("Tom", "John", "Jack");
+ }
+
+}
diff --git a/core-java-modules/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml
index 509f58ea61..76ca66fe70 100644
--- a/core-java-modules/core-java-collections-list/pom.xml
+++ b/core-java-modules/core-java-collections-list/pom.xml
@@ -36,7 +36,6 @@
4.1
- 3.8.13.11.1
diff --git a/core-java-modules/core-java-collections-maps-2/pom.xml b/core-java-modules/core-java-collections-maps-2/pom.xml
index a64a11c6ea..7c4ab19945 100644
--- a/core-java-modules/core-java-collections-maps-2/pom.xml
+++ b/core-java-modules/core-java-collections-maps-2/pom.xml
@@ -21,20 +21,15 @@
${eclipse-collections.version}
- net.sf.trove4j
- trove4j
- ${trove4j.version}
+ com.carrotsearch
+ hppc
+ ${hppc.version}it.unimi.dsifastutil${fastutil.version}
-
- colt
- colt
- ${colt.version}
- org.apache.commonscommons-lang3
@@ -69,9 +64,8 @@
4.11.7.08.2.0
- 3.0.2
+ 0.7.28.1.0
- 1.2.03.11.1
diff --git a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java
index 5559895730..09b1a8847d 100644
--- a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java
+++ b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/Product.java
@@ -26,7 +26,7 @@ public class Product {
return tags;
}
- public Product addTagsOfOtherProdcut(Product product) {
+ public Product addTagsOfOtherProduct(Product product) {
this.tags.addAll(product.getTags());
return this;
}
@@ -100,11 +100,11 @@ public class Product {
HashMap productsByName = new HashMap<>();
Product eBike2 = new Product("E-Bike", "A bike with a battery");
eBike2.getTags().add("sport");
- productsByName.merge("E-Bike", eBike2, Product::addTagsOfOtherProdcut);
+ productsByName.merge("E-Bike", eBike2, Product::addTagsOfOtherProduct);
//Prior to Java 8:
if(productsByName.containsKey("E-Bike")) {
- productsByName.get("E-Bike").addTagsOfOtherProdcut(eBike2);
+ productsByName.get("E-Bike").addTagsOfOtherProduct(eBike2);
} else {
productsByName.put("E-Bike", eBike2);
}
@@ -117,7 +117,7 @@ public class Product {
productsByName.compute("E-Bike", (k,v) -> {
if(v != null) {
- return v.addTagsOfOtherProdcut(eBike2);
+ return v.addTagsOfOtherProduct(eBike2);
} else {
return eBike2;
}
@@ -125,7 +125,7 @@ public class Product {
//Prior to Java 8:
if(productsByName.containsKey("E-Bike")) {
- productsByName.get("E-Bike").addTagsOfOtherProdcut(eBike2);
+ productsByName.get("E-Bike").addTagsOfOtherProduct(eBike2);
} else {
productsByName.put("E-Bike", eBike2);
}
diff --git a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java
index 30bec12ccc..e53290f93a 100644
--- a/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java
+++ b/core-java-modules/core-java-collections-maps-2/src/main/java/com/baeldung/map/primitives/PrimitiveMaps.java
@@ -1,29 +1,68 @@
package com.baeldung.map.primitives;
-import cern.colt.map.AbstractIntDoubleMap;
-import cern.colt.map.OpenIntDoubleHashMap;
-import gnu.trove.map.TDoubleIntMap;
-import gnu.trove.map.hash.TDoubleIntHashMap;
+import com.carrotsearch.hppc.IntLongHashMap;
+import com.carrotsearch.hppc.IntLongScatterMap;
+import com.carrotsearch.hppc.IntObjectHashMap;
+import com.carrotsearch.hppc.IntObjectMap;
+import com.carrotsearch.hppc.IntObjectScatterMap;
+
import it.unimi.dsi.fastutil.ints.Int2BooleanMap;
+import it.unimi.dsi.fastutil.ints.Int2BooleanMaps;
import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMap;
import it.unimi.dsi.fastutil.ints.Int2BooleanSortedMaps;
+import it.unimi.dsi.fastutil.objects.ObjectIterator;
+
import org.eclipse.collections.api.map.primitive.ImmutableIntIntMap;
import org.eclipse.collections.api.map.primitive.MutableIntIntMap;
import org.eclipse.collections.api.map.primitive.MutableObjectDoubleMap;
import org.eclipse.collections.impl.factory.primitive.IntIntMaps;
import org.eclipse.collections.impl.factory.primitive.ObjectDoubleMaps;
+import static java.lang.String.format;
+
+import java.math.BigDecimal;
+
public class PrimitiveMaps {
public static void main(String[] args) {
+ hppcMap();
eclipseCollectionsMap();
- troveMap();
- coltMap();
fastutilMap();
}
+ private static void hppcMap() {
+ //Regular maps
+ IntLongHashMap intLongHashMap = new IntLongHashMap();
+ intLongHashMap.put(25,1L);
+ intLongHashMap.put(150,Long.MAX_VALUE);
+ intLongHashMap.put(1,0L);
+
+ intLongHashMap.get(150);
+
+ IntObjectMap intObjectMap = new IntObjectHashMap();
+ intObjectMap.put(1, BigDecimal.valueOf(1));
+ intObjectMap.put(2, BigDecimal.valueOf(2500));
+
+ BigDecimal value = intObjectMap.get(2);
+
+ //Scatter maps
+ IntLongScatterMap intLongScatterMap = new IntLongScatterMap();
+ intLongScatterMap.put(1, 1L);
+ intLongScatterMap.put(2, -2L);
+ intLongScatterMap.put(1000,0L);
+
+ intLongScatterMap.get(1000);
+
+ IntObjectScatterMap intObjectScatterMap = new IntObjectScatterMap();
+ intObjectScatterMap.put(1, BigDecimal.valueOf(1));
+ intObjectScatterMap.put(2, BigDecimal.valueOf(2500));
+
+ value = intObjectScatterMap.get(2);
+ }
+
+
private static void fastutilMap() {
Int2BooleanMap int2BooleanMap = new Int2BooleanOpenHashMap();
int2BooleanMap.put(1, true);
@@ -32,13 +71,19 @@ public class PrimitiveMaps {
boolean value = int2BooleanMap.get(1);
- Int2BooleanSortedMap int2BooleanSorted = Int2BooleanSortedMaps.EMPTY_MAP;
- }
+ //Lambda style iteration
+ Int2BooleanMaps.fastForEach(int2BooleanMap, entry -> {
+ System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue()));
+ });
+
+ //Iterator based loop
+ ObjectIterator iterator = Int2BooleanMaps.fastIterator(int2BooleanMap);
+ while(iterator.hasNext()) {
+ Int2BooleanMap.Entry entry = iterator.next();
+ System.out.println(String.format("Key: %d, Value: %b",entry.getIntKey(),entry.getBooleanValue()));
+
+ }
- private static void coltMap() {
- AbstractIntDoubleMap map = new OpenIntDoubleHashMap();
- map.put(1, 4.5);
- double value = map.get(1);
}
private static void eclipseCollectionsMap() {
@@ -53,17 +98,5 @@ public class PrimitiveMaps {
dObject.addToValue("stability", 0.8);
}
- private static void troveMap() {
- double[] doubles = new double[] {1.2, 4.5, 0.3};
- int[] ints = new int[] {1, 4, 0};
- TDoubleIntMap doubleIntMap = new TDoubleIntHashMap(doubles, ints);
-
- doubleIntMap.put(1.2, 22);
- doubleIntMap.put(4.5, 16);
-
- doubleIntMap.adjustValue(1.2, 1);
- doubleIntMap.adjustValue(4.5, 4);
- doubleIntMap.adjustValue(0.3, 7);
- }
}
diff --git a/core-java-modules/core-java-collections-maps-3/README.md b/core-java-modules/core-java-collections-maps-3/README.md
index 7386f7e9b7..530a9310c2 100644
--- a/core-java-modules/core-java-collections-maps-3/README.md
+++ b/core-java-modules/core-java-collections-maps-3/README.md
@@ -6,4 +6,7 @@ This module contains articles about Map data structures in Java.
- [Java TreeMap vs HashMap](https://www.baeldung.com/java-treemap-vs-hashmap)
- [Comparing Two HashMaps in Java](https://www.baeldung.com/java-compare-hashmaps)
- [The Map.computeIfAbsent() Method](https://www.baeldung.com/java-map-computeifabsent)
+- [Collections.synchronizedMap vs. ConcurrentHashMap](https://www.baeldung.com/java-synchronizedmap-vs-concurrenthashmap)
+- [Java HashMap Load Factor](https://www.baeldung.com/java-hashmap-load-factor)
+- [Converting java.util.Properties to HashMap](https://www.baeldung.com/java-convert-properties-to-hashmap)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-maps-2)
diff --git a/core-java-modules/core-java-collections-maps-3/pom.xml b/core-java-modules/core-java-collections-maps-3/pom.xml
index f547968b22..c9fda26fc3 100644
--- a/core-java-modules/core-java-collections-maps-3/pom.xml
+++ b/core-java-modules/core-java-collections-maps-3/pom.xml
@@ -15,7 +15,16 @@
-
+
+ org.openjdk.jmh
+ jmh-core
+ ${jmh-core.version}
+
+
+ com.google.guava
+ guava
+ ${guava.version}
+
diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java
new file mode 100644
index 0000000000..c788dbc27d
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/concurrenthashmap/MapPerformanceComparison.java
@@ -0,0 +1,96 @@
+package com.baeldung.map.concurrenthashmap;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Threads;
+import org.openjdk.jmh.annotations.Warmup;
+
+@Fork(5)
+@Threads(10)
+@Warmup(iterations = 5)
+@State(Scope.Benchmark)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+public class MapPerformanceComparison {
+
+ private int TEST_NO_ITEMS;
+
+ public static void main(String[] args) throws Exception {
+ org.openjdk.jmh.Main.main(args);
+ }
+
+ @Setup
+ public void setup() {
+ TEST_NO_ITEMS = 1000;
+ }
+
+ @Benchmark
+ public void randomReadAndWriteSynchronizedMap() {
+ Map map = Collections.synchronizedMap(new HashMap());
+ performReadAndWriteTest(map);
+ }
+
+ @Benchmark
+ public void randomReadAndWriteConcurrentHashMap() {
+ Map map = new ConcurrentHashMap<>();
+ performReadAndWriteTest(map);
+ }
+
+ private void performReadAndWriteTest(final Map map) {
+ for (int i = 0; i < TEST_NO_ITEMS; i++) {
+ Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
+ map.get(String.valueOf(randNumber));
+ map.put(String.valueOf(randNumber), randNumber);
+ }
+ }
+
+ @Benchmark
+ public void randomWriteSynchronizedMap() {
+ Map map = Collections.synchronizedMap(new HashMap());
+ performWriteTest(map);
+ }
+
+ @Benchmark
+ public void randomWriteConcurrentHashMap() {
+ Map map = new ConcurrentHashMap<>();
+ performWriteTest(map);
+ }
+
+ private void performWriteTest(final Map map) {
+ for (int i = 0; i < TEST_NO_ITEMS; i++) {
+ Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
+ map.put(String.valueOf(randNumber), randNumber);
+ }
+ }
+
+ @Benchmark
+ public void randomReadSynchronizedMap() {
+ Map map = Collections.synchronizedMap(new HashMap());
+ performReadTest(map);
+ }
+
+ @Benchmark
+ public void randomReadConcurrentHashMap() {
+ Map map = new ConcurrentHashMap<>();
+ performReadTest(map);
+ }
+
+ private void performReadTest(final Map map) {
+ for (int i = 0; i < TEST_NO_ITEMS; i++) {
+ Integer randNumber = (int) Math.ceil(Math.random() * TEST_NO_ITEMS);
+ map.get(String.valueOf(randNumber));
+ }
+ }
+}
diff --git a/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java
new file mode 100644
index 0000000000..3472f998f5
--- /dev/null
+++ b/core-java-modules/core-java-collections-maps-3/src/main/java/com/baeldung/map/propertieshashmap/PropertiesToHashMapConverter.java
@@ -0,0 +1,39 @@
+package com.baeldung.map.propertieshashmap;
+
+import com.google.common.collect.Maps;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+
+public class PropertiesToHashMapConverter {
+
+ @SuppressWarnings({"rawtypes", "unchecked"})
+ public static HashMap typeCastConvert(Properties prop) {
+ Map step1 = prop;
+ Map step2 = (Map) step1;
+ return new HashMap<>(step2);
+ }
+
+ public static HashMap loopConvert(Properties prop) {
+ HashMap retMap = new HashMap<>();
+ for (Map.Entry
- 1.19
- 1.193.6.1
diff --git a/core-java-modules/core-java-concurrency-advanced-3/README.md b/core-java-modules/core-java-concurrency-advanced-3/README.md
index 8858760981..9495d5f479 100644
--- a/core-java-modules/core-java-concurrency-advanced-3/README.md
+++ b/core-java-modules/core-java-concurrency-advanced-3/README.md
@@ -13,6 +13,7 @@ This module contains articles about advanced topics about multithreading with co
- [Java Thread Deadlock and Livelock](https://www.baeldung.com/java-deadlock-livelock)
- [Guide to AtomicStampedReference in Java](https://www.baeldung.com/java-atomicstampedreference)
- [The ABA Problem in Concurrency](https://www.baeldung.com/cs/aba-concurrency)
-- [Introduction to Lock-Free Data Structures](https://www.baeldung.com/lock-free-programming)
+- [Introduction to Lock-Free Data Structures with Java Examples](https://www.baeldung.com/lock-free-programming)
- [Introduction to Exchanger in Java](https://www.baeldung.com/java-exchanger)
+- [Why Not To Start A Thread In The Constructor?](https://www.baeldung.com/java-thread-constructor)
- [[<-- previous]](/core-java-modules/core-java-concurrency-advanced-2)
diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/deadlockAndLivelock/LivelockExample.java b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/deadlockAndLivelock/LivelockExample.java
index b0d66a92c2..7c3ea6f94e 100644
--- a/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/deadlockAndLivelock/LivelockExample.java
+++ b/core-java-modules/core-java-concurrency-advanced-3/src/main/java/com/baeldung/deadlockAndLivelock/LivelockExample.java
@@ -73,7 +73,7 @@ public class LivelockExample {
public void tryLock(Lock lock, long millis) {
try {
- lock.tryLock(10, TimeUnit.MILLISECONDS);
+ lock.tryLock(millis, TimeUnit.MILLISECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java
new file mode 100644
index 0000000000..8d12218c05
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersManualTest.java
@@ -0,0 +1,109 @@
+package com.baeldung.workstealing;
+
+import org.junit.Test;
+import org.openjdk.jmh.annotations.*;
+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;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ForkJoinPool;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.logging.Logger;
+
+import static org.junit.Assert.fail;
+
+/**
+ * This test expects the file target/test-classes/META-INF/BenchmarkList to be present.
+ *
+ * Before running the test ensure that the file is present.
+ * If not, please run mvn install on the module.
+ *
+ */
+
+public class PrimeNumbersManualTest {
+
+ private static Logger logger = Logger.getAnonymousLogger();
+
+ @Test
+ public void givenPrimesCalculated_whenUsingPoolsAndOneThread_thenOneThreadSlowest() {
+ Options opt = new OptionsBuilder()
+ .include(Benchmarker.class.getSimpleName())
+ .forks(1)
+ .build();
+
+ try {
+ new Runner(opt).run();
+ } catch (RunnerException e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void givenNewWorkStealingPool_whenGettingPrimes_thenStealCountChanges() {
+ StringBuilder info = new StringBuilder();
+
+ for (int granularity : PrimeNumbers.GRANULARITIES) {
+ int parallelism = ForkJoinPool.getCommonPoolParallelism();
+ ForkJoinPool pool =
+ (ForkJoinPool) Executors.newWorkStealingPool(parallelism);
+
+ stealCountInfo(info, granularity, pool);
+ }
+ logger.info("\nExecutors.newWorkStealingPool ->" + info.toString());
+ }
+
+ @Test
+ public void givenCommonPool_whenGettingPrimes_thenStealCountChangesSlowly() {
+ StringBuilder info = new StringBuilder();
+
+ for (int granularity : PrimeNumbers.GRANULARITIES) {
+ ForkJoinPool pool = ForkJoinPool.commonPool();
+ stealCountInfo(info, granularity, pool);
+ }
+ logger.info("\nForkJoinPool.commonPool ->" + info.toString());
+ }
+
+ private void stealCountInfo(StringBuilder info, int granularity, ForkJoinPool forkJoinPool) {
+ PrimeNumbers primes = new PrimeNumbers(1, 10000, granularity, new AtomicInteger(0));
+ forkJoinPool.invoke(primes);
+ forkJoinPool.shutdown();
+
+ long steals = forkJoinPool.getStealCount();
+ String output = "\nGranularity: [" + granularity + "], Steals: [" + steals + "]";
+ info.append(output);
+ }
+
+
+ @BenchmarkMode(Mode.AverageTime)
+ @OutputTimeUnit(TimeUnit.MILLISECONDS)
+ @State(Scope.Benchmark)
+ @Fork(value = 2, warmups = 1, jvmArgs = {"-Xms2G", "-Xmx2G"})
+ public static class Benchmarker {
+
+ @Benchmark
+ public void singleThread() {
+ PrimeNumbers primes = new PrimeNumbers(10000);
+ primes.findPrimeNumbers(); // get prime numbers using a single thread
+ }
+
+ @Benchmark
+ public void commonPoolBenchmark() {
+ PrimeNumbers primes = new PrimeNumbers(10000);
+ ForkJoinPool pool = ForkJoinPool.commonPool();
+ pool.invoke(primes);
+ pool.shutdown();
+ }
+
+ @Benchmark
+ public void newWorkStealingPoolBenchmark() {
+ PrimeNumbers primes = new PrimeNumbers(10000);
+ int parallelism = ForkJoinPool.getCommonPoolParallelism();
+ ForkJoinPool stealer = (ForkJoinPool) Executors.newWorkStealingPool(parallelism);
+ stealer.invoke(primes);
+ stealer.shutdown();
+ }
+ }
+}
diff --git a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java b/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java
deleted file mode 100644
index 4fbbef4e61..0000000000
--- a/core-java-modules/core-java-concurrency-advanced-3/src/test/java/com/baeldung/workstealing/PrimeNumbersUnitManualTest.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package com.baeldung.workstealing;
-
-import org.junit.Test;
-import org.openjdk.jmh.annotations.*;
-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;
-
-import java.util.concurrent.Executors;
-import java.util.concurrent.ForkJoinPool;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.logging.Logger;
-
-import static org.junit.Assert.fail;
-
-public class PrimeNumbersUnitManualTest {
-
- private static Logger logger = Logger.getAnonymousLogger();
-
- @Test
- public void givenPrimesCalculated_whenUsingPoolsAndOneThread_thenOneThreadSlowest() {
- Options opt = new OptionsBuilder()
- .include(Benchmarker.class.getSimpleName())
- .forks(1)
- .build();
-
- try {
- new Runner(opt).run();
- } catch (RunnerException e) {
- fail();
- }
- }
-
- @Test
- public void givenNewWorkStealingPool_whenGettingPrimes_thenStealCountChanges() {
- StringBuilder info = new StringBuilder();
-
- for (int granularity : PrimeNumbers.GRANULARITIES) {
- int parallelism = ForkJoinPool.getCommonPoolParallelism();
- ForkJoinPool pool =
- (ForkJoinPool) Executors.newWorkStealingPool(parallelism);
-
- stealCountInfo(info, granularity, pool);
- }
- logger.info("\nExecutors.newWorkStealingPool ->" + info.toString());
- }
-
- @Test
- public void givenCommonPool_whenGettingPrimes_thenStealCountChangesSlowly() {
- StringBuilder info = new StringBuilder();
-
- for (int granularity : PrimeNumbers.GRANULARITIES) {
- ForkJoinPool pool = ForkJoinPool.commonPool();
- stealCountInfo(info, granularity, pool);
- }
- logger.info("\nForkJoinPool.commonPool ->" + info.toString());
- }
-
- private void stealCountInfo(StringBuilder info, int granularity, ForkJoinPool forkJoinPool) {
- PrimeNumbers primes = new PrimeNumbers(1, 10000, granularity, new AtomicInteger(0));
- forkJoinPool.invoke(primes);
- forkJoinPool.shutdown();
-
- long steals = forkJoinPool.getStealCount();
- String output = "\nGranularity: [" + granularity + "], Steals: [" + steals + "]";
- info.append(output);
- }
-
-
- @BenchmarkMode(Mode.AverageTime)
- @OutputTimeUnit(TimeUnit.MILLISECONDS)
- @State(Scope.Benchmark)
- @Fork(value = 2, warmups = 1, jvmArgs = {"-Xms2G", "-Xmx2G"})
- public static class Benchmarker {
-
- @Benchmark
- public void singleThread() {
- PrimeNumbers primes = new PrimeNumbers(10000);
- primes.findPrimeNumbers(); // get prime numbers using a single thread
- }
-
- @Benchmark
- public void commonPoolBenchmark() {
- PrimeNumbers primes = new PrimeNumbers(10000);
- ForkJoinPool pool = ForkJoinPool.commonPool();
- pool.invoke(primes);
- pool.shutdown();
- }
-
- @Benchmark
- public void newWorkStealingPoolBenchmark() {
- PrimeNumbers primes = new PrimeNumbers(10000);
- int parallelism = ForkJoinPool.getCommonPoolParallelism();
- ForkJoinPool stealer = (ForkJoinPool) Executors.newWorkStealingPool(parallelism);
- stealer.invoke(primes);
- stealer.shutdown();
- }
- }
-}
diff --git a/core-java-modules/core-java-concurrency-advanced-4/README.md b/core-java-modules/core-java-concurrency-advanced-4/README.md
new file mode 100644
index 0000000000..5b93cec0dd
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/README.md
@@ -0,0 +1,4 @@
+### Relevant Articles:
+
+- [Binary Semaphore vs Reentrant Lock](https://www.baeldung.com/java-binary-semaphore-vs-reentrant-lock)
+- [Bad Practices With Synchronization](https://www.baeldung.com/java-synchronization-bad-practices)
diff --git a/core-java-modules/core-java-concurrency-advanced-4/pom.xml b/core-java-modules/core-java-concurrency-advanced-4/pom.xml
new file mode 100644
index 0000000000..eb9ed3adc1
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/pom.xml
@@ -0,0 +1,47 @@
+
+
+
+ 4.0.0
+ core-java-concurrency-advanced-4
+ 0.1.0-SNAPSHOT
+ core-java-concurrency-advanced-4
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+
+
+ core-java-concurrency-advanced-4
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
+
+
+
+
+ src/main/resources
+ true
+
+
+
+
+
+ 1.8
+ 1.8
+
+
+
diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java
new file mode 100644
index 0000000000..ca6b7db765
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalBadPractice.java
@@ -0,0 +1,35 @@
+package com.baeldung.synchronizationbadpractices;
+
+public class AnimalBadPractice {
+
+ private String name;
+ private String owner;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+ public synchronized void setName(String name) {
+ this.name = name;
+ }
+
+ public void setOwner(String owner) {
+ synchronized(this) {
+ this.owner = owner;
+ }
+ }
+
+ public AnimalBadPractice() {
+
+ }
+
+ public AnimalBadPractice(String name, String owner) {
+ this.name = name;
+ this.owner = owner;
+ }
+
+}
diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java
new file mode 100644
index 0000000000..b49cfa05d4
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/AnimalSolution.java
@@ -0,0 +1,42 @@
+package com.baeldung.synchronizationbadpractices;
+
+public class AnimalSolution {
+
+ private final Object objLock1 = new Object();
+ private final Object objLock2 = new Object();
+
+ private String name;
+ private String owner;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getOwner() {
+ return owner;
+ }
+
+
+ public void setName(String name) {
+ synchronized(objLock1) {
+ this.name = name;
+ }
+ }
+
+ public void setOwner(String owner) {
+ synchronized(objLock2) {
+ this.owner = owner;
+ }
+ }
+
+ public AnimalSolution() {
+
+ }
+
+ public AnimalSolution(String name, String owner) {
+ this.name = name;
+ this.owner = owner;
+ }
+
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java
new file mode 100644
index 0000000000..84d2e1cbb6
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationBadPracticeExample.java
@@ -0,0 +1,51 @@
+package com.baeldung.synchronizationbadpractices;
+
+public class SynchronizationBadPracticeExample {
+
+ public void stringBadPractice1() {
+ String stringLock = "LOCK_STRING";
+ synchronized (stringLock) {
+ // ...
+ }
+ }
+
+ private final String stringLock = "LOCK_STRING";
+ public void stringBadPractice2() {
+ synchronized (stringLock) {
+ // ...
+ }
+ }
+
+ private final String internedStringLock = new String("LOCK_STRING").intern();
+ public void stringBadPractice3() {
+ synchronized (internedStringLock) {
+ // ...
+ }
+ }
+
+ private final Boolean booleanLock = Boolean.FALSE;
+ public void booleanBadPractice() {
+ synchronized (booleanLock) {
+ // ...
+ }
+ }
+
+ private int count = 0;
+ private final Integer intLock = count;
+ public void boxedPrimitiveBadPractice() {
+ synchronized (intLock) {
+ count++;
+ // ...
+ }
+ }
+
+ public void classBadPractice() throws InterruptedException {
+ AnimalBadPractice animalObj = new AnimalBadPractice("Tommy", "John");
+ synchronized(animalObj) {
+ while (true) {
+ Thread.sleep(Integer.MAX_VALUE);
+ }
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java
new file mode 100644
index 0000000000..a3ab8a2cee
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/src/main/java/com/baeldung/synchronizationbadpractices/SynchronizationSolutionExample.java
@@ -0,0 +1,30 @@
+package com.baeldung.synchronizationbadpractices;
+
+public class SynchronizationSolutionExample {
+
+ private final String stringLock = new String("LOCK_STRING");
+ public void stringSolution() {
+ synchronized (stringLock) {
+ // ...
+ }
+ }
+
+ private int count = 0;
+ private final Integer intLock = new Integer(count);
+ public void boxedPrimitiveSolution() {
+ synchronized(intLock) {
+ count++;
+ // ...
+ }
+ }
+
+ private static int staticCount = 0;
+ private static final Object staticObjLock = new Object();
+ public void staticVariableSolution() {
+ synchronized(staticObjLock) {
+ staticCount++;
+ // ...
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java
new file mode 100644
index 0000000000..f456e82f39
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced-4/src/test/java/com/baeldung/binarysemaphorereentrantlock/BinarySemaphoreVsReentrantLockUnitTest.java
@@ -0,0 +1,58 @@
+package com.baeldung.binarysemaphorereentrantlock;
+
+import static org.junit.Assert.assertEquals;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.junit.Test;
+
+public class BinarySemaphoreVsReentrantLockUnitTest {
+
+ @Test
+ public void givenBinarySemaphore_whenAcquireAndRelease_thenCheckAvailablePermits() throws InterruptedException {
+ Semaphore binarySemaphore = new Semaphore(1);
+ try {
+ binarySemaphore.acquire();
+ assertEquals(0, binarySemaphore.availablePermits());
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ } finally {
+ binarySemaphore.release();
+ assertEquals(1, binarySemaphore.availablePermits());
+ }
+ }
+
+ @Test
+ public void givenReentrantLock_whenLockAndUnlock_thenCheckHoldCountAndIsLocked() throws InterruptedException {
+ ReentrantLock reentrantLock = new ReentrantLock();
+ try {
+ reentrantLock.lock();
+ assertEquals(1, reentrantLock.getHoldCount());
+ assertEquals(true, reentrantLock.isLocked());
+ } finally {
+ reentrantLock.unlock();
+ assertEquals(0, reentrantLock.getHoldCount());
+ assertEquals(false, reentrantLock.isLocked());
+ }
+ }
+
+ @Test
+ public void givenReentrantLock_whenLockMultipleTimes_thenUnlockMultipleTimesToRelease() throws InterruptedException {
+ ReentrantLock reentrantLock = new ReentrantLock();
+ try {
+ reentrantLock.lock();
+ reentrantLock.lock();
+ assertEquals(2, reentrantLock.getHoldCount());
+ assertEquals(true, reentrantLock.isLocked());
+ } finally {
+ reentrantLock.unlock();
+ assertEquals(1, reentrantLock.getHoldCount());
+ assertEquals(true, reentrantLock.isLocked());
+
+ reentrantLock.unlock();
+ assertEquals(0, reentrantLock.getHoldCount());
+ assertEquals(false, reentrantLock.isLocked());
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java
new file mode 100644
index 0000000000..5a41cd9dbf
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-advanced/src/main/java/com/baeldung/threadlocal/ThreadLocalAwareThreadPool.java
@@ -0,0 +1,25 @@
+package com.baeldung.threadlocal;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+public class ThreadLocalAwareThreadPool extends ThreadPoolExecutor {
+
+ public ThreadLocalAwareThreadPool(int corePoolSize,
+ int maximumPoolSize,
+ long keepAliveTime,
+ TimeUnit unit,
+ BlockingQueue workQueue,
+ ThreadFactory threadFactory,
+ RejectedExecutionHandler handler) {
+ super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler);
+ }
+
+ @Override
+ protected void afterExecute(Runnable r, Throwable t) {
+ // Call remove on each ThreadLocal
+ }
+}
diff --git a/core-java-modules/core-java-concurrency-basic-2/README.md b/core-java-modules/core-java-concurrency-basic-2/README.md
index c7143baf36..bf973f7036 100644
--- a/core-java-modules/core-java-concurrency-basic-2/README.md
+++ b/core-java-modules/core-java-concurrency-basic-2/README.md
@@ -3,10 +3,13 @@
This module contains articles about basic Java concurrency
### Relevant Articles:
+
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
- [wait and notify() Methods in Java](https://www.baeldung.com/java-wait-notify)
- [Difference Between Wait and Sleep in Java](https://www.baeldung.com/java-wait-and-sleep)
- [Guide to the Synchronized Keyword in Java](https://www.baeldung.com/java-synchronized)
- [Life Cycle of a Thread in Java](https://www.baeldung.com/java-thread-lifecycle)
- [Guide to AtomicMarkableReference](https://www.baeldung.com/java-atomicmarkablereference)
+- [Why are Local Variables Thread-Safe in Java](https://www.baeldung.com/java-local-variables-thread-safe)
+- [How to Stop Execution After a Certain Time in Java](https://www.baeldung.com/java-stop-execution-after-certain-time)
- [[<-- Prev]](/core-java-modules/core-java-concurrency-basic)
diff --git a/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StopExecution.java b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StopExecution.java
new file mode 100644
index 0000000000..20f66da5da
--- /dev/null
+++ b/core-java-modules/core-java-concurrency-basic-2/src/main/java/com/baeldung/concurrent/stopexecution/StopExecution.java
@@ -0,0 +1,263 @@
+package com.baeldung.concurrent.stopexecution;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Timer;
+import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+public class StopExecution {
+ private static final Logger LOG = LoggerFactory.getLogger(StopExecution.class);
+
+ public static void main(String[] args) {
+ StopExecution stopExecution = new StopExecution();
+ //stopExecution.testUsingLoop();
+ //stopExecution.testTimer();
+ stopExecution.testScheduledExecutor();
+ LOG.info("done");
+ }
+
+ public void testUsingLoop() {
+ long start = System.currentTimeMillis();
+ long end = start + 5000;
+ List items = new ArrayList<>();
+ int counter = 0;
+
+ // Let this loop run only upto 5 seconds
+ while (System.currentTimeMillis() < end && counter < items.size()) {
+ // Fetch the item from the list.
+ // Some expensive operation on the item.
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ counter++;
+ }
+ }
+
+ public static void testThreads() {
+ Thread thread = new Thread(new Runnable() {
+ @Override
+ public void run() {
+ LOG.info("inside run");
+
+ try {
+ Thread.sleep(10000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ LOG.info("exit run");
+ }
+ });
+ thread.start();
+ while (thread.getState() != Thread.State.TERMINATED) {
+ LOG.info(thread.getState().name());
+ try {
+ Thread.sleep(500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void testExecutor() {
+ final ExecutorService service = Executors.newSingleThreadExecutor();
+ Future f = null;
+ try {
+ f = service.submit(() -> {
+ // Do you long running calculation here
+ try {
+ Thread.sleep(2737); // Simulate some delay
+ } catch (InterruptedException e) {
+ LOG.info("Interrupted");
+ return "interrupted";
+ }
+ LOG.info("Sleep finished");
+ return "42";
+ });
+
+ LOG.info(f.get(2, TimeUnit.SECONDS));
+ } catch (TimeoutException e) {
+ f.cancel(true);
+ LOG.error("Calculation took to long");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ service.shutdown();
+ }
+ }
+
+ public void testExecutor2() {
+ final ExecutorService service = Executors.newSingleThreadExecutor();
+ Future f = null;
+ try {
+ f = service.submit(new LongRunningTask());
+ LOG.info("testExecutor2");
+ f.get(1, TimeUnit.SECONDS);
+ } catch (final TimeoutException e) {
+ f.cancel(true);
+ LOG.error("Calculation took to long");
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ service.shutdownNow();
+ }
+ }
+
+ public void testScheduledExecutor() {
+ LOG.info("testScheduledExecutor");
+ ScheduledExecutorService executor = Executors.newScheduledThreadPool(2);
+ Future future = executor.submit(new LongRunningTask());
+ executor.schedule(new Runnable() {
+ public void run() {
+ future.cancel(true);
+ }
+ }, 1000, TimeUnit.MILLISECONDS);
+ executor.shutdown();
+ }
+
+ public void testThreadAndInterrupt() {
+
+ Thread t;
+ try {
+ t = new Thread(new LongRunningTask());
+
+ LOG.info("testExecutor3");
+ long end = System.currentTimeMillis() + 2000;
+ t.start();
+ while (t.isAlive() && System.currentTimeMillis() < end) {
+ Thread.sleep(50);
+ }
+ t.interrupt();
+ } catch (final Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void testTimer() {
+ LOG.info("Timer test");
+ Thread t = new Thread(new LongRunningTask());
+ Timer timeoutTimer = new Timer();
+ timeoutTimer.schedule(new TimeOutTask(t, timeoutTimer), 1000);
+ t.start();
+ }
+
+ class MyRunnableTask implements Runnable {
+ public void run() {
+ try {
+ LOG.info("MyRunnable...");
+ Thread.sleep(10000);
+ } catch (InterruptedException ie) {
+ LOG.info("MyRunnable interrupted...");
+ }
+ }
+ }
+
+ class TimeOutTask extends TimerTask {
+ private Thread t;
+ private Timer timer;
+
+ TimeOutTask(Thread t, Timer timer) {
+ this.t = t;
+ this.timer = timer;
+ }
+
+ public void run() {
+ if (t != null && t.isAlive()) {
+ t.interrupt();
+ timer.cancel();
+ }
+ }
+ }
+
+ class LongRunningTask implements Runnable {
+ @Override
+ public void run() {
+ longRunningSort();
+ }
+
+ private void longRunningOperation() {
+ LOG.info("long Running operation started");
+
+ try {
+ //Thread.sleep(500);
+ longFileRead();
+ LOG.info("long running operation finished");
+ } catch (InterruptedException e) {
+ LOG.info("long Running operation interrupted");
+ }
+ }
+
+ private void longRunningSort() {
+ LOG.info("long Running task started");
+ // Do you long running calculation here
+ int len = 100000;
+ List numbers = new ArrayList<>();
+ try {
+ for (int i = len; i > 0; i--) {
+ //Thread.sleep(5)
+ numbers.add(i);
+ }
+
+ int i = 0;
+ for (i = 0; i < len; i++) {
+ int minIndex = i;
+ for (int j = i + 1; j < len; j++) {
+ if (numbers.get(minIndex) > numbers.get(j))
+ minIndex = j;
+ }
+ if (minIndex != i) {
+ int temp = numbers.get(i);
+ numbers.set(i, numbers.get(minIndex));
+ numbers.set(minIndex, temp);
+ }
+ throwExceptionOnThreadInterrupt();
+ }
+ LOG.info("Index position: " + i);
+ LOG.info("Long running task finished");
+ } catch (InterruptedException e) {
+ LOG.info("long Running operation interrupted");
+ }
+ }
+
+ private void longFileRead() throws InterruptedException {
+ String file = "input.txt";
+ ClassLoader classloader = getClass().getClassLoader();
+
+ try (InputStream inputStream = classloader.getResourceAsStream(file)) {
+ Reader inputStreamReader = new InputStreamReader(inputStream);
+
+ int data = inputStreamReader.read();
+ while (data != -1) {
+ char theChar = (char) data;
+ data = inputStreamReader.read();
+ throwExceptionOnThreadInterrupt();
+ }
+ } catch (IOException e) {
+ LOG.error("Exception: ", e);
+ }
+ }
+
+ private void throwExceptionOnThreadInterrupt() throws InterruptedException {
+ if (Thread.currentThread().interrupted()) {
+ throw new InterruptedException();
+ }
+ }
+ }
+
+}
+
+
diff --git a/core-java-modules/core-java-concurrency-collections-2/pom.xml b/core-java-modules/core-java-concurrency-collections-2/pom.xml
index f9ee41f6d5..19d43aa7dd 100644
--- a/core-java-modules/core-java-concurrency-collections-2/pom.xml
+++ b/core-java-modules/core-java-concurrency-collections-2/pom.xml
@@ -23,12 +23,12 @@
org.openjdk.jmhjmh-core
- ${jmh.version}
+ ${jmh-core.version}org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}org.assertj
@@ -39,7 +39,6 @@
- 1.2128.2-jre3.6.1
diff --git a/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java
index 7ee849b0a2..ce96c107f8 100644
--- a/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java
+++ b/core-java-modules/core-java-concurrency-collections/src/test/java/com/baeldung/java/stream/ThreadPoolInParallelStreamIntegrationTest.java
@@ -21,14 +21,16 @@ public class ThreadPoolInParallelStreamIntegrationTest {
long lastNum = 1_000_000;
List aList = LongStream.rangeClosed(firstNum, lastNum).boxed().collect(Collectors.toList());
-
ForkJoinPool customThreadPool = new ForkJoinPool(4);
- long actualTotal = customThreadPool
- .submit(() -> aList.parallelStream()
- .reduce(0L, Long::sum))
- .get();
- assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal);
+ try {
+ long actualTotal = customThreadPool
+ .submit(() -> aList.parallelStream().reduce(0L, Long::sum))
+ .get();
+ assertEquals((lastNum + firstNum) * lastNum / 2, actualTotal);
+ } finally {
+ customThreadPool.shutdown();
+ }
}
@Test
diff --git a/core-java-modules/core-java-console/README.md b/core-java-modules/core-java-console/README.md
index 725e2482bb..0a31727588 100644
--- a/core-java-modules/core-java-console/README.md
+++ b/core-java-modules/core-java-console/README.md
@@ -1,5 +1,8 @@
#Core Java Console
-[Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output)
-[Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf)
-[ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
\ No newline at end of file
+### Relevant Articles:
+
+- [Read and Write User Input in Java](http://www.baeldung.com/java-console-input-output)
+- [Formatting with printf() in Java](https://www.baeldung.com/java-printstream-printf)
+- [ASCII Art in Java](http://www.baeldung.com/ascii-art-in-java)
+- [System.console() vs. System.out](https://www.baeldung.com/java-system-console-vs-system-out)
diff --git a/core-java-modules/core-java-console/pom.xml b/core-java-modules/core-java-console/pom.xml
index 1d58d8c253..fc4f1875ca 100644
--- a/core-java-modules/core-java-console/pom.xml
+++ b/core-java-modules/core-java-console/pom.xml
@@ -45,7 +45,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}javacom.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
@@ -105,7 +104,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}run-benchmarks
@@ -134,7 +132,6 @@
3.0.0-M1
- 1.6.01.81.8
diff --git a/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java
new file mode 100644
index 0000000000..082a5219c9
--- /dev/null
+++ b/core-java-modules/core-java-console/src/main/java/com/baeldung/consoleout/ConsoleAndOut.java
@@ -0,0 +1,31 @@
+package com.baeldung.consoleout;
+
+import java.io.Console;
+
+public class ConsoleAndOut {
+ public static void main(String[] args) {
+ try {
+ printConsoleObject();
+ readPasswordFromConsole();
+ } catch (Exception ex) {
+ // Eating NullPointerExcpetion which will occur when this
+ // program will be run from mediums other than console
+ }
+ printSysOut();
+ }
+
+ static void printConsoleObject() {
+ Console console = System.console();
+ console.writer().print(console);
+ }
+
+ static void readPasswordFromConsole() {
+ Console console = System.console();
+ char[] password = console.readPassword("Enter password: ");
+ console.printf(String.valueOf(password));
+ }
+
+ static void printSysOut() {
+ System.out.println(System.out);
+ }
+}
diff --git a/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java
new file mode 100644
index 0000000000..619a65a1fc
--- /dev/null
+++ b/core-java-modules/core-java-console/src/test/java/com/baeldung/consoleout/ConsoleAndOutUnitTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.consoleout;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import org.junit.jupiter.api.Test;
+
+class ConsoleAndOutUnitTest {
+
+ @Test
+ void whenRetreivingConsole_thenPrintConsoleObject() {
+ assertThrows(NullPointerException.class, () -> {
+ ConsoleAndOut.printConsoleObject();
+ });
+ }
+
+ @Test
+ void whenReadingPassword_thenReadPassword() {
+ assertThrows(NullPointerException.class, () -> {
+ ConsoleAndOut.readPasswordFromConsole();
+ });
+ }
+
+ @Test
+ void whenRetrievingSysOut_thenPrintSysOutObject() {
+ ConsoleAndOut.printSysOut();
+ }
+}
diff --git a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java
index 226556d4bb..9a0779ccac 100644
--- a/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java
+++ b/core-java-modules/core-java-date-operations-1/src/test/java/com/baeldung/date/DateDiffUnitTest.java
@@ -1,6 +1,8 @@
package com.baeldung.date;
-import static org.junit.Assert.assertEquals;
+import org.joda.time.Days;
+import org.joda.time.Minutes;
+import org.junit.Test;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@@ -16,7 +18,7 @@ import java.util.Locale;
import java.util.TimeZone;
import java.util.concurrent.TimeUnit;
-import org.junit.Test;
+import static org.junit.Assert.*;
public class DateDiffUnitTest {
@@ -29,18 +31,39 @@ public class DateDiffUnitTest {
long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
- assertEquals(diff, 6);
+ assertEquals(6, diff);
}
@Test
- public void givenTwoDatesInJava8_whenDifferentiating_thenWeGetSix() {
- LocalDate now = LocalDate.now();
- LocalDate sixDaysBehind = now.minusDays(6);
+ public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenWorks() {
+ LocalDate aDate = LocalDate.of(2020, 9, 11);
+ LocalDate sixDaysBehind = aDate.minusDays(6);
- Period period = Period.between(now, sixDaysBehind);
+ Period period = Period.between(aDate, sixDaysBehind);
int diff = Math.abs(period.getDays());
- assertEquals(diff, 6);
+ assertEquals(6, diff);
+ }
+
+ @Test
+ public void givenTwoDatesInJava8_whenUsingPeriodGetDays_thenDoesNotWork() {
+ LocalDate aDate = LocalDate.of(2020, 9, 11);
+ LocalDate sixtyDaysBehind = aDate.minusDays(60);
+ Period period = Period.between(aDate, sixtyDaysBehind);
+ int diff = Math.abs(period.getDays());
+ //not equals
+ assertNotEquals(60, diff);
+ }
+
+ @Test
+ public void givenTwoDatesInJava8_whenUsingPeriod_thenWeGet0Year1Month29Days() {
+ LocalDate aDate = LocalDate.of(2020, 9, 11);
+ LocalDate sixtyDaysBehind = aDate.minusDays(60);
+ Period period = Period.between(aDate, sixtyDaysBehind);
+ int years = Math.abs(period.getYears());
+ int months = Math.abs(period.getMonths());
+ int days = Math.abs(period.getDays());
+ assertArrayEquals(new int[] { 0, 1, 29 }, new int[] { years, months, days });
}
@Test
@@ -51,7 +74,7 @@ public class DateDiffUnitTest {
Duration duration = Duration.between(now, sixMinutesBehind);
long diff = Math.abs(duration.toMinutes());
- assertEquals(diff, 6);
+ assertEquals(6, diff);
}
@Test
@@ -61,7 +84,7 @@ public class DateDiffUnitTest {
long diff = ChronoUnit.SECONDS.between(now, tenSecondsLater);
- assertEquals(diff, 10);
+ assertEquals(10, diff);
}
@Test
@@ -69,9 +92,9 @@ public class DateDiffUnitTest {
LocalDateTime ldt = LocalDateTime.now();
ZonedDateTime now = ldt.atZone(ZoneId.of("America/Montreal"));
ZonedDateTime sixDaysBehind = now.withZoneSameInstant(ZoneId.of("Asia/Singapore"))
- .minusDays(6);
+ .minusDays(6);
long diff = ChronoUnit.DAYS.between(sixDaysBehind, now);
- assertEquals(diff, 6);
+ assertEquals(6, diff);
}
@Test
@@ -81,7 +104,7 @@ public class DateDiffUnitTest {
long diff = now.until(tenSecondsLater, ChronoUnit.SECONDS);
- assertEquals(diff, 10);
+ assertEquals(10, diff);
}
@Test
@@ -89,10 +112,9 @@ public class DateDiffUnitTest {
org.joda.time.LocalDate now = org.joda.time.LocalDate.now();
org.joda.time.LocalDate sixDaysBehind = now.minusDays(6);
- org.joda.time.Period period = new org.joda.time.Period(now, sixDaysBehind);
- long diff = Math.abs(period.getDays());
+ long diff = Math.abs(Days.daysBetween(now, sixDaysBehind).getDays());
- assertEquals(diff, 6);
+ assertEquals(6, diff);
}
@Test
@@ -100,8 +122,9 @@ public class DateDiffUnitTest {
org.joda.time.LocalDateTime now = org.joda.time.LocalDateTime.now();
org.joda.time.LocalDateTime sixMinutesBehind = now.minusMinutes(6);
- org.joda.time.Period period = new org.joda.time.Period(now, sixMinutesBehind);
- long diff = Math.abs(period.getDays());
+ long diff = Math.abs(Minutes.minutesBetween(now, sixMinutesBehind).getMinutes());
+ assertEquals(6, diff);
+
}
@Test
@@ -111,6 +134,6 @@ public class DateDiffUnitTest {
long diff = Math.abs(now.numDaysFrom(sixDaysBehind));
- assertEquals(diff, 6);
+ assertEquals(6, diff);
}
-}
\ No newline at end of file
+}
diff --git a/core-java-modules/core-java-date-operations-2/README.md b/core-java-modules/core-java-date-operations-2/README.md
index 6dc1302d99..557e4c3517 100644
--- a/core-java-modules/core-java-date-operations-2/README.md
+++ b/core-java-modules/core-java-date-operations-2/README.md
@@ -2,6 +2,7 @@
This module contains articles about date operations in Java.
### Relevant Articles:
+
- [Get the Current Date Prior to Java 8](https://www.baeldung.com/java-get-the-current-date-legacy)
- [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)
@@ -9,4 +10,5 @@ This module contains articles about date operations in Java.
- [How to Set the JVM Time Zone](https://www.baeldung.com/java-jvm-time-zone)
- [How to determine day of week by passing specific date in Java?](https://www.baeldung.com/java-get-day-of-week)
- [Finding Leap Years in Java](https://www.baeldung.com/java-leap-year)
+- [Getting the Week Number From Any Date](https://www.baeldung.com/java-get-week-number)
- [[<-- Prev]](/core-java-modules/core-java-date-operations-1)
diff --git a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java
index e5fd80285c..bb36dd634e 100644
--- a/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java
+++ b/core-java-modules/core-java-datetime-conversion/src/test/java/com/baeldung/datetime/ConvertInstantToTimestampUnitTest.java
@@ -6,6 +6,7 @@ import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.Instant;
+import java.time.format.DateTimeFormatter;
import java.util.TimeZone;
import static org.assertj.core.api.Assertions.assertThat;
@@ -21,9 +22,12 @@ public class ConvertInstantToTimestampUnitTest {
instant = timestamp.toInstant();
assertThat(instant.toEpochMilli()).isEqualTo(timestamp.getTime());
- DateFormat df = DateFormat.getDateTimeInstance();
- df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
+ formatter = formatter.withZone(TimeZone.getTimeZone("UTC").toZoneId());
+
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
df.setTimeZone(TimeZone.getTimeZone("UTC"));
- assertThat(instant.toString()).isEqualTo(df.format(timestamp).toString());
+
+ assertThat(formatter.format(instant)).isEqualTo(df.format(timestamp));
}
}
diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java
index e07422a9c6..0d2bb810f0 100644
--- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java
+++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/date/StringToDateUnitTest.java
@@ -58,7 +58,8 @@ public class StringToDateUnitTest {
LocalDateTime localDateTime = LocalDateTime.of(2015, 05, 05, 10, 15, 30);
ZonedDateTime expectedZonedDateTime = ZonedDateTime.of(localDateTime, ZoneId.of("Europe/Paris"));
- ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-05-05T10:15:30+01:00[Europe/Paris]");
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
+ ZonedDateTime zonedDateTime = ZonedDateTime.parse("2015-05-05 10:15:30 Europe/Paris", formatter);
assertThat(zonedDateTime).isEqualTo(expectedZonedDateTime);
}
diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java
index f3b2b11893..b1c88cb44c 100644
--- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java
+++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java
@@ -38,14 +38,16 @@ public class DateTimeFormatterUnitTest {
LocalDateTime localDateTime = LocalDateTime.of(2018, 1, 1, 10, 15, 50, 500);
ZoneId losAngelesTimeZone = TimeZone.getTimeZone("America/Los_Angeles").toZoneId();
- DateTimeFormatter localizedFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL);
- DateTimeFormatter frLocalizedFormatter =
- DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withLocale(Locale.FRANCE);
+ DateTimeFormatter localizedFormatter = DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy z", Locale.US);
+ DateTimeFormatter frLocalizedFormatter = DateTimeFormatter.ofPattern("EEEE, MMMM dd, yyyy z", Locale.FRANCE);
String formattedDateTime = localizedFormatter.format(ZonedDateTime.of(localDateTime, losAngelesTimeZone));
String frFormattedDateTime = frLocalizedFormatter.format(ZonedDateTime.of(localDateTime, losAngelesTimeZone));
- Assert.assertEquals("Monday, January 1, 2018 10:15:50 AM PST", formattedDateTime);
- Assert.assertEquals("lundi 1 janvier 2018 10 h 15 PST", frFormattedDateTime);
+ System.out.println(formattedDateTime);
+ System.out.println(frFormattedDateTime);
+
+ Assert.assertEquals("Monday, January 01, 2018 PST", formattedDateTime);
+ Assert.assertEquals("lundi, janvier 01, 2018 PST", frFormattedDateTime);
}
@Test
@@ -105,14 +107,15 @@ public class DateTimeFormatterUnitTest {
Assert.assertEquals("8/23/16", DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT).format(anotherSummerDay));
}
- @Test
- public void shouldPrintStyledDateTime() {
- LocalDateTime anotherSummerDay = LocalDateTime.of(2016, 8, 23, 13, 12, 45);
- Assert.assertEquals("Tuesday, August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
- Assert.assertEquals("August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
- Assert.assertEquals("Aug 23, 2016 1:12:45 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
- Assert.assertEquals("8/23/16 1:12 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
- }
+ // Note: The exact output format using the different FormatStyle constants differs by JVM/Java version
+ // @Test
+ // public void shouldPrintStyledDateTime() {
+ // LocalDateTime anotherSummerDay = LocalDateTime.of(2016, 8, 23, 13, 12, 45);
+ // Assert.assertEquals("Tuesday, August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
+ // Assert.assertEquals("August 23, 2016 1:12:45 PM EET", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
+ // Assert.assertEquals("Aug 23, 2016 1:12:45 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
+ // Assert.assertEquals("8/23/16 1:12 PM", DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT).withZone(ZoneId.of("Europe/Helsinki")).format(anotherSummerDay));
+ // }
@Test
public void shouldPrintFormattedDateTimeWithPredefined() {
@@ -126,11 +129,12 @@ public class DateTimeFormatterUnitTest {
Assert.assertEquals(LocalDate.of(2018, 3, 12), LocalDate.from(DateTimeFormatter.ISO_LOCAL_DATE.parse("2018-03-09")).plusDays(3));
}
- @Test
- public void shouldParseFormatStyleFull() {
- ZonedDateTime dateTime = ZonedDateTime.from(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).parse("Tuesday, August 23, 2016 1:12:45 PM EET"));
- Assert.assertEquals(ZonedDateTime.of(LocalDateTime.of(2016, 8, 23, 22, 12, 45), ZoneId.of("Europe/Bucharest")), dateTime.plusHours(9));
- }
+ // Note: The exact output format using the different FormatStyle constants differs by JVM/Java version
+ // @Test
+ // public void shouldParseFormatStyleFull() {
+ // ZonedDateTime dateTime = ZonedDateTime.from(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.FULL).parse("Tuesday, August 23, 2016 1:12:45 PM EET"));
+ // Assert.assertEquals(ZonedDateTime.of(LocalDateTime.of(2016, 8, 23, 22, 12, 45), ZoneId.of("Europe/Bucharest")), dateTime.plusHours(9));
+ // }
@Test
public void shouldParseDateWithCustomFormatter() {
diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java
deleted file mode 100644
index b25ff2edb3..0000000000
--- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterTest.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.timestamp;
-
-import org.junit.Assert;
-import org.junit.jupiter.api.Test;
-
-import java.sql.Timestamp;
-import java.time.format.DateTimeFormatter;
-
-public class TimestampToStringConverterTest {
-
- @Test
- public void givenDatePattern_whenFormatting_thenResultingStringIsCorrect() {
- Timestamp timestamp = Timestamp.valueOf("2018-12-12 01:02:03.123456789");
- DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
-
- String timestampAsString = formatter.format(timestamp.toLocalDateTime());
- Assert.assertEquals("2018-12-12T01:02:03.123456789", timestampAsString);
- }
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java
new file mode 100644
index 0000000000..b928047a9a
--- /dev/null
+++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/timestamp/TimestampToStringConverterUnitTest.java
@@ -0,0 +1,19 @@
+package com.baeldung.timestamp;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Timestamp;
+import java.time.format.DateTimeFormatter;
+
+public class TimestampToStringConverterUnitTest {
+
+ @Test
+ public void givenDatePattern_whenFormatting_thenResultingStringIsCorrect() {
+ Timestamp timestamp = Timestamp.valueOf("2018-12-12 01:02:03.123456789");
+ DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME;
+
+ String timestampAsString = formatter.format(timestamp.toLocalDateTime());
+ Assert.assertEquals("2018-12-12T01:02:03.123456789", timestampAsString);
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md
index 46ffd490be..e6441c2c12 100644
--- a/core-java-modules/core-java-exceptions-2/README.md
+++ b/core-java-modules/core-java-exceptions-2/README.md
@@ -12,3 +12,5 @@ This module contains articles about core java exceptions
- [Java – Try with Resources](https://www.baeldung.com/java-try-with-resources)
- [Java Global Exception Handler](https://www.baeldung.com/java-global-exception-handler)
- [How to Find an Exception’s Root Cause in Java](https://www.baeldung.com/java-exception-root-cause)
+- [Java IOException “Too many open files”](https://www.baeldung.com/java-too-many-open-files)
+- [When Does Java Throw the ExceptionInInitializerError?](https://www.baeldung.com/java-exceptionininitializererror)
diff --git a/core-java-modules/core-java-exceptions-3/README.md b/core-java-modules/core-java-exceptions-3/README.md
new file mode 100644
index 0000000000..e1372381a8
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/README.md
@@ -0,0 +1,10 @@
+### Relevant Articles:
+
+- [NoSuchMethodError in Java](https://www.baeldung.com/java-nosuchmethod-error)
+- [IllegalArgumentException or NullPointerException for a Null Parameter?](https://www.baeldung.com/java-illegalargumentexception-or-nullpointerexception)
+- [IllegalMonitorStateException in Java](https://www.baeldung.com/java-illegalmonitorstateexception)
+- [AbstractMethodError in Java](https://www.baeldung.com/java-abstractmethoderror)
+- [Java IndexOutOfBoundsException “Source Does Not Fit in Dest”](https://www.baeldung.com/java-indexoutofboundsexception)
+- [Localizing Exception Messages in Java](https://www.baeldung.com/java-localize-exception-messages)
+- [Explanation of ClassCastException in Java](https://www.baeldung.com/java-classcastexception)
+- [NoSuchFieldError in Java](https://www.baeldung.com/java-nosuchfielderror)
diff --git a/core-java-modules/core-java-exceptions-3/pom.xml b/core-java-modules/core-java-exceptions-3/pom.xml
new file mode 100644
index 0000000000..8c36fd0af1
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/pom.xml
@@ -0,0 +1,41 @@
+
+
+ 4.0.0
+ com.baeldung.exceptions
+ core-java-exceptions-3
+ 0.1.0-SNAPSHOT
+ core-java-exceptions-3
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+
+ com.h2database
+ h2
+ 1.4.191
+ test
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj-core.version}
+ test
+
+
+
+
+
+ 3.10.0
+
+
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java
new file mode 100644
index 0000000000..34e6f1c998
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemo.java
@@ -0,0 +1,14 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CopyListUsingAddAllMethodDemo {
+ static List copyList(List source) {
+ List destination = new ArrayList<>();
+
+ destination.addAll(source);
+
+ return destination;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java
new file mode 100644
index 0000000000..664e2152d8
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemo.java
@@ -0,0 +1,10 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import java.util.Collections;
+import java.util.List;
+
+public class CopyListUsingCollectionsCopyMethodDemo {
+ static void copyList(List source, List destination) {
+ Collections.copy(destination, source);
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java
new file mode 100644
index 0000000000..493031ba0a
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemo.java
@@ -0,0 +1,10 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class CopyListUsingConstructorDemo {
+ static List copyList(List source) {
+ return new ArrayList<>(source);
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java
new file mode 100644
index 0000000000..d9d0247d2f
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemo.java
@@ -0,0 +1,12 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class CopyListUsingJava8StreamDemo {
+ static List copyList(List source) {
+ return source
+ .stream()
+ .collect(Collectors.toList());
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java
new file mode 100644
index 0000000000..78b7b03bc1
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemo.java
@@ -0,0 +1,13 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+public class IndexOutOfBoundsExceptionDemo {
+ static List copyList(List source) {
+ List destination = new ArrayList<>(source.size());
+ Collections.copy(destination, source);
+ return destination;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java
new file mode 100644
index 0000000000..f31c19bc0f
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Amphibian.java
@@ -0,0 +1,9 @@
+package com.baeldung.exceptions.classcastexception;
+
+public class Amphibian implements Animal {
+
+ @Override
+ public String getName() {
+ return "Amphibian";
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Animal.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Animal.java
new file mode 100644
index 0000000000..b57f68f053
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Animal.java
@@ -0,0 +1,6 @@
+package com.baeldung.exceptions.classcastexception;
+
+public interface Animal {
+
+ String getName();
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Box.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Box.java
new file mode 100644
index 0000000000..bb67407218
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Box.java
@@ -0,0 +1,14 @@
+package com.baeldung.exceptions.classcastexception;
+
+public class Box {
+
+ private T content;
+
+ public T getContent() {
+ return content;
+ }
+
+ public void setContent(T content) {
+ this.content = content;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java
new file mode 100644
index 0000000000..a3837f4c2f
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Frog.java
@@ -0,0 +1,9 @@
+package com.baeldung.exceptions.classcastexception;
+
+public class Frog extends Amphibian {
+
+ @Override
+ public String getName() {
+ return super.getName() + ": Frog";
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Mammal.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Mammal.java
new file mode 100644
index 0000000000..2723cc5b7b
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/classcastexception/Mammal.java
@@ -0,0 +1,9 @@
+package com.baeldung.exceptions.classcastexception;
+
+public class Mammal implements Animal {
+
+ @Override
+ public String getName() {
+ return "Mammal";
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/Data.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/Data.java
new file mode 100644
index 0000000000..b5867d15e7
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/Data.java
@@ -0,0 +1,14 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+public class Data {
+ private String message;
+
+ public void send(String message) {
+ this.message = message;
+ }
+
+ public String receive() {
+ return message;
+ }
+}
+
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java
new file mode 100644
index 0000000000..ff6b926cdc
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedReceiver.java
@@ -0,0 +1,39 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SynchronizedReceiver implements Runnable {
+ private static Logger log = LoggerFactory.getLogger(SynchronizedReceiver.class);
+ private final Data data;
+ private String message;
+ private boolean illegalMonitorStateExceptionOccurred;
+
+ public SynchronizedReceiver(Data data) {
+ this.data = data;
+ }
+
+ @Override
+ public void run() {
+ synchronized (data) {
+ try {
+ data.wait();
+ this.message = data.receive();
+ } catch (InterruptedException e) {
+ log.error("thread was interrupted", e);
+ Thread.currentThread().interrupt();
+ } catch (IllegalMonitorStateException e) {
+ log.error("illegal monitor state exception occurred", e);
+ illegalMonitorStateExceptionOccurred = true;
+ }
+ }
+ }
+
+ public boolean hasIllegalMonitorStateExceptionOccurred() {
+ return illegalMonitorStateExceptionOccurred;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java
new file mode 100644
index 0000000000..1618bc8efa
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/SynchronizedSender.java
@@ -0,0 +1,37 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SynchronizedSender implements Runnable {
+ private static Logger log = LoggerFactory.getLogger(SynchronizedSender.class);
+ private final Data data;
+ private boolean illegalMonitorStateExceptionOccurred;
+
+ public SynchronizedSender(Data data) {
+ this.data = data;
+ }
+
+ @Override
+ public void run() {
+ synchronized (data) {
+ try {
+ Thread.sleep(1000);
+
+ data.send("test");
+
+ data.notifyAll();
+ } catch (InterruptedException e) {
+ log.error("thread was interrupted", e);
+ Thread.currentThread().interrupt();
+ } catch (IllegalMonitorStateException e) {
+ log.error("illegal monitor state exception occurred", e);
+ illegalMonitorStateExceptionOccurred = true;
+ }
+ }
+ }
+
+ public boolean hasIllegalMonitorStateExceptionOccurred() {
+ return illegalMonitorStateExceptionOccurred;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java
new file mode 100644
index 0000000000..3a0b72e6cd
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedReceiver.java
@@ -0,0 +1,37 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UnsynchronizedReceiver implements Runnable {
+ private static Logger log = LoggerFactory.getLogger(UnsynchronizedReceiver.class);
+ private final Data data;
+ private String message;
+ private boolean illegalMonitorStateExceptionOccurred;
+
+ public UnsynchronizedReceiver(Data data) {
+ this.data = data;
+ }
+
+ @Override
+ public void run() {
+ try {
+ data.wait();
+ this.message = data.receive();
+ } catch (InterruptedException e) {
+ log.error("thread was interrupted", e);
+ Thread.currentThread().interrupt();
+ } catch (IllegalMonitorStateException e) {
+ log.error("illegal monitor state exception occurred", e);
+ illegalMonitorStateExceptionOccurred = true;
+ }
+ }
+
+ public boolean hasIllegalMonitorStateExceptionOccurred() {
+ return illegalMonitorStateExceptionOccurred;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java
new file mode 100644
index 0000000000..7f15418bfa
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/illegalmonitorstate/UnsynchronizedSender.java
@@ -0,0 +1,35 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class UnsynchronizedSender implements Runnable {
+ private static Logger log = LoggerFactory.getLogger(UnsynchronizedSender.class);
+ private final Data data;
+ private boolean illegalMonitorStateExceptionOccurred;
+
+ public UnsynchronizedSender(Data data) {
+ this.data = data;
+ }
+
+ @Override
+ public void run() {
+ try {
+ Thread.sleep(1000);
+
+ data.send("test");
+
+ data.notifyAll();
+ } catch (InterruptedException e) {
+ log.error("thread was interrupted", e);
+ Thread.currentThread().interrupt();
+ } catch (IllegalMonitorStateException e) {
+ log.error("illegal monitor state exception occurred", e);
+ illegalMonitorStateExceptionOccurred = true;
+ }
+ }
+
+ public boolean hasIllegalMonitorStateExceptionOccurred() {
+ return illegalMonitorStateExceptionOccurred;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java
new file mode 100644
index 0000000000..c3f9980b99
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/LocalizedException.java
@@ -0,0 +1,47 @@
+package com.baeldung.exceptions.localization;
+
+import java.util.Locale;
+
+public class LocalizedException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ private final String messageKey;
+ private final Locale locale;
+
+ public LocalizedException(String messageKey) {
+ this(messageKey, Locale.getDefault());
+ }
+
+ public LocalizedException(String messageKey, Locale locale) {
+ this.messageKey = messageKey;
+ this.locale = locale;
+ }
+
+ /**
+ * @return a localized message based on the messageKey provided at instantiation.
+ */
+ public String getMessage() {
+
+ /*
+ * This is a deliberate role reversal of the default implementation of getLocalizedMessage.
+ * some logging frameworks like Log4J 1 & 2 and Logback will use getMessage instead of
+ * getLocalizedMessage when logging Throwables. If we want to use these frameworks in client
+ * applications to log localized messages, then we'll need to override getMessage in a
+ * similar fashion to return the appropriate content. Or, you can call getLocalizedMessage
+ * on your own to create the log content.
+ */
+ return getLocalizedMessage();
+ }
+
+ /**
+ * @return a localized message based on the messageKey provided at instantiation.
+ */
+ public String getLocalizedMessage() {
+
+ /*
+ * java.util.logging uses getLocalizedMessage when logging Throwables.
+ */
+ return Messages.getMessageForLocale(messageKey, locale);
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java
new file mode 100644
index 0000000000..1079bedd1a
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/localization/Messages.java
@@ -0,0 +1,27 @@
+package com.baeldung.exceptions.localization;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+public class Messages {
+
+ /**
+ * Retrieves the value for the messageKey from the locale-specific messages.properties, or from
+ * the base messages.properties for unsupported locales.
+ *
+ * @param messageKey The key for the message in the messages.properties ResourceBundle.
+ * @param locale The locale to search the message key.
+ * @return The value defined for the messageKey in the provided locale.
+ */
+ public static String getMessageForLocale(String messageKey, Locale locale) {
+
+ /*
+ * For more complex implementations, you will want a var-args parameter for MessageFormat
+ * substitutions. Then we can read the value from the bundle and pass the value with the
+ * substitutions to MessageFormat to create the final message value.
+ */
+ return ResourceBundle.getBundle("messages", locale)
+ .getString(messageKey);
+ }
+
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java
new file mode 100644
index 0000000000..31ac54ac6b
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/Dependency.java
@@ -0,0 +1,8 @@
+package com.baeldung.exceptions.nosuchfielderror;
+
+public class Dependency {
+
+ // This needed to be commented post compilation of NoSuchFielDError and Compile
+ public static String message = "Hello Baeldung!!";
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java
new file mode 100644
index 0000000000..021ed57d87
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExample.java
@@ -0,0 +1,20 @@
+package com.baeldung.exceptions.nosuchfielderror;
+
+public class FieldErrorExample {
+
+ public static void main(String... args) {
+
+ fetchAndPrint();
+ }
+
+ public static String getDependentMessage() {
+
+ return Dependency.message;
+ }
+
+ public static void fetchAndPrint() {
+
+ System.out.println(getDependentMessage());
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/MainMenu.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/MainMenu.java
new file mode 100644
index 0000000000..f12cbe1897
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/MainMenu.java
@@ -0,0 +1,11 @@
+package com.baeldung.exceptions.nosuchmethoderror;
+
+public class MainMenu {
+ public static void main(String[] args) {
+ System.out.println("Today's Specials: " + getSpecials());
+ }
+
+ public static String getSpecials() {
+ return SpecialToday.getDesert();
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/SpecialToday.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/SpecialToday.java
new file mode 100644
index 0000000000..1b0dea9784
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/exceptions/nosuchmethoderror/SpecialToday.java
@@ -0,0 +1,8 @@
+package com.baeldung.exceptions.nosuchmethoderror;
+public class SpecialToday {
+ private static String desert = "Chocolate Cake";
+
+ public static String getDesert() {
+ return desert;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java
new file mode 100644
index 0000000000..c2c76bdc46
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/java/com/baeldung/nullmethodparameter/NullParameterExample.java
@@ -0,0 +1,17 @@
+package com.baeldung.nullmethodparameter;
+
+public class NullParameterExample {
+ public void processSomethingNotNull(Object myParameter) {
+ if (myParameter == null) {
+ throw new IllegalArgumentException("Parameter 'myParameter' cannot be null");
+ }
+ //Do something with the parameter
+ }
+
+ public void processSomethingElseNotNull(Object myParameter) {
+ if (myParameter == null) {
+ throw new NullPointerException("Parameter 'myParameter' cannot be null");
+ }
+ //Do something with the parameter
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties b/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties
new file mode 100644
index 0000000000..b6122d7f21
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/resources/messages.properties
@@ -0,0 +1 @@
+message.exception = I am an exception.
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties b/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties
new file mode 100644
index 0000000000..f28e0d54ff
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/main/resources/messages_fr.properties
@@ -0,0 +1 @@
+message.exception = Je suis une exception.
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java
new file mode 100644
index 0000000000..204bbff696
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingAddAllMethodDemoUnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CopyListUsingAddAllMethodDemoUnitTest {
+
+ @Test
+ void whenPassValidArrayList_thenCopyListUsingAddAllMethod() {
+ List source = Arrays.asList(11, 22, 33);
+
+ assertEquals(source, CopyListUsingAddAllMethodDemo.copyList(source));
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java
new file mode 100644
index 0000000000..7ebf7461a6
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingCollectionsCopyMethodDemoUnitTest.java
@@ -0,0 +1,31 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class CopyListUsingCollectionsCopyMethodDemoUnitTest {
+ @Test
+ void whenCopyListUsingCollectionsCopy_thenOverrideAllDestinationListValues() {
+ List source = Arrays.asList(11, 22, 33);
+ List destination = Arrays.asList(1, 2, 3);
+
+ CopyListUsingCollectionsCopyMethodDemo.copyList(source, destination);
+
+ assertEquals(source, destination);
+ }
+
+ @Test
+ void whenCopyListUsingCollectionsCopy_thenOverrideInitialDestinationValuesAndOthersShouldBeUnchanged(){
+ List source = Arrays.asList(11, 22, 33);
+ List destination = Arrays.asList(1, 2, 3, 4, 5);
+ List expectedList = Arrays.asList(11, 22, 33, 4, 5);
+
+ CopyListUsingCollectionsCopyMethodDemo.copyList(source, destination);
+
+ assertEquals(expectedList, destination);
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java
new file mode 100644
index 0000000000..cd15c5055c
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingConstructorDemoUnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CopyListUsingConstructorDemoUnitTest {
+
+ @Test
+ void whenCopyListUsingConstructor_thenMakeACopyOfList() {
+ List source = Arrays.asList(11, 22, 33);
+
+ assertEquals(source, CopyListUsingConstructorDemo.copyList(source));
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java
new file mode 100644
index 0000000000..9fb8e16b2a
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/CopyListUsingJava8StreamDemoUnitTest.java
@@ -0,0 +1,18 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class CopyListUsingJava8StreamDemoUnitTest {
+
+ @Test
+ void whenCopyListUsingStream_thenMakeACopyOfArrayList() {
+ List source = Arrays.asList(11, 22, 33);
+
+ assertEquals(source, CopyListUsingJava8StreamDemo.copyList(source));
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java
new file mode 100644
index 0000000000..9929fa78d3
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exception/indexoutofbounds/IndexOutOfBoundsExceptionDemoUnitTest.java
@@ -0,0 +1,28 @@
+package com.baeldung.exception.indexoutofbounds;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+
+class IndexOutOfBoundsExceptionDemoUnitTest {
+
+ @Test
+ void givenDestinationArrayListSizeIsZero_whenCopySourceArrayListToDestination_thenShouldThrowIndexOutOfBoundsException() {
+ List source = Arrays.asList(1, 2, 3, 4, 5);
+
+ assertThrows(IndexOutOfBoundsException.class, () -> IndexOutOfBoundsExceptionDemo.copyList(source));
+ }
+
+ @Test
+ void givenSourceAndDestinationListSizeIsEqual_whenCopySourceArrayListToDestination_thenShouldNotThrowIndexOutOfBoundsException() {
+ List source = Collections.emptyList();
+
+ assertEquals(source, IndexOutOfBoundsExceptionDemo.copyList(source));
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java
new file mode 100644
index 0000000000..cadc884487
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/abstractmethoderror/AbstractMethodErrorUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.exceptions.abstractmethoderror;
+
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+class AbstractMethodErrorUnitTest {
+ private static final String url = "jdbc:h2:mem:A-DATABASE;INIT=CREATE SCHEMA IF NOT EXISTS myschema";
+ private static final String username = "sa";
+
+ @Test
+ void givenOldH2Database_whenCallgetSchemaMethod_thenThrowAbstractMethodError() throws SQLException {
+ Connection conn = DriverManager.getConnection(url, username, "");
+ assertNotNull(conn);
+ Assertions.assertThrows(AbstractMethodError.class, () -> conn.getSchema());
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java
new file mode 100644
index 0000000000..7fac000fa8
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/CheckedCastsUnitTest.java
@@ -0,0 +1,40 @@
+package com.baeldung.exceptions.classcastexception;
+
+import org.junit.Test;
+
+import java.io.Serializable;
+
+public class CheckedCastsUnitTest {
+
+ @Test(expected = ClassCastException.class)
+ public void givenBaseTypeVariableReferencingChildInstance_whenCastToIncompatibleSubtype_thenClassCastException() {
+ Animal animal = new Frog();
+
+ //A checked downcast to Mammal is incompatible from Frog because Frog is not a subtype of Mammal.
+ Mammal mammal = (Mammal) animal;
+ }
+
+ @Test(expected = ClassCastException.class)
+ public void givenBaseTypeVariableReferencingChildInstance_whenCastToIncompatibleInterface_thenClassCastException() {
+ Animal animal = new Frog();
+
+ //A checked cast to Serializable is incompatible from Frog because Frog is not a subtype of Serializable.
+ Serializable serial = (Serializable) animal;
+ }
+
+ @Test(expected = ClassCastException.class)
+ public void givenObjectVariableReferencingPrimitiveArray_whenCastToBoxedTypeArray_thenClassCastException() {
+ Object primitives = new int[1];
+
+ //A checked cast to Integer[] is incompatible from primitive arrays. Auto-boxing does not work for arrays.
+ Integer[] integers = (Integer[]) primitives;
+ }
+
+ @Test(expected = ClassCastException.class)
+ public void givenObjectVariableReferencingPrimitiveArray_whenCastToPromotedTypeArray_thenClassCastException() {
+ Object primitives = new int[1];
+
+ //A checked cast to long[] is incompatible from int[]. Type promotion does not work for arrays.
+ long[] longs = (long[]) primitives;
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/GenericConversionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/GenericConversionUnitTest.java
new file mode 100644
index 0000000000..027ece2db7
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/GenericConversionUnitTest.java
@@ -0,0 +1,21 @@
+package com.baeldung.exceptions.classcastexception;
+
+import org.junit.Test;
+
+public class GenericConversionUnitTest {
+
+ @Test(expected = ClassCastException.class)
+ public void givenIncompatibleType_whenConvertInstanceOfObject_thenClassCastException() {
+ // Should have been null, but due to type erasure, inside convertInstanceOfObject,
+ // it will attempt to cast to Object instead of String, so it casts to Object, which is always possible.
+ String shouldBeNull = convertInstanceOfObject(123);
+ }
+
+ public static T convertInstanceOfObject(Object o) {
+ try {
+ return (T) o; // Casts to Object due to type erasure
+ } catch (ClassCastException e) {
+ return null; // Will never reach this
+ }
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/UncheckedConversionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/UncheckedConversionUnitTest.java
new file mode 100644
index 0000000000..60e7d5a147
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/classcastexception/UncheckedConversionUnitTest.java
@@ -0,0 +1,17 @@
+package com.baeldung.exceptions.classcastexception;
+
+import org.junit.Test;
+
+public class UncheckedConversionUnitTest {
+
+ @Test(expected = ClassCastException.class)
+ public void givenPollutedGenericType_whenGetProperty_thenClassCastException() {
+ Box originalBox = new Box<>();
+ Box raw = originalBox;
+ raw.setContent(2.5);
+ Box bound = (Box) raw;
+
+ //An incompatible element was found in the raw box.
+ Long content = bound.getContent();
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java
new file mode 100644
index 0000000000..82c00bc72f
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/illegalmonitorstate/IllegalMonitorStateExceptionUnitTest.java
@@ -0,0 +1,72 @@
+package com.baeldung.exceptions.illegalmonitorstate;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class IllegalMonitorStateExceptionUnitTest {
+
+ @Test
+ void whenSyncSenderAndSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldNotBeThrown() throws InterruptedException {
+ Data data = new Data();
+
+ SynchronizedReceiver receiver = new SynchronizedReceiver(data);
+ Thread receiverThread = new Thread(receiver, "receiver-thread");
+ receiverThread.start();
+
+ SynchronizedSender sender = new SynchronizedSender(data);
+ Thread senderThread = new Thread(sender, "sender-thread");
+ senderThread.start();
+
+ senderThread.join(1000);
+ receiverThread.join(1000);
+
+ Thread.sleep(2000);
+
+ assertEquals("test", receiver.getMessage());
+ assertFalse(sender.hasIllegalMonitorStateExceptionOccurred());
+ assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred());
+ }
+
+ @Test
+ void whenSyncSenderAndUnSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldNotBeThrown() throws InterruptedException {
+ Data data = new Data();
+
+ UnsynchronizedReceiver receiver = new UnsynchronizedReceiver(data);
+ Thread receiverThread = new Thread(receiver, "receiver-thread");
+ receiverThread.start();
+
+ SynchronizedSender sender = new SynchronizedSender(data);
+ Thread senderThread = new Thread(sender, "sender-thread");
+ senderThread.start();
+
+
+ receiverThread.join(1000);
+ senderThread.join(1000);
+
+ assertNull(receiver.getMessage());
+ assertFalse(sender.hasIllegalMonitorStateExceptionOccurred());
+ assertTrue(receiver.hasIllegalMonitorStateExceptionOccurred());
+ }
+
+ @Test
+ void whenUnSyncSenderAndSyncReceiverAreUsed_thenIllegalMonitorExceptionShouldBeThrown() throws InterruptedException {
+ Data data = new Data();
+
+ SynchronizedReceiver receiver = new SynchronizedReceiver(data);
+ Thread receiverThread = new Thread(receiver, "receiver-thread");
+ receiverThread.start();
+
+ UnsynchronizedSender sender = new UnsynchronizedSender(data);
+ Thread senderThread = new Thread(sender, "sender-thread");
+ senderThread.start();
+
+
+ receiverThread.join(1000);
+ senderThread.join(1000);
+
+ assertNull(receiver.getMessage());
+ assertFalse(receiver.hasIllegalMonitorStateExceptionOccurred());
+ assertTrue(sender.hasIllegalMonitorStateExceptionOccurred());
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java
new file mode 100644
index 0000000000..a46ca05d23
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/LocalizedExceptionUnitTest.java
@@ -0,0 +1,61 @@
+package com.baeldung.exceptions.localization;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Locale;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class LocalizedExceptionUnitTest {
+
+ private Locale originalDefaultLocale;
+
+ @Before
+ public void saveOriginalDefaultLocale() {
+ originalDefaultLocale = Locale.getDefault();
+ }
+
+ @After
+ public void restoreOriginalDefaultLocale() {
+ Locale.setDefault(originalDefaultLocale);
+ }
+
+ @Test
+ public void givenUsEnglishDefaultLocale_whenLocalizingMessage_thenMessageComesFromDefaultMessages() {
+ Locale.setDefault(Locale.US);
+
+ LocalizedException localizedException = new LocalizedException("message.exception");
+ String usEnglishLocalizedExceptionMessage = localizedException.getLocalizedMessage();
+
+ assertThat(usEnglishLocalizedExceptionMessage).isEqualTo("I am an exception.");
+ }
+
+ @Test
+ public void givenFranceFrenchDefaultLocale_whenLocalizingMessage_thenMessageComesFromFrenchTranslationMessages() {
+ Locale.setDefault(Locale.FRANCE);
+
+ LocalizedException localizedException = new LocalizedException("message.exception");
+ String franceFrenchLocalizedExceptionMessage = localizedException.getLocalizedMessage();
+
+ assertThat(franceFrenchLocalizedExceptionMessage).isEqualTo("Je suis une exception.");
+ }
+
+ @Test
+ public void givenUsEnglishProvidedLocale_whenLocalizingMessage_thenMessageComesFromDefaultMessage() {
+ LocalizedException localizedException = new LocalizedException("message.exception", Locale.US);
+ String usEnglishLocalizedExceptionMessage = localizedException.getLocalizedMessage();
+
+ assertThat(usEnglishLocalizedExceptionMessage).isEqualTo("I am an exception.");
+ }
+
+ @Test
+ public void givenFranceFrenchProvidedLocale_whenLocalizingMessage_thenMessageComesFromFrenchTranslationMessages() {
+ LocalizedException localizedException = new LocalizedException("message.exception", Locale.FRANCE);
+ String franceFrenchLocalizedExceptionMessage = localizedException.getLocalizedMessage();
+
+ assertThat(franceFrenchLocalizedExceptionMessage).isEqualTo("Je suis une exception.");
+ }
+
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java
new file mode 100644
index 0000000000..7a6cb8ed32
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/localization/MessagesUnitTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.exceptions.localization;
+
+import org.junit.Test;
+
+import java.util.Locale;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class MessagesUnitTest {
+
+ @Test
+ public void givenUsEnglishLocale_whenRetrievingMessage_thenEnglishTranslationIsReturned() {
+ String translatedMessage = Messages.getMessageForLocale("message.exception", Locale.US);
+
+ assertThat(translatedMessage).isEqualTo("I am an exception.");
+ }
+
+ @Test
+ public void givenFranceFrenchLocale_whenRetrievingMessage_thenFrenchTranslationIsReturned() {
+ String translatedMessage = Messages.getMessageForLocale("message.exception", Locale.FRANCE);
+
+ assertThat(translatedMessage).isEqualTo("Je suis une exception.");
+ }
+
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java
new file mode 100644
index 0000000000..d9a3efacc8
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchfielderror/FieldErrorExampleUnitTest.java
@@ -0,0 +1,16 @@
+package com.baeldung.exceptions.nosuchfielderror;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class FieldErrorExampleUnitTest {
+
+ @Test
+ public void whenDependentMessage_returnMessage() {
+
+ String dependentMessage = FieldErrorExample.getDependentMessage();
+ assertTrue("Hello Baeldung!!".equals(dependentMessage));
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchmethoderror/MainMenuUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchmethoderror/MainMenuUnitTest.java
new file mode 100644
index 0000000000..ce4374a9ba
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/exceptions/nosuchmethoderror/MainMenuUnitTest.java
@@ -0,0 +1,13 @@
+package com.baeldung.exceptions.nosuchmethoderror;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+
+class MainMenuUnitTest {
+
+ @Test
+ void whenGetSpecials_thenNotNull() {
+ assertNotNull(MainMenu.getSpecials());
+ }
+}
diff --git a/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java
new file mode 100644
index 0000000000..aa4b332e52
--- /dev/null
+++ b/core-java-modules/core-java-exceptions-3/src/test/java/com/baeldung/nullmethodparameter/NullParameterExampleUnitTest.java
@@ -0,0 +1,17 @@
+package com.baeldung.nullmethodparameter;
+
+import org.junit.Test;
+
+public class NullParameterExampleUnitTest {
+ @Test(expected = IllegalArgumentException.class)
+ public void givenNullParameter_whenProcessSomethingNotNull_thenIllegalArgumentException() {
+ NullParameterExample example = new NullParameterExample();
+ example.processSomethingNotNull(null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void givenNullParameter_whenProcessSomethingElseNotNull_thenNullPointerException() {
+ NullParameterExample example = new NullParameterExample();
+ example.processSomethingElseNotNull(null);
+ }
+}
diff --git a/core-java-modules/core-java-functional/README.md b/core-java-modules/core-java-functional/README.md
new file mode 100644
index 0000000000..5891b4a943
--- /dev/null
+++ b/core-java-modules/core-java-functional/README.md
@@ -0,0 +1,3 @@
+## Relevant articles:
+
+- [Functional Programming in Java](https://www.baeldung.com/java-functional-programming)
diff --git a/core-java-modules/core-java-functional/pom.xml b/core-java-modules/core-java-functional/pom.xml
new file mode 100644
index 0000000000..f00600c794
--- /dev/null
+++ b/core-java-modules/core-java-functional/pom.xml
@@ -0,0 +1,18 @@
+
+
+ 4.0.0
+ core-java-functional
+ 0.1.0-SNAPSHOT
+ core-java-functional
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java
new file mode 100644
index 0000000000..594fea4b8c
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Currying.java
@@ -0,0 +1,26 @@
+package com.baeldung.functional;
+
+import java.util.function.Function;
+
+public class Currying {
+
+ private static Function> weight = mass -> gravity -> mass * gravity;
+
+ private static Function weightOnEarth = weight.apply(9.81);
+
+ private static Function weightOnMars = weight.apply(3.75);
+
+ public static Double weightOnEarth(Double mass) {
+ return weightOnEarth.apply(mass);
+ }
+
+ public static Double weightOnMars(Double mass) {
+ return weightOnMars.apply(mass);
+ }
+
+ public static Function weightOnEarth() {
+ final double gravity = 9.81;
+ return mass -> mass * gravity;
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java
new file mode 100644
index 0000000000..13b408ab27
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FirstClassFunctions.java
@@ -0,0 +1,24 @@
+package com.baeldung.functional;
+
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+public class FirstClassFunctions {
+
+ public static List sortWithoutLambda(List numbers) {
+ Collections.sort(numbers, new Comparator() {
+ @Override
+ public int compare(Integer n1, Integer n2) {
+ return n1.compareTo(n2);
+ }
+ });
+ return numbers;
+ }
+
+ public static List sortWithLambda(List numbers) {
+ Collections.sort(numbers, (n1, n2) -> n1.compareTo(n2));
+ return numbers;
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java
new file mode 100644
index 0000000000..57103be98a
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/FunctionComposition.java
@@ -0,0 +1,20 @@
+package com.baeldung.functional;
+
+import java.util.function.Function;
+
+public class FunctionComposition {
+
+ private static Function log = (value) -> Math.log(value);
+ private static Function sqrt = (value) -> Math.sqrt(value);
+
+ public static Double logThenSqrt(Double number) {
+ Function logThenSqrt = sqrt.compose(log);
+ return (logThenSqrt.apply(3.14));
+ }
+
+ public static Double sqrtThenLog(Double number) {
+ Function sqrtThenLog = sqrt.andThen(log);
+ return (sqrtThenLog.apply(3.14));
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java
new file mode 100644
index 0000000000..738680f743
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ImmutableData.java
@@ -0,0 +1,36 @@
+package com.baeldung.functional;
+
+public class ImmutableData {
+
+ private final String someData;
+
+ private final AnotherImmutableData anotherImmutableData;
+
+ public ImmutableData(final String someData, final AnotherImmutableData anotherImmutableData) {
+ this.someData = someData;
+ this.anotherImmutableData = anotherImmutableData;
+ }
+
+ public String getSomeData() {
+ return someData;
+ }
+
+ public AnotherImmutableData getAnotherImmutableData() {
+ return anotherImmutableData;
+ }
+
+ public class AnotherImmutableData {
+
+ private final Integer someOtherData;
+
+ public AnotherImmutableData(final Integer someData) {
+ this.someOtherData = someData;
+ }
+
+ public Integer getSomeOtherData() {
+ return someOtherData;
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java
new file mode 100644
index 0000000000..c1223c73c7
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Monads.java
@@ -0,0 +1,11 @@
+package com.baeldung.functional;
+
+import java.util.Optional;
+
+public class Monads {
+
+ public static Optional add(Optional val1, Optional val2) {
+ return val1.flatMap(first -> val2.flatMap(second -> Optional.of(first + second)));
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java
new file mode 100644
index 0000000000..522b9de9eb
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/PureFunctions.java
@@ -0,0 +1,13 @@
+package com.baeldung.functional;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class PureFunctions {
+
+ public static Integer sum(List numbers) {
+ return numbers.stream()
+ .collect(Collectors.summingInt(Integer::intValue));
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java
new file mode 100644
index 0000000000..d5492df69d
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/Recursion.java
@@ -0,0 +1,17 @@
+package com.baeldung.functional;
+
+public class Recursion {
+
+ public static Integer headRecursion(Integer number) {
+
+ return (number == 1) ? 1 : number * headRecursion(number - 1);
+
+ }
+
+ public static Integer tailRecursion(Integer number, Integer result) {
+
+ return (number == 1) ? result : tailRecursion(number - 1, result * number);
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java
new file mode 100644
index 0000000000..1392cdd00a
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/main/java/com/baeldung/functional/ReferentialTransparency.java
@@ -0,0 +1,39 @@
+package com.baeldung.functional;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public class ReferentialTransparency {
+
+ private static Logger logger = Logger.getGlobal();
+
+ public void main() {
+
+ String data = new SimpleData().setData("Baeldung")
+ .getData();
+ logger.log(Level.INFO, new SimpleData().setData("Baeldung")
+ .getData());
+ logger.log(Level.INFO, data);
+ logger.log(Level.INFO, "Baeldung");
+ }
+
+ public class SimpleData {
+
+ private Logger logger = Logger.getGlobal();
+
+ private String data;
+
+ public String getData() {
+ logger.log(Level.INFO, "Get data called for SimpleData");
+ return data;
+ }
+
+ public SimpleData setData(String data) {
+ logger.log(Level.INFO, "Set data called for SimpleData");
+ this.data = data;
+ return this;
+ }
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java
new file mode 100644
index 0000000000..0cf96ed566
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/CurryingUnitTest.java
@@ -0,0 +1,22 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.Test;
+
+public class CurryingUnitTest {
+
+ @Test
+ public void testWeightOnEarth() {
+
+ assertEquals(588.6, Currying.weightOnEarth(60.0), 0.1);
+
+ }
+
+ @Test
+ public void testWeightOnMars() {
+
+ assertEquals(225.0, Currying.weightOnMars(60.0), 0.1);
+
+ }
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java
new file mode 100644
index 0000000000..8056b44f21
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FirstClassFunctionsUnitTest.java
@@ -0,0 +1,27 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+public class FirstClassFunctionsUnitTest {
+
+ @Test
+ public void testSortingWithoutLambda() {
+
+ assertEquals(new Integer(8), FirstClassFunctions.sortWithoutLambda(Arrays.asList(new Integer(10), new Integer(8)))
+ .get(0));
+
+ }
+
+ @Test
+ public void testSortingWithLambda() {
+
+ assertEquals(new Integer(8), FirstClassFunctions.sortWithLambda(Arrays.asList(new Integer(10), new Integer(8)))
+ .get(0));
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java
new file mode 100644
index 0000000000..48d8fb695c
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/FunctionCompositionUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.Test;
+
+public class FunctionCompositionUnitTest {
+
+ @Test
+ public void testLogThenSqrt() {
+
+ assertEquals(1.07, FunctionComposition.logThenSqrt(3.14), 0.01);
+
+ }
+
+ @Test
+ public void testSqrtThenLog() {
+
+ assertEquals(0.57, FunctionComposition.sqrtThenLog(3.14), 0.01);
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java
new file mode 100644
index 0000000000..8258eef59e
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/MonadsUnitTest.java
@@ -0,0 +1,19 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Optional;
+
+import org.junit.Test;
+
+public class MonadsUnitTest {
+
+ @Test
+ public void testOptionalAdd() {
+
+ assertEquals(5, Monads.add(Optional.of(new Integer(2)), Optional.of(new Integer(3)))
+ .get());
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java
new file mode 100644
index 0000000000..23cca8bf8d
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/PureFunctionsUnitTets.java
@@ -0,0 +1,18 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.Arrays;
+
+import org.junit.Test;
+
+public class PureFunctionsUnitTets {
+
+ @Test
+ public void testSortingWithoutLambda() {
+
+ assertEquals(new Integer(18), PureFunctions.sum(Arrays.asList(new Integer(10), new Integer(8))));
+
+ }
+
+}
diff --git a/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java
new file mode 100644
index 0000000000..aa406dc7ab
--- /dev/null
+++ b/core-java-modules/core-java-functional/src/test/java/com/baeldung/functional/RecursionUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.functional;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.Test;
+
+public class RecursionUnitTest {
+
+ @Test
+ public void testHeadRecursion() {
+
+ assertEquals(120, Recursion.headRecursion(5));
+
+ }
+
+ @Test
+ public void testTailRecursion() {
+
+ assertEquals(120, Recursion.tailRecursion(5, 1));
+
+ }
+
+}
diff --git a/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java b/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java
index 2275128dfe..c108d9ed96 100644
--- a/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java
+++ b/core-java-modules/core-java-io-2/src/main/java/com/baeldung/listfiles/ListFiles.java
@@ -24,9 +24,20 @@ public class ListFiles {
.collect(Collectors.toSet());
}
+ public Set listFilesUsingFilesList(String dir) throws IOException {
+ try (Stream stream = Files.list(Paths.get(dir))) {
+ return stream
+ .filter(file -> !Files.isDirectory(file))
+ .map(Path::getFileName)
+ .map(Path::toString)
+ .collect(Collectors.toSet());
+ }
+ }
+
public Set listFilesUsingFileWalk(String dir, int depth) throws IOException {
try (Stream stream = Files.walk(Paths.get(dir), depth)) {
- return stream.filter(file -> !Files.isDirectory(file))
+ return stream
+ .filter(file -> !Files.isDirectory(file))
.map(Path::getFileName)
.map(Path::toString)
.collect(Collectors.toSet());
diff --git a/core-java-modules/core-java-io-2/src/main/resources/logback.xml b/core-java-modules/core-java-io-2/src/main/resources/logback.xml
new file mode 100644
index 0000000000..f46a64b3cb
--- /dev/null
+++ b/core-java-modules/core-java-io-2/src/main/resources/logback.xml
@@ -0,0 +1,12 @@
+
+
+
+
+ [%d{ISO8601}]-[%thread] %-5level %logger - %msg%n
+
+
+
+
+
+
+
diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java
index a87097f085..5b4efc9e58 100644
--- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java
+++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/listfiles/ListFilesUnitTest.java
@@ -25,10 +25,15 @@ public class ListFilesUnitTest {
};
@Test
- public void givenDir_whenUsingJAVAIO_thenListAllFiles() throws IOException {
+ public void givenDir_whenUsingJAVAIO_thenListAllFiles() {
assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingJavaIO(DIRECTORY));
}
+ @Test
+ public void givenDir_whenUsingFilesList_thenListAllFiles() throws IOException {
+ assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingFilesList(DIRECTORY));
+ }
+
@Test
public void givenDir_whenWalkingTree_thenListAllFiles() throws IOException {
assertEquals(EXPECTED_FILE_LIST, listFiles.listFilesUsingFileWalk(DIRECTORY,DEPTH));
diff --git a/core-java-modules/core-java-io-3/.gitignore b/core-java-modules/core-java-io-3/.gitignore
new file mode 100644
index 0000000000..0c0cd871c5
--- /dev/null
+++ b/core-java-modules/core-java-io-3/.gitignore
@@ -0,0 +1,2 @@
+test-link*
+0.*
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-3/README.md b/core-java-modules/core-java-io-3/README.md
index 39752346d3..d0ac5387a8 100644
--- a/core-java-modules/core-java-io-3/README.md
+++ b/core-java-modules/core-java-io-3/README.md
@@ -3,5 +3,15 @@
This module contains articles about core Java input and output (IO)
### Relevant Articles:
+
- [Java – Create a File](https://www.baeldung.com/java-how-to-create-a-file)
+- [Check If a Directory Is Empty in Java](https://www.baeldung.com/java-check-empty-directory)
+- [Check If a File or Directory Exists in Java](https://www.baeldung.com/java-file-directory-exists)
+- [Copy a Directory in Java](https://www.baeldung.com/java-copy-directory)
+- [Java Files Open Options](https://www.baeldung.com/java-file-options)
+- [Creating Temporary Directories in Java](https://www.baeldung.com/java-temp-directories)
+- [Reading a Line at a Given Line Number From a File in Java](https://www.baeldung.com/java-read-line-at-number)
+- [Find the Last Modified File in a Directory with Java](https://www.baeldung.com/java-last-modified-file)
+- [Get a Filename Without the Extension in Java](https://www.baeldung.com/java-filename-without-extension)
+- [Writing byte[] to a File in Java](https://www.baeldung.com/java-write-byte-array-file)
- [[<-- Prev]](/core-java-modules/core-java-io-2)
diff --git a/core-java-modules/core-java-io-3/pom.xml b/core-java-modules/core-java-io-3/pom.xml
index cb341ca2ae..cc4dca5fa5 100644
--- a/core-java-modules/core-java-io-3/pom.xml
+++ b/core-java-modules/core-java-io-3/pom.xml
@@ -46,41 +46,14 @@
${assertj.version}test
-
-
- com.github.tomakehurst
- wiremock
- ${wiremock.version}
- test
-
- core-java-io-3
-
-
- src/main/resources
- true
-
-
-
-
- org.apache.maven.plugins
- maven-javadoc-plugin
- ${maven-javadoc-plugin.version}
-
- ${maven.compiler.source}
- ${maven.compiler.target}
-
-
- 3.6.1
- 3.0.0-M1
- 2.26.3
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java
new file mode 100644
index 0000000000..b8aa283b48
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/ApacheCommons.java
@@ -0,0 +1,15 @@
+package com.baeldung.copydirectory;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+
+public class ApacheCommons {
+
+ public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException {
+ File sourceDirectory = new File(sourceDirectoryLocation);
+ File destinationDirectory = new File(destinationDirectoryLocation);
+ FileUtils.copyDirectory(sourceDirectory, destinationDirectory);
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java
new file mode 100644
index 0000000000..2070977534
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/CoreOld.java
@@ -0,0 +1,38 @@
+package com.baeldung.copydirectory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class CoreOld {
+
+ public static void copyDirectoryJavaUnder7(File source, File destination) throws IOException {
+ if (source.isDirectory()) {
+ copyDirectory(source, destination);
+ } else {
+ copyFile(source, destination);
+ }
+ }
+
+ private static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException {
+ if (!destinationDirectory.exists()) {
+ destinationDirectory.mkdir();
+ }
+ for (String f : sourceDirectory.list()) {
+ copyDirectoryJavaUnder7(new File(sourceDirectory, f), new File(destinationDirectory, f));
+ }
+ }
+
+ private static void copyFile(File sourceFile, File destinationFile) throws IOException {
+ try (InputStream in = new FileInputStream(sourceFile); OutputStream out = new FileOutputStream(destinationFile)) {
+ byte[] buf = new byte[1024];
+ int length;
+ while ((length = in.read(buf)) > 0) {
+ out.write(buf, 0, length);
+ }
+ }
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java
new file mode 100644
index 0000000000..b574042ee5
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/copydirectory/JavaNio.java
@@ -0,0 +1,22 @@
+package com.baeldung.copydirectory;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+public class JavaNio {
+
+ public static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException {
+ Files.walk(Paths.get(sourceDirectoryLocation))
+ .forEach(source -> {
+ Path destination = Paths.get(destinationDirectoryLocation, source.toString()
+ .substring(sourceDirectoryLocation.length()));
+ try {
+ Files.copy(source, destination);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java
new file mode 100644
index 0000000000..102c454c49
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/main/java/com/baeldung/filenamewithoutextension/MyFilenameUtil.java
@@ -0,0 +1,14 @@
+package com.baeldung.filenamewithoutextension;
+
+public class MyFilenameUtil {
+ private MyFilenameUtil() {}
+
+ public static String removeFileExtension(String filename, boolean removeAllExtensions) {
+ if (filename == null || filename.isEmpty()) {
+ return filename;
+ }
+
+ String extPattern = "(? opFile = Arrays.stream(dir.listFiles(File::isFile))
+ .max((f1, f2) -> Long.compare(f1.lastModified(), f2.lastModified()));
+
+ if (opFile.isPresent()) {
+ return opFile.get();
+ }
+ }
+
+ return null;
+ }
+
+ public static Path findUsingNIOApi(String sdir) throws IOException {
+ Path dir = Paths.get(sdir);
+ if (Files.isDirectory(dir)) {
+ Optional opPath = Files.list(dir)
+ .filter(p -> !Files.isDirectory(p))
+ .sorted((p1, p2) -> Long.valueOf(p2.toFile().lastModified())
+ .compareTo(p1.toFile().lastModified()))
+ .findFirst();
+
+ if (opPath.isPresent()) {
+ return opPath.get();
+ }
+ }
+
+ return null;
+ }
+
+ public static File findUsingCommonsIO(String sdir) {
+ File dir = new File(sdir);
+ if (dir.isDirectory()) {
+ File[] dirFiles = dir.listFiles((FileFilter) FileFilterUtils.fileFileFilter());
+ if (dirFiles != null && dirFiles.length > 0) {
+ Arrays.sort(dirFiles, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
+ return dirFiles[0];
+ }
+ }
+
+ return null;
+ }
+
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java
new file mode 100644
index 0000000000..eee49a37d7
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/ApacheCommonsUnitTest.java
@@ -0,0 +1,59 @@
+package com.baeldung.copydirectory;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Comparator;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ApacheCommonsUnitTest {
+
+ private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory3";
+ private final String subDirectoryName = "/childDirectory";
+ private final String fileName = "/file.txt";
+ private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory3";
+
+ @BeforeEach
+ public void createDirectoryWithSubdirectoryAndFile() throws IOException {
+ Files.createDirectories(Paths.get(sourceDirectoryLocation));
+ Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName));
+ Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName));
+ }
+
+ @Test
+ public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException {
+ ApacheCommons.copyDirectory(sourceDirectoryLocation, destinationDirectoryLocation);
+
+ assertTrue(new File(destinationDirectoryLocation).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists());
+ }
+
+ @Test
+ public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() {
+ assertThrows(Exception.class, () -> ApacheCommons.copyDirectory("nonExistingDirectory", destinationDirectoryLocation));
+ }
+
+ @AfterEach
+ public void cleanUp() throws IOException {
+ Files.walk(Paths.get(sourceDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ if (new File(destinationDirectoryLocation).exists()) {
+ Files.walk(Paths.get(destinationDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java
new file mode 100644
index 0000000000..1aaca066a0
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/CoreOldUnitTest.java
@@ -0,0 +1,63 @@
+package com.baeldung.copydirectory;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Comparator;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class CoreOldUnitTest {
+
+ private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory1";
+ private final String subDirectoryName = "/childDirectory";
+ private final String fileName = "/file.txt";
+ private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory1";
+
+ @BeforeEach
+ public void createDirectoryWithSubdirectoryAndFile() throws IOException {
+ Files.createDirectories(Paths.get(sourceDirectoryLocation));
+ Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName));
+ Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName));
+ }
+
+ @Test
+ public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException {
+ File sourceDirectory = new File(sourceDirectoryLocation);
+ File destinationDirectory = new File(destinationDirectoryLocation);
+ CoreOld.copyDirectoryJavaUnder7(sourceDirectory, destinationDirectory);
+
+ assertTrue(new File(destinationDirectoryLocation).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists());
+ }
+
+ @Test
+ public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() throws IOException {
+ File sourceDirectory = new File("nonExistingDirectory");
+ File destinationDirectory = new File(destinationDirectoryLocation);
+ assertThrows(IOException.class, () -> CoreOld.copyDirectoryJavaUnder7(sourceDirectory, destinationDirectory));
+ }
+
+ @AfterEach
+ public void cleanUp() throws IOException {
+ Files.walk(Paths.get(sourceDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ if (new File(destinationDirectoryLocation).exists()) {
+ Files.walk(Paths.get(destinationDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java
new file mode 100644
index 0000000000..3293e90c0c
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/copydirectory/JavaNioUnitTest.java
@@ -0,0 +1,59 @@
+package com.baeldung.copydirectory;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Comparator;
+
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class JavaNioUnitTest {
+
+ private final String sourceDirectoryLocation = "src/test/resources/sourceDirectory2";
+ private final String subDirectoryName = "/childDirectory";
+ private final String fileName = "/file.txt";
+ private final String destinationDirectoryLocation = "src/test/resources/destinationDirectory2";
+
+ @BeforeEach
+ public void createDirectoryWithSubdirectoryAndFile() throws IOException {
+ Files.createDirectories(Paths.get(sourceDirectoryLocation));
+ Files.createDirectories(Paths.get(sourceDirectoryLocation + subDirectoryName));
+ Files.createFile(Paths.get(sourceDirectoryLocation + subDirectoryName + fileName));
+ }
+
+ @Test
+ public void whenSourceDirectoryExists_thenDirectoryIsFullyCopied() throws IOException {
+ JavaNio.copyDirectory(sourceDirectoryLocation, destinationDirectoryLocation);
+
+ assertTrue(new File(destinationDirectoryLocation).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName).exists());
+ assertTrue(new File(destinationDirectoryLocation + subDirectoryName + fileName).exists());
+ }
+
+ @Test
+ public void whenSourceDirectoryDoesNotExist_thenExceptionIsThrown() {
+ assertThrows(IOException.class, () -> JavaNio.copyDirectory("nonExistingDirectory", destinationDirectoryLocation));
+ }
+
+ @AfterEach
+ public void cleanUp() throws IOException {
+ Files.walk(Paths.get(sourceDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ if (new File(destinationDirectoryLocation).exists()) {
+ Files.walk(Paths.get(destinationDirectoryLocation))
+ .sorted(Comparator.reverseOrder())
+ .map(Path::toFile)
+ .forEach(File::delete);
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java
index f3cdb22f4d..f26a1ab3ad 100644
--- a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/createfile/CreateFileUnitTest.java
@@ -6,6 +6,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -37,6 +38,12 @@ public class CreateFileUnitTest {
assertTrue(success);
}
+ @Test
+ void givenUsingFileOutputStream_whenCreatingFile_thenCorrect() throws IOException {
+ try(FileOutputStream fileOutputStream = new FileOutputStream(FILE_NAME)){
+ }
+ }
+
@Test
public void givenUsingGuava_whenCreatingFile_thenCorrect() throws IOException {
com.google.common.io.Files.touch(new File(FILE_NAME));
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java
new file mode 100644
index 0000000000..7f7936494f
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/emptiness/DirectoryEmptinessUnitTest.java
@@ -0,0 +1,64 @@
+package com.baeldung.emptiness;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.stream.Stream;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class DirectoryEmptinessUnitTest {
+
+ @Test
+ public void givenPath_whenInvalid_thenReturnsFalse() throws IOException {
+ assertThat(isEmpty(Paths.get("invalid-addr"))).isFalse();
+ }
+
+ @Test
+ public void givenPath_whenNotDirectory_thenReturnsFalse() throws IOException, URISyntaxException {
+ Path aFile = Paths.get(getClass().getResource("/notDir.txt").toURI());
+ assertThat(isEmpty(aFile)).isFalse();
+ }
+
+ @Test
+ public void givenPath_whenNotEmptyDir_thenReturnsFalse() throws IOException {
+ Path currentDir = new File("").toPath().toAbsolutePath();
+ assertThat(isEmpty(currentDir)).isFalse();
+ }
+
+ @Test
+ public void givenPath_whenIsEmpty_thenReturnsTrue() throws Exception {
+ Path path = Files.createTempDirectory("baeldung-empty");
+ assertThat(isEmpty(path)).isTrue();
+ }
+
+ private static boolean isEmpty(Path path) throws IOException {
+ if (Files.isDirectory(path)) {
+ try (DirectoryStream directory = Files.newDirectoryStream(path)) {
+ return !directory.iterator().hasNext();
+ }
+ }
+
+ return false;
+ }
+
+ private static boolean isEmpty2(Path path) throws IOException {
+ if (Files.isDirectory(path)) {
+ try (Stream entries = Files.list(path)) {
+ return !entries.findFirst().isPresent();
+ }
+ }
+
+ return false;
+ }
+
+ private static boolean isEmptyInefficient(Path path) {
+ return path.toFile().listFiles().length == 0;
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java
new file mode 100644
index 0000000000..747ae85b65
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/existence/ExistenceUnitTest.java
@@ -0,0 +1,98 @@
+package com.baeldung.existence;
+
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class ExistenceUnitTest {
+
+ @Test
+ public void givenFile_whenDoesNotExist_thenFilesReturnsFalse() {
+ Path path = Paths.get("does-not-exist.txt");
+
+ assertFalse(Files.exists(path));
+ assertTrue(Files.notExists(path));
+ }
+
+ @Test
+ public void givenFile_whenExists_thenFilesShouldReturnTrue() throws IOException {
+ Path tempFile = Files.createTempFile("baeldung", "exist-nio");
+ assertTrue(Files.exists(tempFile));
+ assertFalse(Files.notExists(tempFile));
+
+ Path tempDirectory = Files.createTempDirectory("baeldung-exists");
+ assertTrue(Files.exists(tempDirectory));
+ assertFalse(Files.notExists(tempDirectory));
+
+ assertTrue(Files.isDirectory(tempDirectory));
+ assertFalse(Files.isDirectory(tempFile));
+ assertTrue(Files.isRegularFile(tempFile));
+
+ assertTrue(Files.isReadable(tempFile));
+
+ Files.deleteIfExists(tempFile);
+ Files.deleteIfExists(tempDirectory);
+ }
+
+ @Test
+ public void givenSymbolicLink_whenTargetDoesNotExists_thenFollowOrNotBasedOnTheOptions() throws IOException {
+ Path target = Files.createTempFile("baeldung", "target");
+ Path symbol = Paths.get("test-link-" + ThreadLocalRandom.current().nextInt());
+ Path symbolicLink = null;
+
+ try {
+ symbolicLink = Files.createSymbolicLink(symbol, target);
+ } catch (FileSystemException ex) {
+ System.out.println("Your OS security policy prevents the current user from creating symbolic links.\n" +
+ "Most probably you're running Windows with UAC.\n" +
+ "If this is the case, please see - https://docs.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links\n" +
+ "You must change your security settings to run this test under Windows.");
+ return;
+ }
+
+ assertTrue(Files.exists(symbolicLink));
+ assertTrue(Files.isSymbolicLink(symbolicLink));
+ assertFalse(Files.isSymbolicLink(target));
+
+ Files.deleteIfExists(target);
+ assertFalse(Files.exists(symbolicLink));
+ assertTrue(Files.exists(symbolicLink, LinkOption.NOFOLLOW_LINKS));
+
+ Files.deleteIfExists(symbolicLink);
+ }
+
+ @Test
+ public void givenFile_whenDoesNotExist_thenFileReturnsFalse() {
+ assertFalse(new File("invalid").exists());
+ assertFalse(new File("invalid").isFile());
+ }
+
+ @Test
+ public void givenFile_whenExist_thenShouldReturnTrue() throws IOException {
+ Path tempFilePath = Files.createTempFile("baeldung", "exist-io");
+ Path tempDirectoryPath = Files.createTempDirectory("baeldung-exists-io");
+
+ File tempFile = new File(tempFilePath.toString());
+ File tempDirectory = new File(tempDirectoryPath.toString());
+
+ assertTrue(tempFile.exists());
+ assertTrue(tempDirectory.exists());
+
+ assertTrue(tempFile.isFile());
+ assertFalse(tempDirectory.isFile());
+
+ assertTrue(tempDirectory.isDirectory());
+ assertFalse(tempFile.isDirectory());
+
+ assertTrue(tempFile.canRead());
+
+ Files.deleteIfExists(tempFilePath);
+ Files.deleteIfExists(tempDirectoryPath);
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/filenamewithoutextension/FileNameDelExtensionUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/filenamewithoutextension/FileNameDelExtensionUnitTest.java
new file mode 100644
index 0000000000..3c5e7fbdad
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/filenamewithoutextension/FileNameDelExtensionUnitTest.java
@@ -0,0 +1,72 @@
+package com.baeldung.filenamewithoutextension;
+
+import com.google.common.io.Files;
+import org.apache.commons.io.FilenameUtils;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class FileNameDelExtensionUnitTest {
+
+ @Test
+ public void givenDotFileWithoutExt_whenCallGuavaMethod_thenCannotGetDesiredResult() {
+ //negative assertion
+ assertNotEquals(".baeldung", Files.getNameWithoutExtension(".baeldung"));
+ }
+
+ @Test
+ public void givenFileWithoutMultipleExt_whenCallGuavaMethod_thenCannotRemoveAllExtensions() {
+ //negative assertion
+ assertNotEquals("baeldung", Files.getNameWithoutExtension("baeldung.tar.gz"));
+ }
+
+ @Test
+ public void givenDotFileWithoutExt_whenCallApacheCommonsMethod_thenCannotGetDesiredResult() {
+ //negative assertion
+ assertNotEquals(".baeldung", FilenameUtils.removeExtension(".baeldung"));
+ }
+
+ @Test
+ public void givenFileWithoutMultipleExt_whenCallApacheCommonsMethod_thenCannotRemoveAllExtensions() {
+ //negative assertion
+ assertNotEquals("baeldung", FilenameUtils.removeExtension("baeldung.tar.gz"));
+ }
+
+ @Test
+ public void givenFilenameNoExt_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals("baeldung", MyFilenameUtil.removeFileExtension("baeldung", true));
+ assertEquals("baeldung", MyFilenameUtil.removeFileExtension("baeldung", false));
+ }
+
+ @Test
+ public void givenSingleExt_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals("baeldung", MyFilenameUtil.removeFileExtension("baeldung.txt", true));
+ assertEquals("baeldung", MyFilenameUtil.removeFileExtension("baeldung.txt", false));
+ }
+
+
+ @Test
+ public void givenDotFile_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals(".baeldung", MyFilenameUtil.removeFileExtension(".baeldung", true));
+ assertEquals(".baeldung", MyFilenameUtil.removeFileExtension(".baeldung", false));
+ }
+
+ @Test
+ public void givenDotFileWithExt_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals(".baeldung", MyFilenameUtil.removeFileExtension(".baeldung.conf", true));
+ assertEquals(".baeldung", MyFilenameUtil.removeFileExtension(".baeldung.conf", false));
+ }
+
+ @Test
+ public void givenDoubleExt_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals("baeldung", MyFilenameUtil.removeFileExtension("baeldung.tar.gz", true));
+ assertEquals("baeldung.tar", MyFilenameUtil.removeFileExtension("baeldung.tar.gz", false));
+ }
+
+ @Test
+ public void givenDotFileWithDoubleExt_whenCallFilenameUtilMethod_thenGetExpectedFilename() {
+ assertEquals(".baeldung", MyFilenameUtil.removeFileExtension(".baeldung.conf.bak", true));
+ assertEquals(".baeldung.conf", MyFilenameUtil.removeFileExtension(".baeldung.conf.bak", false));
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/lastmodifiedfile/LastModifiedFileAppUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/lastmodifiedfile/LastModifiedFileAppUnitTest.java
new file mode 100644
index 0000000000..fe704c3c40
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/lastmodifiedfile/LastModifiedFileAppUnitTest.java
@@ -0,0 +1,78 @@
+package com.baeldung.lastmodifiedfile;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+public class LastModifiedFileAppUnitTest {
+
+ private final static String SOURCEDIRECTORY = "src/test/resources/lastmodfiles";
+
+ @BeforeAll
+ public static void setUpFiles() throws IOException, InterruptedException {
+ File srcDir = new File(SOURCEDIRECTORY);
+ if (!srcDir.exists()) {
+ srcDir.mkdir();
+ }
+
+ FileUtils.cleanDirectory(srcDir);
+
+ File file01 = new File(SOURCEDIRECTORY + "/file01.txt");
+ file01.createNewFile();
+
+ Thread.sleep(2000);
+
+ File file02 = new File(SOURCEDIRECTORY + "/file02.txt");
+ file02.createNewFile();
+
+ Thread.sleep(2000);
+
+ File file03 = new File(SOURCEDIRECTORY + "/file03.txt");
+ file03.createNewFile();
+
+ Thread.sleep(2000);
+
+ Files.write(Paths.get(SOURCEDIRECTORY + "/file02.txt"), "Hello File02".getBytes());
+
+ }
+
+ @Test
+ public void givenDirectory_whenUsingIoApi_thenFindLastModfile() throws IOException {
+ File lastModFile = LastModifiedFileApp.findUsingIOApi(SOURCEDIRECTORY);
+
+ assertThat(lastModFile).isNotNull();
+ assertThat(lastModFile.getName()).isEqualTo("file02.txt");
+ }
+
+ @Test
+ public void givenDirectory_whenUsingNioApi_thenFindLastModfile() throws IOException {
+ Path lastModPath = LastModifiedFileApp.findUsingNIOApi(SOURCEDIRECTORY);
+
+ assertThat(lastModPath).isNotNull();
+ assertThat(lastModPath.toFile().getName()).isEqualTo("file02.txt");
+ }
+
+ @Test
+ public void givenDirectory_whenUsingApacheCommons_thenFindLastModfile() throws IOException {
+ File lastModFile = LastModifiedFileApp.findUsingCommonsIO(SOURCEDIRECTORY);
+
+ assertThat(lastModFile).isNotNull();
+ assertThat(lastModFile.getName()).isEqualTo("file02.txt");
+ }
+
+ @AfterAll
+ public static void cleanUp() throws IOException {
+ File srcDir = new File(SOURCEDIRECTORY);
+ FileUtils.deleteDirectory(srcDir);
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/linenumber/LineAtGivenNumberUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/linenumber/LineAtGivenNumberUnitTest.java
new file mode 100644
index 0000000000..ffe3221d62
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/linenumber/LineAtGivenNumberUnitTest.java
@@ -0,0 +1,82 @@
+package com.baeldung.linenumber;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.List;
+import java.util.Scanner;
+import java.util.stream.Stream;
+
+import static org.junit.Assert.assertEquals;
+
+public class LineAtGivenNumberUnitTest {
+
+ private static final String FILE_PATH = "src/test/resources/linesInput.txt";
+
+ @Test
+ public void givenFile_whenUsingBufferedReader_thenExtractedLineIsCorrect() throws IOException {
+ try (BufferedReader br = Files.newBufferedReader(Paths.get(FILE_PATH))) {
+ for (int i = 0; i < 3; i++) {
+ br.readLine();
+ }
+
+ String extractedLine = br.readLine();
+ assertEquals("Line 4", extractedLine);
+ }
+ }
+
+ @Test
+ public void givenFile_whenUsingScanner_thenExtractedLineIsCorrect() throws IOException {
+ try (Scanner scanner = new Scanner(new File(FILE_PATH))) {
+ for (int i = 0; i < 3; i++) {
+ scanner.nextLine();
+ }
+
+ String extractedLine = scanner.nextLine();
+ assertEquals("Line 4", extractedLine);
+ }
+ }
+
+ @Test
+ public void givenSmallFile_whenUsingFilesAPI_thenExtractedLineIsCorrect() throws IOException {
+ String extractedLine = Files.readAllLines(Paths.get(FILE_PATH)).get(4);
+
+ assertEquals("Line 5", extractedLine);
+ }
+
+ @Test
+ public void givenLargeFile_whenUsingFilesAPI_thenExtractedLineIsCorrect() throws IOException {
+ try (Stream lines = Files.lines(Paths.get(FILE_PATH))) {
+ String extractedLine = lines.skip(4).findFirst().get();
+
+ assertEquals("Line 5", extractedLine);
+ }
+ }
+
+ @Test
+ public void givenFile_whenUsingFileUtils_thenExtractedLineIsCorrect() throws IOException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ File file = new File(classLoader.getResource("linesInput.txt").getFile());
+
+ List lines = FileUtils.readLines(file, "UTF-8");
+
+ String extractedLine = lines.get(0);
+ assertEquals("Line 1", extractedLine);
+ }
+
+ @Test
+ public void givenFile_whenUsingIOUtils_thenExtractedLineIsCorrect() throws IOException {
+ String fileContent = IOUtils.toString(new FileInputStream(FILE_PATH), StandardCharsets.UTF_8);
+
+ String extractedLine = fileContent.split(System.lineSeparator())[0];
+ assertEquals("Line 1", extractedLine);
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java
new file mode 100644
index 0000000000..323c965edf
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/openoptions/OpenOptionsUnitTest.java
@@ -0,0 +1,96 @@
+package com.baeldung.openoptions;
+
+import org.hamcrest.CoreMatchers;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.io.*;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+
+import static org.junit.Assert.*;
+
+public class OpenOptionsUnitTest {
+
+ private static final String HOME = System.getProperty("user.home");
+ private static final String DUMMY_FILE_NAME = "sample.txt";
+ private static final String EXISTING_FILE_NAME = "existingFile.txt";
+
+ private static final String DUMMY_TEXT = "This is a sample text.";
+ private static final String ANOTHER_DUMMY_TEXT = "This is a another text.";
+
+ @BeforeClass
+ public static void beforeAll() throws IOException {
+ Path path = Paths.get(HOME, DUMMY_FILE_NAME);
+
+ try (OutputStream out = Files.newOutputStream(path)) {
+ out.write(DUMMY_TEXT.getBytes());
+ }
+
+ Files.createFile(Paths.get(HOME, EXISTING_FILE_NAME));
+ }
+
+ @AfterClass
+ public static void afterAll() throws IOException {
+ Files.delete(Paths.get(HOME, "newfile.txt"));
+ Files.delete(Paths.get(HOME, "sparse.txt"));
+ Files.delete(Paths.get(HOME, DUMMY_FILE_NAME));
+ }
+
+ @Test
+ public void givenExistingPath_whenCreateNewFile_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, "newfile.txt");
+ assertFalse(Files.exists(path));
+
+ Files.write(path, DUMMY_TEXT.getBytes(), StandardOpenOption.CREATE);
+ assertTrue(Files.exists(path));
+ }
+
+ @Test
+ public void givenExistingPath_whenReadExistingFile_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, DUMMY_FILE_NAME);
+
+ try (InputStream in = Files.newInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
+ String line;
+ while ((line = reader.readLine()) != null) {
+ assertThat(line, CoreMatchers.containsString(DUMMY_TEXT));
+ }
+ }
+ }
+
+ @Test
+ public void givenExistingPath_whenWriteToExistingFile_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, DUMMY_FILE_NAME);
+
+ try (OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND, StandardOpenOption.WRITE)) {
+ out.write(ANOTHER_DUMMY_TEXT.getBytes());
+ }
+ }
+
+ @Test
+ public void givenExistingPath_whenCreateSparseFile_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, "sparse.txt");
+ Files.write(path, DUMMY_TEXT.getBytes(), StandardOpenOption.CREATE_NEW, StandardOpenOption.SPARSE);
+ }
+
+ @Test
+ public void givenExistingPath_whenDeleteOnClose_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, EXISTING_FILE_NAME);
+ assertTrue(Files.exists(path)); // file was already created and exists
+
+ try (OutputStream out = Files.newOutputStream(path, StandardOpenOption.APPEND, StandardOpenOption.WRITE, StandardOpenOption.DELETE_ON_CLOSE)) {
+ out.write(ANOTHER_DUMMY_TEXT.getBytes());
+ }
+
+ assertFalse(Files.exists(path)); // file is deleted
+ }
+
+ @Test
+ public void givenExistingPath_whenWriteAndSync_thenCorrect() throws IOException {
+ Path path = Paths.get(HOME, DUMMY_FILE_NAME);
+ Files.write(path, ANOTHER_DUMMY_TEXT.getBytes(), StandardOpenOption.APPEND, StandardOpenOption.WRITE, StandardOpenOption.SYNC);
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java
new file mode 100644
index 0000000000..5cf7d88cd6
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/tempdirectory/TemporaryDirectoriesUnitTest.java
@@ -0,0 +1,82 @@
+package com.baeldung.tempdirectory;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.attribute.FileAttribute;
+import java.nio.file.attribute.PosixFileAttributes;
+import java.nio.file.attribute.PosixFilePermission;
+import java.nio.file.attribute.PosixFilePermissions;
+import java.util.Set;
+import java.util.UUID;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+
+/**
+ * Tests several possibilities on how to create
+ * temporary directories.
+ *
+ * @author Rui Vilao (rpvilao@gmail.com)
+ */
+public class TemporaryDirectoriesUnitTest {
+
+ @Test
+ public void givenTempDirWithPrefixNoTargetSpecified_whenCreateWithPlainJava_thenInsideOSTempDirStructure() throws IOException {
+ final String tmpdir = Files.createTempDirectory("tmpDirPrefix").toFile().getAbsolutePath();
+ final String tmpDirsLocation = System.getProperty("java.io.tmpdir");
+
+ assertThat(tmpdir).startsWith(tmpDirsLocation);
+ }
+
+ @Test
+ public void givenTempDirWithPrefixNoTargetSpecified_whenCreateWithGuava_thenInsideOSTempDirStructure() throws IOException {
+ final String tmpdir = com.google.common.io.Files.createTempDir().getAbsolutePath();
+ final String tmpDirsLocation = System.getProperty("java.io.tmpdir");
+
+ assertThat(tmpdir).startsWith(tmpDirsLocation);
+ }
+
+ @Test
+ public void givenTempDirWithPrefixNoTargetSpecified_whenCreateWithApacheCommonsIo_thenInsideOSTempDirStructure() throws IOException {
+ final String tmpDirsLocation = System.getProperty("java.io.tmpdir");
+ final Path path = Paths.get(FileUtils.getTempDirectory().getAbsolutePath(), UUID.randomUUID().toString());
+ final String tmpdir = Files.createDirectories(path).toFile().getAbsolutePath();
+
+ assertThat(tmpdir).startsWith(tmpDirsLocation);
+ }
+
+ @Test
+ public void givenTempDirWithPrefixWithTargetSpecified_whenCreatePlainJava_thenInsideTarget() throws IOException {
+ final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix");
+ assertThat(tmpdir.toFile().getPath()).startsWith("target");
+ }
+
+ @Test
+ public void givenTempDirWithPrefixWithTargetSpecifiedWithDeleteOnExit_whenCreatePlainJava_thenInsideTarget() throws IOException {
+ final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix");
+ assertThat(tmpdir.toFile().getPath()).startsWith("target");
+ tmpdir.toFile().deleteOnExit();
+ // we can really assert this test, just as an example.
+ }
+
+ @Test
+ public void givenTempDirWithPrefixWithFileAttrs_whenCreatePlainJava_thenAttributesAreSet() throws IOException {
+ boolean isPosix = FileSystems.getDefault().supportedFileAttributeViews().contains("posix");
+
+ if(!isPosix){
+ System.out.println("You must be under a Posix Compliant Filesystem to run this test.");
+ } else {
+ final FileAttribute> attrs = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("r--------"));
+
+ final Path tmpdir = Files.createTempDirectory(Paths.get("target"), "tmpDirPrefix", attrs);
+ assertThat(tmpdir.toFile().getPath()).startsWith("target");
+ assertThat(tmpdir.toFile().canWrite()).isFalse();
+ }
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java
new file mode 100644
index 0000000000..ef8c8e2470
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/java/com/baeldung/writebytearray/WriteByteArrayUnitTest.java
@@ -0,0 +1,77 @@
+package com.baeldung.writebytearray;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+
+import org.apache.commons.io.FileUtils;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import com.google.common.io.ByteSink;
+import com.google.common.io.MoreFiles;
+
+public class WriteByteArrayUnitTest {
+ private static byte[] dataForWriting;
+
+ @Rule
+ public TemporaryFolder tempFolder = new TemporaryFolder();
+
+ @BeforeClass
+ public static void setup() throws IOException {
+ dataForWriting = Files.readAllBytes(Paths.get("src/test/resources/example-image.jpg"));
+ }
+
+ @Test
+ public void whenUsingFileOutputStream_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-fos.jpg");
+ try (FileOutputStream outputStream = new FileOutputStream(outputFile)) {
+ outputStream.write(dataForWriting);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+ }
+
+ @Test
+ public void whenUsingNioFiles_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-nio-files.jpg");
+ Files.write(outputFile.toPath(), dataForWriting);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+
+ @Test
+ public void whenUsingGuavaFiles_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-guava-files.jpg");
+ com.google.common.io.Files.write(dataForWriting, outputFile);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+
+ @Test
+ public void whenUsingGuavaByteSink_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-guava-bs.jpg");
+ ByteSink byteSink = com.google.common.io.Files.asByteSink(outputFile);
+ byteSink.write(dataForWriting);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+
+ @Test
+ public void whenUsingGuavaByteSinkMoreFiles_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-guava-bs.jpg");
+ ByteSink byteSink = MoreFiles.asByteSink(outputFile.toPath(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);
+ byteSink.write(dataForWriting);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+
+ @Test
+ public void whenUsingCommonsIo_thenByteArrayIsWritten() throws IOException {
+ File outputFile = tempFolder.newFile("example-file-utils.jpg");
+ FileUtils.writeByteArrayToFile(outputFile, dataForWriting);
+ assertThat(outputFile).hasBinaryContent(dataForWriting);
+ }
+}
diff --git a/core-java-modules/core-java-io-3/src/test/resources/example-image.jpg b/core-java-modules/core-java-io-3/src/test/resources/example-image.jpg
new file mode 100644
index 0000000000..43b8962793
Binary files /dev/null and b/core-java-modules/core-java-io-3/src/test/resources/example-image.jpg differ
diff --git a/core-java-modules/core-java-io-3/src/test/resources/linesInput.txt b/core-java-modules/core-java-io-3/src/test/resources/linesInput.txt
new file mode 100644
index 0000000000..572d5d9483
--- /dev/null
+++ b/core-java-modules/core-java-io-3/src/test/resources/linesInput.txt
@@ -0,0 +1,5 @@
+Line 1
+Line 2
+Line 3
+Line 4
+Line 5
diff --git a/spring-mvc-java-2/src/main/webapp/resources/hello.css b/core-java-modules/core-java-io-3/src/test/resources/notDir.txt
similarity index 100%
rename from spring-mvc-java-2/src/main/webapp/resources/hello.css
rename to core-java-modules/core-java-io-3/src/test/resources/notDir.txt
diff --git a/core-java-modules/core-java-io-4/.gitignore b/core-java-modules/core-java-io-4/.gitignore
new file mode 100644
index 0000000000..0c0cd871c5
--- /dev/null
+++ b/core-java-modules/core-java-io-4/.gitignore
@@ -0,0 +1,2 @@
+test-link*
+0.*
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-4/README.md b/core-java-modules/core-java-io-4/README.md
new file mode 100644
index 0000000000..c837e2bffc
--- /dev/null
+++ b/core-java-modules/core-java-io-4/README.md
@@ -0,0 +1,8 @@
+## Core Java IO
+
+This module contains articles about core Java input and output (IO)
+
+### Relevant Articles:
+
+- [Java File Separator vs File Path Separator](https://www.baeldung.com/java-file-vs-file-path-separator)
+- [[<-- Prev]](/core-java-modules/core-java-io-3)
diff --git a/core-java-modules/core-java-io-4/pom.xml b/core-java-modules/core-java-io-4/pom.xml
new file mode 100644
index 0000000000..ee31b35ba9
--- /dev/null
+++ b/core-java-modules/core-java-io-4/pom.xml
@@ -0,0 +1,52 @@
+
+
+ 4.0.0
+ core-java-io-4
+ 0.1.0-SNAPSHOT
+ core-java-io-4
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+
+ commons-io
+ commons-io
+ ${commons-io.version}
+
+
+
+ log4j
+ log4j
+ ${log4j.version}
+
+
+ org.slf4j
+ log4j-over-slf4j
+ ${org.slf4j.version}
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+
+
+
+
+
+ 3.6.1
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java
new file mode 100644
index 0000000000..959aae8aff
--- /dev/null
+++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FilePathSeparatorUnitTest.java
@@ -0,0 +1,63 @@
+package com.baeldung.fileseparator;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.StringJoiner;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+public class FilePathSeparatorUnitTest {
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenCheckPathSeparator_thenResultIsAsExpectedOnWindows() throws IOException {
+ assertEquals(";", File.pathSeparator);
+ assertEquals(';', File.pathSeparatorChar);
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenCheckPathSeparator_thenResultIsAsExpected() throws IOException {
+ assertEquals(":", File.pathSeparator);
+ assertEquals(':', File.pathSeparatorChar);
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenBuildPathUsingString_thenResultIsAsExpectedOnWindows() throws IOException {
+ String[] pathNames = { "path1", "path2", "path3" };
+ String path = String.join(File.pathSeparator, pathNames);
+ assertEquals("path1;path2;path3",path);
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenBuildPathUsingString_thenResultIsAsExpected() throws IOException {
+ String[] pathNames = { "path1", "path2", "path3" };
+ String path = String.join(File.pathSeparator, pathNames);
+ assertEquals("path1:path2:path3", path);
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenbuildPathUsingStringJoiner_thenResultIsAsExpectedOnWindows() throws IOException {
+ assertEquals("path1;path2", buildPathUsingStringJoiner("path1", "path2"));
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenbuildPathUsingStringJoiner_thenResultIsAsExpected() throws IOException {
+ assertEquals("path1:path2", buildPathUsingStringJoiner("path1", "path2"));
+ }
+
+ private String buildPathUsingStringJoiner(String path1, String path2) {
+ StringJoiner joiner = new StringJoiner(File.pathSeparator);
+ joiner.add(path1);
+ joiner.add(path2);
+ return joiner.toString();
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java
new file mode 100644
index 0000000000..f908dcc9bb
--- /dev/null
+++ b/core-java-modules/core-java-io-4/src/test/java/com/baeldung/fileseparator/FileSeparatorUnitTest.java
@@ -0,0 +1,63 @@
+package com.baeldung.fileseparator;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.File;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledOnOs;
+import org.junit.jupiter.api.condition.OS;
+
+public class FileSeparatorUnitTest {
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenCheckFileSeparator_thenCorrectOnWindows() {
+ assertEquals("\\", File.separator);
+ assertEquals('\\', File.separatorChar);
+
+ String fileSeparator = FileSystems.getDefault().getSeparator();
+ assertEquals("\\",fileSeparator);
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenCheckFileSeparator_thenCorrect() {
+ assertEquals("/", File.separator);
+ assertEquals('/', File.separatorChar);
+
+ String fileSeparator = FileSystems.getDefault().getSeparator();
+ assertEquals("/",fileSeparator);
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenBuildFilePathUsingPathsClass_thenCorrectOnWindows() {
+ Path path = Paths.get("dir1", "dir2");
+ assertEquals("dir1\\dir2", path.toString());
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenBuildFilePathUsingPathsClass_thenCorrect() {
+ Path path = Paths.get("dir1", "dir2");
+ assertEquals("dir1/dir2", path.toString());
+ }
+
+ @Test
+ @EnabledOnOs(OS.WINDOWS)
+ public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpectedOnWindows() {
+ File file = new File("file1", "file2");
+ assertEquals("file1\\file2", file.toString());
+ }
+
+ @Test
+ @EnabledOnOs({ OS.LINUX, OS.MAC })
+ public void whenBuildFilePathUsingFileClass_thenOutputIsAsExpected() {
+ File file = new File("file1", "file2");
+ assertEquals("file1/file2", file.toString());
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java b/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java
index caedd1747b..c20752639f 100644
--- a/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java
+++ b/core-java-modules/core-java-io-conversions/src/test/java/com/baeldung/filetoinputstream/JavaXToInputStreamUnitTest.java
@@ -5,12 +5,12 @@ import com.google.common.io.CharSource;
import com.google.common.io.Files;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
-import org.apache.commons.io.input.ReaderInputStream;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
+import java.nio.charset.StandardCharsets;
public class JavaXToInputStreamUnitTest {
protected final Logger logger = LoggerFactory.getLogger(getClass());
@@ -28,7 +28,7 @@ public class JavaXToInputStreamUnitTest {
@Test
public final void givenUsingGuava_whenConvertingStringToInputStream_thenCorrect() throws IOException {
final String initialString = "text";
- final InputStream targetStream = new ReaderInputStream(CharSource.wrap(initialString).openStream());
+ final InputStream targetStream = CharSource.wrap(initialString).asByteSource(StandardCharsets.UTF_8).openStream();
IOUtils.closeQuietly(targetStream);
}
diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml
index 0968536e65..02b5adae7c 100644
--- a/core-java-modules/core-java-io/pom.xml
+++ b/core-java-modules/core-java-io/pom.xml
@@ -60,7 +60,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}javacom.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
@@ -108,7 +107,6 @@
org.codehaus.mojoexec-maven-plugin
-
run-benchmarks
diff --git a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java
index 140d809d44..a18663f544 100644
--- a/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java
+++ b/core-java-modules/core-java-io/src/main/java/com/baeldung/unzip/UnzipFile.java
@@ -16,31 +16,42 @@ public class UnzipFile {
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
final File newFile = newFile(destDir, zipEntry);
- final FileOutputStream fos = new FileOutputStream(newFile);
- int len;
- while ((len = zis.read(buffer)) > 0) {
- fos.write(buffer, 0, len);
+ if (zipEntry.isDirectory()) {
+ if (!newFile.isDirectory() && !newFile.mkdirs()) {
+ throw new IOException("Failed to create directory " + newFile);
+ }
+ } else {
+ File parent = newFile.getParentFile();
+ if (!parent.isDirectory() && !parent.mkdirs()) {
+ throw new IOException("Failed to create directory " + parent);
+ }
+
+ final FileOutputStream fos = new FileOutputStream(newFile);
+ int len;
+ while ((len = zis.read(buffer)) > 0) {
+ fos.write(buffer, 0, len);
+ }
+ fos.close();
}
- fos.close();
zipEntry = zis.getNextEntry();
}
zis.closeEntry();
zis.close();
}
-
+
/**
* @see https://snyk.io/research/zip-slip-vulnerability
*/
public static File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
File destFile = new File(destinationDir, zipEntry.getName());
-
+
String destDirPath = destinationDir.getCanonicalPath();
String destFilePath = destFile.getCanonicalPath();
-
+
if (!destFilePath.startsWith(destDirPath + File.separator)) {
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
}
-
+
return destFile;
}
}
\ No newline at end of file
diff --git a/core-java-modules/core-java-jar/.gitignore b/core-java-modules/core-java-jar/.gitignore
new file mode 100644
index 0000000000..ba516c02b5
--- /dev/null
+++ b/core-java-modules/core-java-jar/.gitignore
@@ -0,0 +1 @@
+!src/test/resources/example-jar/stripe-0.0.1-SNAPSHOT.jar
diff --git a/core-java-modules/core-java-jar/README.md b/core-java-modules/core-java-jar/README.md
index f6bb7677d4..f83ea496ab 100644
--- a/core-java-modules/core-java-jar/README.md
+++ b/core-java-modules/core-java-jar/README.md
@@ -7,3 +7,4 @@ This module contains articles about JAR files
- [How to Create an Executable JAR with Maven](http://www.baeldung.com/executable-jar-with-maven)
- [Importance of Main Manifest Attribute in a Self-Executing JAR](http://www.baeldung.com/java-jar-executable-manifest-main-class)
- [Guide to Creating and Running a Jar File in Java](https://www.baeldung.com/java-create-jar)
+- [Get Names of Classes Inside a JAR File](https://www.baeldung.com/jar-file-get-class-names)
diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml
index 6e9d713d7c..45500de739 100644
--- a/core-java-modules/core-java-jar/pom.xml
+++ b/core-java-modules/core-java-jar/pom.xml
@@ -189,7 +189,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}javacom.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
@@ -249,7 +248,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}run-benchmarks
@@ -397,7 +395,6 @@
1.4.43.1.12.0.3.RELEASE
- 1.6.01.81.8
diff --git a/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/GetClassNamesFromJar.java b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/GetClassNamesFromJar.java
new file mode 100644
index 0000000000..0d8a67dbd6
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/main/java/com/baeldung/jar/GetClassNamesFromJar.java
@@ -0,0 +1,43 @@
+package com.baeldung.jar;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+public class GetClassNamesFromJar {
+
+ public static Set getClassNamesFromJarFile(File givenFile) throws IOException {
+ Set classNames = new HashSet<>();
+ try (JarFile jarFile = new JarFile(givenFile)) {
+ Enumeration e = jarFile.entries();
+ while (e.hasMoreElements()) {
+ JarEntry jarEntry = e.nextElement();
+ if (jarEntry.getName().endsWith(".class")) {
+ String className = jarEntry.getName()
+ .replace("/", ".")
+ .replace(".class", "");
+ classNames.add(className);
+ }
+ }
+ return classNames;
+ }
+ }
+
+ public static Set getClassesFromJarFile(File jarFile) throws IOException, ClassNotFoundException {
+ Set classNames = getClassNamesFromJarFile(jarFile);
+ Set classes = new HashSet<>(classNames.size());
+ try (URLClassLoader cl = URLClassLoader.newInstance(new URL[] { new URL("jar:file:" + jarFile + "!/") })) {
+ for (String name : classNames) {
+ Class clazz = cl.loadClass(name); // Loading the class by its name
+ classes.add(clazz);
+ }
+ }
+ return classes;
+ }
+}
diff --git a/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/GetClassNamesFromJarUnitTest.java b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/GetClassNamesFromJarUnitTest.java
new file mode 100644
index 0000000000..7af3ff59fd
--- /dev/null
+++ b/core-java-modules/core-java-jar/src/test/java/com/baeldung/jar/GetClassNamesFromJarUnitTest.java
@@ -0,0 +1,39 @@
+package com.baeldung.jar;
+
+import com.google.common.collect.Sets;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class GetClassNamesFromJarUnitTest {
+ private static final String JAR_PATH = "example-jar/stripe-0.0.1-SNAPSHOT.jar";
+ private static final Set EXPECTED_CLASS_NAMES = Sets.newHashSet(
+ "com.baeldung.stripe.StripeApplication",
+ "com.baeldung.stripe.ChargeRequest",
+ "com.baeldung.stripe.StripeService",
+ "com.baeldung.stripe.ChargeRequest$Currency",
+ "com.baeldung.stripe.ChargeController",
+ "com.baeldung.stripe.CheckoutController");
+
+ @Test
+ public void givenJarFilePath_whenLoadClassNames_thenGetClassNames() throws IOException, URISyntaxException {
+ File jarFile = new File(Objects.requireNonNull(getClass().getClassLoader().getResource(JAR_PATH)).toURI());
+ Set classNames = GetClassNamesFromJar.getClassNamesFromJarFile(jarFile);
+ Assert.assertEquals(EXPECTED_CLASS_NAMES, classNames);
+ }
+
+ @Test
+ public void givenJarFilePath_whenLoadClass_thenGetClassObjects() throws IOException, ClassNotFoundException, URISyntaxException {
+ File jarFile = new File(Objects.requireNonNull(getClass().getClassLoader().getResource(JAR_PATH)).toURI());
+ Set classes = GetClassNamesFromJar.getClassesFromJarFile(jarFile);
+ Set names = classes.stream().map(Class::getName).collect(Collectors.toSet());
+ Assert.assertEquals(EXPECTED_CLASS_NAMES, names);
+ }
+}
diff --git a/core-java-modules/core-java-jar/src/test/resources/example-jar/stripe-0.0.1-SNAPSHOT.jar b/core-java-modules/core-java-jar/src/test/resources/example-jar/stripe-0.0.1-SNAPSHOT.jar
new file mode 100644
index 0000000000..213d7f9400
Binary files /dev/null and b/core-java-modules/core-java-jar/src/test/resources/example-jar/stripe-0.0.1-SNAPSHOT.jar differ
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml
index fe6689dcc3..fb6d2b1065 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml
@@ -17,7 +17,7 @@
com.baeldung.servicemodule
- servicemodule
+ servicemodule1${servicemodule.version}
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml
index fd59c151e6..f80d7d4815 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml
@@ -6,9 +6,15 @@
4.0.0com.baeldung.decoupling-pattern1decoupling-pattern1
- 1.0
+ 1.0-SNAPSHOTpom
+
+ com.baeldung.core-java-modules
+ core-java-jpms
+ 0.0.1-SNAPSHOT
+
+
servicemoduleconsumermodule
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml
index c2da228ce6..4c811ea866 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml
@@ -4,7 +4,8 @@
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">
4.0.0
- servicemodule
+ com.baeldung.servicemodule
+ servicemodule1jar
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml
index e6b351b1b9..c7bff60a8b 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml
@@ -17,7 +17,7 @@
com.baeldung.servicemodule
- servicemodule
+ servicemodule2${servicemodule.version}
@@ -32,6 +32,11 @@
org.apache.maven.pluginsmaven-compiler-plugin
+ ${compiler.plugin.version}
+
+ ${source.version}
+ ${target.version}
+
@@ -41,4 +46,4 @@
1.0
-
\ No newline at end of file
+
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml
index 17bca54edb..91b92b9df5 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml
@@ -9,6 +9,12 @@
1.0-SNAPSHOTpom
+
+ com.baeldung.core-java-modules
+ core-java-jpms
+ 0.0.1-SNAPSHOT
+
+
servicemoduleprovidermodule
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml
index 3e8d5c0c39..6c0f1956b9 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml
@@ -27,6 +27,11 @@
org.apache.maven.pluginsmaven-compiler-plugin
+ ${compiler.plugin.version}
+
+ ${source.version}
+ ${target.version}
+
diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml
index 51d64998df..50201911a6 100644
--- a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml
+++ b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml
@@ -4,7 +4,8 @@
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">
4.0.0
- servicemodule
+ com.baeldung.servicemodule
+ servicemodule21.0
@@ -18,6 +19,11 @@
org.apache.maven.pluginsmaven-compiler-plugin
+ ${compiler.plugin.version}
+
+ ${source.version}
+ ${target.version}
+
diff --git a/core-java-modules/core-java-jpms/pom.xml b/core-java-modules/core-java-jpms/pom.xml
index 5809c0f579..ee7eb02f10 100644
--- a/core-java-modules/core-java-jpms/pom.xml
+++ b/core-java-modules/core-java-jpms/pom.xml
@@ -20,4 +20,26 @@
decoupling-pattern2
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${compiler.plugin.version}
+
+ ${source.version}
+ ${target.version}
+
+
+
+
+
+
+
+ 3.8.0
+ 11
+ 11
+
+
diff --git a/core-java-modules/core-java-jvm-2/README.md b/core-java-modules/core-java-jvm-2/README.md
index 1aa69e7e63..ccca3a11ac 100644
--- a/core-java-modules/core-java-jvm-2/README.md
+++ b/core-java-modules/core-java-jvm-2/README.md
@@ -8,4 +8,8 @@ This module contains articles about working with the Java Virtual Machine (JVM).
- [Measuring Object Sizes in the JVM](https://www.baeldung.com/jvm-measuring-object-sizes)
- [Adding Shutdown Hooks for JVM Applications](https://www.baeldung.com/jvm-shutdown-hooks)
- [boolean and boolean[] Memory Layout in the JVM](https://www.baeldung.com/jvm-boolean-memory-layout)
-- More articles: [[<-- prev]](/core-java-modules/core-java-jvm)
\ No newline at end of file
+- [Where Is the Array Length Stored in JVM?](https://www.baeldung.com/java-jvm-array-length)
+- [Memory Address of Objects in Java](https://www.baeldung.com/java-object-memory-address)
+- [List All Classes Loaded in a Specific Class Loader](https://www.baeldung.com/java-list-classes-class-loader)
+- [An Introduction to the Constant Pool in the JVM](https://www.baeldung.com/jvm-constant-pool)
+- More articles: [[<-- prev]](/core-java-modules/core-java-jvm)
diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java
new file mode 100644
index 0000000000..b9aea05272
--- /dev/null
+++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/constantpool/ConstantPool.java
@@ -0,0 +1,8 @@
+package com.baeldung.constantpool;
+
+public class ConstantPool {
+
+ public void sayHello() {
+ System.out.println("Hello World");
+ }
+}
diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java
new file mode 100644
index 0000000000..bd9573d6b5
--- /dev/null
+++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/Launcher.java
@@ -0,0 +1,19 @@
+package com.baeldung.loadedclasslisting;
+
+import java.util.Arrays;
+
+public class Launcher {
+
+ public static void main(String[] args) {
+ printClassesLoadedBy("BOOTSTRAP");
+ printClassesLoadedBy("SYSTEM");
+ printClassesLoadedBy("EXTENSION");
+ }
+
+ private static void printClassesLoadedBy(String classLoaderType) {
+ System.out.println(classLoaderType + " ClassLoader : ");
+ Class>[] classes = ListLoadedClassesAgent.listLoadedClasses(classLoaderType);
+ Arrays.asList(classes)
+ .forEach(clazz -> System.out.println(clazz.getCanonicalName()));
+ }
+}
diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java
new file mode 100644
index 0000000000..337214a664
--- /dev/null
+++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/ListLoadedClassesAgent.java
@@ -0,0 +1,40 @@
+package com.baeldung.loadedclasslisting;
+
+import java.lang.instrument.Instrumentation;
+
+public class ListLoadedClassesAgent {
+
+ private static Instrumentation instrumentation;
+
+ public static void premain(String agentArgs, Instrumentation instrumentation) {
+ ListLoadedClassesAgent.instrumentation = instrumentation;
+ }
+
+ public static Class>[] listLoadedClasses(String classLoaderType) {
+ if (instrumentation == null) {
+ throw new IllegalStateException(
+ "ListLoadedClassesAgent is not initialized.");
+ }
+ return instrumentation.getInitiatedClasses(
+ getClassLoader(classLoaderType));
+ }
+
+ private static ClassLoader getClassLoader(String classLoaderType) {
+ ClassLoader classLoader = null;
+ switch (classLoaderType) {
+ case "SYSTEM":
+ classLoader = ClassLoader.getSystemClassLoader();
+ break;
+ case "EXTENSION":
+ classLoader = ClassLoader.getSystemClassLoader().getParent();
+ break;
+ // passing a null value to the Instrumentation : getInitiatedClasses method
+ // defaults to the bootstrap class loader
+ case "BOOTSTRAP":
+ break;
+ default:
+ break;
+ }
+ return classLoader;
+ }
+}
diff --git a/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF
new file mode 100644
index 0000000000..4a60bda0b7
--- /dev/null
+++ b/core-java-modules/core-java-jvm-2/src/main/java/com/baeldung/loadedclasslisting/MANIFEST.MF
@@ -0,0 +1 @@
+Premain-Class: com.baeldung.loadedclasslisting.ListLoadedClassesAgent
\ No newline at end of file
diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml
index 08e536998c..17ff2f658f 100644
--- a/core-java-modules/core-java-jvm/pom.xml
+++ b/core-java-modules/core-java-jvm/pom.xml
@@ -77,7 +77,6 @@
3.6.13.27.0-GA
- 2.1.0.11.8.00.108.0.1
diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java
index cab8546129..98e35d0af2 100644
--- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java
+++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/entity/Human.java
@@ -37,7 +37,7 @@ public class Human {
public static int compareByNameThenAge(final Human lhs, final Human rhs) {
if (lhs.name.equals(rhs.name)) {
- return lhs.age - rhs.age;
+ return Integer.compare(lhs.age, rhs.age);
} else {
return lhs.name.compareTo(rhs.name);
}
diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Bar.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
index 4cf0aa2399..3ee78bd7a3 100644
--- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
+++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Bar.java
@@ -6,8 +6,11 @@ public interface Bar {
String method(String string);
- default String defaultMethod() {
- return "String from Bar";
+ default String defaultBar() {
+ return "Default String from Bar";
}
+ default String defaultCommon() {
+ return "Default Common from Bar";
+ }
}
diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Baz.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
index c7efe14c89..1e1e9ae094 100644
--- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
+++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/Baz.java
@@ -6,7 +6,11 @@ public interface Baz {
String method(String string);
- default String defaultMethod() {
- return "String from Baz";
+ default String defaultBaz() {
+ return "Default String from Baz";
+ }
+
+ default String defaultCommon(){
+ return "Default Common from Baz";
}
}
diff --git a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
index 9141cd8eb8..27ab86dca3 100644
--- a/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
+++ b/core-java-modules/core-java-lambdas/src/main/java/com/baeldung/java8/lambda/tips/FooExtended.java
@@ -5,8 +5,7 @@ package com.baeldung.java8.lambda.tips;
public interface FooExtended extends Baz, Bar {
@Override
- default String defaultMethod() {
- return Bar.super.defaultMethod();
+ default String defaultCommon() {
+ return Bar.super.defaultCommon();
}
-
}
diff --git a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
index 9e510575fc..e5f876c84b 100644
--- a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
+++ b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/Java8SortUnitTest.java
@@ -54,7 +54,7 @@ public class Java8SortUnitTest {
final List humans = Lists.newArrayList(new Human("Sarah", 12), new Human("Sarah", 10), new Human("Zack", 12));
humans.sort((lhs, rhs) -> {
if (lhs.getName().equals(rhs.getName())) {
- return lhs.getAge() - rhs.getAge();
+ return Integer.compare(lhs.getAge(), rhs.getAge());
} else {
return lhs.getName().compareTo(rhs.getName());
}
diff --git a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
index b409f8e37f..acc3bc8fa3 100644
--- a/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
+++ b/core-java-modules/core-java-lambdas/src/test/java/com/baeldung/java8/lambda/tips/Java8FunctionalInteracesLambdasUnitTest.java
@@ -39,9 +39,9 @@ public class Java8FunctionalInteracesLambdasUnitTest {
@Test
public void defaultMethodFromExtendedInterface_whenReturnDefiniteString_thenCorrect() {
final FooExtended fooExtended = string -> string;
- final String result = fooExtended.defaultMethod();
+ final String result = fooExtended.defaultCommon();
- assertEquals("String from Bar", result);
+ assertEquals("Default Common from Bar", result);
}
@Test
diff --git a/core-java-modules/core-java-lang-2/pom.xml b/core-java-modules/core-java-lang-2/pom.xml
index 5f2d4ec901..9da76fa168 100644
--- a/core-java-modules/core-java-lang-2/pom.xml
+++ b/core-java-modules/core-java-lang-2/pom.xml
@@ -65,11 +65,8 @@
- 1.19
- 1.193.12.21.9.4
- 3.1029.0-jre
diff --git a/core-java-modules/core-java-lang-3/README.md b/core-java-modules/core-java-lang-3/README.md
index f496b74bfb..8ed945a56c 100644
--- a/core-java-modules/core-java-lang-3/README.md
+++ b/core-java-modules/core-java-lang-3/README.md
@@ -2,4 +2,14 @@
This module contains articles about core features in the Java language
+- [Class.isInstance vs Class.isAssignableFrom](https://www.baeldung.com/java-isinstance-isassignablefrom)
+- [Converting a Java String Into a Boolean](https://www.baeldung.com/java-string-to-boolean)
+- [When are Static Variables Initialized in Java?](https://www.baeldung.com/java-static-variables-initialization)
+- [Checking if a Class Exists in Java](https://www.baeldung.com/java-check-class-exists)
+- [The Difference Between a.getClass() and A.class in Java](https://www.baeldung.com/java-getclass-vs-class)
+- [Constants in Java: Patterns and Anti-Patterns](https://www.baeldung.com/java-constants-good-practices)
+- [The transient Keyword in Java](https://www.baeldung.com/java-transient-keyword)
+- [How to Access an Iteration Counter in a For Each Loop](https://www.baeldung.com/java-foreach-counter)
+- [Comparing Doubles in Java](https://www.baeldung.com/java-comparing-doubles)
+- [Guide to Implementing the compareTo Method](https://www.baeldung.com/java-compareto)
- [[<-- Prev]](/core-java-modules/core-java-lang-2)
diff --git a/core-java-modules/core-java-lang-3/pom.xml b/core-java-modules/core-java-lang-3/pom.xml
index de290717b1..f98074ad1b 100644
--- a/core-java-modules/core-java-lang-3/pom.xml
+++ b/core-java-modules/core-java-lang-3/pom.xml
@@ -23,6 +23,18 @@
${assertj.version}test
+
+ com.google.guava
+ guava
+ ${guava.version}
+ test
+
+
+ org.apache.commons
+ commons-math3
+ 3.6.1
+ test
+
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java
new file mode 100644
index 0000000000..db1f41e6df
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccount.java
@@ -0,0 +1,16 @@
+package com.baeldung.compareto;
+
+public class BankAccount implements Comparable {
+
+ private final int balance;
+
+ public BankAccount(int balance) {
+ this.balance = balance;
+ }
+
+ @Override
+ public int compareTo(BankAccount anotherAccount) {
+ return this.balance - anotherAccount.balance;
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java
new file mode 100644
index 0000000000..95e55fdf22
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/BankAccountFix.java
@@ -0,0 +1,16 @@
+package com.baeldung.compareto;
+
+public class BankAccountFix implements Comparable {
+
+ private final int balance;
+
+ public BankAccountFix(int balance) {
+ this.balance = balance;
+ }
+
+ @Override
+ public int compareTo(BankAccountFix anotherAccount) {
+ return Integer.compare(this.balance, anotherAccount.balance);
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java
new file mode 100644
index 0000000000..173ee32434
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/FootballPlayer.java
@@ -0,0 +1,32 @@
+package com.baeldung.compareto;
+
+public class FootballPlayer implements Comparable {
+
+ private final String name;
+ private final int goalsScored;
+
+ public FootballPlayer(String name, int goalsScored) {
+ this.name = name;
+ this.goalsScored = goalsScored;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public int compareTo(FootballPlayer anotherPlayer) {
+ return Integer.compare(this.goalsScored, anotherPlayer.goalsScored);
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object)
+ return true;
+ if (object == null || getClass() != object.getClass())
+ return false;
+ FootballPlayer player = (FootballPlayer) object;
+ return name.equals(player.name);
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java
new file mode 100644
index 0000000000..022155ccae
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/compareto/HandballPlayer.java
@@ -0,0 +1,12 @@
+package com.baeldung.compareto;
+
+public class HandballPlayer {
+
+ private final String name;
+ private final int height;
+
+ public HandballPlayer(String name, int height) {
+ this.name = name;
+ this.height = height;
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/Calculator.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/Calculator.java
new file mode 100644
index 0000000000..78b51c1c93
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/Calculator.java
@@ -0,0 +1,37 @@
+package com.baeldung.constantspatterns;
+
+public class Calculator {
+ public static final double PI = 3.14159265359;
+ private static final double UPPER_LIMIT = 0x1.fffffffffffffP+1023;
+
+ public enum Operation {
+ ADD, SUBTRACT, DIVIDE, MULTIPLY
+ }
+
+ public double operateOnTwoNumbers(double numberOne, double numberTwo, Operation operation) {
+ if (numberOne > UPPER_LIMIT) {
+ throw new IllegalArgumentException("'numberOne' is too large");
+ }
+ if (numberTwo > UPPER_LIMIT) {
+ throw new IllegalArgumentException("'numberTwo' is too large");
+ }
+ double answer = 0;
+
+ switch (operation) {
+ case ADD:
+ answer = numberOne + numberTwo;
+ break;
+ case SUBTRACT:
+ answer = numberOne - numberTwo;
+ break;
+ case DIVIDE:
+ answer = numberOne / numberTwo;
+ break;
+ case MULTIPLY:
+ answer = numberOne * numberTwo;
+ break;
+ }
+
+ return answer;
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/CalculatorConstants.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/CalculatorConstants.java
new file mode 100644
index 0000000000..2237782b00
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/CalculatorConstants.java
@@ -0,0 +1,10 @@
+package com.baeldung.constantspatterns;
+
+public interface CalculatorConstants {
+ double PI = 3.14159265359;
+ double UPPER_LIMIT = 0x1.fffffffffffffP+1023;
+
+ enum Operation {
+ ADD, SUBTRACT, MULTIPLY, DIVIDE
+ };
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/GeometryCalculator.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/GeometryCalculator.java
new file mode 100644
index 0000000000..47a0dc5233
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/GeometryCalculator.java
@@ -0,0 +1,32 @@
+package com.baeldung.constantspatterns;
+
+public class GeometryCalculator implements CalculatorConstants {
+ public static final double UPPER_LIMIT = 100000000000000000000.0;
+
+ public double operateOnTwoNumbers(double numberOne, double numberTwo, Operation operation) {
+ if (numberOne > UPPER_LIMIT) {
+ throw new IllegalArgumentException("'numberOne' is too large");
+ }
+ if (numberTwo > UPPER_LIMIT) {
+ throw new IllegalArgumentException("'numberTwo' is too large");
+ }
+ double answer = 0;
+
+ switch (operation) {
+ case ADD:
+ answer = numberOne + numberTwo;
+ break;
+ case SUBTRACT:
+ answer = numberOne - numberTwo;
+ break;
+ case DIVIDE:
+ answer = numberOne / numberTwo;
+ break;
+ case MULTIPLY:
+ answer = numberOne * numberTwo;
+ break;
+ }
+
+ return answer;
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/calculations/MathConstants.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/calculations/MathConstants.java
new file mode 100644
index 0000000000..1c9c4172ca
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/constantspatterns/calculations/MathConstants.java
@@ -0,0 +1,16 @@
+package com.baeldung.constantspatterns.calculations;
+
+public final class MathConstants {
+ public static final double PI = 3.14159265359;
+ static final double GOLDEN_RATIO = 1.6180;
+ static final double GRAVITATIONAL_ACCELERATION = 9.8;
+ static final double EULERS_NUMBER = 2.7182818284590452353602874713527;
+
+ public enum Operation {
+ ADD, SUBTRACT, DIVIDE, MULTIPLY
+ }
+
+ private MathConstants() {
+
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Animal.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Animal.java
new file mode 100644
index 0000000000..426f1403af
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Animal.java
@@ -0,0 +1,5 @@
+package com.baeldung.getclassobject;
+
+public class Animal {
+ protected int numberOfEyes;
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Monkey.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Monkey.java
new file mode 100644
index 0000000000..76ad8a96e3
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/Monkey.java
@@ -0,0 +1,4 @@
+package com.baeldung.getclassobject;
+
+public class Monkey extends Animal {
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeAbstractClass.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeAbstractClass.java
new file mode 100644
index 0000000000..7ee34cf62a
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeAbstractClass.java
@@ -0,0 +1,4 @@
+package com.baeldung.getclassobject;
+
+public abstract class SomeAbstractClass {
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeInterface.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeInterface.java
new file mode 100644
index 0000000000..eec8048481
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeInterface.java
@@ -0,0 +1,4 @@
+package com.baeldung.getclassobject;
+
+interface SomeInterface {
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeUtils.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeUtils.java
new file mode 100644
index 0000000000..294ef5bc9e
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/getclassobject/SomeUtils.java
@@ -0,0 +1,9 @@
+package com.baeldung.getclassobject;
+
+public class SomeUtils {
+ private SomeUtils() {
+ throw new RuntimeException("This Util class is not allowed to be instantiated!");
+ }
+ // public static utilMethods
+ // ...
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java
new file mode 100644
index 0000000000..40d997cb0e
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/iterationcounter/IterationCounter.java
@@ -0,0 +1,68 @@
+package com.baeldung.iterationcounter;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.stream.Stream;
+
+public class IterationCounter {
+ public static final List IMDB_TOP_MOVIES = Arrays.asList("The Shawshank Redemption",
+ "The Godfather", "The Godfather II", "The Dark Knight");
+
+ public static List getRankingsWithForLoop(List movies) {
+ List rankings = new ArrayList<>();
+ for (int i = 0; i < movies.size(); i++) {
+ String ranking = (i + 1) + ": " + movies.get(i);
+ rankings.add(ranking);
+ }
+ return rankings;
+ }
+
+ public static List getRankingsWithForEachLoop(List movies) {
+ List rankings = new ArrayList<>();
+ int i = 0;
+ for (String movie : movies) {
+ String ranking = (i + 1) + ": " + movies.get(i);
+ rankings.add(ranking);
+
+ i++;
+ }
+ return rankings;
+ }
+
+ public static List getRankingsWithFunctionalForEachLoop(List movies) {
+ List rankings = new ArrayList<>();
+ forEachWithCounter(movies, (i, movie) -> {
+ String ranking = (i + 1) + ": " + movie;
+ rankings.add(ranking);
+ });
+
+ return rankings;
+ }
+
+ public static void forEachWithCounter(Iterable source, BiConsumer consumer) {
+ int i = 0;
+ for (T item : source) {
+ consumer.accept(i, item);
+ i++;
+ }
+ }
+
+ public static List getRankingsWithStream(Stream movies) {
+ List rankings = new ArrayList<>();
+ movies.forEach(withCounter((i, movie) -> {
+ String ranking = (i + 1) + ": " + movie;
+ rankings.add(ranking);
+ }));
+
+ return rankings;
+ }
+
+ public static Consumer withCounter(BiConsumer consumer) {
+ AtomicInteger counter = new AtomicInteger(0);
+ return item -> consumer.accept(counter.getAndIncrement(), item);
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java
new file mode 100644
index 0000000000..5822d83841
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/Book.java
@@ -0,0 +1,42 @@
+package com.baeldung.transientkw;
+
+import java.io.Serializable;
+
+public class Book implements Serializable {
+
+ private static final long serialVersionUID = -2936687026040726549L;
+
+ private String bookName;
+ private transient String description;
+ private transient int copies;
+ private final transient String bookCategory = "Fiction";
+
+ public String getBookName() {
+ return bookName;
+ }
+
+ public void setBookName(String bookName) {
+ this.bookName = bookName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public int getCopies() {
+ return copies;
+ }
+
+ public void setCopies(int copies) {
+ this.copies = copies;
+ }
+
+ public String getBookCategory() {
+ return bookCategory;
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java
new file mode 100644
index 0000000000..38e018baa3
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/main/java/com/baeldung/transientkw/BookSerDe.java
@@ -0,0 +1,44 @@
+package com.baeldung.transientkw;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+public class BookSerDe {
+ static String fileName = "book.ser";
+
+ /**
+ * Method to serialize Book objects to the file
+ * @throws FileNotFoundException
+ */
+ public static void serialize(Book book) throws Exception {
+ FileOutputStream file = new FileOutputStream(fileName);
+ ObjectOutputStream out = new ObjectOutputStream(file);
+
+ out.writeObject(book);
+
+ out.close();
+ file.close();
+ }
+
+ /**
+ * Method to deserialize the person object
+ * @return book
+ * @throws IOException, ClassNotFoundException
+ */
+ public static Book deserialize() throws Exception {
+ FileInputStream file = new FileInputStream(fileName);
+ ObjectInputStream in = new ObjectInputStream(file);
+
+ Book book = (Book) in.readObject();
+
+ in.close();
+ file.close();
+
+ return book;
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java
new file mode 100644
index 0000000000..b565f9de31
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/checkclassexistence/CheckClassExistenceUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.checkclassexistence;
+
+import org.junit.Test;
+
+public class CheckClassExistenceUnitTest {
+
+ public static class InitializingClass {
+ static {
+ if (true) { //enable throwing of an exception in a static initialization block
+ throw new RuntimeException();
+ }
+ }
+ }
+
+ @Test(expected = ClassNotFoundException.class) //thrown when class does not exist
+ public void givenNonExistingClass_whenUsingForName_thenClassNotFound() throws ClassNotFoundException {
+ Class.forName("class.that.does.not.exist");
+ }
+
+ @Test
+ public void givenExistingClass_whenUsingForName_thenNoException() throws ClassNotFoundException {
+ Class.forName("java.lang.String");
+ }
+
+ @Test(expected = ExceptionInInitializerError.class) //thrown when exception occurs inside of a static initialization block
+ public void givenInitializingClass_whenUsingForName_thenInitializationError() throws ClassNotFoundException {
+ Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass");
+ }
+
+ @Test
+ public void givenInitializingClass_whenUsingForNameWithoutInitialization_thenNoException() throws ClassNotFoundException {
+ Class.forName("com.baeldung.checkclassexistence.CheckClassExistenceUnitTest$InitializingClass", false, getClass().getClassLoader());
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java
new file mode 100644
index 0000000000..c70dabd014
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/comparedouble/CompareDoubleUnitTest.java
@@ -0,0 +1,71 @@
+package com.baeldung.comparedouble;
+
+import com.google.common.math.DoubleMath;
+import org.apache.commons.math3.util.Precision;
+import org.junit.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+public class CompareDoubleUnitTest {
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingSimpleComparison_thenFails() {
+ double d1 = getFirstDouble(0);
+
+ double d2 = .1 * 8;
+
+ assertThat(d1 == d2).isFalse();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingThresholdComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+ assertThat(Math.abs(d1 - d2) < epsilon).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingGuavaFuzzyComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+
+ assertThat(DoubleMath.fuzzyEquals(d1, d2, epsilon)).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingCommonsMathComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+
+ assertThat(Precision.equals(d1, d2, epsilon)).isTrue();
+ assertThat(Precision.equals(d1, d2)).isTrue();
+ }
+
+ @Test
+ public void givenDoubleValuesThatShouldHaveSameValue_whenUsingJunitComparison_thenSuccess() {
+ double d1 = getFirstDouble(0);
+ double d2 = .1 * 8;
+
+ double epsilon = 0.000001d;
+
+ assertEquals(d1, d2, epsilon);
+ }
+
+ private double getFirstDouble(double d1) {
+ for (int i = 1; i <= 8; i++) {
+ d1 += .1;
+ }
+ return d1;
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java
new file mode 100644
index 0000000000..2082386dba
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/ArraysSortingUnitTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.compareto;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ArraysSortingUnitTest {
+
+ @Test
+ public void givenArrayOfNumbers_whenSortingArray_thenNumbersAreSortedAscending() {
+ int[] numbers = new int[] {5, 3, 9, 11, 1, 7};
+ Arrays.sort(numbers);
+ assertThat(numbers).containsExactly(1, 3, 5, 7, 9, 11);
+ }
+
+ @Test
+ public void givenArrayOfStrings_whenSortingArray_thenStringsAreSortedAlphabetically() {
+ String[] players = new String[] {"ronaldo", "modric", "ramos", "messi"};
+ Arrays.sort(players);
+ assertThat(players).containsExactly("messi", "modric", "ramos", "ronaldo");
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java
new file mode 100644
index 0000000000..9ca16d1372
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountFixUnitTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.compareto;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class BankAccountFixUnitTest {
+
+ @Test
+ public void givenComparisonBasedImpl_whenUsingSmallIntegers_thenComparisonWorks() {
+ BankAccountFix accountOne = new BankAccountFix(5000);
+ BankAccountFix accountTwo = new BankAccountFix(1000);
+ int comparison = accountOne.compareTo(accountTwo);
+ assertThat(comparison).isPositive();
+ }
+
+ @Test
+ public void givenComparisonBasedImpl_whenUsingLargeIntegers_thenComparisonWorks() {
+ BankAccountFix accountOne = new BankAccountFix(1900000000);
+ BankAccountFix accountTwo = new BankAccountFix(-2000000000);
+ int comparison = accountOne.compareTo(accountTwo);
+ assertThat(comparison).isPositive();
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java
new file mode 100644
index 0000000000..6ef9372ff9
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/BankAccountUnitTest.java
@@ -0,0 +1,25 @@
+package com.baeldung.compareto;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.*;
+
+public class BankAccountUnitTest {
+
+ @Test
+ public void givenSubtractionBasedImpl_whenUsingSmallIntegers_thenComparisonWorks() {
+ BankAccount accountOne = new BankAccount(5000);
+ BankAccount accountTwo = new BankAccount(1000);
+ int comparison = accountOne.compareTo(accountTwo);
+ assertThat(comparison).isPositive();
+ }
+
+ @Test
+ public void givenSubtractionBasedImpl_whenUsingLargeIntegers_thenComparisonBreaks() {
+ BankAccount accountOne = new BankAccount(1900000000);
+ BankAccount accountTwo = new BankAccount(-2000000000);
+ int comparison = accountOne.compareTo(accountTwo);
+ assertThat(comparison).isNegative();
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java
new file mode 100644
index 0000000000..6abd1e113b
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/FootballPlayerUnitTest.java
@@ -0,0 +1,57 @@
+package com.baeldung.compareto;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.TreeSet;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class FootballPlayerUnitTest {
+
+ @Test
+ public void givenInconsistentCompareToAndEqualsImpl_whenUsingSortedSet_thenSomeElementsAreNotAdded() {
+ FootballPlayer messi = new FootballPlayer("Messi", 800);
+ FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 800);
+
+ TreeSet set = new TreeSet<>();
+ set.add(messi);
+ set.add(ronaldo);
+
+ assertThat(set).hasSize(1);
+ assertThat(set).doesNotContain(ronaldo);
+ }
+
+ @Test
+ public void givenCompareToImpl_whenUsingCustomComparator_thenComparatorLogicIsApplied() {
+ FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 900);
+ FootballPlayer messi = new FootballPlayer("Messi", 800);
+ FootballPlayer modric = new FootballPlayer("Modric", 100);
+
+ List players = Arrays.asList(ronaldo, messi, modric);
+ Comparator nameComparator = Comparator.comparing(FootballPlayer::getName);
+ Collections.sort(players, nameComparator);
+
+ assertThat(players).containsExactly(messi, modric, ronaldo);
+ }
+
+ @Test
+ public void givenCompareToImpl_whenSavingElementsInTreeMap_thenKeysAreSortedUsingCompareTo() {
+ FootballPlayer ronaldo = new FootballPlayer("Ronaldo", 900);
+ FootballPlayer messi = new FootballPlayer("Messi", 800);
+ FootballPlayer modric = new FootballPlayer("Modric", 100);
+
+ Map players = new TreeMap<>();
+ players.put(ronaldo, "forward");
+ players.put(messi, "forward");
+ players.put(modric, "midfielder");
+
+ assertThat(players.keySet()).containsExactly(modric, messi, ronaldo);
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java
new file mode 100644
index 0000000000..143286f15f
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/compareto/HandballPlayerUnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.compareto;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.Arrays;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+
+public class HandballPlayerUnitTest {
+
+ @Test
+ public void givenComparableIsNotImplemented_whenSortingArray_thenExceptionIsThrown() {
+ HandballPlayer duvnjak = new HandballPlayer("Duvnjak", 197);
+ HandballPlayer hansen = new HandballPlayer("Hansen", 196);
+
+ HandballPlayer[] players = new HandballPlayer[] {duvnjak, hansen};
+
+ assertThatExceptionOfType(ClassCastException.class).isThrownBy(() -> Arrays.sort(players));
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/constantspatterns/ConstantPatternUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/constantspatterns/ConstantPatternUnitTest.java
new file mode 100644
index 0000000000..ba8f237fd3
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/constantspatterns/ConstantPatternUnitTest.java
@@ -0,0 +1,23 @@
+package com.baeldung.constantspatterns;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import org.junit.Test;
+
+public class ConstantPatternUnitTest {
+ @Test
+ public void givenTwoNumbersAndAdd_whenCallingCalculatorOperatOneTwoNumbers_thenCorrectAnswerReturned() {
+ Calculator calculator = new Calculator();
+ double expected = 4;
+ double answer = calculator.operateOnTwoNumbers(2, 2, Calculator.Operation.ADD);
+ assertEquals(expected, answer);
+ }
+
+ @Test
+ public void givenTwoNumbersAndAdd_whenCallingGeometryCalculatorOperatOneTwoNumbers_thenCorrectAnswerReturned() {
+ GeometryCalculator calculator = new GeometryCalculator();
+ double expected = 4;
+ double answer = calculator.operateOnTwoNumbers(2, 2, GeometryCalculator.Operation.ADD);
+ assertEquals(expected, answer);
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/getclassobject/GetClassObjectUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/getclassobject/GetClassObjectUnitTest.java
new file mode 100644
index 0000000000..20b5b8e0c8
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/getclassobject/GetClassObjectUnitTest.java
@@ -0,0 +1,55 @@
+package com.baeldung.getclassobject;
+
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class GetClassObjectUnitTest {
+ @Test
+ public void givenObjectAndType_whenGettingClassObject_thenTwoMethodsHaveTheSameResult() {
+ String str = "I am an object of the String class";
+ Class fromStrObject = str.getClass();
+ Class clazz = String.class;
+ assertSame(fromStrObject, clazz);
+ }
+
+ @Test
+ public void givenClassInheritance_whenGettingRuntimeTypeAndStaticType_thenGetDifferentResult() {
+ Animal animal = new Monkey();
+ Class runtimeType = animal.getClass();
+ Class staticType = Animal.class;
+ //Not equals
+ assertNotEquals(staticType, runtimeType);
+
+ Class monkeyClass = Monkey.class;
+ assertSame(runtimeType, monkeyClass);
+ }
+
+ @Test
+ public void givenPrimitiveType_whenGettingClassObject_thenOnlyStaticTypeWorks() {
+ int number = 7;
+ // Class numberClass = number.getClass(); <-- compilation error
+ Class intType = int.class;
+
+ assertNotNull(intType);
+ assertEquals("int", intType.getName());
+ assertTrue(intType.isPrimitive());
+ }
+
+ @Test
+ public void givenTypeCannotInstantiate_whenGetTypeStatically_thenGetTypesSuccefully() {
+ Class interfaceType = SomeInterface.class;
+ Class abstractClassType = SomeAbstractClass.class;
+ Class utilClassType = SomeUtils.class;
+
+ assertNotNull(interfaceType);
+ assertTrue(interfaceType.isInterface());
+ assertEquals("SomeInterface", interfaceType.getSimpleName());
+
+ assertNotNull(abstractClassType);
+ assertEquals("SomeAbstractClass", abstractClassType.getSimpleName());
+
+ assertNotNull(utilClassType);
+ assertEquals("SomeUtils", utilClassType.getSimpleName());
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java
new file mode 100644
index 0000000000..6746e570ca
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/iterationcounter/IterationCounterUnitTest.java
@@ -0,0 +1,36 @@
+package com.baeldung.iterationcounter;
+
+import org.junit.Test;
+
+import static com.baeldung.iterationcounter.IterationCounter.*;
+import static org.assertj.core.api.Assertions.*;
+
+public class IterationCounterUnitTest {
+ @Test
+ public void givenRankings_whenCalculateWithForLoop_thenRankingsCorrect() {
+ assertThat(getRankingsWithForLoop(IMDB_TOP_MOVIES))
+ .containsExactly("1: The Shawshank Redemption",
+ "2: The Godfather", "3: The Godfather II", "4: The Dark Knight");
+ }
+
+ @Test
+ public void givenRankings_whenCalculateWithForEachLoop_thenRankingsCorrect() {
+ assertThat(getRankingsWithForEachLoop(IMDB_TOP_MOVIES))
+ .containsExactly("1: The Shawshank Redemption",
+ "2: The Godfather", "3: The Godfather II", "4: The Dark Knight");
+ }
+
+ @Test
+ public void givenRankings_whenCalculateWithFunctionalForEach_thenRankingsCorrect() {
+ assertThat(getRankingsWithFunctionalForEachLoop(IMDB_TOP_MOVIES))
+ .containsExactly("1: The Shawshank Redemption",
+ "2: The Godfather", "3: The Godfather II", "4: The Dark Knight");
+ }
+
+ @Test
+ public void givenRankings_whenCalculateWithStream_thenRankingsCorrect() {
+ assertThat(getRankingsWithStream(IMDB_TOP_MOVIES.stream()))
+ .containsExactly("1: The Shawshank Redemption",
+ "2: The Godfather", "3: The Godfather II", "4: The Dark Knight");
+ }
+}
diff --git a/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java
new file mode 100644
index 0000000000..cf63a0ddda
--- /dev/null
+++ b/core-java-modules/core-java-lang-3/src/test/java/com/baeldung/transientkw/TransientUnitTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.transientkw;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+class TransientUnitTest {
+
+ @Test
+ void givenTransient_whenSerDe_thenVerifyValues() throws Exception {
+ Book book = new Book();
+ book.setBookName("Java Reference");
+ book.setDescription("will not be saved");
+ book.setCopies(25);
+
+ BookSerDe.serialize(book);
+ Book book2 = BookSerDe.deserialize();
+
+ assertEquals("Java Reference", book2.getBookName());
+ assertNull(book2.getDescription());
+ assertEquals(0, book2.getCopies());
+ }
+
+ @Test
+ void givenFinalTransient_whenSerDe_thenValuePersisted() throws Exception {
+ Book book = new Book();
+
+ BookSerDe.serialize(book);
+ Book book2 = BookSerDe.deserialize();
+
+ assertEquals("Fiction", book2.getBookCategory());
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-4/README.md b/core-java-modules/core-java-lang-4/README.md
new file mode 100644
index 0000000000..77d14f0fc8
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/README.md
@@ -0,0 +1,5 @@
+## Core Java Lang (Part 4)
+
+This module contains articles about core features in the Java language
+
+- [The Java final Keyword – Impact on Performance](https://www.baeldung.com/java-final-performance)
diff --git a/core-java-modules/core-java-lang-4/pom.xml b/core-java-modules/core-java-lang-4/pom.xml
new file mode 100644
index 0000000000..f00a9318f7
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/pom.xml
@@ -0,0 +1,43 @@
+
+
+ 4.0.0
+ core-java-lang-4
+ 0.1.0-SNAPSHOT
+ core-java-lang-4
+ jar
+
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+ org.openjdk.jmh
+ jmh-core
+ ${jmh-core.version}
+
+
+ org.openjdk.jmh
+ jmh-generator-annprocess
+ ${jmh-generator.version}
+ test
+
+
+
+
+ core-java-lang-4
+
+
+ src/main/resources
+ true
+
+
+
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java
new file mode 100644
index 0000000000..ee34114195
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/BenchmarkRunner.java
@@ -0,0 +1,34 @@
+package com.baeldung.finalkeyword;
+
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+
+import java.util.concurrent.TimeUnit;
+
+public class BenchmarkRunner {
+
+ public static void main(String[] args) throws Exception {
+ org.openjdk.jmh.Main.main(args);
+ }
+
+ @Benchmark
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ public static String concatNonFinalStrings() {
+ String x = "x";
+ String y = "y";
+ return x + y;
+ }
+
+ @Benchmark
+ @OutputTimeUnit(TimeUnit.NANOSECONDS)
+ @BenchmarkMode(Mode.AverageTime)
+ public static String concatFinalStrings() {
+ final String x = "x";
+ final String y = "y";
+ return x + y;
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java
new file mode 100644
index 0000000000..1aeef76e58
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableFinal.java
@@ -0,0 +1,19 @@
+package com.baeldung.finalkeyword;
+
+import java.io.Console;
+
+public class ClassVariableFinal {
+
+ static final boolean doX = false;
+ static final boolean doY = true;
+
+ public static void main(String[] args) {
+ Console console = System.console();
+ if (doX) {
+ console.writer().println("x");
+ } else if (doY) {
+ console.writer().println("y");
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java
new file mode 100644
index 0000000000..a6d83a66cb
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/ClassVariableNonFinal.java
@@ -0,0 +1,19 @@
+package com.baeldung.finalkeyword;
+
+import java.io.Console;
+
+public class ClassVariableNonFinal {
+
+ static boolean doX = false;
+ static boolean doY = true;
+
+ public static void main(String[] args) {
+ Console console = System.console();
+ if (doX) {
+ console.writer().println("x");
+ } else if (doY) {
+ console.writer().println("y");
+ }
+ }
+
+}
diff --git a/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/package-info.java b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/package-info.java
new file mode 100644
index 0000000000..fd1e3cf8d8
--- /dev/null
+++ b/core-java-modules/core-java-lang-4/src/main/java/com/baeldung/finalkeyword/package-info.java
@@ -0,0 +1,13 @@
+/**
+* This module is about impact of the final keyword on performance
+ *
+ * This module explores if there are any performance benefits from
+ * using the final keyword in our code. This module examines the performance
+ * implications of using final on a variable, method, and class level.
+ *
+*
+* @since 1.0
+* @author baeldung
+* @version 1.1
+*/
+package com.baeldung.finalkeyword;
diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md
index 09039f6ed0..5e1dc5af0e 100644
--- a/core-java-modules/core-java-lang-math-2/README.md
+++ b/core-java-modules/core-java-lang-math-2/README.md
@@ -9,8 +9,9 @@
- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap)
- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points)
- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines)
-- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
+- [Round Up to the Nearest Hundred in Java](https://www.baeldung.com/java-round-up-nearest-hundred)
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)
- [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging)
- [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication)
-- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math)
+- [Largest Power of 2 That Is Less Than the Given Number with Java](https://www.baeldung.com/java-largest-power-of-2-less-than-number)
+- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math)[[Next -->]](/core-java-modules/core-java-lang-math-3)
diff --git a/core-java-modules/core-java-lang-math-2/pom.xml b/core-java-modules/core-java-lang-math-2/pom.xml
index e2cced4fbf..56e18158b3 100644
--- a/core-java-modules/core-java-lang-math-2/pom.xml
+++ b/core-java-modules/core-java-lang-math-2/pom.xml
@@ -58,22 +58,10 @@
org.openjdk.jmhjmh-generator-annprocess
- ${jmh.version}
+ ${jmh-generator.version}
-
-
-
-
- org.codehaus.mojo
- exec-maven-plugin
- ${exec-maven-plugin.version}
-
-
-
-
-
3.6.13.9.0
@@ -83,7 +71,6 @@
1.0.0-beta41.2.00.6.0
- 1.19
\ No newline at end of file
diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
new file mode 100644
index 0000000000..ca6b25b3e7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2.java
@@ -0,0 +1,60 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import org.nd4j.linalg.io.Assert;
+
+public class LargestPowerOf2 {
+ public long findLargestPowerOf2LessThanTheGivenNumber(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long firstPowerOf2 = 1;
+ long nextPowerOf2 = 2;
+
+ while (nextPowerOf2 < input) {
+ firstPowerOf2 = nextPowerOf2;
+ nextPowerOf2 = nextPowerOf2 * 2;
+ }
+ return firstPowerOf2;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingLogBase2(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+
+ long temp = input;
+ if (input % 2 == 0) {
+ temp = input - 1;
+ }
+
+ // Find log base 2 of a given number
+ long power = (long) (Math.log(temp) / Math.log(2));
+ long result = (long) Math.pow(2, power);
+
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitwiseAnd(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ for (long i = input - 1; i > 1; i--) {
+ if ((i & (i - 1)) == 0) {
+ result = i;
+ break;
+ }
+ }
+ return result;
+ }
+
+ public long findLargestPowerOf2LessThanTheGivenNumberUsingBitShiftApproach(long input) {
+ Assert.isTrue(input > 1, "Invalid input");
+ long result = 1;
+ long powerOf2;
+
+ for (long i = 0; i < Long.BYTES * 8; i++) {
+ powerOf2 = 1 << i;
+ if (powerOf2 >= input) {
+ break;
+ }
+ result = powerOf2;
+ }
+ return result;
+ }
+}
diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
new file mode 100644
index 0000000000..63f7b03cf7
--- /dev/null
+++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/largestpowerof2/LargestPowerOf2UnitTest.java
@@ -0,0 +1,67 @@
+package com.baeldung.algorithms.largestpowerof2;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class LargestPowerOf2UnitTest {
+ private long input;
+ private long expectedResult;
+
+ public LargestPowerOf2UnitTest(long input, long expectedResult) {
+ this.input = input;
+ this.expectedResult = expectedResult;
+ }
+
+ @Parameterized.Parameters(name = "{index}: verifyLargestPowerOf2LessThanTheGivenNumber({0}) = {1}")
+ public static Collection
-
+
+
+ org.assertj
+ assertj-core
+ 3.6.1
+ test
+
+
\ No newline at end of file
diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramChannelBuilder.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramChannelBuilder.java
new file mode 100644
index 0000000000..43e0747622
--- /dev/null
+++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramChannelBuilder.java
@@ -0,0 +1,18 @@
+package com.baeldung.datagramchannel;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.nio.channels.DatagramChannel;
+
+public class DatagramChannelBuilder {
+
+ public static DatagramChannel openChannel() throws IOException {
+ DatagramChannel datagramChannel = DatagramChannel.open();
+ return datagramChannel;
+ }
+
+ public static DatagramChannel bindChannel(SocketAddress local) throws IOException {
+ return openChannel().bind(local);
+ }
+
+}
diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramClient.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramClient.java
new file mode 100644
index 0000000000..e377cc431c
--- /dev/null
+++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramClient.java
@@ -0,0 +1,31 @@
+package com.baeldung.datagramchannel;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+
+public class DatagramClient {
+
+ public static DatagramChannel startClient() throws IOException {
+ DatagramChannel client = DatagramChannelBuilder.bindChannel(null);
+ client.configureBlocking(false);
+ return client;
+ }
+
+ public static void sendMessage(DatagramChannel client, String msg, SocketAddress serverAddress) throws IOException {
+ ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
+ client.send(buffer, serverAddress);
+ }
+
+ public static void main(String[] args) throws IOException {
+ DatagramChannel client = startClient();
+ String msg = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
+ InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
+
+ sendMessage(client, msg, serverAddress);
+
+ }
+
+}
diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramServer.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramServer.java
new file mode 100644
index 0000000000..ed3345a26d
--- /dev/null
+++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/datagramchannel/DatagramServer.java
@@ -0,0 +1,46 @@
+package com.baeldung.datagramchannel;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+
+public class DatagramServer {
+
+ public static DatagramChannel startServer() throws IOException {
+ InetSocketAddress address = new InetSocketAddress("localhost", 7001);
+ DatagramChannel server = DatagramChannelBuilder.bindChannel(address);
+
+ System.out.println("Server started at #" + address);
+
+ return server;
+ }
+
+ public static String receiveMessage(DatagramChannel server) throws IOException {
+ ByteBuffer buffer = ByteBuffer.allocate(1024);
+ SocketAddress remoteAdd = server.receive(buffer);
+ String message = extractMessage(buffer);
+
+ System.out.println("Client at #" + remoteAdd + " sent: " + message);
+
+ return message;
+ }
+
+ private static String extractMessage(ByteBuffer buffer) {
+ buffer.flip();
+
+ byte[] bytes = new byte[buffer.remaining()];
+ buffer.get(bytes);
+
+ String msg = new String(bytes);
+
+ return msg;
+ }
+
+ public static void main(String[] args) throws IOException {
+ DatagramChannel server = startServer();
+ receiveMessage(server);
+ }
+
+}
diff --git a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java
index 8cf2e941fe..9e9edcd0ba 100644
--- a/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java
+++ b/core-java-modules/core-java-nio-2/src/main/java/com/baeldung/selector/EchoServer.java
@@ -49,11 +49,11 @@ public class EchoServer {
if (new String(buffer.array()).trim().equals(POISON_PILL)) {
client.close();
System.out.println("Not accepting client messages anymore");
+ } else {
+ buffer.flip();
+ client.write(buffer);
+ buffer.clear();
}
-
- buffer.flip();
- client.write(buffer);
- buffer.clear();
}
private static void register(Selector selector, ServerSocketChannel serverSocket) throws IOException {
diff --git a/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/datagramchannel/DatagramChannelUnitTest.java b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/datagramchannel/DatagramChannelUnitTest.java
new file mode 100644
index 0000000000..f816072ee7
--- /dev/null
+++ b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/datagramchannel/DatagramChannelUnitTest.java
@@ -0,0 +1,29 @@
+package com.baeldung.datagramchannel;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.channels.DatagramChannel;
+import org.junit.jupiter.api.Test;
+
+public class DatagramChannelUnitTest {
+
+ @Test
+ public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
+ DatagramChannel server = DatagramServer.startServer();
+ DatagramChannel client = DatagramClient.startClient();
+
+ String msg1 = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
+ String msg2 = "Hi again!, Are you there!";
+
+ InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
+
+ DatagramClient.sendMessage(client, msg1, serverAddress);
+ DatagramClient.sendMessage(client, msg2, serverAddress);
+
+ assertEquals("Hello, this is a Baeldung's DatagramChannel based UDP client!", DatagramServer.receiveMessage(server));
+ assertEquals("Hi again!, Are you there!", DatagramServer.receiveMessage(server));
+ }
+
+}
diff --git a/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/SelectorManualTest.java b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/SelectorManualTest.java
new file mode 100644
index 0000000000..7a6c9e6eab
--- /dev/null
+++ b/core-java-modules/core-java-nio-2/src/test/java/com/baeldung/selector/SelectorManualTest.java
@@ -0,0 +1,64 @@
+package com.baeldung.selector;
+
+import org.junit.Test;
+import java.io.IOException;
+import java.nio.channels.Pipe;
+import java.nio.channels.SelectableChannel;
+import java.nio.channels.Selector;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import static java.nio.channels.SelectionKey.OP_READ;
+
+public class SelectorManualTest {
+
+ @Test
+ public void whenWakeUpCalledOnSelector_thenBlockedThreadReturns() throws IOException, InterruptedException {
+ Pipe pipe = Pipe.open();
+
+ Selector selector = Selector.open();
+ SelectableChannel channel = pipe.source();
+ channel.configureBlocking(false);
+ channel.register(selector, OP_READ);
+
+ List invocationStepsTracker = Collections.synchronizedList(new ArrayList<>());
+
+ CountDownLatch latch = new CountDownLatch(1);
+
+ Thread thread = new Thread(() -> {
+ invocationStepsTracker.add(">> Count down");
+ latch.countDown();
+ try {
+ invocationStepsTracker.add(">> Start select");
+ selector.select();
+ invocationStepsTracker.add(">> End select");
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+
+ invocationStepsTracker.add(">> Start await");
+ thread.start();
+ latch.await();
+ invocationStepsTracker.add(">> End await");
+
+ invocationStepsTracker.add(">> Wakeup thread");
+
+ selector.wakeup();
+ channel.close();
+
+ assertThat(invocationStepsTracker)
+ .containsExactly(
+ ">> Start await",
+ ">> Count down",
+ ">> Start select",
+ ">> End await",
+ ">> Wakeup thread",
+ ">> End select"
+ );
+ }
+}
diff --git a/core-java-modules/core-java-optional/README.md b/core-java-modules/core-java-optional/README.md
index d9d2fe813b..6c83003ea2 100644
--- a/core-java-modules/core-java-optional/README.md
+++ b/core-java-modules/core-java-optional/README.md
@@ -4,7 +4,6 @@ This module contains articles about Java Optional.
### Relevant Articles:
- [Java Optional as Return Type](https://www.baeldung.com/java-optional-return)
-- [Guide to Java 8 Optional](https://www.baeldung.com/java-optional)
- [Java Optional – orElse() vs orElseGet()](https://www.baeldung.com/java-optional-or-else-vs-or-else-get)
- [Transforming an Empty String into an Empty Optional](https://www.baeldung.com/java-empty-string-to-empty-optional)
- [Filtering a Stream of Optionals in Java](https://www.baeldung.com/java-filter-stream-of-optional)
diff --git a/core-java-modules/core-java-optional/pom.xml b/core-java-modules/core-java-optional/pom.xml
index 575ccb0759..a6127f5fdd 100644
--- a/core-java-modules/core-java-optional/pom.xml
+++ b/core-java-modules/core-java-optional/pom.xml
@@ -67,8 +67,6 @@
5.4.0.Final
- 1.19
- 1.1927.1-jre3.10.03.1.1
diff --git a/core-java-modules/core-java-os/README.md b/core-java-modules/core-java-os/README.md
index f2ec3f9d48..10e04a8ba6 100644
--- a/core-java-modules/core-java-os/README.md
+++ b/core-java-modules/core-java-os/README.md
@@ -12,5 +12,6 @@ This module contains articles about working with the operating system (OS) in Ja
- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java)
- [Pattern Search with Grep in Java](http://www.baeldung.com/grep-in-java)
- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java)
+- [Taking Screenshots Using Java](https://www.baeldung.com/java-taking-screenshots)
-This module uses Java 9, so make sure to have the JDK 9 installed to run it.
\ No newline at end of file
+This module uses Java 9, so make sure to have the JDK 9 installed to run it.
diff --git a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java
index 37378f9d6c..fc6d907bfd 100644
--- a/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java
+++ b/core-java-modules/core-java-os/src/main/java/com/baeldung/java9/process/OutputStreamExample.java
@@ -6,8 +6,7 @@ import java.util.logging.Logger;
public class OutputStreamExample {
public static void main(String[] args) {
- Logger log = Logger.getLogger(OutputStreamExample.class.getName());
- log.log(Level.INFO, Integer.toString(sum(1,2)));
+ System.out.println(sum(1,2));
}
public static int sum(int a, int b) {
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java
deleted file mode 100644
index dbaad211d9..0000000000
--- a/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherTest.java
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.core.pwd;
-
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class CurrentDirectoryFetcherTest {
-
- private static final String CURRENT_DIR = "core-java-os";
-
- @Test
- public void whenUsingSystemProperties_thenReturnCurrentDirectory() {
- assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingSystemProperties()
- .endsWith(CURRENT_DIR));
- }
-
- @Test
- public void whenUsingJavaNioPaths_thenReturnCurrentDirectory() {
- assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingPaths()
- .endsWith(CURRENT_DIR));
- }
-
- @Test
- public void whenUsingJavaNioFileSystems_thenReturnCurrentDirectory() {
- assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingFileSystems()
- .endsWith(CURRENT_DIR));
- }
-
- @Test
- public void whenUsingJavaIoFile_thenReturnCurrentDirectory() {
- assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingFile()
- .endsWith(CURRENT_DIR));
- }
-}
\ No newline at end of file
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java
new file mode 100644
index 0000000000..c92049816f
--- /dev/null
+++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/core/pwd/CurrentDirectoryFetcherUnitTest.java
@@ -0,0 +1,34 @@
+package com.baeldung.core.pwd;
+
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class CurrentDirectoryFetcherUnitTest {
+
+ private static final String CURRENT_DIR = "core-java-os";
+
+ @Test
+ public void whenUsingSystemProperties_thenReturnCurrentDirectory() {
+ assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingSystemProperties()
+ .endsWith(CURRENT_DIR));
+ }
+
+ @Test
+ public void whenUsingJavaNioPaths_thenReturnCurrentDirectory() {
+ assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingPaths()
+ .endsWith(CURRENT_DIR));
+ }
+
+ @Test
+ public void whenUsingJavaNioFileSystems_thenReturnCurrentDirectory() {
+ assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingFileSystems()
+ .endsWith(CURRENT_DIR));
+ }
+
+ @Test
+ public void whenUsingJavaIoFile_thenReturnCurrentDirectory() {
+ assertTrue(CurrentDirectoryFetcher.currentDirectoryUsingFile()
+ .endsWith(CURRENT_DIR));
+ }
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java
index 8cefceef1d..a7a23fb6fc 100644
--- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java
+++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessAPIEnhancementsUnitTest.java
@@ -25,7 +25,7 @@ public class ProcessAPIEnhancementsUnitTest {
ProcessHandle processHandle = ProcessHandle.current();
ProcessHandle.Info processInfo = processHandle.info();
assertNotNull(processHandle.pid());
- assertEquals(false, processInfo.arguments()
+ assertEquals(true, processInfo.arguments()
.isPresent());
assertEquals(true, processInfo.command()
.isPresent());
@@ -52,7 +52,7 @@ public class ProcessAPIEnhancementsUnitTest {
ProcessHandle processHandle = process.toHandle();
ProcessHandle.Info processInfo = processHandle.info();
assertNotNull(processHandle.pid());
- assertEquals(false, processInfo.arguments()
+ assertEquals(true, processInfo.arguments()
.isPresent());
assertEquals(true, processInfo.command()
.isPresent());
@@ -61,7 +61,7 @@ public class ProcessAPIEnhancementsUnitTest {
.contains("java"));
assertEquals(true, processInfo.startInstant()
.isPresent());
- assertEquals(true, processInfo.totalCpuDuration()
+ assertEquals(false, processInfo.totalCpuDuration()
.isPresent());
assertEquals(true, processInfo.user()
.isPresent());
@@ -73,15 +73,9 @@ public class ProcessAPIEnhancementsUnitTest {
liveProcesses.filter(ProcessHandle::isAlive)
.forEach(ph -> {
assertNotNull(ph.pid());
- assertEquals(true, ph.info()
- .command()
- .isPresent());
assertEquals(true, ph.info()
.startInstant()
.isPresent());
- assertEquals(true, ph.info()
- .totalCpuDuration()
- .isPresent());
assertEquals(true, ph.info()
.user()
.isPresent());
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java
index 6ad07c5c3a..cb5a20f184 100644
--- a/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java
+++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/java9/process/ProcessUnderstandingUnitTest.java
@@ -5,10 +5,10 @@ import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.String;
-import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.lang.Integer;
@@ -16,28 +16,6 @@ import org.junit.jupiter.api.Test;
class ProcessUnderstandingUnitTest {
- @Test
- public void givenSourceProgram_whenExecutedFromAnotherProgram_thenSourceProgramOutput3() throws IOException {
- Process process = Runtime.getRuntime()
- .exec("javac -cp src src\\main\\java\\com\\baeldung\\java9\\process\\OutputStreamExample.java");
- process = Runtime.getRuntime()
- .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample");
- BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
- int value = Integer.parseInt(output.readLine());
- assertEquals(3, value);
- }
-
- @Test
- public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException {
- Process process = Runtime.getRuntime()
- .exec("javac -cp src src\\main\\java\\com\\baeldung\\java9\\process\\OutputStreamExample.java");
- process = Runtime.getRuntime()
- .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample");
- BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
- int value = Integer.parseInt(output.readLine());
- assertEquals(3, value);
- }
-
@Test
public void givenSubProcess_whenEncounteringError_thenErrorStreamNotNull() throws IOException {
Process process = Runtime.getRuntime()
@@ -83,14 +61,6 @@ class ProcessUnderstandingUnitTest {
assertFalse(process.isAlive());
}
- @Test
- public void givenProcessNotCreated_fromWithinJavaApplicationDestroying_thenProcessNotAlive() {
- Optional optionalProcessHandle = ProcessHandle.of(5232);
- ProcessHandle processHandle = optionalProcessHandle.get();
- processHandle.destroy();
- assertFalse(processHandle.isAlive());
- }
-
//@Test - windows specific
public void givenSubProcess_whenCurrentThreadWaitsIndefinitelyuntilSubProcessEnds_thenProcessWaitForReturnsGrt0() throws IOException, InterruptedException {
ProcessBuilder builder = new ProcessBuilder("notepad.exe");
@@ -118,4 +88,22 @@ class ProcessUnderstandingUnitTest {
.filter(ph -> (ph.pid() > 10000 && ph.pid() < 50000))
.count()) > 0);
}
+
+ @Test
+ public void givenSourceProgram_whenReadingInputStream_thenFirstLineEquals3() throws IOException {
+
+ Runtime.getRuntime()
+ .exec("javac -cp src src/main/java/com/baeldung/java9/process/OutputStreamExample.java"
+ .replace("/", File.separator));
+
+ Process process = Runtime.getRuntime()
+ .exec("java -cp src/main/java com.baeldung.java9.process.OutputStreamExample"
+ .replace("/", File.separator));
+
+ BufferedReader output = new BufferedReader(new InputStreamReader(process.getInputStream()));
+ String line = output.readLine();
+ int value = Integer.parseInt(line);
+
+ assertEquals(3, value);
+ }
}
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java
index 8fc5f9f160..d35cf6a665 100644
--- a/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java
+++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/processbuilder/ProcessBuilderUnitTest.java
@@ -40,7 +40,7 @@ public class ProcessBuilderUnitTest {
List 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")));
+ assertThat("Results should contain java version: ", results, hasItem(containsString("version")));
int exitCode = process.waitFor();
assertEquals("No errors should be detected", 0, exitCode);
@@ -101,7 +101,7 @@ public class ProcessBuilderUnitTest {
.collect(Collectors.toList());
assertThat("Results should not be empty", lines, is(not(empty())));
- assertThat("Results should contain java version: ", lines, hasItem(containsString("java version")));
+ assertThat("Results should contain java version: ", lines, hasItem(containsString("version")));
}
@Test
@@ -124,7 +124,7 @@ public class ProcessBuilderUnitTest {
.collect(Collectors.toList());
assertThat("Results should not be empty", lines, is(not(empty())));
- assertThat("Results should contain java version: ", lines, hasItem(containsString("java version")));
+ assertThat("Results should contain java version: ", lines, hasItem(containsString("version")));
}
@Test
diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java
new file mode 100644
index 0000000000..bf271ef2cc
--- /dev/null
+++ b/core-java-modules/core-java-os/src/test/java/com/baeldung/screenshot/ScreenshotUnitTest.java
@@ -0,0 +1,57 @@
+package com.baeldung.screenshot;
+
+import javax.imageio.ImageIO;
+import java.awt.Component;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Rectangle;
+import java.awt.Robot;
+import java.awt.Toolkit;
+import java.awt.image.BufferedImage;
+import java.io.File;
+
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+@Ignore
+public class ScreenshotUnitTest {
+
+ @Test
+ public void givenMainScreen_whenTakeScreenshot_thenSaveToFile() throws Exception {
+ Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
+ BufferedImage capture = new Robot().createScreenCapture(screenRect);
+ File imageFile = File.createTempFile("single-screen", "bmp");
+ ImageIO.write(capture, "bmp", imageFile);
+ assertTrue(imageFile.exists());
+ }
+
+ @Test
+ public void givenMultipleScreens_whenTakeScreenshot_thenSaveToFile() throws Exception {
+ GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice[] screens = ge.getScreenDevices();
+ Rectangle allScreenBounds = new Rectangle();
+ for (GraphicsDevice screen : screens) {
+ Rectangle screenBounds = screen.getDefaultConfiguration().getBounds();
+ allScreenBounds.width += screenBounds.width;
+ allScreenBounds.height = Math.max(allScreenBounds.height, screenBounds.height);
+ }
+ BufferedImage capture = new Robot().createScreenCapture(allScreenBounds);
+ File imageFile = File.createTempFile("all-screens", "bmp");
+ ImageIO.write(capture, "bmp", imageFile);
+ assertTrue(imageFile.exists());
+ }
+
+ // This methods needs a component as a parameter and can only be run from an application with a GUI
+ @Test
+ public void givenComponent_whenTakeScreenshot_thenSaveToFile(Component component) throws Exception {
+ Rectangle componentRect = component.getBounds();
+ BufferedImage bufferedImage = new BufferedImage(componentRect.width, componentRect.height, BufferedImage.TYPE_INT_ARGB);
+ component.paint(bufferedImage.getGraphics());
+ File imageFile = File.createTempFile("component-screenshot", "bmp");
+ ImageIO.write(bufferedImage, "bmp", imageFile);
+ assertTrue(imageFile.exists());
+ }
+
+}
\ No newline at end of file
diff --git a/core-java-modules/core-java-reflection-2/README.md b/core-java-modules/core-java-reflection-2/README.md
new file mode 100644
index 0000000000..3195cddc42
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/README.md
@@ -0,0 +1,7 @@
+### Relevant Articles:
+
+- [Reading the Value of ‘private’ Fields from a Different Class in Java](https://www.baeldung.com/java-reflection-read-private-field-value)
+- [Set Field Value With Reflection](https://www.baeldung.com/java-set-private-field-value)
+- [Checking If a Method is Static Using Reflection in Java](https://www.baeldung.com/java-check-method-is-static)
+- [Checking if a Java Class is ‘abstract’ Using Reflection](https://www.baeldung.com/java-reflection-is-class-abstract)
+- [Invoking a Private Method in Java](https://www.baeldung.com/java-call-private-method)
diff --git a/core-java-modules/core-java-reflection-2/pom.xml b/core-java-modules/core-java-reflection-2/pom.xml
index ea76ee8c98..02a806f87c 100644
--- a/core-java-modules/core-java-reflection-2/pom.xml
+++ b/core-java-modules/core-java-reflection-2/pom.xml
@@ -14,6 +14,15 @@
../
+
+
+ org.springframework
+ spring-test
+ ${spring.version}
+ test
+
+
+
core-java-reflection-2
@@ -40,5 +49,6 @@
3.8.01.81.8
+ 5.3.4
\ No newline at end of file
diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/privatemethods/LongArrayUtil.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/privatemethods/LongArrayUtil.java
new file mode 100644
index 0000000000..03d8daabbf
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/access/privatemethods/LongArrayUtil.java
@@ -0,0 +1,18 @@
+package com.baeldung.reflection.access.privatemethods;
+
+public class LongArrayUtil {
+
+ public static int indexOf(long[] array, long target) {
+ return indexOf(array, target, 0, array.length);
+ }
+
+ private static int indexOf(long[] array, long target, int start, int end) {
+ for (int i = start; i < end; i++) {
+ if (array[i] == target) {
+ return i;
+ }
+ }
+ return -1;
+ }
+
+}
diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/AbstractExample.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/AbstractExample.java
new file mode 100644
index 0000000000..e8ad3bc3bd
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/AbstractExample.java
@@ -0,0 +1,15 @@
+package com.baeldung.reflection.check.abstractclass;
+
+import java.time.LocalDate;
+import java.time.LocalTime;
+
+public abstract class AbstractExample {
+
+ public static String getAuthorName() {
+ return "Umang Budhwar";
+ }
+
+ public abstract LocalDate getLocalDate();
+
+ public abstract LocalTime getLocalTime();
+}
diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java
new file mode 100644
index 0000000000..d226611084
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/abstractclass/InterfaceExample.java
@@ -0,0 +1,4 @@
+package com.baeldung.reflection.check.abstractclass;
+
+public interface InterfaceExample {
+}
diff --git a/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java
new file mode 100644
index 0000000000..5afb9b79c4
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/main/java/com/baeldung/reflection/check/staticmethods/StaticUtility.java
@@ -0,0 +1,19 @@
+package com.baeldung.reflection.check.staticmethods;
+
+import java.time.LocalDate;
+import java.time.LocalTime;
+
+public class StaticUtility {
+
+ public static String getAuthorName() {
+ return "Umang Budhwar";
+ }
+
+ public static LocalDate getLocalDate() {
+ return LocalDate.now();
+ }
+
+ public static LocalTime getLocalTime() {
+ return LocalTime.now();
+ }
+}
diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/access/privatemethods/InvokePrivateMethodsUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/access/privatemethods/InvokePrivateMethodsUnitTest.java
new file mode 100644
index 0000000000..e98eb9ec7f
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/access/privatemethods/InvokePrivateMethodsUnitTest.java
@@ -0,0 +1,28 @@
+package com.baeldung.reflection.access.privatemethods;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.test.util.ReflectionTestUtils;
+
+import java.lang.reflect.Method;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class InvokePrivateMethodsUnitTest {
+
+ private final long[] someLongArray = new long[] { 1L, 2L, 1L, 4L, 2L };
+
+ @Test
+ void whenSearchingForLongValueInSubsequenceUsingReflection_thenTheCorrectIndexOfTheValueIsReturned() throws Exception {
+ Method indexOfMethod = LongArrayUtil.class.getDeclaredMethod("indexOf", long[].class, long.class, int.class, int.class);
+ indexOfMethod.setAccessible(true);
+
+ assertEquals(2, indexOfMethod.invoke(LongArrayUtil.class, someLongArray, 1L, 1, someLongArray.length), "The index should be 2.");
+ }
+
+ @Test
+ void whenSearchingForLongValueInSubsequenceUsingSpring_thenTheCorrectIndexOfTheValueIsReturned() throws Exception {
+ int indexOfSearchTarget = ReflectionTestUtils.invokeMethod(LongArrayUtil.class, "indexOf", someLongArray, 1L, 1, someLongArray.length);
+ assertEquals(2, indexOfSearchTarget, "The index should be 2.");
+ }
+
+}
diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java
new file mode 100644
index 0000000000..d9a955ca6d
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/abstractclass/AbstractExampleUnitTest.java
@@ -0,0 +1,36 @@
+package com.baeldung.reflection.check.abstractclass;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.Modifier;
+import java.util.Date;
+
+class AbstractExampleUnitTest {
+
+ @Test
+ void givenAbstractClass_whenCheckModifierIsAbstract_thenTrue() {
+ Class clazz = AbstractExample.class;
+ Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
+ }
+
+ @Test
+ void givenInterface_whenCheckModifierIsAbstract_thenTrue() {
+ Class clazz = InterfaceExample.class;
+ Assertions.assertTrue(Modifier.isAbstract(clazz.getModifiers()));
+ }
+
+ @Test
+ void givenAbstractClass_whenCheckIsAbstractClass_thenTrue() {
+ Class clazz = AbstractExample.class;
+ int mod = clazz.getModifiers();
+ Assertions.assertTrue(Modifier.isAbstract(mod) && !Modifier.isInterface(mod));
+ }
+
+ @Test
+ void givenConcreteClass_whenCheckIsAbstractClass_thenFalse() {
+ Class clazz = Date.class;
+ int mod = clazz.getModifiers();
+ Assertions.assertFalse(Modifier.isAbstract(mod) && !Modifier.isInterface(mod));
+ }
+}
diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java
new file mode 100644
index 0000000000..a4540407d5
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/check/staticmethods/StaticUtilityUnitTest.java
@@ -0,0 +1,30 @@
+package com.baeldung.reflection.check.staticmethods;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+class StaticUtilityUnitTest {
+
+ @Test
+ void whenCheckStaticMethod_ThenSuccess() throws Exception {
+ Method method = StaticUtility.class.getMethod("getAuthorName", null);
+ Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
+ }
+
+ @Test
+ void whenCheckAllStaticMethods_thenSuccess() {
+ List methodList = Arrays.asList(StaticUtility.class.getMethods())
+ .stream()
+ .filter(method -> Modifier.isStatic(method.getModifiers()))
+ .collect(Collectors.toList());
+ Assertions.assertEquals(3, methodList.size());
+ }
+
+}
diff --git a/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/set/fields/SetFieldsUsingReflectionUnitTest.java b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/set/fields/SetFieldsUsingReflectionUnitTest.java
new file mode 100644
index 0000000000..3fe6994041
--- /dev/null
+++ b/core-java-modules/core-java-reflection-2/src/test/java/com/baeldung/reflection/set/fields/SetFieldsUsingReflectionUnitTest.java
@@ -0,0 +1,183 @@
+package com.baeldung.reflection.set.fields;
+
+import java.lang.reflect.Field;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import com.baeldung.reflection.access.privatefields.Person;
+
+public class SetFieldsUsingReflectionUnitTest {
+
+ @Test
+ public void whenSetIntegerFields_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field ageField = person.getClass()
+ .getDeclaredField("age");
+ ageField.setAccessible(true);
+
+ byte age = 26;
+ ageField.setByte(person, age);
+ Assertions.assertEquals(age, person.getAge());
+
+ Field uidNumberField = person.getClass()
+ .getDeclaredField("uidNumber");
+ uidNumberField.setAccessible(true);
+
+ short uidNumber = 5555;
+ uidNumberField.setShort(person, uidNumber);
+ Assertions.assertEquals(uidNumber, person.getUidNumber());
+
+ Field pinCodeField = person.getClass()
+ .getDeclaredField("pinCode");
+ pinCodeField.setAccessible(true);
+
+ int pinCode = 411057;
+ pinCodeField.setInt(person, pinCode);
+ Assertions.assertEquals(pinCode, person.getPinCode());
+
+ Field contactNumberField = person.getClass()
+ .getDeclaredField("contactNumber");
+ contactNumberField.setAccessible(true);
+
+ long contactNumber = 123456789L;
+ contactNumberField.setLong(person, contactNumber);
+ Assertions.assertEquals(contactNumber, person.getContactNumber());
+
+ }
+
+ @Test
+ public void whenDoUnboxing_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field pinCodeField = person.getClass()
+ .getDeclaredField("pinCode");
+ pinCodeField.setAccessible(true);
+
+ Integer pinCode = 411057;
+ pinCodeField.setInt(person, pinCode);
+ Assertions.assertEquals(pinCode, person.getPinCode());
+ }
+
+ @Test
+ public void whenDoNarrowing_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field pinCodeField = person.getClass()
+ .getDeclaredField("pinCode");
+ pinCodeField.setAccessible(true);
+
+ short pinCode = 4110;
+ pinCodeField.setInt(person, pinCode);
+ Assertions.assertEquals(pinCode, person.getPinCode());
+ }
+
+ @Test
+ public void whenSetFloatingTypeFields_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field heightField = person.getClass()
+ .getDeclaredField("height");
+ heightField.setAccessible(true);
+
+ float height = 6.1242f;
+ heightField.setFloat(person, height);
+ Assertions.assertEquals(height, person.getHeight());
+
+ Field weightField = person.getClass()
+ .getDeclaredField("weight");
+ weightField.setAccessible(true);
+
+ double weight = 75.2564;
+ weightField.setDouble(person, weight);
+ Assertions.assertEquals(weight, person.getWeight());
+ }
+
+ @Test
+ public void whenSetCharacterFields_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field genderField = person.getClass()
+ .getDeclaredField("gender");
+ genderField.setAccessible(true);
+
+ char gender = 'M';
+ genderField.setChar(person, gender);
+ Assertions.assertEquals(gender, person.getGender());
+ }
+
+ @Test
+ public void whenSetBooleanFields_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field activeField = person.getClass()
+ .getDeclaredField("active");
+ activeField.setAccessible(true);
+
+ activeField.setBoolean(person, true);
+ Assertions.assertTrue(person.isActive());
+ }
+
+ @Test
+ public void whenSetObjectFields_thenSuccess() throws Exception {
+ Person person = new Person();
+
+ Field nameField = person.getClass()
+ .getDeclaredField("name");
+ nameField.setAccessible(true);
+
+ String name = "Umang Budhwar";
+ nameField.set(person, name);
+ Assertions.assertEquals(name, person.getName());
+ }
+
+ @Test
+ public void givenInt_whenSetStringField_thenIllegalArgumentException() throws Exception {
+ Person person = new Person();
+ Field nameField = person.getClass()
+ .getDeclaredField("name");
+ nameField.setAccessible(true);
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> nameField.setInt(person, 26));
+ }
+
+ @Test
+ public void givenInt_whenSetLongField_thenIllegalArgumentException() throws Exception {
+ Person person = new Person();
+
+ Field pinCodeField = person.getClass()
+ .getDeclaredField("pinCode");
+ pinCodeField.setAccessible(true);
+
+ long pinCode = 411057L;
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> pinCodeField.setLong(person, pinCode));
+ }
+
+ @Test
+ public void whenFieldNotSetAccessible_thenIllegalAccessException() throws Exception {
+ Person person = new Person();
+ Field nameField = person.getClass()
+ .getDeclaredField("name");
+
+ Assertions.assertThrows(IllegalAccessException.class, () -> nameField.set(person, "Umang Budhwar"));
+ }
+
+ @Test
+ public void whenAccessingWrongProperty_thenNoSuchFieldException() throws Exception {
+ Person person = new Person();
+
+ Assertions.assertThrows(NoSuchFieldException.class, () -> person.getClass()
+ .getDeclaredField("firstName"));
+ }
+
+ @Test
+ public void whenAccessingNullProperty_thenNullPointerException() throws Exception {
+ Person person = new Person();
+
+ Assertions.assertThrows(NullPointerException.class, () -> person.getClass()
+ .getDeclaredField(null));
+ }
+
+}
diff --git a/core-java-modules/core-java-reflection/README.MD b/core-java-modules/core-java-reflection/README.MD
deleted file mode 100644
index d6b3a02e6a..0000000000
--- a/core-java-modules/core-java-reflection/README.MD
+++ /dev/null
@@ -1,12 +0,0 @@
-## Relevant Articles
-
-- [Void Type in Java](https://www.baeldung.com/java-void-type)
-- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
-- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-reflection)
-- [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)
-- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
-- [How to Find all Getters Returning Null](http://www.baeldung.com/java-getters-returning-null)
-- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
diff --git a/core-java-modules/core-java-reflection/README.md b/core-java-modules/core-java-reflection/README.md
new file mode 100644
index 0000000000..62d8719981
--- /dev/null
+++ b/core-java-modules/core-java-reflection/README.md
@@ -0,0 +1,10 @@
+## Relevant Articles
+
+- [Void Type in Java](https://www.baeldung.com/java-void-type)
+- [Retrieve Fields from a Java Class Using Reflection](https://www.baeldung.com/java-reflection-class-fields)
+- [Method Parameter Reflection in Java](http://www.baeldung.com/java-parameter-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)
+- [What Causes java.lang.reflect.InvocationTargetException?](https://www.baeldung.com/java-lang-reflect-invocationtargetexception)
+- [How to Get a Name of a Method Being Executed?](http://www.baeldung.com/java-name-of-executing-method)
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java
deleted file mode 100644
index 3f36243c29..0000000000
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Animal.java
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.java.reflection;
-
-public abstract class Animal implements Eating {
-
- public static final String CATEGORY = "domestic";
-
- private String name;
-
- public Animal(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- protected abstract String getSound();
-
-}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java
deleted file mode 100644
index 479425cad4..0000000000
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Eating.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.java.reflection;
-
-public interface Eating {
- String eats();
-}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java
deleted file mode 100644
index 4f3a20c3b9..0000000000
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Greetings.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.baeldung.java.reflection;
-
-@Greeter(greet="Good morning")
-public class Greetings {
-
-}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java
deleted file mode 100644
index 047c00cb13..0000000000
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Locomotion.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.java.reflection;
-
-public interface Locomotion {
- String getLocomotion();
-}
diff --git a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java b/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java
deleted file mode 100644
index f3d7f9f001..0000000000
--- a/core-java-modules/core-java-reflection/src/main/java/com/baeldung/reflection/java/reflection/Person.java
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.baeldung.java.reflection;
-
-public class Person {
- private String name;
- private int age;
-}
diff --git a/core-java-modules/core-java-regex/README.md b/core-java-modules/core-java-regex/README.md
index 8830af2c2d..92321fa656 100644
--- a/core-java-modules/core-java-regex/README.md
+++ b/core-java-modules/core-java-regex/README.md
@@ -3,11 +3,13 @@
## Core Java 8 Cookbooks and Examples
### 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)
- [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)
-- [How to Use Regular Expressions to Replace Tokens in Strings](https://www.baeldung.com/java-regex-token-replacement)
+- [How to Use Regular Expressions to Replace Tokens in Strings in Java](https://www.baeldung.com/java-regex-token-replacement)
- [Regular Expressions \s and \s+ in Java](https://www.baeldung.com/java-regex-s-splus)
- [Validate Phone Numbers With Java Regex](https://www.baeldung.com/java-regex-validate-phone-numbers)
+- [How to Count the Number of Matches for a Regex?](https://www.baeldung.com/java-count-regex-matches)
diff --git a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java
index 6427d11dd6..3e601a7828 100644
--- a/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java
+++ b/core-java-modules/core-java-regex/src/test/java/com/baeldung/regex/countmatches/CountMatchesUnitTest.java
@@ -1,12 +1,11 @@
package com.baeldung.regex.countmatches;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
+import org.junit.Test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Unit Test intended to count number of matches of a RegEx using Java 8 and 9.
@@ -65,7 +64,7 @@ public class CountMatchesUnitTest {
count++;
}
- assertNotEquals(3, count);
+ assertEquals(2, count);
}
@Test
diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md
index 24a821bd4d..684f2504cc 100644
--- a/core-java-modules/core-java-security-2/README.md
+++ b/core-java-modules/core-java-security-2/README.md
@@ -9,4 +9,12 @@ This module contains articles about core Java Security
- [Hashing a Password in Java](https://www.baeldung.com/java-password-hashing)
- [SHA-256 and SHA3-256 Hashing in Java](https://www.baeldung.com/sha-256-hashing-java)
- [Checksums in Java](https://www.baeldung.com/java-checksums)
+- [How to Read PEM File to Get Public and Private Keys](https://www.baeldung.com/java-read-pem-file-keys)
+- [Listing the Available Cipher Algorithms](https://www.baeldung.com/java-list-cipher-algorithms)
+- [Get a List of Trusted Certificates in Java](https://www.baeldung.com/java-list-trusted-certificates)
+- [Security Context Basics: User, Subject and Principal](https://www.baeldung.com/security-context-basics)
+- [Java AES Encryption and Decryption](https://www.baeldung.com/java-aes-encryption-decryption)
+- [InvalidAlgorithmParameterException: Wrong IV Length](https://www.baeldung.com/java-invalidalgorithmparameter-exception)
+- [The java.security.egd JVM Option](https://www.baeldung.com/java-security-egd)
+- [RSA in Java](https://www.baeldung.com/java-rsa)
- More articles: [[<-- prev]](/core-java-modules/core-java-security)
diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml
index 890b4147ca..895509410d 100644
--- a/core-java-modules/core-java-security-2/pom.xml
+++ b/core-java-modules/core-java-security-2/pom.xml
@@ -53,7 +53,7 @@
1.11
- 3.10.0
+ 3.18.02.3.1
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java
new file mode 100644
index 0000000000..2952eef625
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/AESUtil.java
@@ -0,0 +1,156 @@
+package com.baeldung.aes;
+
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.BadPaddingException;
+import javax.crypto.KeyGenerator;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.SealedObject;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.Serializable;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SecureRandom;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.util.Base64;
+
+public class AESUtil {
+
+ public static String encrypt(String algorithm, String input, SecretKey key, IvParameterSpec iv)
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);
+ byte[] cipherText = cipher.doFinal(input.getBytes());
+ return Base64.getEncoder()
+ .encodeToString(cipherText);
+ }
+
+ public static String decrypt(String algorithm, String cipherText, SecretKey key, IvParameterSpec iv)
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);
+ byte[] plainText = cipher.doFinal(Base64.getDecoder()
+ .decode(cipherText));
+ return new String(plainText);
+ }
+
+ public static SecretKey generateKey(int n) throws NoSuchAlgorithmException {
+ KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
+ keyGenerator.init(n);
+ SecretKey key = keyGenerator.generateKey();
+ return key;
+ }
+
+ public static SecretKey getKeyFromPassword(String password, String salt)
+ throws NoSuchAlgorithmException, InvalidKeySpecException {
+ SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256");
+ KeySpec spec = new PBEKeySpec(password.toCharArray(), salt.getBytes(), 65536, 256);
+ SecretKey secret = new SecretKeySpec(factory.generateSecret(spec)
+ .getEncoded(), "AES");
+ return secret;
+ }
+
+ public static IvParameterSpec generateIv() {
+ byte[] iv = new byte[16];
+ new SecureRandom().nextBytes(iv);
+ return new IvParameterSpec(iv);
+ }
+
+ public static void encryptFile(String algorithm, SecretKey key, IvParameterSpec iv,
+ File inputFile, File outputFile) throws IOException, NoSuchPaddingException,
+ NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException,
+ BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);
+ FileInputStream inputStream = new FileInputStream(inputFile);
+ FileOutputStream outputStream = new FileOutputStream(outputFile);
+ byte[] buffer = new byte[64];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ byte[] output = cipher.update(buffer, 0, bytesRead);
+ if (output != null) {
+ outputStream.write(output);
+ }
+ }
+ byte[] outputBytes = cipher.doFinal();
+ if (outputBytes != null) {
+ outputStream.write(outputBytes);
+ }
+ inputStream.close();
+ outputStream.close();
+ }
+
+ public static void decryptFile(String algorithm, SecretKey key, IvParameterSpec iv,
+ File encryptedFile, File decryptedFile) throws IOException, NoSuchPaddingException,
+ NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidKeyException,
+ BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);
+ FileInputStream inputStream = new FileInputStream(encryptedFile);
+ FileOutputStream outputStream = new FileOutputStream(decryptedFile);
+ byte[] buffer = new byte[64];
+ int bytesRead;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ byte[] output = cipher.update(buffer, 0, bytesRead);
+ if (output != null) {
+ outputStream.write(output);
+ }
+ }
+ byte[] output = cipher.doFinal();
+ if (output != null) {
+ outputStream.write(output);
+ }
+ inputStream.close();
+ outputStream.close();
+ }
+
+ public static SealedObject encryptObject(String algorithm, Serializable object, SecretKey key,
+ IvParameterSpec iv) throws NoSuchPaddingException, NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException, InvalidKeyException, IOException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);
+ SealedObject sealedObject = new SealedObject(object, cipher);
+ return sealedObject;
+ }
+
+ public static Serializable decryptObject(String algorithm, SealedObject sealedObject, SecretKey key,
+ IvParameterSpec iv) throws NoSuchPaddingException, NoSuchAlgorithmException,
+ InvalidAlgorithmParameterException, InvalidKeyException, ClassNotFoundException,
+ BadPaddingException, IllegalBlockSizeException, IOException {
+ Cipher cipher = Cipher.getInstance(algorithm);
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);
+ Serializable unsealObject = (Serializable) sealedObject.getObject(cipher);
+ return unsealObject;
+ }
+
+ public static String encryptPasswordBased(String plainText, SecretKey key, IvParameterSpec iv)
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
+ cipher.init(Cipher.ENCRYPT_MODE, key, iv);
+ return Base64.getEncoder()
+ .encodeToString(cipher.doFinal(plainText.getBytes()));
+ }
+
+ public static String decryptPasswordBased(String cipherText, SecretKey key, IvParameterSpec iv)
+ throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
+ InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
+ Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");
+ cipher.init(Cipher.DECRYPT_MODE, key, iv);
+ return new String(cipher.doFinal(Base64.getDecoder()
+ .decode(cipherText)));
+ }
+
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java
new file mode 100644
index 0000000000..13cd1c5e9d
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/aes/Student.java
@@ -0,0 +1,40 @@
+package com.baeldung.aes;
+
+import java.io.Serializable;
+import java.util.Objects;
+
+public class Student implements Serializable {
+ private String name;
+ private int age;
+
+ public Student(String name, int age) {
+ this.name = name;
+ this.age = age;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o)
+ return true;
+ if (o == null || getClass() != o.getClass())
+ return false;
+ Student student = (Student) o;
+ return age == student.age && Objects.equals(name, student.name);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java
new file mode 100644
index 0000000000..347d3b4cba
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/egd/JavaSecurityEgdTester.java
@@ -0,0 +1,23 @@
+package com.baeldung.egd;
+
+import java.security.SecureRandom;
+
+/**
+ * JavaSecurityEgdTester - run this with JVM parameter java.security.egd, e.g.:
+ * java -Djava.security.egd=file:/dev/urandom -cp . com.baeldung.egd.JavaSecurityEgdTester
+ */
+public class JavaSecurityEgdTester {
+ public static final double NANOSECS = 1000000000.0;
+ public static final String JAVA_SECURITY_EGD = "java.security.egd";
+
+ public static void main(String[] args) {
+ SecureRandom secureRandom = new SecureRandom();
+ long start = System.nanoTime();
+ byte[] randomBytes = new byte[256];
+ secureRandom.nextBytes(randomBytes);
+ double duration = (System.nanoTime() - start) / NANOSECS;
+
+ String message = String.format("java.security.egd=%s took %.3f seconds and used the %s algorithm", System.getProperty(JAVA_SECURITY_EGD), duration, secureRandom.getAlgorithm());
+ System.out.println(message);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
index 0f28408083..699e9141a4 100644
--- a/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
+++ b/core-java-modules/core-java-security-2/src/main/java/com/baeldung/hashing/SHACommonUtils.java
@@ -3,7 +3,7 @@ package com.baeldung.hashing;
class SHACommonUtils {
public static String bytesToHex(byte[] hash) {
- StringBuffer hexString = new StringBuffer();
+ StringBuilder hexString = new StringBuilder(2 * hash.length);
for (byte h : hash) {
String hex = Integer.toHexString(0xff & h);
if (hex.length() == 1)
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java
new file mode 100644
index 0000000000..531c20ca79
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/aes/AESUtilUnitTest.java
@@ -0,0 +1,101 @@
+package com.baeldung.aes;
+
+import org.assertj.core.api.WithAssertions;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.crypto.SealedObject;
+import javax.crypto.SecretKey;
+import javax.crypto.spec.IvParameterSpec;
+import javax.crypto.BadPaddingException;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.NoSuchPaddingException;
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.InvalidKeySpecException;
+
+class AESUtilUnitTest implements WithAssertions {
+
+ @Test
+ void givenString_whenEncrypt_thenSuccess()
+ throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException,
+ BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException {
+ // given
+ String input = "baeldung";
+ SecretKey key = AESUtil.generateKey(128);
+ IvParameterSpec ivParameterSpec = AESUtil.generateIv();
+ String algorithm = "AES/CBC/PKCS5Padding";
+
+ // when
+ String cipherText = AESUtil.encrypt(algorithm, input, key, ivParameterSpec);
+ String plainText = AESUtil.decrypt(algorithm, cipherText, key, ivParameterSpec);
+
+ // then
+ Assertions.assertEquals(input, plainText);
+ }
+
+ @Test
+ void givenFile_whenEncrypt_thenSuccess()
+ throws NoSuchAlgorithmException, IOException, IllegalBlockSizeException, InvalidKeyException,
+ BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException {
+ // given
+ SecretKey key = AESUtil.generateKey(128);
+ String algorithm = "AES/CBC/PKCS5Padding";
+ IvParameterSpec ivParameterSpec = AESUtil.generateIv();
+ File inputFile = Paths.get("src/test/resources/baeldung.txt")
+ .toFile();
+ File encryptedFile = new File("classpath:baeldung.encrypted");
+ File decryptedFile = new File("document.decrypted");
+
+ // when
+ AESUtil.encryptFile(algorithm, key, ivParameterSpec, inputFile, encryptedFile);
+ AESUtil.decryptFile(algorithm, key, ivParameterSpec, encryptedFile, decryptedFile);
+
+ // then
+ assertThat(inputFile).hasSameTextualContentAs(decryptedFile);
+ encryptedFile.delete();
+ decryptedFile.delete();
+ }
+
+ @Test
+ void givenObject_whenEncrypt_thenSuccess()
+ throws NoSuchAlgorithmException, IllegalBlockSizeException, InvalidKeyException,
+ InvalidAlgorithmParameterException, NoSuchPaddingException, IOException, BadPaddingException,
+ ClassNotFoundException {
+ // given
+ Student student = new Student("Baeldung", 20);
+ SecretKey key = AESUtil.generateKey(128);
+ IvParameterSpec ivParameterSpec = AESUtil.generateIv();
+ String algorithm = "AES/CBC/PKCS5Padding";
+
+ // when
+ SealedObject sealedObject = AESUtil.encryptObject(algorithm, student, key, ivParameterSpec);
+ Student object = (Student) AESUtil.decryptObject(algorithm, sealedObject, key, ivParameterSpec);
+
+ // then
+ assertThat(student).isEqualTo(object);
+ }
+
+ @Test
+ void givenPassword_whenEncrypt_thenSuccess()
+ throws InvalidKeySpecException, NoSuchAlgorithmException, IllegalBlockSizeException,
+ InvalidKeyException, BadPaddingException, InvalidAlgorithmParameterException, NoSuchPaddingException {
+ // given
+ String plainText = "www.baeldung.com";
+ String password = "baeldung";
+ String salt = "12345678";
+ IvParameterSpec ivParameterSpec = AESUtil.generateIv();
+ SecretKey key = AESUtil.getKeyFromPassword(password, salt);
+
+ // when
+ String cipherText = AESUtil.encryptPasswordBased(plainText, key, ivParameterSpec);
+ String decryptedCipherText = AESUtil.decryptPasswordBased(cipherText, key, ivParameterSpec);
+
+ // then
+ Assertions.assertEquals(plainText, decryptedCipherText);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java
new file mode 100644
index 0000000000..fa38aca272
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/cipher/AvailableCiphersUnitTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.cipher;
+
+import org.junit.jupiter.api.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.security.Provider;
+import java.security.Security;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class AvailableCiphersUnitTest {
+ private final Logger logger = LoggerFactory.getLogger(AvailableCiphersUnitTest.class);
+
+ @Test
+ public void whenGetServices_thenGetAllCipherAlgorithms() {
+ for (Provider provider : Security.getProviders()) {
+ for (Provider.Service service : provider.getServices()) {
+ logger.info(service.getAlgorithm());
+ }
+ }
+ }
+
+ @Test
+ public void whenGetServicesWithFilter_thenGetAllCompatibleCipherAlgorithms() {
+ List algorithms = Arrays.stream(Security.getProviders())
+ .flatMap(provider -> provider.getServices().stream())
+ .filter(service -> "Cipher".equals(service.getType()))
+ .map(Provider.Service::getAlgorithm)
+ .collect(Collectors.toList());
+
+ algorithms.forEach(logger::info);
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java
new file mode 100644
index 0000000000..ac93f71125
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/rsa/RsaUnitTest.java
@@ -0,0 +1,92 @@
+package com.baeldung.cipher;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import javax.crypto.Cipher;
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.FileOutputStream;
+import java.io.FileReader;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.security.KeyPair;
+import java.security.KeyPairGenerator;
+import java.security.PrivateKey;
+import java.security.PublicKey;
+
+public class RsaUnitTest {
+
+ @Test
+ public void givenRsaKeyPair_whenEncryptAndDecryptString_thenCompareResults() throws Exception {
+ KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
+ generator.initialize(2048);
+ KeyPair pair = generator.generateKeyPair();
+ PrivateKey privateKey = pair.getPrivate();
+ PublicKey publicKey = pair.getPublic();
+
+ String secretMessage = "Baeldung secret message";
+ Cipher encryptCipher = Cipher.getInstance("RSA");
+ encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
+ byte[] secretMessageBytes = secretMessage.getBytes(StandardCharsets.UTF_8);
+ byte[] encryptedMessageBytes = encryptCipher.doFinal(secretMessageBytes);
+
+ Cipher decryptCipher = Cipher.getInstance("RSA");
+ decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
+ byte[] decryptedMessageBytes = decryptCipher.doFinal(encryptedMessageBytes);
+ String decryptedMessage = new String(decryptedMessageBytes, StandardCharsets.UTF_8);
+
+ Assertions.assertEquals(secretMessage, decryptedMessage);
+ }
+
+ @Test
+ public void givenRsaKeyPair_whenEncryptAndDecryptFile_thenCompareResults() throws Exception {
+ KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA");
+ generator.initialize(2048);
+ KeyPair pair = generator.generateKeyPair();
+ PrivateKey privateKey = pair.getPrivate();
+ PublicKey publicKey = pair.getPublic();
+
+ String originalContent = "some secret message";
+ Path tempFile = Files.createTempFile("temp", "txt");
+ writeString(tempFile, originalContent);
+
+ byte[] fileBytes = Files.readAllBytes(tempFile);
+ Cipher encryptCipher = Cipher.getInstance("RSA");
+ encryptCipher.init(Cipher.ENCRYPT_MODE, publicKey);
+ byte[] encryptedFileBytes = encryptCipher.doFinal(fileBytes);
+ try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
+ stream.write(encryptedFileBytes);
+ }
+
+ encryptedFileBytes = Files.readAllBytes(tempFile);
+ Cipher decryptCipher = Cipher.getInstance("RSA");
+ decryptCipher.init(Cipher.DECRYPT_MODE, privateKey);
+ byte[] decryptedFileBytes = decryptCipher.doFinal(encryptedFileBytes);
+ try (FileOutputStream stream = new FileOutputStream(tempFile.toFile())) {
+ stream.write(decryptedFileBytes);
+ }
+
+ String fileContent = readString(tempFile);
+
+ Assertions.assertEquals(originalContent, fileContent);
+ }
+
+ private void writeString(Path path, String content) throws Exception {
+ try (BufferedWriter writer = Files.newBufferedWriter(path)) {
+ writer.write(content);
+ }
+ }
+
+ private String readString(Path path) throws Exception {
+ StringBuilder resultStringBuilder = new StringBuilder();
+ try (BufferedReader br = new BufferedReader(new FileReader(path.toFile()))) {
+ String line;
+ while ((line = br.readLine()) != null) {
+ resultStringBuilder.append(line);
+ }
+ }
+ return resultStringBuilder.toString();
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/java/com/baeldung/trustedcert/CertificatesUnitTest.java b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/trustedcert/CertificatesUnitTest.java
new file mode 100644
index 0000000000..4f40c3c195
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/java/com/baeldung/trustedcert/CertificatesUnitTest.java
@@ -0,0 +1,94 @@
+package com.baeldung.trustedcert;
+
+import org.junit.jupiter.api.Test;
+
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.X509TrustManager;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.Certificate;
+import java.security.cert.CertificateException;
+import java.security.cert.PKIXParameters;
+import java.security.cert.TrustAnchor;
+import java.security.cert.X509Certificate;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class CertificatesUnitTest {
+
+ private static final String GODADDY_CA_ALIAS = "godaddyrootg2ca [jdk]";
+
+ @Test
+ public void whenLoadingCacertsKeyStore_thenCertificatesArePresent() throws Exception {
+ KeyStore keyStore = loadKeyStore();
+ PKIXParameters params = new PKIXParameters(keyStore);
+
+ Set trustAnchors = params.getTrustAnchors();
+ List certificates = trustAnchors.stream()
+ .map(TrustAnchor::getTrustedCert)
+ .collect(Collectors.toList());
+
+ assertFalse(certificates.isEmpty());
+ }
+
+ @Test
+ public void whenLoadingDefaultKeyStore_thenCertificatesArePresent() throws Exception {
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ trustManagerFactory.init((KeyStore)null);
+
+ List trustManagers = Arrays.asList(trustManagerFactory.getTrustManagers());
+ List certificates = trustManagers.stream()
+ .filter(X509TrustManager.class::isInstance)
+ .map(X509TrustManager.class::cast)
+ .map(trustManager -> Arrays.asList(trustManager.getAcceptedIssuers()))
+ .flatMap(Collection::stream)
+ .collect(Collectors.toList());
+
+ assertFalse(certificates.isEmpty());
+ }
+
+ @Test
+ public void whenLoadingKeyStore_thenGoDaddyCALabelIsPresent() throws Exception {
+ KeyStore keyStore = loadKeyStore();
+
+ Enumeration aliasEnumeration = keyStore.aliases();
+ List aliases = Collections.list(aliasEnumeration);
+
+ assertTrue(aliases.contains(GODADDY_CA_ALIAS));
+ }
+
+ @Test
+ public void whenLoadingKeyStore_thenGoDaddyCertificateIsPresent() throws Exception {
+ KeyStore keyStore = loadKeyStore();
+
+ Certificate goDaddyCertificate = keyStore.getCertificate(GODADDY_CA_ALIAS);
+
+ assertNotNull(goDaddyCertificate);
+ }
+
+ private KeyStore loadKeyStore() throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException {
+ String relativeCacertsPath = "/lib/security/cacerts".replace("/", File.separator);
+ String filename = System.getProperty("java.home") + relativeCacertsPath;
+ FileInputStream is = new FileInputStream(filename);
+
+ KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
+ String password = "changeit";
+ keystore.load(is, password.toCharArray());
+
+ return keystore;
+ }
+}
diff --git a/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt b/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt
new file mode 100644
index 0000000000..dc6988d2f9
--- /dev/null
+++ b/core-java-modules/core-java-security-2/src/test/resources/baeldung.txt
@@ -0,0 +1,2 @@
+Hello Baeldung
+This is AES file encryption sample
\ No newline at end of file
diff --git a/core-java-modules/core-java-streams-2/pom.xml b/core-java-modules/core-java-streams-2/pom.xml
index 2a0a4348b0..323e01261f 100644
--- a/core-java-modules/core-java-streams-2/pom.xml
+++ b/core-java-modules/core-java-streams-2/pom.xml
@@ -47,7 +47,6 @@
- UTF-81.91.93.11.1
diff --git a/core-java-modules/core-java-streams-3/README.md b/core-java-modules/core-java-streams-3/README.md
index 65713aa04f..f81dca485b 100644
--- a/core-java-modules/core-java-streams-3/README.md
+++ b/core-java-modules/core-java-streams-3/README.md
@@ -6,9 +6,9 @@ This module contains articles about the Stream API in Java.
- [The Difference Between map() and flatMap()](https://www.baeldung.com/java-difference-map-and-flatmap)
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
-- [Guide to Java 8’s Collectors](https://www.baeldung.com/java-8-collectors)
- [Primitive Type Streams in Java 8](https://www.baeldung.com/java-8-primitive-streams)
- [Debugging Java 8 Streams with IntelliJ](https://www.baeldung.com/intellij-debugging-java-streams)
- [Add BigDecimals using the Stream API](https://www.baeldung.com/java-stream-add-bigdecimals)
- [Should We Close a Java Stream?](https://www.baeldung.com/java-stream-close)
+- [Returning Stream vs. Collection](https://www.baeldung.com/java-return-stream-collection)
- More articles: [[<-- prev>]](/../core-java-streams-2)
diff --git a/core-java-modules/core-java-streams-3/pom.xml b/core-java-modules/core-java-streams-3/pom.xml
index cbb7366a7d..6597c999d8 100644
--- a/core-java-modules/core-java-streams-3/pom.xml
+++ b/core-java-modules/core-java-streams-3/pom.xml
@@ -49,8 +49,6 @@
3.6.1
-
- 2.22.1
diff --git a/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationSpliterator.java b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationSpliterator.java
new file mode 100644
index 0000000000..5227fcb6c4
--- /dev/null
+++ b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationSpliterator.java
@@ -0,0 +1,30 @@
+package com.baeldung.streams.conversion;
+
+import java.util.Enumeration;
+import java.util.Spliterators.AbstractSpliterator;
+import java.util.function.Consumer;
+
+public class EnumerationSpliterator extends AbstractSpliterator {
+
+ private final Enumeration enumeration;
+
+ public EnumerationSpliterator(long est, int additionalCharacteristics, Enumeration enumeration) {
+ super(est, additionalCharacteristics);
+ this.enumeration = enumeration;
+ }
+
+ @Override
+ public boolean tryAdvance(Consumer super T> action) {
+ if (enumeration.hasMoreElements()) {
+ action.accept(enumeration.nextElement());
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void forEachRemaining(Consumer super T> action) {
+ while (enumeration.hasMoreElements())
+ action.accept(enumeration.nextElement());
+ }
+}
diff --git a/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationStreamConversion.java b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationStreamConversion.java
new file mode 100644
index 0000000000..cf041b9426
--- /dev/null
+++ b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/conversion/EnumerationStreamConversion.java
@@ -0,0 +1,16 @@
+package com.baeldung.streams.conversion;
+
+import java.util.Enumeration;
+import java.util.Spliterator;
+import java.util.stream.Stream;
+import java.util.stream.StreamSupport;
+
+public class EnumerationStreamConversion {
+
+ public static Stream convert(Enumeration enumeration) {
+ EnumerationSpliterator spliterator = new EnumerationSpliterator(Long.MAX_VALUE, Spliterator.ORDERED, enumeration);
+ Stream stream = StreamSupport.stream(spliterator, false);
+
+ return stream;
+ }
+}
diff --git a/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/streamvscollection/StreamVsCollectionExample.java b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/streamvscollection/StreamVsCollectionExample.java
new file mode 100644
index 0000000000..379d231bed
--- /dev/null
+++ b/core-java-modules/core-java-streams-3/src/main/java/com/baeldung/streams/streamvscollection/StreamVsCollectionExample.java
@@ -0,0 +1,95 @@
+package com.baeldung.streams.streamvscollection;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class StreamVsCollectionExample {
+
+ static ArrayList userNameSource = new ArrayList<>();
+
+ static {
+ userNameSource.add("john");
+ userNameSource.add("smith");
+ userNameSource.add("tom");
+ userNameSource.add("rob");
+ userNameSource.add("charlie");
+ userNameSource.add("alfred");
+ }
+
+ public static Stream userNames() {
+ return userNameSource.stream();
+ }
+
+ public static List userNameList() {
+ return userNames().collect(Collectors.toList());
+ }
+
+ public static Set userNameSet() {
+ return userNames().collect(Collectors.toSet());
+ }
+
+ public static Map userNameMap() {
+ return userNames().collect(Collectors.toMap(u1 -> u1.toString(), u1 -> u1.toString()));
+ }
+
+ public static Stream filterUserNames() {
+ return userNames().filter(i -> i.length() >= 4);
+ }
+
+ public static Stream sortUserNames() {
+ return userNames().sorted();
+ }
+
+ public static Stream limitUserNames() {
+ return userNames().limit(3);
+ }
+
+ public static Stream sortFilterLimitUserNames() {
+ return filterUserNames().sorted().limit(3);
+ }
+
+ public static void printStream(Stream stream) {
+ stream.forEach(System.out::println);
+ }
+
+ public static void modifyList() {
+ userNameSource.remove(2);
+ }
+
+ public static Map modifyMap() {
+ Map userNameMap = userNameMap();
+ userNameMap.put("bob", "bob");
+ userNameMap.remove("alfred");
+
+ return userNameMap;
+ }
+
+ public static void tryStreamTraversal() {
+ Stream userNameStream = userNames();
+ userNameStream.forEach(System.out::println);
+
+ try {
+ userNameStream.forEach(System.out::println);
+ } catch(IllegalStateException e) {
+ System.out.println("stream has already been operated upon or closed");
+ }
+ }
+
+ public static void main(String[] args) {
+ System.out.println(userNameMap());
+ System.out.println(modifyMap());
+ tryStreamTraversal();
+
+ Set set = userNames().collect(Collectors.toCollection(TreeSet::new));
+ set.forEach(val -> System.out.println(val));
+
+ }
+
+
+}
diff --git a/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/conversion/EnumerationStreamConversionUnitTest.java b/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/conversion/EnumerationStreamConversionUnitTest.java
new file mode 100644
index 0000000000..a075312fb5
--- /dev/null
+++ b/core-java-modules/core-java-streams-3/src/test/java/com/baeldung/streams/conversion/EnumerationStreamConversionUnitTest.java
@@ -0,0 +1,35 @@
+package com.baeldung.streams.conversion;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Vector;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.junit.Assert;
+import org.junit.jupiter.api.Test;
+
+public class EnumerationStreamConversionUnitTest {
+
+ @Test
+ public void givenEnumeration_whenConvertedToStream_thenNotNull() {
+ Vector input = new Vector<>(Arrays.asList(1, 2, 3, 4, 5));
+
+ Stream resultingStream = EnumerationStreamConversion.convert(input.elements());
+
+ Assert.assertNotNull(resultingStream);
+ }
+
+ @Test
+ public void whenConvertedToList_thenCorrect() {
+ Vector input = new Vector<>(Arrays.asList(1, 2, 3, 4, 5));
+
+ Stream stream = EnumerationStreamConversion.convert(input.elements());
+ List list = stream.filter(e -> e >= 3)
+ .collect(Collectors.toList());
+ assertThat(list, contains(3, 4, 5));
+ }
+}
diff --git a/core-java-modules/core-java-string-algorithms-2/README.md b/core-java-modules/core-java-string-algorithms-2/README.md
index 94ace77d66..dbfbb3ef3c 100644
--- a/core-java-modules/core-java-string-algorithms-2/README.md
+++ b/core-java-modules/core-java-string-algorithms-2/README.md
@@ -11,6 +11,6 @@ This module contains articles about string-related algorithms.
- [Join Array of Primitives with Separator in Java](https://www.baeldung.com/java-join-primitive-array)
- [Pad a String with Zeros or Spaces in Java](https://www.baeldung.com/java-pad-string)
- [Remove Leading and Trailing Characters from a String](https://www.baeldung.com/java-remove-trailing-characters)
-- [Counting Words in a String](https://www.baeldung.com/java-word-counting)
+- [Counting Words in a String with Java](https://www.baeldung.com/java-word-counting)
- [Finding the Difference Between Two Strings in Java](https://www.baeldung.com/java-difference-between-two-strings)
- More articles: [[<-- prev]](../core-java-string-algorithms)
diff --git a/core-java-modules/core-java-string-algorithms-2/pom.xml b/core-java-modules/core-java-string-algorithms-2/pom.xml
index a635cd8022..ae2685e742 100644
--- a/core-java-modules/core-java-string-algorithms-2/pom.xml
+++ b/core-java-modules/core-java-string-algorithms-2/pom.xml
@@ -34,7 +34,7 @@
org.openjdk.jmhjmh-generator-annprocess
- ${jmh-core.version}
+ ${jmh-generator.version}org.assertj
@@ -61,7 +61,6 @@
- 3.8.13.6.11.2
diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml
index 2725ba84c6..610956588e 100644
--- a/core-java-modules/core-java-string-algorithms-3/pom.xml
+++ b/core-java-modules/core-java-string-algorithms-3/pom.xml
@@ -59,7 +59,6 @@
- 3.8.13.6.128.1-jre
diff --git a/core-java-modules/core-java-string-algorithms/README.md b/core-java-modules/core-java-string-algorithms/README.md
index 70a4b5ffaf..c3eafda23d 100644
--- a/core-java-modules/core-java-string-algorithms/README.md
+++ b/core-java-modules/core-java-string-algorithms/README.md
@@ -3,14 +3,14 @@
This module contains articles about string-related algorithms.
### Relevant Articles:
-- [Check If a String Is a Palindrome](https://www.baeldung.com/java-palindrome)
+- [Check if a String is a Palindrome in Java](https://www.baeldung.com/java-palindrome)
- [Count Occurrences of a Char in a String](https://www.baeldung.com/java-count-chars)
- [Using indexOf to Find All Occurrences of a Word in a String](https://www.baeldung.com/java-indexOf-find-string-occurrences)
- [Removing Stopwords from a String in Java](https://www.baeldung.com/java-string-remove-stopwords)
- [Removing Repeated Characters from a String](https://www.baeldung.com/java-remove-repeated-char)
- [How to Reverse a String in Java](https://www.baeldung.com/java-reverse-string)
- [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)
+- [Check If a String Contains Multiple Keywords in Java](https://www.baeldung.com/string-contains-multiple-words)
- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring)
- [Remove Emojis from a Java String](https://www.baeldung.com/java-string-remove-emojis)
- More articles: [[next -->]](../core-java-string-algorithms-2)
diff --git a/core-java-modules/core-java-string-algorithms/pom.xml b/core-java-modules/core-java-string-algorithms/pom.xml
index 85879d74e2..abafd10f2b 100644
--- a/core-java-modules/core-java-string-algorithms/pom.xml
+++ b/core-java-modules/core-java-string-algorithms/pom.xml
@@ -39,7 +39,7 @@
org.openjdk.jmhjmh-generator-annprocess
- ${jmh-core.version}
+ ${jmh-generator.version}com.vdurmont
@@ -65,7 +65,6 @@
- 3.8.127.0.1-jre0.4.03.6.1
diff --git a/core-java-modules/core-java-string-apis/README.md b/core-java-modules/core-java-string-apis/README.md
index fc36ba8640..c9aa40de7a 100644
--- a/core-java-modules/core-java-string-apis/README.md
+++ b/core-java-modules/core-java-string-apis/README.md
@@ -8,5 +8,5 @@ This module contains articles about string APIs.
- [Guide to java.util.Formatter](https://www.baeldung.com/java-string-formatter)
- [Guide to StreamTokenizer](https://www.baeldung.com/java-streamtokenizer)
- [CharSequence vs. String in Java](https://www.baeldung.com/java-char-sequence-string)
-- [StringBuilder and StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer)
+- [StringBuilder vs StringBuffer in Java](https://www.baeldung.com/java-string-builder-string-buffer)
- [Generate a Secure Random Password in Java](https://www.baeldung.com/java-generate-secure-password)
diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml
index db32bf97a1..5865d9a776 100644
--- a/core-java-modules/core-java-string-operations-2/pom.xml
+++ b/core-java-modules/core-java-string-operations-2/pom.xml
@@ -112,7 +112,6 @@
3.6.12.0.0.Final
- 3.8.128.2-jre6.0.2.Final3.0.0
diff --git a/core-java-modules/core-java-string-operations-3/README.md b/core-java-modules/core-java-string-operations-3/README.md
new file mode 100644
index 0000000000..7f391ee056
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/README.md
@@ -0,0 +1,4 @@
+### Relevant Articles:
+
+- [Version Comparison in Java](https://www.baeldung.com/java-comparing-versions)
+- [Java (String) or .toString()?](https://www.baeldung.com/java-string-casting-vs-tostring)
diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java
new file mode 100644
index 0000000000..e96c87dfe4
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/tostring/StringCastUtils.java
@@ -0,0 +1,17 @@
+package com.baeldung.tostring;
+
+public class StringCastUtils {
+ public static String castToString(Object object) {
+ if (object instanceof String) {
+ return (String) object;
+ }
+ return null;
+ }
+
+ public static String getStringRepresentation(Object object) {
+ if (object != null) {
+ return object.toString();
+ }
+ return null;
+ }
+}
diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java
new file mode 100644
index 0000000000..51a27e1b5c
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/tostring/ToStringUnitTest.java
@@ -0,0 +1,104 @@
+package com.baeldung.tostring;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+
+public class ToStringUnitTest {
+ @Test
+ public void givenString_whenCastToObjectAndString_thenSameAndNoException() {
+ String input = "baeldung";
+
+ Object obj = input;
+ String str = (String) obj;
+
+ assertEquals(obj, str);
+ assertEquals(str, input);
+ assertSame(input, str);
+ }
+
+ @Test(expected = ClassCastException.class)
+ public void givenIntegerObject_whenCastToObjectAndString_thenCastClassException() {
+ Integer input = 1234;
+
+ Object obj = input;
+ String str = (String) obj;
+ }
+
+ @Test
+ public void givenNullInteger_whenCastToObjectAndString_thenSameAndNoException() {
+ Integer input = null;
+
+ Object obj = input;
+ String str = (String) obj;
+
+ assertEquals(obj, str);
+ assertEquals(str, input);
+ assertSame(input, str);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void givenNullInteger_whenToString_thenNullPointerException() {
+ Integer input = null;
+
+ String str = input.toString();
+ }
+
+ @Test
+ public void givenInteger_whenCastToObject_thenToStringEquals() {
+ Integer input = 1234;
+
+ Object obj = input;
+
+ assertEquals("1234", input.toString());
+ assertEquals("1234", obj.toString());
+ assertEquals(input.toString(), obj.toString());
+ }
+
+ @Test
+ public void givenString_whenToString_thenSame() {
+ String str = "baeldung";
+
+ assertEquals("baeldung", str.toString());
+ assertSame(str, str.toString());
+ }
+
+ @Test
+ public void givenString_whenCastToObject_thenCastToStringReturnsSame() {
+ String input = "baeldung";
+
+ Object obj = input;
+
+ assertSame(input, StringCastUtils.castToString(obj));
+ }
+
+ @Test
+ public void givenInteger_whenCastToObject_thenCastToStringReturnsNull() {
+ Integer input = 1234;
+
+ Object obj = input;
+
+ assertEquals(null, StringCastUtils.castToString(obj));
+ }
+
+ @Test
+ public void givenIntegerNull_whenCastToObject_thenCastToStringReturnsNull() {
+ Integer input = null;
+
+ Object obj = input;
+
+ assertEquals(null, StringCastUtils.castToString(obj));
+ }
+
+ @Test
+ public void givenIntegerNotNull_whenCastToObject_thenGetToStringReturnsString() {
+ Integer input = 1234;
+
+ Object obj = input;
+
+ assertEquals("1234", StringCastUtils.getStringRepresentation(obj));
+ assertNotSame("1234", StringCastUtils.getStringRepresentation(obj));
+ }
+}
diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml
index c5791e929e..9632988392 100644
--- a/core-java-modules/core-java-string-operations/pom.xml
+++ b/core-java-modules/core-java-string-operations/pom.xml
@@ -60,7 +60,6 @@
- 3.93.6.11.10
diff --git a/core-java-modules/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml
index 0f53407ec1..541af2445f 100644
--- a/core-java-modules/core-java-sun/pom.xml
+++ b/core-java-modules/core-java-sun/pom.xml
@@ -44,7 +44,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}javacom.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
@@ -68,7 +67,6 @@
org.codehaus.mojoexec-maven-plugin
-
run-benchmarks
diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml
index 67b8d7179a..3197b1ae6a 100644
--- a/core-java-modules/core-java-time-measurements/pom.xml
+++ b/core-java-modules/core-java-time-measurements/pom.xml
@@ -92,10 +92,11 @@
3.6.12.10
+ 1.18.123.6.11.8.9
- 2.0.0
+ 2.0.71.442.22.1
diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java
new file mode 100644
index 0000000000..211222c665
--- /dev/null
+++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeManualTest.java
@@ -0,0 +1,84 @@
+package com.baeldung.time;
+
+import static org.junit.Assert.assertEquals;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.time.StopWatch;
+import org.junit.Test;
+
+public class ElapsedTimeManualTest {
+
+ @Test
+ public void givenRunningTask_whenMeasuringTimeWithCurrentTimeMillis_thenGetElapsedTime() throws InterruptedException {
+ long start = System.currentTimeMillis();
+
+ simulateRunningTask();
+
+ long finish = System.currentTimeMillis();
+
+ long timeElapsed = finish - start;
+
+ assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
+ }
+
+ @Test
+ public void giveRunningTask_whenMeasuringTimeWithNanoTime_thenGetElapsedTime() throws InterruptedException {
+ long start = System.nanoTime();
+
+ simulateRunningTask();
+
+ long finish = System.nanoTime();
+
+ long timeElapsed = finish - start;
+
+ assertEquals(true, (2000000000L <= timeElapsed) && (timeElapsed <= 3000000000L));
+ }
+
+ @Test
+ public void givenRunningTask_whenMeasuringTimeWithStopWatch_thenGetElapsedTime() throws InterruptedException {
+ StopWatch watch = new StopWatch();
+ watch.start();
+
+ simulateRunningTask();
+
+ watch.stop();
+
+ long timeElapsed = watch.getTime();
+
+ assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
+ }
+
+ /*
+ The below test depends on the elapsed time, which isn't ideal in a test.
+ Also, it slows down test execution artificially.
+ */
+ @Test
+ public void givenRunningTask_whenMeasuringTimeWithInstantClass_thenGetElapsedTime() throws InterruptedException {
+ Instant start = Instant.now();
+ System.out.println("start: " + start);
+
+ simulateRunningTask();
+
+ Instant finish = Instant.now();
+
+ System.out.println("start: " + start);
+ System.out.println("finish: " + finish);
+ long timeElapsed = Duration.between(start, finish).toMillis();
+
+ System.out.println("elapsed: " + timeElapsed);
+ assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
+ }
+
+ /**
+ * Simulate task running for 2.5 seconds.
+ *
+ * @throws InterruptedException
+ */
+ private static void simulateRunningTask() throws InterruptedException {
+ TimeUnit.MILLISECONDS.sleep(2500); // 2.5 seconds
+
+ }
+}
diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java
deleted file mode 100644
index 1d92684ef4..0000000000
--- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/ElapsedTimeUnitTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-package com.baeldung.time;
-
-import static org.junit.Assert.assertEquals;
-
-import java.time.Duration;
-import java.time.Instant;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.commons.lang3.time.StopWatch;
-import org.junit.Test;
-
-public class ElapsedTimeUnitTest {
-
- @Test
- public void givenRunningTask_whenMeasuringTimeWithCurrentTimeMillis_thenGetElapsedTime() throws InterruptedException {
- long start = System.currentTimeMillis();
-
- simulateRunningTask();
-
- long finish = System.currentTimeMillis();
-
- long timeElapsed = finish - start;
-
- assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
- }
-
- @Test
- public void giveRunningTask_whenMeasuringTimeWithNanoTime_thenGetElapsedTime() throws InterruptedException {
- long start = System.nanoTime();
-
- simulateRunningTask();
-
- long finish = System.nanoTime();
-
- long timeElapsed = finish - start;
-
- assertEquals(true, (2000000000L <= timeElapsed) && (timeElapsed <= 3000000000L));
- }
-
- @Test
- public void givenRunningTask_whenMeasuringTimeWithStopWatch_thenGetElapsedTime() throws InterruptedException {
- StopWatch watch = new StopWatch();
- watch.start();
-
- simulateRunningTask();
-
- watch.stop();
-
- long timeElapsed = watch.getTime();
-
- assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
- }
-
- @Test
- public void givenRunningTask_whenMeasuringTimeWithInstantClass_thenGetElapsedTime() throws InterruptedException {
- Instant start = Instant.now();
-
- simulateRunningTask();
-
- Instant finish = Instant.now();
-
- long timeElapsed = Duration.between(start, finish).toMillis();
-
- assertEquals(true, (2000L <= timeElapsed) && (timeElapsed <= 3000L));
- }
-
- /**
- * Simulate task running for 2.5 seconds.
- *
- * @throws InterruptedException
- */
- private static void simulateRunningTask() throws InterruptedException {
- TimeUnit.MILLISECONDS.sleep(2500); // 2.5 seconds
-
- }
-}
diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java
index 8400748710..608199197a 100644
--- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java
+++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/InstantUnitTest.java
@@ -10,8 +10,8 @@ import java.time.Instant;
import java.time.ZoneId;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
+import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Instant.class })
diff --git a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java
index 04c1a0b74e..52dc9ba1c6 100644
--- a/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java
+++ b/core-java-modules/core-java-time-measurements/src/test/java/com/baeldung/time/LocalDateTimeUnitTest.java
@@ -18,19 +18,6 @@ import static org.powermock.api.mockito.PowerMockito.mockStatic;
@PrepareForTest({ LocalDateTime.class })
public class LocalDateTimeUnitTest {
- @Test
- public void givenLocalDateTimeMock_whenNow_thenGetFixedLocalDateTime() {
- Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC"));
- LocalDateTime dateTime = LocalDateTime.now(clock);
- mockStatic(LocalDateTime.class);
- when(LocalDateTime.now()).thenReturn(dateTime);
- String dateTimeExpected = "2014-12-22T10:15:30";
-
- LocalDateTime now = LocalDateTime.now();
-
- assertThat(now).isEqualTo(dateTimeExpected);
- }
-
@Test
public void givenFixedClock_whenNow_thenGetFixedLocalDateTime() {
Clock clock = Clock.fixed(Instant.parse("2014-12-22T10:15:30.00Z"), ZoneId.of("UTC"));
diff --git a/core-java-modules/core-java/README.md b/core-java-modules/core-java/README.md
index 7781382ae5..b0e740e3b5 100644
--- a/core-java-modules/core-java/README.md
+++ b/core-java-modules/core-java/README.md
@@ -1,13 +1,13 @@
## Core Java Cookbooks and Examples
### Relevant Articles:
-[Getting Started with Java Properties](http://www.baeldung.com/java-properties)
-[Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
-[Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
-[Guide to UUID in Java](http://www.baeldung.com/java-uuid)
-[Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
-[Introduction to Javadoc](http://www.baeldung.com/javadoc)
-[Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable)
-[What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid)
-[A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle)
-[Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties)
+- [Getting Started with Java Properties](http://www.baeldung.com/java-properties)
+- [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency)
+- [Introduction to Java Serialization](http://www.baeldung.com/java-serialization)
+- [Guide to UUID in Java](http://www.baeldung.com/java-uuid)
+- [Compiling Java *.class Files with javac](http://www.baeldung.com/javac)
+- [Introduction to Javadoc](http://www.baeldung.com/javadoc)
+- [Guide to the Externalizable Interface in Java](http://www.baeldung.com/java-externalizable)
+- [What is the serialVersionUID?](http://www.baeldung.com/java-serial-version-uid)
+- [A Guide to the ResourceBundle](http://www.baeldung.com/java-resourcebundle)
+- [Merging java.util.Properties Objects](https://www.baeldung.com/java-merging-properties)
diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml
index b8d75058eb..9b595288e6 100644
--- a/core-java-modules/core-java/pom.xml
+++ b/core-java-modules/core-java/pom.xml
@@ -94,7 +94,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}javacom.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed
@@ -154,7 +153,6 @@
org.codehaus.mojoexec-maven-plugin
- ${exec-maven-plugin.version}run-benchmarks
@@ -193,7 +191,6 @@
1.13.0.0-M1
- 1.6.01.81.8
diff --git a/core-java-modules/multimodulemavenproject/daomodule/pom.xml b/core-java-modules/multimodulemavenproject/daomodule/pom.xml
index 15f1215d89..56c2d70d24 100644
--- a/core-java-modules/multimodulemavenproject/daomodule/pom.xml
+++ b/core-java-modules/multimodulemavenproject/daomodule/pom.xml
@@ -20,6 +20,10 @@
org.apache.maven.pluginsmaven-compiler-plugin
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
diff --git a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml
index 3e5a478299..00ad56b3ab 100644
--- a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml
+++ b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml
@@ -20,6 +20,10 @@
org.apache.maven.pluginsmaven-compiler-plugin
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml
index 196e58a419..a9fe04b108 100644
--- a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml
+++ b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml
@@ -38,6 +38,10 @@
org.apache.maven.pluginsmaven-compiler-plugin
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
diff --git a/core-java-modules/multimodulemavenproject/pom.xml b/core-java-modules/multimodulemavenproject/pom.xml
index dcf9f7311e..25f268f8b3 100644
--- a/core-java-modules/multimodulemavenproject/pom.xml
+++ b/core-java-modules/multimodulemavenproject/pom.xml
@@ -59,7 +59,6 @@
3.8.01.91.9
- UTF-83.12.2
diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml
index f4a7e5c8f8..150c10b68f 100644
--- a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml
+++ b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml
@@ -33,6 +33,10 @@
org.apache.maven.pluginsmaven-compiler-plugin
+
+ ${maven.compiler.source}
+ ${maven.compiler.target}
+
diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml
index 589097cf48..d44ce97f14 100644
--- a/core-java-modules/pom.xml
+++ b/core-java-modules/pom.xml
@@ -18,19 +18,9 @@
core-java
-
-
-
-
core-java-8core-java-8-2
-
-
-
-
-
-
core-java-annotationscore-java-arrays-sorting
@@ -39,10 +29,12 @@
core-java-arrays-convertcore-java-arrays-operations-basiccore-java-arrays-operations-advanced
-
+
+ core-java-charcore-java-collectionscore-java-collections-2core-java-collections-3
+ core-java-collections-4core-java-collections-array-listcore-java-collections-listcore-java-collections-list-2
@@ -50,36 +42,39 @@
core-java-collections-mapscore-java-collections-maps-2core-java-collections-maps-3
-
core-java-concurrency-2core-java-concurrency-advancedcore-java-concurrency-advanced-2core-java-concurrency-advanced-3
+ core-java-concurrency-advanced-4core-java-concurrency-basiccore-java-concurrency-basic-2core-java-concurrency-collections
+ core-java-concurrency-collections-2
+ core-java-console
-
+
+ core-java-8-datetime-2core-java-date-operations-2
-
-
+ core-java-8-datetimecore-java-exceptionscore-java-exceptions-2
-
+ core-java-exceptions-3core-java-function
+ core-java-functionalcore-java-iocore-java-io-2core-java-io-3
+ core-java-io-4core-java-io-apiscore-java-io-conversionscore-java-io-conversions-2core-java-jarcore-java-jndi
-
core-java-jvmcore-java-jvm-2
@@ -87,8 +82,10 @@
core-java-langcore-java-lang-2core-java-lang-3
+ core-java-lang-4core-java-lang-mathcore-java-lang-math-2
+ core-java-lang-math-3core-java-lang-oop-constructorscore-java-lang-oop-patternscore-java-lang-oop-generics
@@ -103,11 +100,11 @@
core-java-networkingcore-java-networking-2
+ core-java-networking-3core-java-niocore-java-nio-2core-java-optional
-
core-java-perf
@@ -132,9 +129,6 @@
core-java-suncore-java-regex
-
-
-
pre-jpms
@@ -155,18 +149,6 @@
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
- ${maven-surefire-plugin.version}
-
-
-
-
-
2.22.25.6.2
diff --git a/core-java-modules/pre-jpms/README.MD b/core-java-modules/pre-jpms/README.md
similarity index 100%
rename from core-java-modules/pre-jpms/README.MD
rename to core-java-modules/pre-jpms/README.md
diff --git a/core-kotlin-modules/core-kotlin-advanced/README.md b/core-kotlin-modules/core-kotlin-advanced/README.md
deleted file mode 100644
index 2e99e3b078..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/README.md
+++ /dev/null
@@ -1,11 +0,0 @@
-## Core Kotlin Advanced
-
-This module contains articles about advanced topics in Kotlin.
-
-### Relevant articles:
-- [Building DSLs in Kotlin](https://www.baeldung.com/kotlin-dsl)
-- [Regular Expressions in Kotlin](https://www.baeldung.com/kotlin-regular-expressions)
-- [Idiomatic Logging in Kotlin](https://www.baeldung.com/kotlin-logging)
-- [Mapping of Data Objects in Kotlin](https://www.baeldung.com/kotlin-data-objects)
-- [Reflection with Kotlin](https://www.baeldung.com/kotlin-reflection)
-- [Kotlin Contracts](https://www.baeldung.com/kotlin-contracts)
diff --git a/core-kotlin-modules/core-kotlin-advanced/pom.xml b/core-kotlin-modules/core-kotlin-advanced/pom.xml
deleted file mode 100644
index 5ddfef23cc..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
- 4.0.0
- core-kotlin-advanced
- core-kotlin-advanced
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
-
- 1.3.30
- 3.10.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt
deleted file mode 100644
index ca0b13cdc7..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/CallsInPlaceEffect.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.contract
-
-import kotlin.contracts.ExperimentalContracts
-import kotlin.contracts.InvocationKind
-import kotlin.contracts.contract
-
-@ExperimentalContracts
-inline fun myRun(block: () -> R): R {
- contract {
- callsInPlace(block, InvocationKind.EXACTLY_ONCE)
- }
- return block()
-}
-
-@ExperimentalContracts
-fun callsInPlace() {
- val i: Int
- myRun {
- i = 1 // Without contract initialization is forbidden due to possible re-assignment
- }
- println(i) // Without contract variable might be uninitialized
-}
-
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt
deleted file mode 100644
index 56f667af82..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/contract/ReturnsEffect.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.contract
-
-import kotlin.contracts.ExperimentalContracts
-import kotlin.contracts.contract
-
-data class Request(val arg: String)
-
-class Service {
-
- @ExperimentalContracts
- fun process(request: Request?) {
- validate(request)
- println(request.arg)
- }
-
-}
-
-@ExperimentalContracts
-private fun validate(request: Request?) {
- contract {
- returns() implies (request != null)
- }
- if (request == null) {
- throw IllegalArgumentException("Undefined request")
- }
-}
-
-data class MyEvent(val message: String)
-
-@ExperimentalContracts
-fun processEvent(event: Any?) {
- if (isInterested(event)) {
- println(event.message) // Compiler makes smart cast here with the help of contract
- }
-}
-
-@ExperimentalContracts
-fun isInterested(event: Any?): Boolean {
- contract {
- returns(true) implies (event is MyEvent)
- }
- return event is MyEvent
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt
deleted file mode 100644
index fdbf95f7ba..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/User.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.datamapping
-
-data class User(
- val firstName: String,
- val lastName: String,
- val street: String,
- val houseNumber: String,
- val phone: String,
- val age: Int,
- val password: String)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt
deleted file mode 100644
index 1f3d7f3b47..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserExtensions.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.baeldung.datamapping
-
-import kotlin.reflect.full.memberProperties
-
-fun User.toUserView() = UserView(
- name = "$firstName $lastName",
- address = "$street $houseNumber",
- telephone = phone,
- age = age
-)
-
-fun User.toUserViewReflection() = with(::UserView) {
- val propertiesByName = User::class.memberProperties.associateBy { it.name }
- callBy(parameters.associate { parameter ->
- parameter to when (parameter.name) {
- UserView::name.name -> "$firstName $lastName"
- UserView::address.name -> "$street $houseNumber"
- UserView::telephone.name -> phone
- else -> propertiesByName[parameter.name]?.get(this@toUserViewReflection)
- }
- })
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt
deleted file mode 100644
index e1b6de6b57..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/datamapping/UserView.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.datamapping
-
-data class UserView(
- val name: String,
- val address: String,
- val telephone: String,
- val age: Int
-)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt
deleted file mode 100644
index 207e9dbd53..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/dsl/SqlDsl.kt
+++ /dev/null
@@ -1,114 +0,0 @@
-package com.baeldung.dsl
-
-abstract class Condition {
-
- fun and(initializer: Condition.() -> Unit) {
- addCondition(And().apply(initializer))
- }
-
- fun or(initializer: Condition.() -> Unit) {
- addCondition(Or().apply(initializer))
- }
-
- infix fun String.eq(value: Any?) {
- addCondition(Eq(this, value))
- }
-
- protected abstract fun addCondition(condition: Condition)
-}
-
-open class CompositeCondition(private val sqlOperator: String) : Condition() {
- private val conditions = mutableListOf()
-
- override fun addCondition(condition: Condition) {
- conditions += condition
- }
-
- override fun toString(): String {
- return if (conditions.size == 1) {
- conditions.first().toString()
- } else {
- conditions.joinToString(prefix = "(", postfix = ")", separator = " $sqlOperator ") {
- "$it"
- }
- }
- }
-}
-
-class And : CompositeCondition("and")
-
-class Or : CompositeCondition("or")
-
-class Eq(private val column: String, private val value: Any?) : Condition() {
-
- init {
- if (value != null && value !is Number && value !is String) {
- throw IllegalArgumentException("Only , numbers and strings values can be used in the 'where' clause")
- }
- }
-
- override fun addCondition(condition: Condition) {
- throw IllegalStateException("Can't add a nested condition to the sql 'eq'")
- }
-
- override fun toString(): String {
- return when (value) {
- null -> "$column is null"
- is String -> "$column = '$value'"
- else -> "$column = $value"
- }
- }
-}
-
-class SqlSelectBuilder {
-
- private val columns = mutableListOf()
- private lateinit var table: String
- private var condition: Condition? = null
-
- fun select(vararg columns: String) {
- if (columns.isEmpty()) {
- throw IllegalArgumentException("At least one column should be defined")
- }
- if (this.columns.isNotEmpty()) {
- throw IllegalStateException("Detected an attempt to re-define columns to fetch. Current columns list: "
- + "${this.columns}, new columns list: $columns")
- }
- this.columns.addAll(columns)
- }
-
- fun from(table: String) {
- this.table = table
- }
-
- fun where(initializer: Condition.() -> Unit) {
- condition = And().apply(initializer)
- }
-
- fun build(): String {
- if (!::table.isInitialized) {
- throw IllegalStateException("Failed to build an sql select - target table is undefined")
- }
- return toString()
- }
-
- override fun toString(): String {
- val columnsToFetch =
- if (columns.isEmpty()) {
- "*"
- } else {
- columns.joinToString(", ")
- }
- val conditionString =
- if (condition == null) {
- ""
- } else {
- " where $condition"
- }
- return "select $columnsToFetch from $table$conditionString"
- }
-}
-
-fun query(initializer: SqlSelectBuilder.() -> Unit): SqlSelectBuilder {
- return SqlSelectBuilder().apply(initializer)
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt
deleted file mode 100644
index 01edf5e871..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnAny.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.logging
-
-import org.slf4j.Logger
-
-open class LoggerAsExtensionOnAny {
- val logger = logger()
-
- fun log(s: String) {
- logger().info(s)
- logger.info(s)
- }
-}
-
-class ExtensionSubclass : LoggerAsExtensionOnAny()
-
-fun T.logger(): Logger = getLogger(getClassForLogging(javaClass))
-
-fun main(args: Array) {
- LoggerAsExtensionOnAny().log("test")
- ExtensionSubclass().log("sub")
- "foo".logger().info("foo")
- 1.logger().info("uh-oh!")
- SomeOtherClass().logger()
-}
-
-class SomeOtherClass {
- fun logger(): String {
- return "foo"
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt
deleted file mode 100644
index 8210361345..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsExtensionOnMarkerInterface.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.logging
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-
-interface Logging
-
-inline fun T.logger(): Logger =
- //Wrong logger name!
- //LoggerFactory.getLogger(javaClass.name + " w/interface")
- LoggerFactory.getLogger(getClassForLogging(T::class.java).name + " w/interface")
-
-open class LoggerAsExtensionOnMarkerInterface : Logging {
- companion object : Logging {
- val logger = logger()
- }
-
- fun log(s: String) {
- logger().info(s)
- logger.info(s)
- }
-}
-
-class MarkerExtensionSubclass : LoggerAsExtensionOnMarkerInterface()
-
-fun main(args: Array) {
- LoggerAsExtensionOnMarkerInterface().log("test")
- MarkerExtensionSubclass().log("sub")
- "foo".logger().info("foo")
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt
deleted file mode 100644
index 60ac0800e2..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsProperty.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baeldung.logging
-
-open class LoggerAsProperty {
- private val logger = getLogger(javaClass)
-
- fun log(s: String) {
- logger.info(s)
- }
-
-}
-
-class PropertySubclass : LoggerAsProperty()
-
-fun main(args: Array) {
- LoggerAsProperty().log("test")
- PropertySubclass().log("sub")
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt
deleted file mode 100644
index 83cde2b446..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerAsPropertyDelegate.kt
+++ /dev/null
@@ -1,47 +0,0 @@
-package com.baeldung.logging
-
-import org.slf4j.Logger
-import kotlin.properties.ReadOnlyProperty
-import kotlin.reflect.KProperty
-
-open class LoggerAsPropertyDelegate {
- private val lazyLogger by lazyLogger()
- protected val logger by LoggerDelegate()
- private val logger2 = logger
-
- companion object {
- private val lazyLoggerComp by lazyLogger()
- private val loggerComp by LoggerDelegate()
- }
-
- open fun log(s: String) {
- logger.info(s)
- logger2.info(s)
- lazyLogger.info(s)
- loggerComp.info(s)
- lazyLoggerComp.info(s)
- }
-
-}
-
-class DelegateSubclass : LoggerAsPropertyDelegate() {
- override fun log(s: String) {
- logger.info("-- in sub")
- super.log(s)
- }
-}
-
-fun lazyLogger(forClass: Class<*>): Lazy =
- lazy { getLogger(getClassForLogging(forClass)) }
-
-fun T.lazyLogger(): Lazy = lazyLogger(javaClass)
-
-fun main(args: Array) {
- LoggerAsPropertyDelegate().log("test")
- DelegateSubclass().log("sub")
-}
-
-class LoggerDelegate : ReadOnlyProperty {
- override fun getValue(thisRef: R, property: KProperty<*>) =
- getLogger(getClassForLogging(thisRef.javaClass))
-}
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt
deleted file mode 100644
index 6a44675e45..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/LoggerInCompanionObject.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.baeldung.logging
-
-open class LoggerInCompanionObject {
- companion object {
- private val loggerWithExplicitClass = getLogger(LoggerInCompanionObject::class.java)
- @Suppress("JAVA_CLASS_ON_COMPANION")
- private val loggerWithWrongClass = getLogger(javaClass)
- @Suppress("JAVA_CLASS_ON_COMPANION")
- private val logger = getLogger(javaClass.enclosingClass)
- }
-
- fun log(s: String) {
- loggerWithExplicitClass.info(s)
- loggerWithWrongClass.info(s)
- logger.info(s)
- }
-
- class Inner {
- companion object {
- private val loggerWithExplicitClass = getLogger(Inner::class.java)
- @Suppress("JAVA_CLASS_ON_COMPANION")
- @JvmStatic
- private val loggerWithWrongClass = getLogger(javaClass)
- @Suppress("JAVA_CLASS_ON_COMPANION")
- @JvmStatic
- private val logger = getLogger(javaClass.enclosingClass)
- }
-
- fun log(s: String) {
- loggerWithExplicitClass.info(s)
- loggerWithWrongClass.info(s)
- logger.info(s)
- }
- }
-
-}
-
-class CompanionSubclass : LoggerInCompanionObject()
-
-fun main(args: Array) {
- LoggerInCompanionObject().log("test")
- LoggerInCompanionObject.Inner().log("test")
- CompanionSubclass().log("sub")
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt b/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt
deleted file mode 100644
index 44dba53cb7..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/main/kotlin/com/baeldung/logging/Util.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.logging
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-import kotlin.reflect.full.companionObject
-
-fun getLogger(forClass: Class<*>): Logger = LoggerFactory.getLogger(forClass)
-
-fun getClassForLogging(javaClass: Class): Class<*> {
- return javaClass.enclosingClass?.takeIf {
- it.kotlin.companionObject?.java == javaClass
- } ?: javaClass
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt
deleted file mode 100644
index 44d350ea38..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/datamapping/UserTest.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.datamapping
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.assertAll
-import kotlin.test.assertEquals
-
-class UserTest {
-
- @Test
- fun `maps User to UserResponse using extension function`() {
- val p = buildUser()
- val view = p.toUserView()
- assertUserView(view)
- }
-
- @Test
- fun `maps User to UserResponse using reflection`() {
- val p = buildUser()
- val view = p.toUserViewReflection()
- assertUserView(view)
- }
-
- private fun buildUser(): User {
- return User(
- "Java",
- "Duke",
- "Javastreet",
- "42",
- "1234567",
- 30,
- "s3cr37"
- )
- }
-
- private fun assertUserView(pr: UserView) {
- assertAll(
- { assertEquals("Java Duke", pr.name) },
- { assertEquals("Javastreet 42", pr.address) },
- { assertEquals("1234567", pr.telephone) },
- { assertEquals(30, pr.age) }
- )
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt
deleted file mode 100644
index a370e7f15d..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/dsl/SqlDslTest.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.baeldung.dsl
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.Test
-
-class SqlDslTest {
-
- @Test
- fun `when no columns are specified then star is used`() {
- doTest("select * from table1") {
- from ("table1")
- }
- }
-
- @Test
- fun `when no condition is specified then correct query is built`() {
- doTest("select column1, column2 from table1") {
- select("column1", "column2")
- from ("table1")
- }
- }
-
- @Test(expected = Exception::class)
- fun `when no table is specified then an exception is thrown`() {
- query {
- select("column1")
- }.build()
- }
-
- @Test
- fun `when a list of conditions is specified then it's respected`() {
- doTest("select * from table1 where (column3 = 4 and column4 is null)") {
- from ("table1")
- where {
- "column3" eq 4
- "column4" eq null
- }
- }
- }
-
- @Test
- fun `when 'or' conditions are specified then they are respected`() {
- doTest("select * from table1 where (column3 = 4 or column4 is null)") {
- from ("table1")
- where {
- or {
- "column3" eq 4
- "column4" eq null
- }
- }
- }
- }
-
- @Test
- fun `when either 'and' or 'or' conditions are specified then they are respected`() {
- doTest("select * from table1 where ((column3 = 4 or column4 is null) and column5 = 42)") {
- from ("table1")
- where {
- and {
- or {
- "column3" eq 4
- "column4" eq null
- }
- "column5" eq 42
- }
- }
- }
- }
-
- private fun doTest(expected: String, sql: SqlSelectBuilder.() -> Unit) {
- assertThat(query(sql).build()).isEqualTo(expected)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt
deleted file mode 100644
index c77774dd81..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/JavaReflectionTest.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.baeldung.reflection
-
-import org.junit.Ignore
-import org.junit.Test
-import org.slf4j.LoggerFactory
-
-@Ignore
-class JavaReflectionTest {
- private val LOG = LoggerFactory.getLogger(KClassTest::class.java)
-
- @Test
- fun listJavaClassMethods() {
- Exception::class.java.methods
- .forEach { method -> LOG.info("Method: {}", method) }
- }
-
- @Test
- fun listKotlinClassMethods() {
- JavaReflectionTest::class.java.methods
- .forEach { method -> LOG.info("Method: {}", method) }
- }
-
- @Test
- fun listKotlinDataClassMethods() {
- data class ExampleDataClass(val name: String, var enabled: Boolean)
-
- ExampleDataClass::class.java.methods
- .forEach { method -> LOG.info("Method: {}", method) }
- }
-
-
-}
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt
deleted file mode 100644
index f5d83cd13d..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KClassTest.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-package com.baeldung.reflection
-
-import org.junit.Assert
-import org.junit.Ignore
-import org.junit.Test
-import org.slf4j.LoggerFactory
-import java.math.BigDecimal
-import kotlin.reflect.full.*
-
-class KClassTest {
- private val LOG = LoggerFactory.getLogger(KClassTest::class.java)
-
- @Test
- fun testKClassDetails() {
- val stringClass = String::class
- Assert.assertEquals("kotlin.String", stringClass.qualifiedName)
- Assert.assertFalse(stringClass.isData)
- Assert.assertFalse(stringClass.isCompanion)
- Assert.assertFalse(stringClass.isAbstract)
- Assert.assertTrue(stringClass.isFinal)
- Assert.assertFalse(stringClass.isSealed)
-
- val listClass = List::class
- Assert.assertEquals("kotlin.collections.List", listClass.qualifiedName)
- Assert.assertFalse(listClass.isData)
- Assert.assertFalse(listClass.isCompanion)
- Assert.assertTrue(listClass.isAbstract)
- Assert.assertFalse(listClass.isFinal)
- Assert.assertFalse(listClass.isSealed)
- }
-
- @Test
- fun testGetRelated() {
- LOG.info("Companion Object: {}", TestSubject::class.companionObject)
- LOG.info("Companion Object Instance: {}", TestSubject::class.companionObjectInstance)
- LOG.info("Object Instance: {}", TestObject::class.objectInstance)
-
- Assert.assertSame(TestObject, TestObject::class.objectInstance)
- }
-
- @Test
- fun testNewInstance() {
- val listClass = ArrayList::class
-
- val list = listClass.createInstance()
- Assert.assertTrue(list is ArrayList)
- }
-
- @Test
- @Ignore
- fun testMembers() {
- val bigDecimalClass = BigDecimal::class
-
- LOG.info("Constructors: {}", bigDecimalClass.constructors)
- LOG.info("Functions: {}", bigDecimalClass.functions)
- LOG.info("Properties: {}", bigDecimalClass.memberProperties)
- LOG.info("Extension Functions: {}", bigDecimalClass.memberExtensionFunctions)
- }
-}
-
-class TestSubject {
- companion object {
- val name = "TestSubject"
- }
-}
-
-object TestObject {
- val answer = 42
-}
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt
deleted file mode 100644
index b58c199a7c..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/reflection/KMethodTest.kt
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.baeldung.reflection
-
-import org.junit.Assert
-import org.junit.Test
-import java.io.ByteArrayInputStream
-import java.nio.charset.Charset
-import kotlin.reflect.KMutableProperty
-import kotlin.reflect.full.starProjectedType
-
-class KMethodTest {
-
- @Test
- fun testCallMethod() {
- val str = "Hello"
- val lengthMethod = str::length
-
- Assert.assertEquals(5, lengthMethod())
- }
-
- @Test
- fun testReturnType() {
- val str = "Hello"
- val method = str::byteInputStream
-
- Assert.assertEquals(ByteArrayInputStream::class.starProjectedType, method.returnType)
- Assert.assertFalse(method.returnType.isMarkedNullable)
- }
-
- @Test
- fun testParams() {
- val str = "Hello"
- val method = str::byteInputStream
-
- method.isSuspend
- Assert.assertEquals(1, method.parameters.size)
- Assert.assertTrue(method.parameters[0].isOptional)
- Assert.assertFalse(method.parameters[0].isVararg)
- Assert.assertEquals(Charset::class.starProjectedType, method.parameters[0].type)
- }
-
- @Test
- fun testMethodDetails() {
- val codePoints = String::codePoints
- Assert.assertEquals("codePoints", codePoints.name)
- Assert.assertFalse(codePoints.isSuspend)
- Assert.assertFalse(codePoints.isExternal)
- Assert.assertFalse(codePoints.isInline)
- Assert.assertFalse(codePoints.isOperator)
-
- val byteInputStream = String::byteInputStream
- Assert.assertEquals("byteInputStream", byteInputStream.name)
- Assert.assertFalse(byteInputStream.isSuspend)
- Assert.assertFalse(byteInputStream.isExternal)
- Assert.assertTrue(byteInputStream.isInline)
- Assert.assertFalse(byteInputStream.isOperator)
- }
-
- val readOnlyProperty: Int = 42
- lateinit var mutableProperty: String
-
- @Test
- fun testPropertyDetails() {
- val roProperty = this::readOnlyProperty
- Assert.assertEquals("readOnlyProperty", roProperty.name)
- Assert.assertFalse(roProperty.isLateinit)
- Assert.assertFalse(roProperty.isConst)
- Assert.assertFalse(roProperty is KMutableProperty<*>)
-
- val mProperty = this::mutableProperty
- Assert.assertEquals("mutableProperty", mProperty.name)
- Assert.assertTrue(mProperty.isLateinit)
- Assert.assertFalse(mProperty.isConst)
- Assert.assertTrue(mProperty is KMutableProperty<*>)
- }
-
- @Test
- fun testProperty() {
- val prop = this::mutableProperty
-
- Assert.assertEquals(String::class.starProjectedType, prop.getter.returnType)
-
- prop.set("Hello")
- Assert.assertEquals("Hello", prop.get())
-
- prop.setter("World")
- Assert.assertEquals("World", prop.getter())
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt b/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt
deleted file mode 100644
index 5cb54b4dda..0000000000
--- a/core-kotlin-modules/core-kotlin-advanced/src/test/kotlin/com/baeldung/regex/RegexTest.kt
+++ /dev/null
@@ -1,123 +0,0 @@
-package com.baeldung.regex
-
-import org.junit.Test
-import kotlin.test.*
-
-class RegexTest {
-
- @Test
- fun whenRegexIsInstantiated_thenIsEqualToToRegexMethod() {
- val pattern = """a([bc]+)d?\\"""
-
- assertEquals(Regex.fromLiteral(pattern).pattern, pattern)
- assertEquals(pattern, Regex(pattern).pattern)
- assertEquals(pattern, pattern.toRegex().pattern)
- }
-
- @Test
- fun whenRegexMatches_thenResultIsTrue() {
- val regex = """a([bc]+)d?""".toRegex()
-
- assertTrue(regex.containsMatchIn("xabcdy"))
- assertTrue(regex.matches("abcd"))
- assertFalse(regex matches "xabcdy")
- }
-
- @Test
- fun givenCompletelyMatchingRegex_whenMatchResult_thenDestructuring() {
- val regex = """a([bc]+)d?""".toRegex()
-
- assertNull(regex.matchEntire("xabcdy"))
-
- val matchResult = regex.matchEntire("abbccbbd")
-
- assertNotNull(matchResult)
- assertEquals(matchResult!!.value, matchResult.groupValues[0])
- assertEquals(matchResult.destructured.toList(), matchResult.groupValues.drop(1))
- assertEquals("bbccbb", matchResult.destructured.component1())
- assertNull(matchResult.next())
- }
-
- @Test
- fun givenPartiallyMatchingRegex_whenMatchResult_thenGroups() {
- val regex = """a([bc]+)d?""".toRegex()
- var matchResult = regex.find("abcb abbd")
-
- assertNotNull(matchResult)
- assertEquals(matchResult!!.value, matchResult.groupValues[0])
- assertEquals("abcb", matchResult.value)
- assertEquals(IntRange(0, 3), matchResult.range)
- assertEquals(listOf("abcb", "bcb"), matchResult.groupValues)
- assertEquals(matchResult.destructured.toList(), matchResult.groupValues.drop(1))
-
- matchResult = matchResult.next()
-
- assertNotNull(matchResult)
- assertEquals("abbd", matchResult!!.value)
- assertEquals("bb", matchResult.groupValues[1])
-
- matchResult = matchResult.next()
-
- assertNull(matchResult)
- }
-
- @Test
- fun givenPartiallyMatchingRegex_whenMatchResult_thenDestructuring() {
- val regex = """([\w\s]+) is (\d+) years old""".toRegex()
- val matchResult = regex.find("Mickey Mouse is 95 years old")
- val (name, age) = matchResult!!.destructured
-
- assertEquals("Mickey Mouse", name)
- assertEquals("95", age)
- }
-
- @Test
- fun givenNonMatchingRegex_whenFindCalled_thenNull() {
- val regex = """a([bc]+)d?""".toRegex()
- val matchResult = regex.find("foo")
-
- assertNull(matchResult)
- }
-
- @Test
- fun givenNonMatchingRegex_whenFindAllCalled_thenEmptySet() {
- val regex = """a([bc]+)d?""".toRegex()
- val matchResults = regex.findAll("foo")
-
- assertNotNull(matchResults)
- assertTrue(matchResults.none())
- }
-
- @Test
- fun whenReplace_thenReplacement() {
- val regex = """(red|green|blue)""".toRegex()
- val beautiful = "Roses are red, Violets are blue"
- val grim = regex.replace(beautiful, "dark")
- val shiny = regex.replaceFirst(beautiful, "rainbow")
-
- assertEquals("Roses are dark, Violets are dark", grim)
- assertEquals("Roses are rainbow, Violets are blue", shiny)
- }
-
- @Test
- fun whenComplexReplace_thenReplacement() {
- val regex = """(red|green|blue)""".toRegex()
- val beautiful = "Roses are red, Violets are blue"
- val reallyBeautiful = regex.replace(beautiful) {
- matchResult -> matchResult.value.toUpperCase() + "!"
- }
-
- assertEquals("Roses are RED!, Violets are BLUE!", reallyBeautiful)
- }
-
- @Test
- fun whenSplit_thenList() {
- val regex = """\W+""".toRegex()
- val beautiful = "Roses are red, Violets are blue"
-
- assertEquals(listOf("Roses", "are", "red", "Violets", "are", "blue"), regex.split(beautiful))
- assertEquals(listOf("Roses", "are", "red", "Violets are blue"), regex.split(beautiful, 4))
- assertEquals(regex.toPattern().split(beautiful).asList(), regex.split(beautiful))
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/README.md b/core-kotlin-modules/core-kotlin-annotations/README.md
deleted file mode 100644
index 787b67be11..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/README.md
+++ /dev/null
@@ -1,8 +0,0 @@
-## Core Kotlin Annotations
-
-This module contains articles about core Kotlin annotations.
-
-### Relevant articles:
-- [Kotlin Annotations](https://www.baeldung.com/kotlin-annotations)
-- [Guide to Kotlin @JvmField](https://www.baeldung.com/kotlin-jvm-field-annotation)
-- [Guide to JVM Platform Annotations in Kotlin](https://www.baeldung.com/kotlin-jvm-annotations)
diff --git a/core-kotlin-modules/core-kotlin-annotations/pom.xml b/core-kotlin-modules/core-kotlin-annotations/pom.xml
deleted file mode 100644
index 77670be151..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
- 4.0.0
- core-kotlin-annotations
- core-kotlin-annotations
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
-
- 1.3.30
- 3.10.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt
deleted file mode 100644
index a8f83446dc..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Annotations.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.baeldung.annotations
-
-@Target(AnnotationTarget.FIELD)
-annotation class Positive
-
-@Target(AnnotationTarget.FIELD)
-annotation class AllowedNames(val names: Array)
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt
deleted file mode 100644
index 6864fe416e..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Item.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.annotations
-
-class Item(@Positive val amount: Float, @AllowedNames(["Alice", "Bob"]) val name: String)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt
deleted file mode 100644
index 2b7f2c5590..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Main.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.baeldung.annotations
-
-fun main(args: Array) {
- val item = Item(amount = 1.0f, name = "Bob")
- val validator = Validator()
- println("Is instance valid? ${validator.isValid(item)}")
-}
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt
deleted file mode 100644
index 40139048ab..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/annotations/Validator.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung.annotations
-
-/**
- * Naive annotation-based validator.
- * @author A.Shcherbakov
- */
-class Validator() {
-
- /**
- * Return true if every item's property annotated with @Positive is positive and if
- * every item's property annotated with @AllowedNames has a value specified in that annotation.
- */
- fun isValid(item: Item): Boolean {
- val fields = item::class.java.declaredFields
- for (field in fields) {
- field.isAccessible = true
- for (annotation in field.annotations) {
- val value = field.get(item)
- if (field.isAnnotationPresent(Positive::class.java)) {
- val amount = value as Float
- if (amount < 0) {
- return false
- }
- }
- if (field.isAnnotationPresent(AllowedNames::class.java)) {
- val allowedNames = field.getAnnotation(AllowedNames::class.java)?.names
- val name = value as String
- allowedNames?.let {
- if (!it.contains(name)) {
- return false
- }
- }
- }
- }
- }
- return true
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt
deleted file mode 100644
index 55f60bfa81..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Document.kt
+++ /dev/null
@@ -1,11 +0,0 @@
-package com.baeldung.jvmannotations
-
-import java.util.*
-
-interface Document {
-
- @JvmDefault
- fun getTypeDefault() = "document"
-
- fun getType() = "document"
-}
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java
deleted file mode 100644
index feb71772cb..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.baeldung.jvmannotations;
-
-public class HtmlDocument implements Document {
-
- @Override
- public String getType() {
- return "HTML";
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt
deleted file mode 100644
index 80180bd924..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/Message.kt
+++ /dev/null
@@ -1,66 +0,0 @@
-@file:JvmName("MessageHelper")
-@file:JvmMultifileClass //used
-package com.baeldung.jvmannotations
-
-import java.util.*
-
-@JvmName("getMyUsername")
-fun getMyName() : String {
- return "myUserId"
-}
-
-object MessageBroker {
- @JvmStatic
- var totalMessagesSent = 0
-
- const val maxMessageLength = 0
-
- @JvmStatic
- fun clearAllMessages() {
- }
-
- @JvmStatic
- @JvmOverloads
- @Throws(Exception::class)
- fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List {
- if(sender.isEmpty()) {
- throw Exception()
- }
- return ArrayList()
- }
-}
-
-class Message {
-
- // this would cause a compilation error since sender is immutable
- // @set:JvmName("setSender")
- val sender = "myself"
-
- // this works as name is overridden
- @JvmName("getSenderName")
- fun getSender() : String = "from:$sender"
-
- @get:JvmName("getReceiverName")
- @set:JvmName("setReceiverName")
- var receiver : String = ""
-
- @get:JvmName("getContent")
- @set:JvmName("setContent")
- var text = ""
-
- // generates a warning
- @get:JvmName("getId")
- private val id = 0
-
- @get:JvmName("hasAttachment")
- var hasAttachment = true
-
- var isEncrypted = true
-
- fun setReceivers(receiverNames : List) {
- }
-
- @JvmName("setReceiverIds")
- fun setReceivers(receiverNames : List) {
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt
deleted file mode 100644
index 3b19b12e10..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-@file:JvmMultifileClass
-@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants
-package com.baeldung.jvmannotations
-
-fun convert(message: Message) {
-}
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt
deleted file mode 100644
index 41cb0df939..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/TextDocument.kt
+++ /dev/null
@@ -1,16 +0,0 @@
-package com.baeldung.jvmannotations
-
-import java.util.*
-class TextDocument : Document {
- override fun getType() = "text"
-
- fun transformList(list : List) : List {
- return list.filter { n -> n.toInt() > 1 }
- }
-
- fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> {
- return list.filter { n -> n.toInt() > 1 }
- }
-
- var list : List<@JvmWildcard Any> = ArrayList()
-}
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt
deleted file mode 100644
index 00f2582d5f..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmannotations/XmlDocument.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.jvmannotations
-
-import java.util.*
-
-class XmlDocument(d : Document) : Document by d
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt b/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt
deleted file mode 100644
index e60894ba88..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/main/kotlin/com/baeldung/jvmfield/JvmSample.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.baeldung.jvmfield
-
-class JvmSample(text:String) {
- @JvmField
- val sampleText:String = text
-}
-
-class CompanionSample {
- companion object {
- @JvmField val MAX_LIMIT = 20
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt
deleted file mode 100644
index 5c2b6ef47f..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/annotations/ValidationTest.kt
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.baeldung.annotations
-
-import org.junit.Test
-import kotlin.test.assertTrue
-import kotlin.test.assertFalse
-
-class ValidationTest {
-
- @Test
- fun whenAmountIsOneAndNameIsAlice_thenTrue() {
- assertTrue(Validator().isValid(Item(1f, "Alice")))
- }
-
- @Test
- fun whenAmountIsOneAndNameIsBob_thenTrue() {
- assertTrue(Validator().isValid(Item(1f, "Bob")))
- }
-
-
- @Test
- fun whenAmountIsMinusOneAndNameIsAlice_thenFalse() {
- assertFalse(Validator().isValid(Item(-1f, "Alice")))
- }
-
- @Test
- fun whenAmountIsMinusOneAndNameIsBob_thenFalse() {
- assertFalse(Validator().isValid(Item(-1f, "Bob")))
- }
-
- @Test
- fun whenAmountIsOneAndNameIsTom_thenFalse() {
- assertFalse(Validator().isValid(Item(1f, "Tom")))
- }
-
- @Test
- fun whenAmountIsMinusOneAndNameIsTom_thenFalse() {
- assertFalse(Validator().isValid(Item(-1f, "Tom")))
- }
-
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt
deleted file mode 100644
index 2ec5402e5a..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmannotations/DocumentTest.kt
+++ /dev/null
@@ -1,20 +0,0 @@
-package com.baeldung.range
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-import com.baeldung.jvmannotations.*;
-
-class DocumentTest {
-
- @Test
- fun testDefaultMethod() {
-
- val myDocument = TextDocument()
- val myTextDocument = XmlDocument(myDocument)
-
- assertEquals("text", myDocument.getType())
- assertEquals("text", myTextDocument.getType())
- assertEquals("document", myTextDocument.getTypeDefault())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt b/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt
deleted file mode 100644
index 769c0311c4..0000000000
--- a/core-kotlin-modules/core-kotlin-annotations/src/test/kotlin/com/baeldung/jvmfield/JvmSampleTest.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baeldung.jvmfield
-
-import org.junit.Before
-import org.junit.Test
-import kotlin.test.assertTrue
-
-class JvmSampleTest {
-
- var sample = ""
-
- @Before
- fun setUp() {
- sample = JvmSample("Hello!").sampleText
- }
-
- @Test
- fun givenField_whenCheckValue_thenMatchesValue() {
- assertTrue(sample == "Hello!")
- }
-
- @Test
- fun givenStaticVariable_whenCheckValue_thenMatchesValue() {
- // Sample when is treated as a static variable
- assertTrue(CompanionSample.MAX_LIMIT == 20)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/README.md b/core-kotlin-modules/core-kotlin-collections/README.md
deleted file mode 100644
index dcf2743577..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/README.md
+++ /dev/null
@@ -1,14 +0,0 @@
-## Core Kotlin Collections
-
-This module contains articles about core Kotlin collections.
-
-### Relevant articles:
-- [Split a List Into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts)
-- [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list)
-- [Overview of Kotlin Collections API](https://www.baeldung.com/kotlin-collections-api)
-- [Converting a List to Map in Kotlin](https://www.baeldung.com/kotlin-list-to-map)
-- [Filtering Kotlin Collections](https://www.baeldung.com/kotlin-filter-collection)
-- [Collection Transformations in Kotlin](https://www.baeldung.com/kotlin-collection-transformations)
-- [Difference between fold and reduce in Kotlin](https://www.baeldung.com/kotlin/fold-vs-reduce)
-- [Guide to Sorting in Kotlin](https://www.baeldung.com/kotlin-sort)
-- [Working With Lists in Kotlin](https://www.baeldung.com/kotlin/lists)
diff --git a/core-kotlin-modules/core-kotlin-collections/pom.xml b/core-kotlin-modules/core-kotlin-collections/pom.xml
deleted file mode 100644
index 52401d267c..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/pom.xml
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
- 4.0.0
- core-kotlin-collections
- core-kotlin-collections
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.apache.commons
- commons-math3
- ${commons-math3.version}
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
-
- 1.3.30
- 3.6.1
- 3.10.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt
deleted file mode 100644
index a29eabe623..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/kotlin/collections/ListExample.kt
+++ /dev/null
@@ -1,204 +0,0 @@
-package com.baeldung.kotlin.collections
-
-import kotlin.collections.List
-
-class ListExample {
-
- private val countries = listOf("Germany", "India", "Japan", "Brazil", "Australia")
- private val cities = mutableListOf("Berlin", "Calcutta", "Seoul", "Sao Paulo", "Sydney")
-
- fun createList(): List {
- val countryList = listOf("Germany", "India", "Japan", "Brazil")
- return countryList
- }
-
- fun createMutableList(): MutableList {
- val cityList = mutableListOf("Berlin", "Calcutta", "Seoul", "Sao Paulo")
- return cityList
- }
-
- fun iterateUsingForEachLoop(): List {
- val countryLength = mutableListOf()
- countries.forEach { it ->
- print("$it ")
- println(" Length: ${it.length}")
- countryLength.add(it.length)
- }
- return countryLength
- }
-
- fun iterateUsingForLoop(): List {
- val countryLength = mutableListOf()
- for (country in countries) {
- print("$country ")
- println(" Length: ${country.length}")
- countryLength.add(country.length)
- }
- return countryLength
- }
-
- fun iterateUsingForLoopRange(): List {
- val countryLength = mutableListOf()
- for (i in 0 until countries.size) {
- print("${countries[i]} ")
- println(" Length: ${countries[i].length}")
- countryLength.add(countries[i].length)
- }
- return countryLength
- }
-
- fun iterateUsingForEachIndexedLoop(): List {
- val countryLength = mutableListOf()
- countries.forEachIndexed { i, e ->
- println("country[$i] = $e")
- print(" Index: $i")
- println(" Length: ${e.length}")
- countryLength.add(e.length)
- }
- return countryLength
- }
-
- fun iterateUsingListIterator() {
- val iterator = countries.listIterator()
- while (iterator.hasNext()) {
- val country = iterator.next()
- print("$country ")
- }
- println()
-
- while (iterator.hasPrevious()) {
- println("Index: ${iterator.previousIndex()}")
- }
- }
-
- fun iterateUsingIterator() {
- val iterator = cities.iterator()
- iterator.next()
- iterator.remove()
- println(cities)
- }
-
- fun iterateUsingMutableListIterator() {
- val iterator = cities.listIterator(1)
- iterator.next()
- iterator.add("London")
- iterator.next()
- iterator.set("Milan")
- println(cities)
- }
-
- fun retrieveElementsInList(): String {
- println(countries[2])
- return countries[2]
- }
-
- fun retrieveElementsUsingGet(): String {
- println(countries.get(3))
- return countries.get(3)
- }
-
- fun retrieveElementsFirstAndLast(): String? {
- println(countries.first())
- println(countries.last())
- println(countries.first { it.length > 7 })
- println(countries.last { it.startsWith("J") })
- println(countries.firstOrNull { it.length > 8 })
- return countries.firstOrNull { it.length > 8 }
- }
-
- fun retrieveSubList(): List {
- val subList = countries.subList(1, 4)
- println(subList)
- return subList
- }
-
- fun retrieveListSliceUsingIndices(): List {
- val sliceList = countries.slice(1..4)
- println(sliceList)
- return sliceList
- }
-
- fun retrieveListSliceUsingIndicesList(): List {
- val sliceList = countries.slice(listOf(1, 4))
- println(sliceList)
- return sliceList
- }
-
- fun countList(): Int {
- val count = countries.count()
- println(count)
- return count
- }
-
- fun countListUsingPredicate(): Int {
- val count = countries.count { it.length > 5 }
- println(count)
- return count
- }
-
- fun countListUsingProperty(): Int {
- val size = countries.size
- println(size)
- return size
- }
-
- fun addToList(): List {
- cities.add("Barcelona")
- println(cities)
- cities.add(3, "London")
- println(cities)
- cities.addAll(listOf("Singapore", "Moscow"))
- println(cities)
- cities.addAll(2, listOf("Prague", "Amsterdam"))
- println(cities)
- return cities
- }
-
- fun removeFromList(): List {
- cities.remove("Seoul")
- println(cities)
- cities.removeAt(1)
- println(cities)
- return cities
- }
-
- fun replaceFromList(): List {
- cities.set(3, "Prague")
- println(cities)
- cities[4] = "Moscow"
- println(cities)
- cities.fill("Barcelona")
- println(cities)
- return cities
- }
-
- fun sortMutableList(): List {
- cities.sort()
- println(cities)
- cities.sortDescending()
- println(cities)
- return cities
- }
-
- fun sortList(): List {
- val sortedCountries = countries.sorted()
- println("countries = $countries")
- println("sortedCountries = $sortedCountries")
- val sortedCountriesDescending = countries.sortedDescending()
- println("countries = $countries")
- println("sortedCountriesDescending = $sortedCountriesDescending")
- return sortedCountriesDescending
- }
-
- fun checkOneElementInList(): Boolean {
- return countries.contains("Germany")
- }
-
- fun checkOneElementInListUsingOperator(): Boolean {
- return "Spain" in countries
- }
-
- fun checkElementsInList(): Boolean {
- return cities.containsAll(listOf("Calcutta", "Sao Paulo", "Sydney"))
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt b/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt
deleted file mode 100644
index bf3163bc8f..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/main/kotlin/com/baeldung/sorting/SortingExample.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.sorting
-
-fun sortMethodUsage() {
- val sortedValues = mutableListOf(1, 2, 7, 6, 5, 6)
- sortedValues.sort()
- println(sortedValues)
-}
-
-fun sortByMethodUsage() {
- val sortedValues = mutableListOf(1 to "a", 2 to "b", 7 to "c", 6 to "d", 5 to "c", 6 to "e")
- sortedValues.sortBy { it.second }
- println(sortedValues)
-}
-
-fun sortWithMethodUsage() {
- val sortedValues = mutableListOf(1 to "a", 2 to "b", 7 to "c", 6 to "d", 5 to "c", 6 to "e")
- sortedValues.sortWith(compareBy({it.second}, {it.first}))
- println(sortedValues)
-}
-
-fun > getSimpleComparator() : Comparator {
- val ascComparator = naturalOrder()
- return ascComparator
-}
-
-fun getComplexComparator() {
- val complexComparator = compareBy>({it.first}, {it.second})
-}
-
-fun nullHandlingUsage() {
- val sortedValues = mutableListOf(1 to "a", 2 to null, 7 to "c", 6 to "d", 5 to "c", 6 to "e")
- sortedValues.sortWith(nullsLast(compareBy { it.second }))
- println(sortedValues)
-}
-
-fun extendedComparatorUsage() {
- val students = mutableListOf(21 to "Helen", 21 to "Tom", 20 to "Jim")
-
- val ageComparator = compareBy> {it.first}
- val ageAndNameComparator = ageComparator.thenByDescending {it.second}
- println(students.sortedWith(ageAndNameComparator))
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt
deleted file mode 100644
index 67fbb29026..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/CollectionsTest.kt
+++ /dev/null
@@ -1,212 +0,0 @@
-package com.baeldung.collections
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertFalse
-import kotlin.test.assertTrue
-
-class CollectionsTest {
-
- @Test
- fun whenUseDifferentCollections_thenSuccess() {
- val theList = listOf("one", "two", "three")
- assertTrue(theList.contains("two"))
-
- val theMutableList = mutableListOf("one", "two", "three")
- theMutableList.add("four")
- assertTrue(theMutableList.contains("four"))
-
- val theSet = setOf("one", "two", "three")
- assertTrue(theSet.contains("three"))
-
- val theMutableSet = mutableSetOf("one", "two", "three")
- theMutableSet.add("four")
- assertTrue(theMutableSet.contains("four"))
-
- val theMap = mapOf(1 to "one", 2 to "two", 3 to "three")
- assertEquals(theMap[2], "two")
-
- val theMutableMap = mutableMapOf(1 to "one", 2 to "two", 3 to "three")
- theMutableMap[4] = "four"
- assertEquals(theMutableMap[4], "four")
- }
-
- @Test
- fun whenSliceCollection_thenSuccess() {
- val theList = listOf("one", "two", "three")
- val resultList = theList.slice(1..2)
-
- assertEquals(2, resultList.size)
- assertTrue(resultList.contains("two"))
- }
-
- @Test
- fun whenJoinTwoCollections_thenSuccess() {
- val firstList = listOf("one", "two", "three")
- val secondList = listOf("four", "five", "six")
- val resultList = firstList + secondList
-
- assertEquals(6, resultList.size)
- assertTrue(resultList.contains("two"))
- assertTrue(resultList.contains("five"))
- }
-
- @Test
- fun whenFilterNullValues_thenSuccess() {
- val theList = listOf("one", null, "two", null, "three")
- val resultList = theList.filterNotNull()
-
- assertEquals(3, resultList.size)
- }
-
- @Test
- fun whenFilterNonPositiveValues_thenSuccess() {
- val theList = listOf(1, 2, -3, -4, 5, -6)
- val resultList = theList.filter { it > 0 }
- //val resultList = theList.filter{ x -> x > 0}
-
- assertEquals(3, resultList.size)
- assertTrue(resultList.contains(1))
- assertFalse(resultList.contains(-4))
- }
-
- @Test
- fun whenDropFirstItems_thenRemoved() {
- val theList = listOf("one", "two", "three", "four")
- val resultList = theList.drop(2)
-
- assertEquals(2, resultList.size)
- assertFalse(resultList.contains("one"))
- assertFalse(resultList.contains("two"))
- }
-
- @Test
- fun whenDropFirstItemsBasedOnCondition_thenRemoved() {
- val theList = listOf("one", "two", "three", "four")
- val resultList = theList.dropWhile { it.length < 4 }
-
- assertEquals(2, resultList.size)
- assertFalse(resultList.contains("one"))
- assertFalse(resultList.contains("two"))
- }
-
- @Test
- fun whenExcludeItems_thenRemoved() {
- val firstList = listOf("one", "two", "three")
- val secondList = listOf("one", "three")
- val resultList = firstList - secondList
-
- assertEquals(1, resultList.size)
- assertTrue(resultList.contains("two"))
- }
-
- @Test
- fun whenSearchForExistingItem_thenFound() {
- val theList = listOf("one", "two", "three")
-
- assertTrue("two" in theList)
- }
-
- @Test
- fun whenGroupItems_thenSuccess() {
- val theList = listOf(1, 2, 3, 4, 5, 6)
- val resultMap = theList.groupBy { it % 3 }
-
- assertEquals(3, resultMap.size)
- print(resultMap[1])
- assertTrue(resultMap[1]!!.contains(1))
- assertTrue(resultMap[2]!!.contains(5))
- }
-
- @Test
- fun whenApplyFunctionToAllItems_thenSuccess() {
- val theList = listOf(1, 2, 3, 4, 5, 6)
- val resultList = theList.map { it * it }
- print(resultList)
- assertEquals(4, resultList[1])
- assertEquals(9, resultList[2])
- }
-
- @Test
- fun whenApplyMultiOutputFunctionToAllItems_thenSuccess() {
- val theList = listOf("John", "Tom")
- val resultList = theList.flatMap { it.toLowerCase().toList() }
- print(resultList)
- assertEquals(7, resultList.size)
- assertTrue(resultList.contains('j'))
- }
-
- @Test
- fun whenApplyFunctionToAllItemsWithStartingValue_thenSuccess() {
- val theList = listOf(1, 2, 3, 4, 5, 6)
- val finalResult = theList.fold(1000, { oldResult, currentItem -> oldResult + (currentItem * currentItem) })
- print(finalResult)
- assertEquals(1091, finalResult)
- }
-
- @Test
- fun whenApplyingChunked_thenShouldBreakTheCollection() {
- val theList = listOf(1, 2, 3, 4, 5)
- val chunked = theList.chunked(2)
-
- assertThat(chunked.size).isEqualTo(3)
- assertThat(chunked.first()).contains(1, 2)
- assertThat(chunked[1]).contains(3, 4)
- assertThat(chunked.last()).contains(5)
- }
-
- @Test
- fun whenApplyingChunkedWithTransformation_thenShouldBreakTheCollection() {
- val theList = listOf(1, 2, 3, 4, 5)
- val chunked = theList.chunked(3) { it.joinToString(", ") }
-
- assertThat(chunked.size).isEqualTo(2)
- assertThat(chunked.first()).isEqualTo("1, 2, 3")
- assertThat(chunked.last()).isEqualTo("4, 5")
- }
-
- @Test
- fun whenApplyingWindowed_thenShouldCreateSlidingWindowsOfElements() {
- val theList = (1..6).toList()
- val windowed = theList.windowed(3)
-
- assertThat(windowed.size).isEqualTo(4)
- assertThat(windowed.first()).contains(1, 2, 3)
- assertThat(windowed[1]).contains(2, 3, 4)
- assertThat(windowed[2]).contains(3, 4, 5)
- assertThat(windowed.last()).contains(4, 5, 6)
- }
-
- @Test
- fun whenApplyingWindowedWithTwoSteps_thenShouldCreateSlidingWindowsOfElements() {
- val theList = (1..6).toList()
- val windowed = theList.windowed(size = 3, step = 2)
-
- assertThat(windowed.size).isEqualTo(2)
- assertThat(windowed.first()).contains(1, 2, 3)
- assertThat(windowed.last()).contains(3, 4, 5)
- }
-
- @Test
- fun whenApplyingPartialWindowedWithTwoSteps_thenShouldCreateSlidingWindowsOfElements() {
- val theList = (1..6).toList()
- val windowed = theList.windowed(size = 3, step = 2, partialWindows = true)
-
- assertThat(windowed.size).isEqualTo(3)
- assertThat(windowed.first()).contains(1, 2, 3)
- assertThat(windowed[1]).contains(3, 4, 5)
- assertThat(windowed.last()).contains(5, 6)
- }
-
- @Test
- fun whenApplyingTransformingWindows_thenShouldCreateSlidingWindowsOfElements() {
- val theList = (1..6).toList()
- val windowed = theList.windowed(size = 3, step = 2, partialWindows = true) { it.joinToString(", ") }
-
- assertThat(windowed.size).isEqualTo(3)
- assertThat(windowed.first()).isEqualTo("1, 2, 3")
- assertThat(windowed[1]).isEqualTo("3, 4, 5")
- assertThat(windowed.last()).isEqualTo("5, 6")
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt
deleted file mode 100644
index 68f7040c4c..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class AssociateUnitTest {
- @Test
- fun testToMap() {
- val input = listOf(Pair("one", 1), Pair("two", 2))
- val map = input.toMap()
- assertEquals(mapOf("one" to 1, "two" to 2), map)
- }
-
- @Test
- fun testAssociateWith() {
- val inputs = listOf("Hi", "there")
- val map = inputs.associateWith { k -> k.length }
- assertEquals(mapOf("Hi" to 2, "there" to 5), map)
- }
-
- @Test
- fun testAssociateBy() {
- val inputs = listOf("Hi", "there")
- val map = inputs.associateBy { v -> v.length }
- assertEquals(mapOf(2 to "Hi", 5 to "there"), map)
- }
-
- @Test
- fun testAssociate() {
- val inputs = listOf("Hi", "there")
- val map = inputs.associate { e -> Pair(e.toUpperCase(), e.reversed()) }
- assertEquals(mapOf("HI" to "iH", "THERE" to "ereht"), map)
- }
-
- @Test
- fun testAssociateByDuplicateKeys() {
- val inputs = listOf("one", "two")
- val map = inputs.associateBy { v -> v.length }
- assertEquals(mapOf(3 to "two"), map)
- }
-
- @Test
- fun testGroupBy() {
- val inputs = listOf("one", "two", "three")
- val map = inputs.groupBy { v -> v.length }
- assertEquals(mapOf(3 to listOf("one", "two"), 5 to listOf("three")), map)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt
deleted file mode 100644
index 591577e4f3..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class FilterUnitTest {
- @Test
- fun testFilterWithLambda() {
- val input = listOf(1, 2, 3, 4, 5)
- val filtered = input.filter { it <= 3 }
- assertEquals(listOf(1, 2, 3), filtered)
- }
-
- @Test
- fun testFilterWithMethodReference() {
- val input = listOf(1, 2, 3, 4, 5)
- val filtered = input.filter(this::isSmall)
- assertEquals(listOf(1, 2, 3), filtered)
- }
-
- @Test
- fun testFilterNotWithMethodReference() {
- val input = listOf(1, 2, 3, 4, 5)
- val filtered = input.filterNot(this::isSmall)
- assertEquals(listOf(4, 5), filtered)
- }
-
- @Test
- fun testFilterIndexed() {
- val input = listOf(5, 4, 3, 2, 1)
- val filtered = input.filterIndexed { index, element -> index < 3 }
- assertEquals(listOf(5, 4, 3), filtered)
- }
-
- @Test
- fun testFilterNotNull() {
- val nullable: List = listOf("Hello", null, "World")
- val nonnull: List = nullable.filterNotNull()
- assertEquals(listOf("Hello", "World"), nonnull)
- }
-
- private fun isSmall(i: Int) = i <= 3
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt
deleted file mode 100644
index 69fbceb8e3..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class FlattenUnitTest {
- @Test
- fun testFlatten() {
- val inputs = listOf("one", "two", "three")
- val characters = inputs.map(String::toList)
- val flattened = characters.flatten();
- assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), flattened)
- }
-
- @Test
- fun testFlatMap() {
- val inputs = listOf("one", "two", "three")
- val characters = inputs.flatMap(String::toList)
- assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), characters)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt
deleted file mode 100644
index 2ac0cdca50..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt
+++ /dev/null
@@ -1,46 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class JoinToUnitTest {
- @Test
- fun testJoinToString() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val simpleString = inputs.joinToString()
- assertEquals("Jan, Feb, Mar, Apr, May", simpleString)
-
- val detailedString = inputs.joinToString(separator = ",", prefix="Months: ", postfix=".")
- assertEquals("Months: Jan,Feb,Mar,Apr,May.", detailedString)
- }
-
- @Test
- fun testJoinToStringLimits() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val simpleString = inputs.joinToString(limit = 3)
- assertEquals("Jan, Feb, Mar, ...", simpleString)
- }
-
- @Test
- fun testJoinToStringTransform() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val simpleString = inputs.joinToString(transform = String::toUpperCase)
- assertEquals("JAN, FEB, MAR, APR, MAY", simpleString)
- }
-
- @Test
- fun testJoinTo() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val output = StringBuilder()
- output.append("My ")
- .append(inputs.size)
- .append(" elements: ")
- inputs.joinTo(output)
-
- assertEquals("My 5 elements: Jan, Feb, Mar, Apr, May", output.toString())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt
deleted file mode 100644
index e22fcbe903..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class MapUnitTest {
- @Test
- fun testMapWithLambda() {
- val input = listOf("one", "two", "three")
-
- val reversed = input.map { it.reversed() }
- assertEquals(listOf("eno", "owt", "eerht"), reversed)
-
- val lengths = input.map { it.length }
- assertEquals(listOf(3, 3, 5), lengths)
- }
-
- @Test
- fun testMapIndexed() {
- val input = listOf(3, 2, 1)
- val result = input.mapIndexed { index, value -> index * value }
- assertEquals(listOf(0, 2, 2), result)
- }
-
- @Test
- fun testMapNotNull() {
- val input = listOf(1, 2, 3, 4, 5)
- val smallSquares = input.mapNotNull {
- if (it <= 3) {
- it * it
- } else {
- null
- }
- }
- assertEquals(listOf(1, 4, 9), smallSquares)
- }
-
- @Test
- fun mapMapKeys() {
- val inputs = mapOf("one" to 1, "two" to 2, "three" to 3)
-
- val uppercases = inputs.mapKeys { it.key.toUpperCase() }
- assertEquals(mapOf("ONE" to 1, "TWO" to 2, "THREE" to 3), uppercases)
- }
-
- @Test
- fun mapMapValues() {
- val inputs = mapOf("one" to 1, "two" to 2, "three" to 3)
-
- val squares = inputs.mapValues { it.value * it.value }
- assertEquals(mapOf("one" to 1, "two" to 4, "three" to 9), squares)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt
deleted file mode 100644
index 6821b7cdb9..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class ReduceUnitTest {
- @Test
- fun testJoinToStringAsReduce() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val result = inputs.reduce { acc, next -> "$acc, $next" }
- assertEquals("Jan, Feb, Mar, Apr, May", result)
- }
-
- @Test
- fun testFoldToLength() {
- val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May")
-
- val result = inputs.fold(0) { acc, next -> acc + next.length }
- assertEquals(15, result)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt
deleted file mode 100644
index 66aeeceef4..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.collections.transformations
-
-import org.junit.Assert.assertEquals
-import org.junit.Test
-
-class ZipUnitTest {
- @Test
- fun testZip() {
- val left = listOf("one", "two", "three")
- val right = listOf(1, 2, 3)
- val zipped = left.zip(right)
- assertEquals (listOf(Pair("one", 1), Pair("two", 2), Pair("three", 3)), zipped)
- }
-
- @Test
- fun testZipShort() {
- val left = listOf("one", "two")
- val right = listOf(1, 2, 3)
- val zipped = left.zip(right)
- assertEquals (listOf(Pair("one", 1), Pair("two", 2)), zipped)
- }
-
- @Test
- fun testUnzip() {
- val left = listOf("one", "two", "three")
- val right = listOf(1, 2, 3)
- val zipped = left.zip(right)
-
- val (newLeft, newRight) = zipped.unzip()
- assertEquals(left, newLeft)
- assertEquals(right, newRight)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt
deleted file mode 100644
index 20797cc633..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/ChunkedTest.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.baeldung.filter
-
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Test
-
-internal class ChunkedTest {
-
- @Test
- fun givenDNAFragmentString_whenChunking_thenProduceListOfChunks() {
- val dnaFragment = "ATTCGCGGCCGCCAA"
-
- val fragments = dnaFragment.chunked(3)
-
- assertIterableEquals(listOf("ATT", "CGC", "GGC", "CGC", "CAA"), fragments)
- }
-
- @Test
- fun givenDNAString_whenChunkingWithTransformer_thenProduceTransformedList() {
- val codonTable = mapOf("ATT" to "Isoleucine", "CAA" to "Glutamine", "CGC" to "Arginine", "GGC" to "Glycine")
- val dnaFragment = "ATTCGCGGCCGCCAA"
-
- val proteins = dnaFragment.chunked(3) { codon ->
- codonTable[codon.toString()] ?: error("Unknown codon")
- }
-
- assertIterableEquals(listOf("Isoleucine", "Arginine", "Glycine", "Arginine", "Glutamine"), proteins)
- }
-
- @Test
- fun givenListOfValues_whenChunking_thenProduceListOfArrays() {
- val whole = listOf(1, 4, 7, 4753, 2, 34, 62, 76, 5868, 0)
- val chunks = whole.chunked(6)
-
- val expected = listOf(listOf(1, 4, 7, 4753, 2, 34), listOf(62, 76, 5868, 0))
-
- assertIterableEquals(expected, chunks)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt
deleted file mode 100644
index 4cc6f647e1..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DistinctTest.kt
+++ /dev/null
@@ -1,71 +0,0 @@
-package com.baeldung.filter
-
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Test
-
-internal class DistinctTest {
- data class SmallClass(val key: String, val num: Int)
-
- @Test
- fun whenApplyingDistinct_thenReturnListOfNoDuplicateValues() {
- val array = arrayOf(1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 5, 6, 7, 8, 9)
- val result = array.distinct()
- val expected = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9)
-
- assertIterableEquals(expected, result)
- }
-
- @Test
- fun givenArrayOfClassObjects_whenApplyingDistinctOnClassProperty_thenReturnListDistinctOnThatValue() {
-
- val original = arrayOf(
- SmallClass("key1", 1),
- SmallClass("key2", 2),
- SmallClass("key3", 3),
- SmallClass("key4", 3),
- SmallClass("er", 9),
- SmallClass("er", 10),
- SmallClass("er", 11))
-
- val actual = original.distinctBy { it.key }
-
- val expected = listOf(
- SmallClass("key1", 1),
- SmallClass("key2", 2),
- SmallClass("key3", 3),
- SmallClass("key4", 3),
- SmallClass("er", 9))
-
-
- assertIterableEquals(expected, actual)
- }
-
- @Test
- fun givenArrayOfClassObjects_whenApplyingComplicatedSelector_thenReturnFirstElementToMatchEachSelectorValue() {
- val array = arrayOf(
- SmallClass("key1", 1),
- SmallClass("key2", 2),
- SmallClass("key3", 3),
- SmallClass("key4", 3),
- SmallClass("er", 9),
- SmallClass("er", 10),
- SmallClass("er", 11),
- SmallClass("er", 11),
- SmallClass("er", 91),
- SmallClass("blob", 22),
- SmallClass("dob", 27),
- SmallClass("high", 201_434_314))
-
- val actual = array.distinctBy { Math.floor(it.num / 10.0) }
-
- val expected = listOf(
- SmallClass("key1", 1),
- SmallClass("er", 10),
- SmallClass("er", 91),
- SmallClass("blob", 22),
- SmallClass("high", 201_434_314))
-
- assertIterableEquals(expected, actual)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt
deleted file mode 100644
index 7c2685f39b..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/DropTest.kt
+++ /dev/null
@@ -1,53 +0,0 @@
-package com.baeldung.filter
-
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Test
-
-internal class DropTest {
-
- @Test
- fun whenDroppingFirstTwoItemsOfArray_thenTwoLess() {
- val array = arrayOf(1, 2, 3, 4)
- val result = array.drop(2)
- val expected = listOf(3, 4)
-
- assertIterableEquals(expected, result)
- }
-
- @Test
- fun whenDroppingMoreItemsOfArray_thenEmptyList() {
- val array = arrayOf(1, 2, 3, 4)
- val result = array.drop(5)
- val expected = listOf()
-
- assertIterableEquals(expected, result)
- }
-
- @Test
- fun givenArray_whenDroppingLastElement_thenReturnListWithoutLastElement() {
- val array = arrayOf("1", "2", "3", "4")
- val result = array.dropLast(1)
- val expected = listOf("1", "2", "3")
-
- assertIterableEquals(expected, result)
- }
-
- @Test
- fun givenArrayOfFloats_whenDroppingLastUntilPredicateIsFalse_thenReturnSubsetListOfFloats() {
- val array = arrayOf(1f, 1f, 1f, 1f, 1f, 2f, 1f, 1f, 1f)
- val result = array.dropLastWhile { it == 1f }
- val expected = listOf(1f, 1f, 1f, 1f, 1f, 2f)
-
- assertIterableEquals(expected, result)
- }
-
- @Test
- fun givenList_whenDroppingMoreThanAvailable_thenThrowException() {
- val list = listOf('a', 'e', 'i', 'o', 'u')
- val result = list.drop(6)
- val expected: List = listOf()
-
- assertIterableEquals(expected, result)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt
deleted file mode 100644
index efe6354f25..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/FilterTest.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package com.baeldung.filter
-
-import org.apache.commons.math3.primes.Primes
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Test
-import kotlin.test.assertTrue
-
-internal class FilterTest {
-
- @Test
- fun givenAscendingValueMap_whenFilteringOnValue_ThenReturnSubsetOfMap() {
- val originalMap = mapOf("key1" to 1, "key2" to 2, "key3" to 3)
- val filteredMap = originalMap.filter { it.value < 2 }
- val expectedMap = mapOf("key1" to 1)
-
- assertTrue { expectedMap == filteredMap }
- }
-
- @Test
- fun givenSeveralCollections_whenFilteringToAccumulativeList_thenListContainsAllContents() {
- val array1 = arrayOf(90, 92, 93, 94, 92, 95, 93)
- val array2 = sequenceOf(51, 31, 83, 674_506_111, 256_203_161, 15_485_863)
- val list1 = listOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
- val primes = mutableListOf()
-
- val expected = listOf(2, 3, 5, 7, 31, 83, 15_485_863, 256_203_161, 674_506_111)
-
- val primeCheck = { num: Int -> Primes.isPrime(num) }
-
- array1.filterTo(primes, primeCheck)
- list1.filterTo(primes, primeCheck)
- array2.filterTo(primes, primeCheck)
-
- primes.sort()
-
- assertIterableEquals(expected, primes)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt
deleted file mode 100644
index 793fe68427..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/SliceTest.kt
+++ /dev/null
@@ -1,45 +0,0 @@
-package com.baeldung.filter
-
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Assertions.assertThrows
-import org.junit.jupiter.api.Test
-
-internal class SliceTest {
-
- @Test
- fun whenSlicingAnArrayWithDotRange_ThenListEqualsTheSlice() {
- val original = arrayOf(1, 2, 3, 2, 1)
- val actual = original.slice(1..3)
- val expected = listOf(2, 3, 2)
-
- assertIterableEquals(expected, actual)
- }
-
- @Test
- fun whenSlicingAnArrayWithDownToRange_thenListMadeUpOfReverseSlice() {
- val original = arrayOf(1, 2, 3, 2, 1)
- val actual = original.slice(3 downTo 0)
- val expected = listOf(2, 3, 2, 1)
-
- assertIterableEquals(expected, actual)
- }
-
-// From the 1.3 version of Kotlin APIs, slice doesn't return array of nulls but throw IndexOutOfBoundsException
-// @Test
-// fun whenSlicingBeyondTheRangeOfTheArray_thenContainManyNulls() {
-// val original = arrayOf(12, 3, 34, 4)
-// val actual = original.slice(3..8)
-// val expected = listOf(4, null, null, null, null, null)
-//
-// assertIterableEquals(expected, actual)
-// }
-
- @Test
- fun whenSlicingBeyondRangeOfArrayWithStep_thenOutOfBoundsException() {
- assertThrows(ArrayIndexOutOfBoundsException::class.java) {
- val original = arrayOf(12, 3, 34, 4)
- original.slice(3..8 step 2)
- }
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt
deleted file mode 100644
index d021177de8..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/filter/TakeTest.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung.filter
-
-import org.junit.jupiter.api.Assertions.assertIterableEquals
-import org.junit.jupiter.api.Test
-
-internal class TakeTest {
-
- @Test
- fun `given array of alternating types, when predicating on 'is String', then produce list of array up until predicate is false`() {
- val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6)
- val actualList = originalArray.takeWhile { it is String }
- val expectedList = listOf("val1")
-
- assertIterableEquals(expectedList, actualList)
- }
-
- @Test
- fun `given array of alternating types, when taking 4 items, then produce list of first 4 items`() {
- val originalArray = arrayOf("val1", 2, "val3", 4, "val5", 6)
- val actualList = originalArray.take(4)
- val expectedList = listOf("val1", 2, "val3", 4)
-
- println(originalArray.drop(4))
- println(actualList)
-
- assertIterableEquals(expectedList, actualList)
- }
-
- @Test
- fun `when taking more items than available, then return all elements`() {
- val originalArray = arrayOf(1, 2)
- val actual = originalArray.take(10)
- val expected = listOf(1, 2)
-
- assertIterableEquals(expected, actual)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt
deleted file mode 100644
index 52e7e2a5b5..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/findelement/FindAnElementInAListUnitTest.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.findelement
-
-import org.junit.jupiter.api.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertFalse
-import kotlin.test.assertTrue
-
-class FindAnElementInAListUnitTest {
-
- var batmans: List = listOf("Christian Bale", "Michael Keaton", "Ben Affleck", "George Clooney")
-
- @Test
- fun whenFindASpecificItem_thenItemIsReturned() {
- //Returns the first element matching the given predicate, or null if no such element was found.
- val theFirstBatman = batmans.find { actor -> "Michael Keaton".equals(actor) }
- assertEquals(theFirstBatman, "Michael Keaton")
- }
-
- @Test
- fun whenFilterWithPredicate_thenMatchingItemsAreReturned() {
- //Returns a list containing only elements matching the given predicate.
- val theCoolestBatmans = batmans.filter { actor -> actor.contains("a") }
- assertTrue(theCoolestBatmans.contains("Christian Bale") && theCoolestBatmans.contains("Michael Keaton"))
- }
-
- @Test
- fun whenFilterNotWithPredicate_thenMatchingItemsAreReturned() {
- //Returns a list containing only elements not matching the given predicate.
- val theMehBatmans = batmans.filterNot { actor -> actor.contains("a") }
- assertFalse(theMehBatmans.contains("Christian Bale") && theMehBatmans.contains("Michael Keaton"))
- assertTrue(theMehBatmans.contains("Ben Affleck") && theMehBatmans.contains("George Clooney"))
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt
deleted file mode 100644
index 7b263914c6..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/foldvsreduce/FoldAndReduceTest.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.baeldung.foldvsreduce
-
-import org.junit.Test
-import org.junit.jupiter.api.assertThrows
-import java.lang.RuntimeException
-import kotlin.test.assertEquals
-
-class FoldAndReduceTest {
-
- @Test
- fun testReduceLimitations() {
- val numbers: List = listOf(1, 2, 3)
- val sum: Number = numbers.reduce { acc, next -> acc + next }
- assertEquals(6, sum)
-
- val emptyList = listOf()
- assertThrows { emptyList.reduce { acc, next -> acc + next } }
-
- // doesn't compile
- // val sum = numbers.reduce { acc, next -> acc.toLong() + next.toLong()}
- }
-
- @Test
- fun testFold() {
-
- val numbers: List = listOf(1, 2, 3)
- val sum: Int = numbers.fold(0, { acc, next -> acc + next })
- assertEquals(6, sum)
-
- //change result type
- val sumLong: Long = numbers.fold(0L, { acc, next -> acc + next.toLong() })
- assertEquals(6L, sumLong)
-
- val emptyList = listOf()
- val emptySum = emptyList.fold(0, { acc, next -> acc + next })
- assertEquals(0, emptySum)
-
- //power of changing result type
- val (even, odd) = numbers.fold(Pair(listOf(), listOf()), { acc, next ->
- if (next % 2 == 0) Pair(acc.first + next, acc.second)
- else Pair(acc.first, acc.second + next)
- })
-
- assertEquals(listOf(2), even)
- assertEquals(listOf(1, 3), odd)
- }
-
- @Test
- fun testVariationsOfFold() {
- val numbers = listOf(1, 2, 3)
- val reversed = numbers.foldRight(listOf(), { next, acc -> acc + next})
- assertEquals(listOf(3,2,1), reversed)
-
- val reversedIndexes = numbers.foldRightIndexed(listOf(), { i, _, acc -> acc + i })
- assertEquals(listOf(2,1,0), reversedIndexes)
- }
-
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt
deleted file mode 100644
index 71fe3bf1e0..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/kotlin/collections/ListExampleUnitTest.kt
+++ /dev/null
@@ -1,126 +0,0 @@
-package com.baeldung.kotlin.collections
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.Assertions.assertEquals
-import kotlin.test.assertFalse
-import kotlin.test.assertTrue
-
-class ListExampleUnitTest {
-
- private val classUnderTest: ListExample = ListExample()
-
- @Test
- fun whenListIsCreated_thenContainsElements() {
- assertTrue(classUnderTest.createList().contains("India"))
- assertTrue(classUnderTest.createMutableList().contains("Seoul"))
- }
-
- @Test
- fun whenIterateUsingForEachLoop_thenSuccess() {
- assertEquals(7, classUnderTest.iterateUsingForEachLoop()[0])
- }
-
- @Test
- fun whenIterateUsingForLoop_thenSuccess() {
- assertEquals(5, classUnderTest.iterateUsingForLoop()[1])
- }
-
- @Test
- fun whenIterateUsingForLoopRange_thenSuccess() {
- assertEquals(6, classUnderTest.iterateUsingForLoopRange()[3])
- }
-
- @Test
- fun whenIterateUsingForEachIndexedLoop_thenSuccess() {
- assertEquals(9, classUnderTest.iterateUsingForEachIndexedLoop()[4])
- }
-
- @Test
- fun whenRetrieveElementsInList_thenSuccess() {
- assertEquals("Japan", classUnderTest.retrieveElementsInList())
- }
-
- @Test
- fun whenRetrieveElementsUsingGet_thenSuccess() {
- assertEquals("Brazil", classUnderTest.retrieveElementsUsingGet())
- }
-
- @Test
- fun whenRetrieveElementsFirstAndLast_thenSuccess() {
- assertEquals("Australia", classUnderTest.retrieveElementsFirstAndLast())
- }
-
- @Test
- fun whenRetrieveSubList_thenSuccess() {
- assertEquals(3, classUnderTest.retrieveSubList().size)
- }
-
- @Test
- fun whenRetrieveListSliceUsingIndices_thenSuccess() {
- assertEquals(4, classUnderTest.retrieveListSliceUsingIndices().size)
- }
-
- @Test
- fun whenRetrieveListSliceUsingIndicesList_thenSuccess() {
- assertEquals(2, classUnderTest.retrieveListSliceUsingIndicesList().size)
- }
-
- @Test
- fun whenCountList_thenSuccess() {
- assertEquals(5, classUnderTest.countList())
- }
-
- @Test
- fun whenCountListUsingPredicate_thenSuccess() {
- assertEquals(3, classUnderTest.countListUsingPredicate())
- }
-
- @Test
- fun whenCountListUsingProperty_thenSuccess() {
- assertEquals(5, classUnderTest.countListUsingProperty())
- }
-
- @Test
- fun whenAddToList_thenSuccess() {
- assertEquals(11, classUnderTest.addToList().count())
- }
-
- @Test
- fun whenRemoveFromList_thenSuccess() {
- val list = classUnderTest.removeFromList()
- assertEquals(3, list.size)
- assertEquals("Sao Paulo", list[1])
- }
-
- @Test
- fun whenReplaceFromList_thenSuccess() {
- val list = classUnderTest.replaceFromList()
- assertEquals(5, list.size)
- assertEquals("Barcelona", list[1])
- }
-
- @Test
- fun whenSortMutableList_thenSuccess() {
- assertEquals("Sydney", classUnderTest.sortMutableList()[0])
- }
-
- @Test
- fun whenSortList_thenSuccess() {
- assertEquals("India", classUnderTest.sortList()[1])
- }
-
- @Test
- fun whenCheckOneElementInList_thenSuccess() {
- assertTrue(classUnderTest.checkOneElementInList())
- }
-
- @Test
- fun whenCheckOneElementInListUsingOperator_thenSuccess() {
- assertFalse(classUnderTest.checkOneElementInListUsingOperator())
- }
-
- @Test
- fun whenCheckElementsInList_thenSuccess() {
- assertTrue(classUnderTest.checkElementsInList())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt
deleted file mode 100644
index 93e4f11fdf..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/ListToMapTest.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.baeldung.listtomap
-
-import org.junit.Test
-import kotlin.test.assertTrue
-
-class ListToMapTest {
-
- val user1 = User("John", 18, listOf("Hiking, Swimming"))
- val user2 = User("Sara", 25, listOf("Chess, Board Games"))
- val user3 = User("Dave", 34, listOf("Games, Racing sports"))
- val user4 = User("John", 30, listOf("Reading, Poker"))
-
- @Test
- fun givenList_whenConvertToMap_thenResult() {
- val myList = listOf(user1, user2, user3)
- val myMap = myList.map { it.name to it.age }.toMap()
-
- assertTrue(myMap.get("John") == 18)
- }
-
- @Test
- fun givenList_whenAssociatedBy_thenResult() {
- val myList = listOf(user1, user2, user3)
- val myMap = myList.associateBy({ it.name }, { it.hobbies })
-
- assertTrue(myMap.get("John")!!.contains("Hiking, Swimming"))
- }
-
- @Test
- fun givenStringList_whenConvertToMap_thenResult() {
- val myList = listOf("a", "b", "c")
- val myMap = myList.map { it to it }.toMap()
-
- assertTrue(myMap.get("a") == "a")
- }
-
- @Test
- fun givenStringList_whenAssociate_thenResult() {
- val myList = listOf("a", "b", "c", "c", "b")
- val myMap = myList.associate{ it to it }
-
- assertTrue(myMap.get("a") == "a")
- }
-
- @Test
- fun givenStringList_whenAssociateTo_thenResult() {
- val myList = listOf("a", "b", "c", "c", "b")
- val myMap = mutableMapOf()
-
- myList.associateTo(myMap) {it to it}
-
- assertTrue(myMap.get("a") == "a")
- }
-
- @Test
- fun givenStringList_whenAssociateByTo_thenResult() {
- val myList = listOf(user1, user2, user3, user4)
- val myMap = mutableMapOf()
-
- myList.associateByTo(myMap, {it.name}, {it.age})
-
- assertTrue(myMap.get("Dave") == 34)
- }
-
- @Test
- fun givenStringList_whenAssociateByToUser_thenResult() {
- val myList = listOf(user1, user2, user3, user4)
- val myMap = mutableMapOf()
-
- myList.associateByTo(myMap) {it.name}
-
- assertTrue(myMap.get("Dave")!!.age == 34)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt
deleted file mode 100644
index 89eb9ac701..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/listtomap/User.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.listtomap
-
-data class User(val name: String, val age: Int, val hobbies: List)
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt
deleted file mode 100644
index 7ac0efa4ef..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/sorting/SortingExampleKtTest.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.sorting
-
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Test
-
-class SortingExampleKtTest {
-
- @Test
- fun naturalOrderComparator_ShouldBeAscendingTest() {
- val resultingList = listOf(1, 5, 6, 6, 2, 3, 4).sortedWith(getSimpleComparator())
- assertTrue(listOf(1, 2, 3, 4, 5, 6, 6) == resultingList)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt
deleted file mode 100644
index 627c7eaacf..0000000000
--- a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/splitlist/SplitListIntoPartsTest.kt
+++ /dev/null
@@ -1,99 +0,0 @@
-package com.baeldung.splitlist
-
-import org.junit.jupiter.api.Test
-import kotlin.test.assertEquals
-
-class SplitListIntoPartsTest {
- 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>) {
- assertEquals("[[0, a], [1, b], [2, c]]", resultList.toString())
- }
-
- private fun verifyPartialList(resultList: List>) {
- 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>(evenList.size / 2)) { index, acc, item ->
- if (index % 2 == 0) {
- acc.add(ArrayList(2))
- }
- acc.last().add(item)
- acc
- }
- verifyList(resultList)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-concurrency/README.md b/core-kotlin-modules/core-kotlin-concurrency/README.md
deleted file mode 100644
index 09d9055a2b..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/README.md
+++ /dev/null
@@ -1,7 +0,0 @@
-## Core Kotlin Concurrency
-
-This module contains articles about concurrency in Kotlin.
-
-### Relevant articles:
-- [Threads vs Coroutines in Kotlin](https://www.baeldung.com/kotlin-threads-coroutines)
-- [Introduction to Kotlin Coroutines](https://www.baeldung.com/kotlin-coroutines)
diff --git a/core-kotlin-modules/core-kotlin-concurrency/pom.xml b/core-kotlin-modules/core-kotlin-concurrency/pom.xml
deleted file mode 100644
index 7c3b0fb5b6..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-
-
- 4.0.0
- core-kotlin-concurrency
- core-kotlin-concurrency
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
-
- 1.3.30
- 3.10.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt
deleted file mode 100644
index 80ffb4077a..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleRunnable.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.threadsvscoroutines
-
-class SimpleRunnable: Runnable {
-
- override fun run() {
- println("${Thread.currentThread()} has run.")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt b/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt
deleted file mode 100644
index 6647dac0ef..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/src/main/kotlin/com/baeldung/threadsvscoroutines/SimpleThread.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.threadsvscoroutines
-
-class SimpleThread: Thread() {
-
- override fun run() {
- println("${Thread.currentThread()} has run.")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt
deleted file mode 100644
index 6b9437a8ab..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/coroutines/CoroutinesUnitTest.kt
+++ /dev/null
@@ -1,178 +0,0 @@
-package com.baeldung.coroutines
-
-import kotlinx.coroutines.*
-import org.junit.Test
-import java.util.concurrent.atomic.AtomicInteger
-import kotlin.system.measureTimeMillis
-import kotlin.test.assertEquals
-import kotlin.test.assertTrue
-
-
-class CoroutinesTest {
-
- @Test
- fun givenBuildSequence_whenTakeNElements_thenShouldReturnItInALazyWay() {
- //given
- val fibonacciSeq = sequence {
- var a = 0
- var b = 1
-
- yield(1)
-
- while (true) {
- yield(a + b)
-
- val tmp = a + b
- a = b
- b = tmp
- }
- }
-
- //when
- val res = fibonacciSeq.take(5).toList()
-
- //then
- assertEquals(res, listOf(1, 1, 2, 3, 5))
- }
-
- @Test
- fun givenLazySeq_whenTakeNElements_thenShouldReturnAllElements() {
- //given
- val lazySeq = sequence {
- print("START ")
- for (i in 1..5) {
- yield(i)
- print("STEP ")
- }
- print("END")
- }
- //when
- val res = lazySeq.take(10).toList()
-
- //then
- assertEquals(res, listOf(1, 2, 3, 4, 5))
- }
-
- @Test
- fun givenAsyncCoroutine_whenStartIt_thenShouldExecuteItInTheAsyncWay() {
- //given
- val res = mutableListOf()
-
- //when
- runBlocking {
- val promise = launch(Dispatchers.Default) { expensiveComputation(res) }
- res.add("Hello,")
- promise.join()
- }
-
- //then
- assertEquals(res, listOf("Hello,", "word!"))
- }
-
-
- suspend fun expensiveComputation(res: MutableList) {
- delay(1000L)
- res.add("word!")
- }
-
- @Test
- fun givenHugeAmountOfCoroutines_whenStartIt_thenShouldExecuteItWithoutOutOfMemory() {
- runBlocking {
- //given
- val counter = AtomicInteger(0)
- val numberOfCoroutines = 100_000
-
- //when
- val jobs = List(numberOfCoroutines) {
- launch(Dispatchers.Default) {
- delay(1L)
- counter.incrementAndGet()
- }
- }
- jobs.forEach { it.join() }
-
- //then
- assertEquals(counter.get(), numberOfCoroutines)
- }
- }
-
- @Test
- fun givenCancellableJob_whenRequestForCancel_thenShouldQuit() {
- runBlocking {
- //given
- val job = launch(Dispatchers.Default) {
- while (isActive) {
- //println("is working")
- }
- }
-
- delay(1300L)
-
- //when
- job.cancel()
-
- //then cancel successfully
-
- }
- }
-
- @Test(expected = CancellationException::class)
- fun givenAsyncAction_whenDeclareTimeout_thenShouldFinishWhenTimedOut() {
- runBlocking {
- withTimeout(1300L) {
- repeat(1000) { i ->
- println("Some expensive computation $i ...")
- delay(500L)
- }
- }
- }
- }
-
- @Test
- fun givenHaveTwoExpensiveAction_whenExecuteThemAsync_thenTheyShouldRunConcurrently() {
- runBlocking {
- val delay = 1000L
- val time = measureTimeMillis {
- //given
- val one = async(Dispatchers.Default) { someExpensiveComputation(delay) }
- val two = async(Dispatchers.Default) { someExpensiveComputation(delay) }
-
- //when
- runBlocking {
- one.await()
- two.await()
- }
- }
-
- //then
- assertTrue(time < delay * 2)
- }
- }
-
- @Test
- fun givenTwoExpensiveAction_whenExecuteThemLazy_thenTheyShouldNotConcurrently() {
- runBlocking {
- val delay = 1000L
- val time = measureTimeMillis {
- //given
- val one = async(Dispatchers.Default, CoroutineStart.LAZY) { someExpensiveComputation(delay) }
- val two = async(Dispatchers.Default, CoroutineStart.LAZY) { someExpensiveComputation(delay) }
-
- //when
- runBlocking {
- one.await()
- two.await()
- }
- }
-
- //then
- assertTrue(time > delay * 2)
- }
- }
-
- suspend fun someExpensiveComputation(delayInMilliseconds: Long) {
- delay(delayInMilliseconds)
- }
-
-
-}
diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt
deleted file mode 100644
index ff385d0869..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/CoroutineUnitTest.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.baeldung.threadsvscoroutines
-
-import kotlinx.coroutines.*
-import org.junit.jupiter.api.Test
-
-class CoroutineUnitTest {
-
- @Test
- fun whenCreateCoroutineWithLaunchWithoutContext_thenRun() = runBlocking {
-
- val job = launch {
- println("${Thread.currentThread()} has run.")
- }
-
- }
-
- @Test
- fun whenCreateCoroutineWithLaunchWithDefaultContext_thenRun() = runBlocking {
-
- val job = launch(Dispatchers.Default) {
- println("${Thread.currentThread()} has run.")
- }
- }
-
- @Test
- fun whenCreateCoroutineWithLaunchWithUnconfinedContext_thenRun() = runBlocking {
-
- val job = launch(Dispatchers.Unconfined) {
- println("${Thread.currentThread()} has run.")
- }
- }
-
- @Test
- fun whenCreateCoroutineWithLaunchWithDedicatedThread_thenRun() = runBlocking {
-
- val job = launch(newSingleThreadContext("dedicatedThread")) {
- println("${Thread.currentThread()} has run.")
- }
-
- }
-
- @Test
- fun whenCreateAsyncCoroutine_thenRun() = runBlocking {
-
- val deferred = async(Dispatchers.IO) {
- return@async "${Thread.currentThread()} has run."
- }
-
- val result = deferred.await()
- println(result)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt b/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt
deleted file mode 100644
index 9503751fa3..0000000000
--- a/core-kotlin-modules/core-kotlin-concurrency/src/test/kotlin/com/baeldung/threadsvscoroutines/ThreadUnitTest.kt
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.baeldung.threadsvscoroutines
-
-import org.junit.jupiter.api.Test
-import kotlin.concurrent.thread
-
-class ThreadUnitTest {
-
- @Test
- fun whenCreateThread_thenRun() {
-
- val thread = SimpleThread()
- thread.start()
- }
-
- @Test
- fun whenCreateThreadWithRunnable_thenRun() {
-
- val threadWithRunnable = Thread(SimpleRunnable())
- threadWithRunnable.start()
- }
-
- @Test
- fun whenCreateThreadWithSAMConversions_thenRun() {
-
- val thread = Thread {
- println("${Thread.currentThread()} has run.")
- }
- thread.start()
- }
-
- @Test
- fun whenCreateThreadWithMethodExtension_thenRun() {
-
- thread(start = true) {
- println("${Thread.currentThread()} has run.")
- }
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-datastructures/README.md b/core-kotlin-modules/core-kotlin-datastructures/README.md
deleted file mode 100644
index 3b22730a76..0000000000
--- a/core-kotlin-modules/core-kotlin-datastructures/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-## Core Kotlin
-
-This module contains articles about data structures in Kotlin
-
-### Relevant articles:
-[Implementing a Binary Tree in Kotlin](https://www.baeldung.com/kotlin-binary-tree)
diff --git a/core-kotlin-modules/core-kotlin-datastructures/pom.xml b/core-kotlin-modules/core-kotlin-datastructures/pom.xml
deleted file mode 100644
index eae11c17cf..0000000000
--- a/core-kotlin-modules/core-kotlin-datastructures/pom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
- 4.0.0
- core-kotlin-datastructures
- core-kotlin-datastructures
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.junit.platform
- junit-platform-runner
- ${junit.platform.version}
- test
-
-
-
-
- 1.1.1
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt
deleted file mode 100644
index eee10fbd8b..0000000000
--- a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Main.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.binarytree
-
-/**
- * Example of how to use the {@link Node} class.
- *
- */
-fun main(args: Array) {
- val tree = Node(4)
- val keys = arrayOf(8, 15, 21, 3, 7, 2, 5, 10, 2, 3, 4, 6, 11)
- for (key in keys) {
- tree.insert(key)
- }
- val node = tree.find(4)!!
- println("Node with value ${node.key} [left = ${node.left?.key}, right = ${node.right?.key}]")
- println("Delete node with key = 3")
- node.delete(3)
- print("Tree content after the node elimination: ")
- println(tree.visit().joinToString { it.toString() })
-}
diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt b/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt
deleted file mode 100644
index 77bb98f828..0000000000
--- a/core-kotlin-modules/core-kotlin-datastructures/src/main/kotlin/com/baeldung/binarytree/Node.kt
+++ /dev/null
@@ -1,167 +0,0 @@
-package com.baeldung.binarytree
-
-/**
- * An ADT for a binary search tree.
- * Note that this data type is neither immutable nor thread safe.
- */
-class Node(
- var key: Int,
- var left: Node? = null,
- var right: Node? = null) {
-
- /**
- * Return a node with given value. If no such node exists, return null.
- * @param value
- */
- fun find(value: Int): Node? = when {
- this.key > value -> left?.find(value)
- this.key < value -> right?.find(value)
- else -> this
-
- }
-
- /**
- * Insert a given value into the tree.
- * After insertion, the tree should contain a node with the given value.
- * If the tree already contains the given value, nothing is performed.
- * @param value
- */
- fun insert(value: Int) {
- if (value > this.key) {
- if (this.right == null) {
- this.right = Node(value)
- } else {
- this.right?.insert(value)
- }
- } else if (value < this.key) {
- if (this.left == null) {
- this.left = Node(value)
- } else {
- this.left?.insert(value)
- }
- }
- }
-
- /**
- * Delete the value from the given tree. If the tree does not contain the value, the tree remains unchanged.
- * @param value
- */
- fun delete(value: Int) {
- when {
- value > key -> scan(value, this.right, this)
- value < key -> scan(value, this.left, this)
- else -> removeNode(this, null)
- }
- }
-
- /**
- * Scan the tree in the search of the given value.
- * @param value
- * @param node sub-tree that potentially might contain the sought value
- * @param parent node's parent
- */
- private fun scan(value: Int, node: Node?, parent: Node?) {
- if (node == null) {
- System.out.println("value " + value
- + " seems not present in the tree.")
- return
- }
- when {
- value > node.key -> scan(value, node.right, node)
- value < node.key -> scan(value, node.left, node)
- value == node.key -> removeNode(node, parent)
- }
-
- }
-
- /**
- * Remove the node.
- *
- * Removal process depends on how many children the node has.
- *
- * @param node node that is to be removed
- * @param parent parent of the node to be removed
- */
- private fun removeNode(node: Node, parent: Node?) {
- node.left?.let { leftChild ->
- run {
- node.right?.let {
- removeTwoChildNode(node)
- } ?: removeSingleChildNode(node, leftChild)
- }
- } ?: run {
- node.right?.let { rightChild -> removeSingleChildNode(node, rightChild) } ?: removeNoChildNode(node, parent)
- }
-
-
- }
-
- /**
- * Remove the node without children.
- * @param node
- * @param parent
- */
- private fun removeNoChildNode(node: Node, parent: Node?) {
- parent?.let { p ->
- if (node == p.left) {
- p.left = null
- } else if (node == p.right) {
- p.right = null
- }
- } ?: throw IllegalStateException(
- "Can not remove the root node without child nodes")
-
- }
-
- /**
- * Remove a node that has two children.
- *
- * The process of elimination is to find the biggest key in the left sub-tree and replace the key of the
- * node that is to be deleted with that key.
- */
- private fun removeTwoChildNode(node: Node) {
- val leftChild = node.left!!
- leftChild.right?.let {
- val maxParent = findParentOfMaxChild(leftChild)
- maxParent.right?.let {
- node.key = it.key
- maxParent.right = null
- } ?: throw IllegalStateException("Node with max child must have the right child!")
-
- } ?: run {
- node.key = leftChild.key
- node.left = leftChild.left
- }
-
- }
-
- /**
- * Return a node whose right child contains the biggest value in the given sub-tree.
- * Assume that the node n has a non-null right child.
- *
- * @param n
- */
- private fun findParentOfMaxChild(n: Node): Node {
- return n.right?.let { r -> r.right?.let { findParentOfMaxChild(r) } ?: n }
- ?: throw IllegalArgumentException("Right child must be non-null")
-
- }
-
- /**
- * Remove a parent that has only one child.
- * Removal is effectively is just coping the data from the child parent to the parent parent.
- * @param parent Node to be deleted. Assume that it has just one child
- * @param child Assume it is a child of the parent
- */
- private fun removeSingleChildNode(parent: Node, child: Node) {
- parent.key = child.key
- parent.left = child.left
- parent.right = child.right
- }
-
- fun visit(): Array {
- val a = left?.visit() ?: emptyArray()
- val b = right?.visit() ?: emptyArray()
- return a + arrayOf(key) + b
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt b/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt
deleted file mode 100644
index 5a7f7fc50f..0000000000
--- a/core-kotlin-modules/core-kotlin-datastructures/src/test/kotlin/com/binarytree/NodeTest.kt
+++ /dev/null
@@ -1,320 +0,0 @@
-package com.binarytree
-
-import org.junit.After
-import org.junit.Assert.assertEquals
-import org.junit.Assert.assertNull
-import org.junit.Before
-import org.junit.Test
-
-class NodeTest {
-
- @Before
- fun setUp() {
- }
-
- @After
- fun tearDown() {
- }
-
- /**
- * Test suit for finding the node by value
- * Partition the tests as follows:
- * 1. tree depth: 0, 1, > 1
- * 2. pivot depth location: not present, 0, 1, 2, > 2
- */
-
- /**
- * Find the node by value
- * 1. tree depth: 0
- * 2. pivot depth location: not present
- */
- @Test
- fun givenDepthZero_whenPivotNotPresent_thenNull() {
- val n = Node(1)
- assertNull(n.find(2))
- }
-
- /**
- * Find the node by value
- * 1. tree depth: 0
- * 2. pivot depth location: 0
- */
- @Test
- fun givenDepthZero_whenPivotDepthZero_thenReturnNodeItself() {
- val n = Node(1)
- assertEquals(n, n.find(1))
- }
-
- /**
- * Find the node by value
- * 1. tree depth: 1
- * 2. pivot depth location: not present
- */
- @Test
- fun givenDepthOne_whenPivotNotPresent_thenNull() {
- val n = Node(1, Node(0))
- assertNull(n.find(2))
- }
-
- /**
- * Find the node by value
- * 1. tree depth: 1
- * 2. pivot depth location: not present
- */
- @Test
- fun givenDepthOne_whenPivotAtDepthOne_thenSuccess() {
- val n = Node(1, Node(0))
- assertEquals(n.left, n.find(0)
- )
- }
-
- @Test
- fun givenDepthTwo_whenPivotAtDepth2_then_Success() {
- val left = Node(1, Node(0), Node(2))
- val right = Node(5, Node(4), Node(6))
- val n = Node(3, left, right)
- assertEquals(left.left, n.find(0))
- }
-
-
- /**
- * Test suit for inserting a value
- * Partition the test as follows:
- * 1. tree depth: 0, 1, 2, > 2
- * 2. depth to insert: 0, 1, > 1
- * 3. is duplicate: no, yes
- * 4. sub-tree: left, right
- */
- /**
- * Test for inserting a value
- * 1. tree depth: 0
- * 2. depth to insert: 1
- * 3. is duplicate: no
- * 4. sub-tree: right
- */
- @Test
- fun givenTreeDepthZero_whenInsertNoDuplicateToRight_thenAddNode() {
- val n = Node(1)
- n.insert(2)
- assertEquals(1, n.key)
- with(n.right!!) {
- assertEquals(2, key)
- assertNull(left)
- assertNull(right)
- }
- assertNull(n.left)
- }
-
- /**
- * Test for inserting a value
- * 1. tree depth: 0
- * 2. depth to insert: 1
- * 3. is duplicate: no
- * 4. sub-tree: right
- */
- @Test
- fun givenTreeDepthZero_whenInsertNoDuplicateToLeft_thenSuccess() {
- val n = Node(1)
- n.insert(0)
- assertEquals(1, n.key)
- with(n.left!!) {
- assertEquals(0, key)
- assertNull(left)
- assertNull(right)
- }
- assertNull(n.right)
- }
-
- /**
- * Test for inserting a value
- * 1. tree depth: 0
- * 2. depth to insert: 1
- * 3. is duplicate: yes
- */
- @Test
- fun givenTreeDepthZero_whenInsertDuplicate_thenSuccess() {
- val n = Node(1)
- n.insert(1)
- assertEquals(1, n.key)
- assertNull(n.right)
- assertNull(n.left)
- }
-
-
- /**
- * Test suit for inserting a value
- * Partition the test as follows:
- * 1. tree depth: 0, 1, 2, > 2
- * 2. depth to insert: 0, 1, > 1
- * 3. is duplicate: no, yes
- * 4. sub-tree: left, right
- */
- /**
- * Test for inserting a value
- * 1. tree depth: 1
- * 2. depth to insert: 1
- * 3. is duplicate: no
- * 4. sub-tree: right
- */
- @Test
- fun givenTreeDepthOne_whenInsertNoDuplicateToRight_thenSuccess() {
- val n = Node(10, Node(3))
- n.insert(15)
- assertEquals(10, n.key)
- with(n.right!!) {
- assertEquals(15, key)
- assertNull(left)
- assertNull(right)
- }
- with(n.left!!) {
- assertEquals(3, key)
- assertNull(left)
- assertNull(right)
- }
- }
-
- /**
- * Test for inserting a value
- * 1. tree depth: 1
- * 2. depth to insert: 1
- * 3. is duplicate: no
- * 4. sub-tree: left
- */
- @Test
- fun givenTreeDepthOne_whenInsertNoDuplicateToLeft_thenAddNode() {
- val n = Node(10, null, Node(15))
- n.insert(3)
- assertEquals(10, n.key)
- with(n.right!!) {
- assertEquals(15, key)
- assertNull(left)
- assertNull(right)
- }
- with(n.left!!) {
- assertEquals(3, key)
- assertNull(left)
- assertNull(right)
- }
- }
-
- /**
- * Test for inserting a value
- * 1. tree depth: 1
- * 2. depth to insert: 1
- * 3. is duplicate: yes
- */
- @Test
- fun givenTreeDepthOne_whenInsertDuplicate_thenNoChange() {
- val n = Node(10, null, Node(15))
- n.insert(15)
- assertEquals(10, n.key)
- with(n.right!!) {
- assertEquals(15, key)
- assertNull(left)
- assertNull(right)
- }
- assertNull(n.left)
- }
-
- /**
- * Test suit for removal
- * Partition the input as follows:
- * 1. tree depth: 0, 1, 2, > 2
- * 2. value to delete: absent, present
- * 3. # child nodes: 0, 1, 2
- */
- /**
- * Test for removal value
- * 1. tree depth: 0
- * 2. value to delete: absent
- */
- @Test
- fun givenTreeDepthZero_whenValueAbsent_thenNoChange() {
- val n = Node(1)
- n.delete(0)
- assertEquals(1, n.key)
- assertNull(n.left)
- assertNull(n.right)
- }
-
- /**
- * Test for removal
- * 1. tree depth: 1
- * 2. value to delete: absent
- */
- @Test
- fun givenTreeDepthOne_whenValueAbsent_thenNoChange() {
- val n = Node(1, Node(0), Node(2))
- n.delete(3)
- assertEquals(1, n.key)
- assertEquals(2, n.right!!.key)
- with(n.left!!) {
- assertEquals(0, key)
- assertNull(left)
- assertNull(right)
- }
- with(n.right!!) {
- assertNull(left)
- assertNull(right)
- }
- }
-
- /**
- * Test suit for removal
- * 1. tree depth: 1
- * 2. value to delete: present
- * 3. # child nodes: 0
- */
- @Test
- fun givenTreeDepthOne_whenNodeToDeleteHasNoChildren_thenChangeTree() {
- val n = Node(1, Node(0))
- n.delete(0)
- assertEquals(1, n.key)
- assertNull(n.left)
- assertNull(n.right)
- }
-
- /**
- * Test suit for removal
- * 1. tree depth: 2
- * 2. value to delete: present
- * 3. # child nodes: 1
- */
- @Test
- fun givenTreeDepthTwo_whenNodeToDeleteHasOneChild_thenChangeTree() {
- val n = Node(2, Node(0, null, Node(1)), Node(3))
- n.delete(0)
- assertEquals(2, n.key)
- with(n.right!!) {
- assertEquals(3, key)
- assertNull(left)
- assertNull(right)
- }
- with(n.left!!) {
- assertEquals(1, key)
- assertNull(left)
- assertNull(right)
- }
- }
-
- @Test
- fun givenTreeDepthThree_whenNodeToDeleteHasTwoChildren_thenChangeTree() {
- val l = Node(2, Node(1), Node(5, Node(4), Node(6)))
- val r = Node(10, Node(9), Node(11))
- val n = Node(8, l, r)
- n.delete(8)
- assertEquals(6, n.key)
- with(n.left!!) {
- assertEquals(2, key)
- assertEquals(1, left!!.key)
- assertEquals(5, right!!.key)
- assertEquals(4, right!!.left!!.key)
- }
- with(n.right!!) {
- assertEquals(10, key)
- assertEquals(9, left!!.key)
- assertEquals(11, right!!.key)
- }
- }
-
-}
diff --git a/core-kotlin-modules/core-kotlin-date-time/README.md b/core-kotlin-modules/core-kotlin-date-time/README.md
deleted file mode 100644
index a3e358d4e3..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-## Core Kotlin Date and Time
-
-This module contains articles about Kotlin core date/time features.
-
-### Relevant articles:
-[Working with Dates in Kotlin](https://www.baeldung.com/kotlin-dates)
diff --git a/core-kotlin-modules/core-kotlin-date-time/pom.xml b/core-kotlin-modules/core-kotlin-date-time/pom.xml
deleted file mode 100644
index f3cacefc19..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/pom.xml
+++ /dev/null
@@ -1,36 +0,0 @@
-
-
- 4.0.0
- core-kotlin-date-time
- core-kotlin-date-time
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.assertj
- assertj-core
- ${org.assertj.core.version}
- test
-
-
- org.junit.platform
- junit-platform-runner
- ${junit.platform.version}
- test
-
-
-
-
- 1.1.1
- 3.9.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt
deleted file mode 100644
index 922c3a1988..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseDuration.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.Duration
-import java.time.LocalTime
-
-class UseDuration {
-
- fun modifyDates(localTime: LocalTime, duration: Duration): LocalTime {
- return localTime.plus(duration)
- }
-
- fun getDifferenceBetweenDates(localTime1: LocalTime, localTime2: LocalTime): Duration {
- return Duration.between(localTime1, localTime2)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt
deleted file mode 100644
index 81d50a70b2..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDate.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.DayOfWeek
-import java.time.LocalDate
-import java.time.LocalDateTime
-import java.time.temporal.ChronoUnit
-import java.time.temporal.TemporalAdjusters
-
-class UseLocalDate {
-
- fun getLocalDateUsingFactoryOfMethod(year: Int, month: Int, dayOfMonth: Int): LocalDate {
- return LocalDate.of(year, month, dayOfMonth)
- }
-
- fun getLocalDateUsingParseMethod(representation: String): LocalDate {
- return LocalDate.parse(representation)
- }
-
- fun getLocalDateFromClock(): LocalDate {
- return LocalDate.now()
- }
-
- fun getNextDay(localDate: LocalDate): LocalDate {
- return localDate.plusDays(1)
- }
-
- fun getPreviousDay(localDate: LocalDate): LocalDate {
- return localDate.minus(1, ChronoUnit.DAYS)
- }
-
- fun getDayOfWeek(localDate: LocalDate): DayOfWeek {
- return localDate.dayOfWeek
- }
-
- fun getFirstDayOfMonth(): LocalDate {
- return LocalDate.now().with(TemporalAdjusters.firstDayOfMonth())
- }
-
- fun getStartOfDay(localDate: LocalDate): LocalDateTime {
- return localDate.atStartOfDay()
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt
deleted file mode 100644
index 5d0eb6a911..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalDateTime.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.LocalDateTime
-
-class UseLocalDateTime {
-
- fun getLocalDateTimeUsingParseMethod(representation: String): LocalDateTime {
- return LocalDateTime.parse(representation)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt
deleted file mode 100644
index 24402467e8..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseLocalTime.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.LocalTime
-import java.time.temporal.ChronoUnit
-
-class UseLocalTime {
-
- fun getLocalTimeUsingFactoryOfMethod(hour: Int, min: Int, seconds: Int): LocalTime {
- return LocalTime.of(hour, min, seconds)
- }
-
- fun getLocalTimeUsingParseMethod(timeRepresentation: String): LocalTime {
- return LocalTime.parse(timeRepresentation)
- }
-
- fun getLocalTimeFromClock(): LocalTime {
- return LocalTime.now()
- }
-
- fun addAnHour(localTime: LocalTime): LocalTime {
- return localTime.plus(1, ChronoUnit.HOURS)
- }
-
- fun getHourFromLocalTime(localTime: LocalTime): Int {
- return localTime.hour
- }
-
- fun getLocalTimeWithMinuteSetToValue(localTime: LocalTime, minute: Int): LocalTime {
- return localTime.withMinute(minute)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt
deleted file mode 100644
index d15e02eb37..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UsePeriod.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.LocalDate
-import java.time.Period
-
-class UsePeriod {
-
- fun modifyDates(localDate: LocalDate, period: Period): LocalDate {
- return localDate.plus(period)
- }
-
- fun getDifferenceBetweenDates(localDate1: LocalDate, localDate2: LocalDate): Period {
- return Period.between(localDate1, localDate2)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt b/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt
deleted file mode 100644
index e2f3a207c4..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/main/kotlin/com/baeldung/dates/datetime/UseZonedDateTime.kt
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.baeldung.dates.datetime
-
-import java.time.LocalDateTime
-import java.time.ZoneId
-import java.time.ZonedDateTime
-
-class UseZonedDateTime {
-
- fun getZonedDateTime(localDateTime: LocalDateTime, zoneId: ZoneId): ZonedDateTime {
- return ZonedDateTime.of(localDateTime, zoneId)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt
deleted file mode 100644
index af5e08ea2d..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/CreateDateUnitTest.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.baeldung.kotlin.dates
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import java.time.LocalDate
-import java.time.format.DateTimeFormatter
-
-class CreateDateUnitTest {
-
- @Test
- fun givenString_whenDefaultFormat_thenCreated() {
-
- var date = LocalDate.parse("2018-12-31")
-
- assertThat(date).isEqualTo("2018-12-31")
- }
-
- @Test
- fun givenString_whenCustomFormat_thenCreated() {
-
- var formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy")
- var date = LocalDate.parse("31-12-2018", formatter)
-
- assertThat(date).isEqualTo("2018-12-31")
- }
-
- @Test
- fun givenYMD_whenUsingOf_thenCreated() {
- var date = LocalDate.of(2018, 12, 31)
-
- assertThat(date).isEqualTo("2018-12-31")
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt
deleted file mode 100644
index d297f4b6c3..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/ExtractDateUnitTest.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.kotlin.dates
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import java.time.DayOfWeek
-import java.time.LocalDate
-import java.time.Month
-
-class ExtractDateUnitTest {
-
- @Test
- fun givenDate_thenExtractedYMD() {
- var date = LocalDate.parse("2018-12-31")
-
- assertThat(date.year).isEqualTo(2018)
- assertThat(date.month).isEqualTo(Month.DECEMBER)
- assertThat(date.dayOfMonth).isEqualTo(31)
- }
-
- @Test
- fun givenDate_thenExtractedEraDowDoy() {
- var date = LocalDate.parse("2018-12-31")
-
- assertThat(date.era.toString()).isEqualTo("CE")
- assertThat(date.dayOfWeek).isEqualTo(DayOfWeek.MONDAY)
- assertThat(date.dayOfYear).isEqualTo(365)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt
deleted file mode 100644
index f7ca414aee..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/FormatDateUnitTest.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.kotlin.dates
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import java.time.LocalDate
-import java.time.format.DateTimeFormatter
-
-class FormatDateUnitTest {
-
- @Test
- fun givenDate_whenDefaultFormat_thenFormattedString() {
-
- var date = LocalDate.parse("2018-12-31")
-
- assertThat(date.toString()).isEqualTo("2018-12-31")
- }
-
- @Test
- fun givenDate_whenCustomFormat_thenFormattedString() {
-
- var date = LocalDate.parse("2018-12-31")
-
- var formatter = DateTimeFormatter.ofPattern("dd-MMMM-yyyy")
- var formattedDate = date.format(formatter)
-
- assertThat(formattedDate).isEqualTo("31-December-2018")
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt
deleted file mode 100644
index e8ca2971e8..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/PeriodDateUnitTest.kt
+++ /dev/null
@@ -1,48 +0,0 @@
-package com.baeldung.kotlin.dates
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-import java.time.LocalDate
-import java.time.Period
-
-class PeriodDateUnitTest {
-
- @Test
- fun givenYMD_thenCreatePeriod() {
- var period = Period.of(1, 2, 3)
-
- assertThat(period.toString()).isEqualTo("P1Y2M3D")
- }
-
- @Test
- fun givenPeriod_whenAdd_thenModifiedDate() {
- var period = Period.of(1, 2, 3)
-
- var date = LocalDate.of(2018, 6, 25)
- var modifiedDate = date.plus(period)
-
- assertThat(modifiedDate).isEqualTo("2019-08-28")
- }
-
- @Test
- fun givenPeriod_whenSubtracted_thenModifiedDate() {
- var period = Period.of(1, 2, 3)
-
- var date = LocalDate.of(2018, 6, 25)
- var modifiedDate = date.minus(period)
-
- assertThat(modifiedDate).isEqualTo("2017-04-22")
- }
-
- @Test
- fun givenTwoDate_whenUsingBetween_thenDiffOfDates() {
-
- var date1 = LocalDate.parse("2018-06-25")
- var date2 = LocalDate.parse("2018-12-25")
-
- var period = Period.between(date1, date2)
-
- assertThat(period.toString()).isEqualTo("P6M")
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt
deleted file mode 100644
index f3615a527c..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateTimeUnitTest.kt
+++ /dev/null
@@ -1,21 +0,0 @@
-package com.baeldung.kotlin.datetime
-
-import com.baeldung.dates.datetime.UseLocalDateTime
-import org.junit.Assert.assertEquals
-import org.junit.Test
-import java.time.LocalDate
-import java.time.LocalTime
-import java.time.Month
-
-class UseLocalDateTimeUnitTest {
-
- var useLocalDateTime = UseLocalDateTime()
-
- @Test
- fun givenString_whenUsingParse_thenLocalDateTime() {
- assertEquals(LocalDate.of(2016, Month.MAY, 10), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
- .toLocalDate())
- assertEquals(LocalTime.of(6, 30), useLocalDateTime.getLocalDateTimeUsingParseMethod("2016-05-10T06:30")
- .toLocalTime())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt
deleted file mode 100644
index e6353c9dab..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalDateUnitTest.kt
+++ /dev/null
@@ -1,59 +0,0 @@
-package com.baeldung.kotlin.datetime
-
-import com.baeldung.dates.datetime.UseLocalDate
-import org.junit.Assert
-import org.junit.Test
-import java.time.DayOfWeek
-import java.time.LocalDate
-import java.time.LocalDateTime
-
-class UseLocalDateUnitTest {
-
- var useLocalDate = UseLocalDate()
-
- @Test
- fun givenValues_whenUsingFactoryOf_thenLocalDate() {
- Assert.assertEquals("2016-05-10", useLocalDate.getLocalDateUsingFactoryOfMethod(2016, 5, 10)
- .toString())
- }
-
- @Test
- fun givenString_whenUsingParse_thenLocalDate() {
- Assert.assertEquals("2016-05-10", useLocalDate.getLocalDateUsingParseMethod("2016-05-10")
- .toString())
- }
-
- @Test
- fun whenUsingClock_thenLocalDate() {
- Assert.assertEquals(LocalDate.now(), useLocalDate.getLocalDateFromClock())
- }
-
- @Test
- fun givenDate_whenUsingPlus_thenNextDay() {
- Assert.assertEquals(LocalDate.now()
- .plusDays(1), useLocalDate.getNextDay(LocalDate.now()))
- }
-
- @Test
- fun givenDate_whenUsingMinus_thenPreviousDay() {
- Assert.assertEquals(LocalDate.now()
- .minusDays(1), useLocalDate.getPreviousDay(LocalDate.now()))
- }
-
- @Test
- fun givenToday_whenUsingGetDayOfWeek_thenDayOfWeek() {
- Assert.assertEquals(DayOfWeek.SUNDAY, useLocalDate.getDayOfWeek(LocalDate.parse("2016-05-22")))
- }
-
- @Test
- fun givenToday_whenUsingWithTemporalAdjuster_thenFirstDayOfMonth() {
- Assert.assertEquals(1, useLocalDate.getFirstDayOfMonth()
- .dayOfMonth.toLong())
- }
-
- @Test
- fun givenLocalDate_whenUsingAtStartOfDay_thenReturnMidnight() {
- Assert.assertEquals(LocalDateTime.parse("2016-05-22T00:00:00"), useLocalDate.getStartOfDay(LocalDate.parse("2016-05-22")))
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt
deleted file mode 100644
index 1afe03ca48..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseLocalTimeUnitTest.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baeldung.kotlin.datetime
-
-import com.baeldung.dates.datetime.UseLocalTime
-import org.junit.Assert
-import org.junit.Test
-import java.time.LocalTime
-
-class UseLocalTimeUnitTest {
-
- internal var useLocalTime = UseLocalTime()
-
- @Test
- fun givenValues_whenUsingFactoryOf_thenLocalTime() {
- Assert.assertEquals("07:07:07", useLocalTime.getLocalTimeUsingFactoryOfMethod(7, 7, 7).toString())
- }
-
- @Test
- fun givenString_whenUsingParse_thenLocalTime() {
- Assert.assertEquals("06:30", useLocalTime.getLocalTimeUsingParseMethod("06:30").toString())
- }
-
- @Test
- fun givenTime_whenAddHour_thenLocalTime() {
- Assert.assertEquals("07:30", useLocalTime.addAnHour(LocalTime.of(6, 30)).toString())
- }
-
- @Test
- fun getHourFromLocalTime() {
- Assert.assertEquals(1, useLocalTime.getHourFromLocalTime(LocalTime.of(1, 1)).toLong())
- }
-
- @Test
- fun getLocalTimeWithMinuteSetToValue() {
- Assert.assertEquals(LocalTime.of(10, 20), useLocalTime.getLocalTimeWithMinuteSetToValue(LocalTime.of(10, 10), 20))
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt
deleted file mode 100644
index 36e1e5533a..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UsePeriodUnitTest.kt
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.baeldung.kotlin.datetime
-
-import com.baeldung.dates.datetime.UsePeriod
-import org.junit.Assert
-import org.junit.Test
-import java.time.LocalDate
-import java.time.Period
-
-class UsePeriodUnitTest {
-
- var usingPeriod = UsePeriod()
-
- @Test
- fun givenPeriodAndLocalDate_thenCalculateModifiedDate() {
- val period = Period.ofDays(1)
- val localDate = LocalDate.parse("2007-05-10")
- Assert.assertEquals(localDate.plusDays(1), usingPeriod.modifyDates(localDate, period))
- }
-
- @Test
- fun givenDates_thenGetPeriod() {
- val localDate1 = LocalDate.parse("2007-05-10")
- val localDate2 = LocalDate.parse("2007-05-15")
-
- Assert.assertEquals(Period.ofDays(5), usingPeriod.getDifferenceBetweenDates(localDate1, localDate2))
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt b/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt
deleted file mode 100644
index aa2cdaa4f3..0000000000
--- a/core-kotlin-modules/core-kotlin-date-time/src/test/kotlin/com/baeldung/dates/datetime/UseZonedDateTimeUnitTest.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.kotlin.datetime
-
-import com.baeldung.dates.datetime.UseZonedDateTime
-import org.junit.Assert
-import org.junit.Test
-import java.time.LocalDateTime
-import java.time.ZoneId
-
-class UseZonedDateTimeUnitTest {
-
- internal var zonedDateTime = UseZonedDateTime()
-
- @Test
- fun givenZoneId_thenZonedDateTime() {
- val zoneId = ZoneId.of("Europe/Paris")
- val zonedDatetime = zonedDateTime.getZonedDateTime(LocalDateTime.parse("2016-05-20T06:30"), zoneId)
- Assert.assertEquals(zoneId, ZoneId.from(zonedDatetime))
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/README.md b/core-kotlin-modules/core-kotlin-design-patterns/README.md
deleted file mode 100644
index 4bdc164a47..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/README.md
+++ /dev/null
@@ -1,6 +0,0 @@
-## Core Kotlin Design Patterns
-
-This module contains articles about design patterns in Kotlin
-
-### Relevant articles:
-- [Creational Design Patterns in Kotlin: Builder](https://www.baeldung.com/kotlin-builder-pattern)
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/pom.xml b/core-kotlin-modules/core-kotlin-design-patterns/pom.xml
deleted file mode 100644
index c112602bc2..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/pom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
- 4.0.0
- core-kotlin-design-patterns
- core-kotlin-design-patterns
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.junit.platform
- junit-platform-runner
- ${junit.platform.version}
- test
-
-
-
-
- 1.1.1
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt
deleted file mode 100644
index 3a8a4b9857..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrder.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.baeldung.builder
-
-class FoodOrder private constructor(
- val bread: String?,
- val condiments: String?,
- val meat: String?,
- val fish: String?
-) {
- data class Builder(
- var bread: String? = null,
- var condiments: String? = null,
- var meat: String? = null,
- var fish: String? = null) {
-
- fun bread(bread: String) = apply { this.bread = bread }
- fun condiments(condiments: String) = apply { this.condiments = condiments }
- fun meat(meat: String) = apply { this.meat = meat }
- fun fish(fish: String) = apply { this.fish = fish }
- fun build() = FoodOrder(bread, condiments, meat, fish)
- }
-}
-
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt
deleted file mode 100644
index 0a68832b00..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderApply.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.builder
-
-class FoodOrderApply {
- var bread: String? = null
- var condiments: String? = null
- var meat: String? = null
- var fish: String? = null
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt
deleted file mode 100644
index 0e4219b40e..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/FoodOrderNamed.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.baeldung.builder
-
-data class FoodOrderNamed(
- val bread: String? = null,
- val condiments: String? = null,
- val meat: String? = null,
- val fish: String? = null)
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt
deleted file mode 100644
index cc348e3fbf..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/src/main/kotlin/com/baeldung/builder/Main.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.baeldung.builder
-
-fun main(args: Array) {
- FoodOrder.Builder()
- .bread("bread")
- .condiments("condiments")
- .meat("meat")
- .fish("bread").let { println(it) }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt b/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt
deleted file mode 100644
index a6687b6e0a..0000000000
--- a/core-kotlin-modules/core-kotlin-design-patterns/src/test/kotlin/com/baeldung/builder/BuilderPatternUnitTest.kt
+++ /dev/null
@@ -1,140 +0,0 @@
-package com.baeldung.builder
-
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Test
-
-internal class BuilderPatternUnitTest {
-
- @Test
- fun whenBuildingFoodOrderSettingValues_thenFieldsNotNull() {
-
- val foodOrder = FoodOrder.Builder()
- .bread("white bread")
- .meat("bacon")
- .fish("salmon")
- .condiments("olive oil")
- .build()
-
- Assertions.assertNotNull(foodOrder.bread)
- Assertions.assertNotNull(foodOrder.meat)
- Assertions.assertNotNull(foodOrder.condiments)
- Assertions.assertNotNull(foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderSettingValues_thenFieldsContainsValues() {
-
- val foodOrder = FoodOrder.Builder()
- .bread("white bread")
- .meat("bacon")
- .fish("salmon")
- .condiments("olive oil")
- .build()
-
- Assertions.assertEquals("white bread", foodOrder.bread)
- Assertions.assertEquals("bacon", foodOrder.meat)
- Assertions.assertEquals("olive oil", foodOrder.condiments)
- Assertions.assertEquals("salmon", foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderWithoutSettingValues_thenFieldsNull() {
-
- val foodOrder = FoodOrder.Builder()
- .build()
-
- Assertions.assertNull(foodOrder.bread)
- Assertions.assertNull(foodOrder.meat)
- Assertions.assertNull(foodOrder.condiments)
- Assertions.assertNull(foodOrder.fish)
- }
-
-
- @Test
- fun whenBuildingFoodOrderNamedSettingValues_thenFieldsNotNull() {
-
- val foodOrder = FoodOrderNamed(
- meat = "bacon",
- fish = "salmon",
- condiments = "olive oil",
- bread = "white bread"
- )
-
- Assertions.assertNotNull(foodOrder.bread)
- Assertions.assertNotNull(foodOrder.meat)
- Assertions.assertNotNull(foodOrder.condiments)
- Assertions.assertNotNull(foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderNamedSettingValues_thenFieldsContainsValues() {
-
- val foodOrder = FoodOrderNamed(
- meat = "bacon",
- fish = "salmon",
- condiments = "olive oil",
- bread = "white bread"
- )
-
- Assertions.assertEquals("white bread", foodOrder.bread)
- Assertions.assertEquals("bacon", foodOrder.meat)
- Assertions.assertEquals("olive oil", foodOrder.condiments)
- Assertions.assertEquals("salmon", foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderNamedWithoutSettingValues_thenFieldsNull() {
-
- val foodOrder = FoodOrderNamed()
-
- Assertions.assertNull(foodOrder.bread)
- Assertions.assertNull(foodOrder.meat)
- Assertions.assertNull(foodOrder.condiments)
- Assertions.assertNull(foodOrder.fish)
- }
-
-
- @Test
- fun whenBuildingFoodOrderApplySettingValues_thenFieldsNotNull() {
-
- val foodOrder = FoodOrderApply().apply {
- meat = "bacon"
- fish = "salmon"
- condiments = "olive oil"
- bread = "white bread"
- }
-
- Assertions.assertNotNull(foodOrder.bread)
- Assertions.assertNotNull(foodOrder.meat)
- Assertions.assertNotNull(foodOrder.condiments)
- Assertions.assertNotNull(foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderApplySettingValues_thenFieldsContainsValues() {
-
- val foodOrder = FoodOrderApply().apply {
- meat = "bacon"
- fish = "salmon"
- condiments = "olive oil"
- bread = "white bread"
- }
-
- Assertions.assertEquals("white bread", foodOrder.bread)
- Assertions.assertEquals("bacon", foodOrder.meat)
- Assertions.assertEquals("olive oil", foodOrder.condiments)
- Assertions.assertEquals("salmon", foodOrder.fish)
- }
-
- @Test
- fun whenBuildingFoodOrderApplyWithoutSettingValues_thenFieldsNull() {
-
- val foodOrder = FoodOrderApply()
-
- Assertions.assertNull(foodOrder.bread)
- Assertions.assertNull(foodOrder.meat)
- Assertions.assertNull(foodOrder.condiments)
- Assertions.assertNull(foodOrder.fish)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/README.md b/core-kotlin-modules/core-kotlin-io/README.md
deleted file mode 100644
index 89f9534d4b..0000000000
--- a/core-kotlin-modules/core-kotlin-io/README.md
+++ /dev/null
@@ -1,9 +0,0 @@
-## Core Kotlin I/O
-
-This module contains articles about core Kotlin I/O.
-
-### Relevant articles:
-- [InputStream to String in Kotlin](https://www.baeldung.com/kotlin-inputstream-to-string)
-- [Console I/O in Kotlin](https://www.baeldung.com/kotlin-console-io)
-- [Reading from a File in Kotlin](https://www.baeldung.com/kotlin-read-file)
-- [Writing to a File in Kotlin](https://www.baeldung.com/kotlin-write-file)
diff --git a/core-kotlin-modules/core-kotlin-io/pom.xml b/core-kotlin-modules/core-kotlin-io/pom.xml
deleted file mode 100644
index 9443cd0d5b..0000000000
--- a/core-kotlin-modules/core-kotlin-io/pom.xml
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- 4.0.0
- core-kotlin-io
- core-kotlin-io
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.jetbrains.kotlin
- kotlin-stdlib-jdk8
- ${kotlin.version}
-
-
- org.junit.jupiter
- junit-jupiter
- ${junit-jupiter.version}
- test
-
-
- org.mockito
- mockito-core
- ${mockito.version}
- test
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
- org.jetbrains.kotlin
- kotlin-test
- ${kotlin.version}
- test
-
-
-
-
- 5.4.2
- 2.27.0
- 3.10.0
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt
deleted file mode 100644
index 886a3fc51e..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileReader.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baeldung.filesystem
-
-import java.io.File
-
-class FileReader {
-
- fun readFileLineByLineUsingForEachLine(fileName: String) = File(fileName).forEachLine { println(it) }
-
- fun readFileAsLinesUsingUseLines(fileName: String): List = File(fileName)
- .useLines { it.toList() }
-
- fun readFileAsLinesUsingBufferedReader(fileName: String): List = File(fileName).bufferedReader().readLines()
-
- fun readFileAsLinesUsingReadLines(fileName: String): List = File(fileName).readLines()
-
- fun readFileAsTextUsingInputStream(fileName: String) =
- File(fileName).inputStream().readBytes().toString(Charsets.UTF_8)
-
- fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8)
-
- fun readFileUsingGetResource(fileName: String) = this::class.java.getResource(fileName).readText(Charsets.UTF_8)
-
- fun readFileAsLinesUsingGetResourceAsStream(fileName: String) = this::class.java.getResourceAsStream(fileName).bufferedReader().readLines()
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt
deleted file mode 100644
index 6dc9b95f1f..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/filesystem/FileWriter.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.filesystem
-
-import java.io.File
-
-class FileWriter {
-
- fun writeFileUsingPrintWriter(fileName: String, fileContent: String) =
- File(fileName).printWriter().use { out -> out.print(fileContent) }
-
- fun writeFileUsingBufferedWriter(fileName: String, fileContent: String) =
- File(fileName).bufferedWriter().use { out -> out.write(fileContent) }
-
- fun writeFileDirectly(fileName: String, fileContent: String) =
- File(fileName).writeText(fileContent)
-
- fun writeFileDirectlyAsBytes(fileName: String, fileContent: String) =
- File(fileName).writeBytes(fileContent.toByteArray())
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt b/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt
deleted file mode 100644
index e94a2e84ee..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/main/kotlin/com/baeldung/inputstream/InputStreamExtension.kt
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.baeldung.inputstream
-
-import java.io.InputStream
-
-fun InputStream.readUpToChar(stopChar: Char): String {
- val stringBuilder = StringBuilder()
- var currentChar = this.read().toChar()
- while (currentChar != stopChar) {
- stringBuilder.append(currentChar)
- currentChar = this.read().toChar()
- if (this.available() <= 0) {
- stringBuilder.append(currentChar)
- break
- }
- }
- return stringBuilder.toString()
-}
-
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt
deleted file mode 100644
index c73096fce6..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt
+++ /dev/null
@@ -1,79 +0,0 @@
-package com.baeldung.console
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.AfterEach
-import org.junit.jupiter.api.Test
-import org.mockito.Mockito.`when`
-import org.mockito.Mockito.mock
-import java.io.BufferedReader
-import java.io.ByteArrayInputStream
-import java.io.ByteArrayOutputStream
-import java.io.Console
-import java.io.InputStreamReader
-import java.io.PrintStream
-import java.util.*
-
-
-class ConsoleIOUnitTest {
-
- @Test
- fun givenText_whenPrint_thenPrintText() {
- val expectedTest = "Hello from Kotlin"
- val out = ByteArrayOutputStream()
- System.setOut(PrintStream(out))
-
- print(expectedTest)
- out.flush()
- val printedText = String(out.toByteArray())
-
- assertThat(printedText).isEqualTo(expectedTest)
- }
-
- @Test
- fun givenInput_whenRead_thenReadText() {
- val expectedTest = "Hello from Kotlin"
- val input = ByteArrayInputStream(expectedTest.toByteArray())
- System.setIn(input)
-
- val readText = readLine()
-
- assertThat(readText).isEqualTo(expectedTest)
- }
-
- @Test
- fun givenInput_whenReadWithScanner_thenReadText() {
- val expectedTest = "Hello from Kotlin"
- val scanner = Scanner(ByteArrayInputStream(expectedTest.toByteArray()))
-
- val readText = scanner.nextLine()
-
- assertThat(readText).isEqualTo(expectedTest)
- }
-
- @Test
- fun givenInput_whenReadWithBufferedReader_thenReadText() {
- val expectedTest = "Hello from Kotlin"
- val reader = BufferedReader(InputStreamReader(ByteArrayInputStream(expectedTest.toByteArray())))
-
- val readText = reader.readLine()
-
- assertThat(readText).isEqualTo(expectedTest)
- }
-
- @Test
- fun givenInput_whenReadWithConsole_thenReadText() {
- val expectedTest = "Hello from Kotlin"
- val console = mock(Console::class.java)
- `when`(console.readLine()).thenReturn(expectedTest)
-
- val readText = console.readLine()
-
- assertThat(readText).isEqualTo(expectedTest)
- }
-
- @AfterEach
- fun resetIO() {
- System.setOut(System.out)
- System.setIn(System.`in`)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt
deleted file mode 100644
index ad541c446e..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileReaderTest.kt
+++ /dev/null
@@ -1,67 +0,0 @@
-package com.baeldung.filesystem
-
-import org.junit.jupiter.api.Test
-import kotlin.test.assertTrue
-
-internal class FileReaderTest {
-
- private val fileName = "src/test/resources/Kotlin.in"
-
- private val fileReader = FileReader()
-
- @Test
- fun whenReadFileLineByLineUsingForEachLine_thenCorrect() {
- fileReader.readFileLineByLineUsingForEachLine(fileName)
- }
-
- @Test
- fun whenReadFileAsLinesUsingUseLines_thenCorrect() {
- val lines = fileReader.readFileAsLinesUsingUseLines(fileName)
-
- assertTrue { lines.contains("1. Concise") }
- }
-
- @Test
- fun whenReadFileAsLinesUsingBufferedReader_thenCorrect() {
- val lines = fileReader.readFileAsLinesUsingBufferedReader(fileName)
-
- assertTrue { lines.contains("2. Safe") }
- }
-
- @Test
- fun whenReadFileAsLinesUsingReadLines_thenCorrect() {
- val lines = fileReader.readFileAsLinesUsingReadLines(fileName)
-
- assertTrue { lines.contains("3. Interoperable") }
- }
-
- @Test
- fun whenReadFileAsTextUsingInputStream_thenCorrect() {
- val text = fileReader.readFileAsTextUsingInputStream(fileName)
-
- assertTrue { text.contains("4. Tool-friendly") }
- }
-
- @Test
- fun whenReadDirectlyAsText_thenCorrect() {
- val text = fileReader.readFileDirectlyAsText(fileName)
-
- assertTrue { text.contains("Hello to Kotlin") }
- }
-
- @Test
- fun whenReadFileAsTextUsingGetResource_thenCorrect() {
- val text = fileReader.readFileUsingGetResource("/Kotlin.in")
-
- assertTrue { text.contains("1. Concise") }
- }
-
- @Test
- fun whenReadFileUsingGetResourceAsStream_thenCorrect() {
- val lines = fileReader.readFileAsLinesUsingGetResourceAsStream("/Kotlin.in")
-
- assertTrue { lines.contains("3. Interoperable") }
- }
-
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt
deleted file mode 100644
index 91c66a4fee..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/filesystem/FileWriterTest.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.filesystem
-
-import org.junit.jupiter.api.Test
-import java.io.File
-import kotlin.test.assertEquals
-
-internal class FileWriterTest {
-
- private val fileName = "src/test/resources/Kotlin.out"
-
- private val fileContent = "Kotlin\nConcise, Safe, Interoperable, Tool-friendly"
-
- private val fileWriter = FileWriter()
-
- @Test
- fun whenWrittenWithPrintWriter_thenCorrect() {
- fileWriter.writeFileUsingPrintWriter(fileName, fileContent)
-
- assertEquals(fileContent, File(fileName).readText())
- }
-
- @Test
- fun whenWrittenWithBufferedWriter_thenCorrect() {
- fileWriter.writeFileUsingBufferedWriter(fileName, fileContent)
-
- assertEquals(fileContent, File(fileName).readText())
- }
-
- @Test
- fun whenWrittenDirectly_thenCorrect() {
- fileWriter.writeFileDirectly(fileName, fileContent)
-
- assertEquals(fileContent, File(fileName).readText())
- }
-
- @Test
- fun whenWrittenDirectlyAsBytes_thenCorrect() {
- fileWriter.writeFileDirectlyAsBytes(fileName, fileContent)
-
- assertEquals(fileContent, File(fileName).readText())
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt b/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt
deleted file mode 100644
index a0eb26b762..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/kotlin/com/baeldung/inputstream/InputStreamToStringTest.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.baeldung.inputstream
-
-import kotlinx.io.core.use
-import org.junit.Test
-import java.io.BufferedReader
-import java.io.File
-import kotlin.test.assertEquals
-
-class InputStreamToStringTest {
-
- private val fileName = "src/test/resources/inputstream2string.txt"
- private val endOfLine = System.lineSeparator()
- private val fileFullContent = "Computer programming can be a hassle$endOfLine" +
- "It's like trying to take a defended castle"
-
- @Test
- fun whenReadFileWithBufferedReader_thenFullFileContentIsReadAsString() {
- val file = File(fileName)
- val inputStream = file.inputStream()
- val content = inputStream.bufferedReader().use(BufferedReader::readText)
- assertEquals(fileFullContent, content)
- }
-
- @Test
- fun whenReadFileWithBufferedReaderReadText_thenFullFileContentIsReadAsString() {
- val file = File(fileName)
- val inputStream = file.inputStream()
- val reader = BufferedReader(inputStream.reader())
- var content: String
- try {
- content = reader.readText()
- } finally {
- reader.close()
- }
- assertEquals(fileFullContent, content)
- }
-
- @Test
- fun whenReadFileWithBufferedReaderManually_thenFullFileContentIsReadAsString() {
- val file = File(fileName)
- val inputStream = file.inputStream()
- val reader = BufferedReader(inputStream.reader())
- val content = StringBuilder()
- try {
- var line = reader.readLine()
- while (line != null) {
- content.append(line)
- line = reader.readLine()
- }
- } finally {
- reader.close()
- }
- assertEquals(fileFullContent.replace(endOfLine, ""), content.toString())
-
- }
-
- @Test
- fun whenReadFileUpToStopChar_thenPartBeforeStopCharIsReadAsString() {
- val file = File(fileName)
- val inputStream = file.inputStream()
- val content = inputStream.use { it.readUpToChar(' ') }
- assertEquals("Computer", content)
- }
-
- @Test
- fun whenReadFileWithoutContainingStopChar_thenFullFileContentIsReadAsString() {
- val file = File(fileName)
- val inputStream = file.inputStream()
- val content = inputStream.use { it.readUpToChar('-') }
- assertEquals(fileFullContent, content)
- }
-
-}
-
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in b/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in
deleted file mode 100644
index d140d4429e..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.in
+++ /dev/null
@@ -1,5 +0,0 @@
-Hello to Kotlin. Its:
-1. Concise
-2. Safe
-3. Interoperable
-4. Tool-friendly
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out b/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out
deleted file mode 100644
index 63d15d2528..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/resources/Kotlin.out
+++ /dev/null
@@ -1,2 +0,0 @@
-Kotlin
-Concise, Safe, Interoperable, Tool-friendly
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt b/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt
deleted file mode 100644
index 40ef9fc5f3..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/resources/inputstream2string.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-Computer programming can be a hassle
-It's like trying to take a defended castle
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
deleted file mode 100644
index ca6ee9cea8..0000000000
--- a/core-kotlin-modules/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
+++ /dev/null
@@ -1 +0,0 @@
-mock-maker-inline
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/README.md b/core-kotlin-modules/core-kotlin-lang-2/README.md
deleted file mode 100644
index e7f232856b..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/README.md
+++ /dev/null
@@ -1,16 +0,0 @@
-## Core Kotlin Lang
-
-This module contains articles about core features in the Kotlin language.
-
-### Relevant articles:
-- [Kotlin return, break, continue Keywords](https://www.baeldung.com/kotlin-return-break-continue)
-- [Infix Functions in Kotlin](https://www.baeldung.com/kotlin-infix-functions)
-- [Lambda Expressions in Kotlin](https://www.baeldung.com/kotlin-lambda-expressions)
-- [Creating Java static final Equivalents in Kotlin](https://www.baeldung.com/kotlin-java-static-final)
-- [Lazy Initialization in Kotlin](https://www.baeldung.com/kotlin-lazy-initialization)
-- [Comprehensive Guide to Null Safety in Kotlin](https://www.baeldung.com/kotlin-null-safety)
-- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
-- [If-Else Expression in Kotlin](https://www.baeldung.com/kotlin/if-else-expression)
-- [Checking Whether a lateinit var Is Initialized in Kotlin](https://www.baeldung.com/kotlin/checking-lateinit)
-- [Not-Null Assertion (!!) Operator in Kotlin](https://www.baeldung.com/kotlin/not-null-assertion)
-- [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang)
diff --git a/core-kotlin-modules/core-kotlin-lang-2/pom.xml b/core-kotlin-modules/core-kotlin-lang-2/pom.xml
deleted file mode 100644
index 753147728d..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/pom.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- 4.0.0
- core-kotlin-lang-2
- core-kotlin-lang-2
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java b/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java
deleted file mode 100644
index 273749e17e..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/main/java/com/baeldung/lazy/ClassWithHeavyInitialization.java
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.baeldung.lazy;
-
-public class ClassWithHeavyInitialization {
- private ClassWithHeavyInitialization() {
- }
-
- private static class LazyHolder {
- public static final ClassWithHeavyInitialization INSTANCE = new ClassWithHeavyInitialization();
- }
-
- public static ClassWithHeavyInitialization getInstance() {
- return LazyHolder.INSTANCE;
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt
deleted file mode 100644
index f4e42a4f4f..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExample.kt
+++ /dev/null
@@ -1,86 +0,0 @@
-package com.baeldung.ifelseexpression
-
-fun ifStatementUsage(): String {
- val number = 15
-
- if (number > 0) {
- return "Positive number"
- }
- return "Positive number not found"
-}
-
-fun ifElseStatementUsage(): String {
- val number = -50
-
- if (number > 0) {
- return "Positive number"
- } else {
- return "Negative number"
- }
-}
-
-fun ifElseExpressionUsage(): String {
- val number = -50
-
- val result = if (number > 0) {
- "Positive number"
- } else {
- "Negative number"
- }
- return result
-}
-
-fun ifElseExpressionSingleLineUsage(): String {
- val number = -50
- val result = if (number > 0) "Positive number" else "Negative number"
-
- return result
-}
-
-fun ifElseMultipleExpressionUsage(): Int {
- val x = 24
- val y = 73
-
- val result = if (x > y) {
- println("$x is greater than $y")
- x
- } else {
- println("$x is less than or equal to $y")
- y
- }
- return result
-}
-
-fun ifElseLadderExpressionUsage(): String {
- val number = 60
-
- val result = if (number < 0) {
- "Negative number"
- } else if (number in 0..9) {
- "Single digit number"
- } else if (number in 10..99) {
- "Double digit number"
- } else {
- "Number has more digits"
- }
- return result
-}
-
-fun ifElseNestedExpressionUsage(): Int {
- val x = 37
- val y = 89
- val z = 6
-
- val result = if (x > y) {
- if (x > z)
- x
- else
- z
- } else {
- if (y > z)
- y
- else
- z
- }
- return result
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt
deleted file mode 100644
index f35f9cdac2..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/lambda/Lambda.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.baeldung.lambda
-
-fun inferredType(input: Int): Int {
- val square = { number: Int -> number * number }
-
- return square(input)
-}
-
-fun intToBiggerString(argument: Int): String {
-
- val magnitude100String = { input: Int ->
- val magnitude = input * 100
- magnitude.toString()
- }
-
- return magnitude100String(argument)
-}
-
-fun manyLambda(nums: Array): List {
- val newList = nums.map { intToBiggerString(it) }
-
- return newList
-}
-
-fun empty() {
- val noReturn: (Int) -> Unit = { num -> println(num) }
-
- noReturn(5)
-}
-
-fun invokeLambda(lambda: (Double) -> Boolean): Boolean {
- return lambda(4.329)
-}
-
-fun extendString(arg: String, num: Int): String {
- val another: String.(Int) -> String = { this + it }
-
- return arg.another(num)
-}
-
-fun getCalculationLambda(): (Int) -> Any {
- val calculateGrade = { grade: Int ->
- when (grade) {
- in 0..40 -> "Fail"
- in 41..70 -> "Pass"
- in 71..100 -> "Distinction"
- else -> false
- }
- }
-
- return calculateGrade
-}
-
-fun getCalculationLambdaWithReturn(): (Int) -> String {
- val calculateGrade: Int.() -> String = lambda@{
- if (this < 0 || this > 100) {
- return@lambda "Error"
- } else if (this < 40) {
- return@lambda "Fail"
- } else if (this < 70) {
- return@lambda "Pass"
- }
-
- "Distinction"
- }
-
- return calculateGrade
-}
-
-fun getCalculationAnonymousFunction(): (Int) -> String {
- val calculateGrade = fun(grade: Int): String {
- if (grade < 0 || grade > 100) {
- return "Error"
- } else if (grade < 40) {
- return "Fail"
- } else if (grade < 70) {
- return "Pass"
- }
-
- return "Distinction"
- }
-
- return calculateGrade
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt b/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt
deleted file mode 100644
index 37ad8c65e2..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/main/kotlin/com/baeldung/scope/ScopeFunctions.kt
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.baeldung.scope
-
-data class Student(var studentId: String = "", var name: String = "", var surname: String = "") {
-}
-
-data class Teacher(var teacherId: Int = 0, var name: String = "", var surname: String = "") {
- fun setId(anId: Int): Teacher = apply { teacherId = anId }
- fun setName(aName: String): Teacher = apply { name = aName }
- fun setSurname(aSurname: String): Teacher = apply { surname = aSurname }
-}
-
-data class Headers(val headerInfo: String)
-
-data class Response(val headers: Headers)
-
-data class RestClient(val url: String) {
- fun getResponse() = Response(Headers("some header info"))
-}
-
-data class BankAccount(val id: Int) {
- fun checkAuthorization(username: String) = Unit
- fun addPayee(payee: String) = Unit
- fun makePayment(paymentDetails: String) = Unit
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java b/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java
deleted file mode 100644
index 01c87d9543..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/java/com/baeldung/lazy/LazyJavaUnitTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.baeldung.lazy;
-
-import org.junit.Test;
-
-import static junit.framework.TestCase.assertTrue;
-
-public class LazyJavaUnitTest {
-
- @Test
- public void giveHeavyClass_whenInitLazy_thenShouldReturnInstanceOnFirstCall() {
- //when
- ClassWithHeavyInitialization classWithHeavyInitialization = ClassWithHeavyInitialization.getInstance();
- ClassWithHeavyInitialization classWithHeavyInitialization2 = ClassWithHeavyInitialization.getInstance();
-
- //then
- assertTrue(classWithHeavyInitialization == classWithHeavyInitialization2);
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt
deleted file mode 100644
index d9bf433208..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/ConstantUnitTest.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baeldung.constant
-
-import org.junit.jupiter.api.Test
-import kotlin.test.assertEquals
-
-class ConstantUnitTest {
-
- @Test
- fun givenConstant_whenCompareWithActualValue_thenReturnTrue() {
- assertEquals(10, TestKotlinConstantObject.COMPILE_TIME_CONST)
- assertEquals(30, TestKotlinConstantObject.RUN_TIME_CONST)
- assertEquals(20, TestKotlinConstantObject.JAVA_STATIC_FINAL_FIELD)
-
- assertEquals(40, TestKotlinConstantClass.COMPANION_OBJECT_NUMBER)
- }
-}
-
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt
deleted file mode 100644
index 3c4d4db220..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantClass.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.constant
-
-
-class TestKotlinConstantClass {
- companion object {
- const val COMPANION_OBJECT_NUMBER = 40
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt
deleted file mode 100644
index a6951b4481..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/constant/TestKotlinConstantObject.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.baeldung.constant
-
-
-object TestKotlinConstantObject {
- const val COMPILE_TIME_CONST = 10
-
- val RUN_TIME_CONST: Int
-
- @JvmField
- val JAVA_STATIC_FINAL_FIELD = 20
-
- init {
- RUN_TIME_CONST = TestKotlinConstantObject.COMPILE_TIME_CONST + 20;
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt
deleted file mode 100644
index 266e41e07b..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/ifelseexpression/IfElseExpressionExampleTest.kt
+++ /dev/null
@@ -1,43 +0,0 @@
-package com.baeldung.ifelseexpression
-
-import org.junit.jupiter.api.Test
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Assertions.assertNotEquals
-
-class IfElseExpressionExampleTest {
-
- @Test
- fun givenNumber_whenIfStatementCalled_thenReturnsString() {
- assertEquals("Positive number", ifStatementUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseStatementCalled_thenReturnsString() {
- assertEquals("Negative number", ifElseStatementUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseExpressionCalled_thenReturnsString() {
- assertEquals("Negative number", ifElseExpressionUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseExpressionSingleLineCalled_thenReturnsString() {
- assertEquals("Negative number", ifElseExpressionSingleLineUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseMultipleExpressionCalled_thenReturnsNumber() {
- assertEquals(73, ifElseMultipleExpressionUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseLadderExpressionCalled_thenReturnsString() {
- assertEquals("Double digit number", ifElseLadderExpressionUsage())
- }
-
- @Test
- fun givenNumber_whenIfElseNestedExpressionCalled_thenReturnsNumber() {
- assertEquals(89, ifElseNestedExpressionUsage())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt
deleted file mode 100644
index 0b09d34013..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/infixfunctions/InfixFunctionsTest.kt
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.baeldung.infixfunctions
-
-import org.junit.Assert
-import org.junit.Test
-
-class InfixFunctionsTest {
- @Test
- fun testColours() {
- val color = 0x123456
- val red = (color and 0xff0000) shr 16
- val green = (color and 0x00ff00) shr 8
- val blue = (color and 0x0000ff) shr 0
-
- Assert.assertEquals(0x12, red)
- Assert.assertEquals(0x34, green)
- Assert.assertEquals(0x56, blue)
- }
-
- @Test
- fun testNewAssertions() {
- class Assertion(private val target: T) {
- infix fun isEqualTo(other: T) {
- Assert.assertEquals(other, target)
- }
-
- infix fun isDifferentFrom(other: T) {
- Assert.assertNotEquals(other, target)
- }
- }
-
- val result = Assertion(5)
-
- result isEqualTo 5
-
- // The following two lines are expected to fail
- // result isEqualTo 6
- // result isDifferentFrom 5
- }
-
- @Test
- fun testNewStringMethod() {
- infix fun String.substringMatches(r: Regex) : List {
- return r.findAll(this)
- .map { it.value }
- .toList()
- }
-
- val matches = "a bc def" substringMatches ".*? ".toRegex()
- Assert.assertEquals(listOf("a ", "bc "), matches)
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java
deleted file mode 100644
index 91c777c036..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaKotlinUnitTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baeldung.lambda;
-
-import kotlin.jvm.functions.Function1;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Created by Paul Jervis on 24/04/2018.
- */
-class LambdaKotlinUnitTest {
-
- @Test
- void givenJava6_whenUsingAnonnymousClass_thenReturnLambdaResult() {
- assertTrue(LambdaKt.invokeLambda(new Function1() {
- @Override
- public Boolean invoke(Double c) {
- return c >= 0;
- }
- }));
- }
-
- @Test
- void givenJava8_whenUsingLambda_thenReturnLambdaResult() {
- assertTrue(LambdaKt.invokeLambda(c -> c >= 0));
- }
-
- @Test
- void givenJava8_whenCallingMethodWithStringExtension_thenImplementExtension() {
- String actual = LambdaKt.extendString("Word", 90);
- String expected = "Word90";
-
- assertEquals(expected, actual);
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt
deleted file mode 100644
index bddabee462..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lambda/LambdaTest.kt
+++ /dev/null
@@ -1,96 +0,0 @@
-package com.baeldung.lambda
-
-import org.junit.jupiter.api.Assertions.assertFalse
-import org.junit.jupiter.api.Assertions.assertTrue
-import org.junit.jupiter.api.Test
-import kotlin.test.assertEquals
-
-class LambdaTest {
-
- @Test
- fun whenCallingALambda_thenPerformTheAction() {
- assertEquals(9, inferredType(3))
- }
-
- @Test
- fun whenCallingAMoreComplicatedLambda_thenPerformTheAction() {
- assertEquals("500", intToBiggerString(5))
- }
-
- @Test
- fun whenPassingALambdaObject_thenCallTriggerLambda() {
- val lambda = { arg: Double ->
- arg == 4.329
- }
-
- val result = invokeLambda(lambda)
-
- assertTrue(result)
- }
-
- @Test
- fun whenPassingALambdaLiteral_thenCallTriggerLambda() {
- val result = invokeLambda({
- true
- })
-
- assertTrue(result)
- }
-
- @Test
- fun whenPassingALambdaLiteralOutsideBrackets_thenCallTriggerLambda() {
- val result = invokeLambda { arg -> arg.isNaN() }
-
- assertFalse(result)
- }
-
- @Test
- fun whenPassingAnAnonymousFunction_thenCallTriggerLambda() {
- val result = invokeLambda(fun(arg: Double): Boolean {
- return arg >= 0
- })
-
- assertTrue(result)
- }
-
- @Test
- fun whenUsingLambda_thenCalculateGrade() {
- val gradeCalculation = getCalculationLambda()
-
- assertEquals(false, gradeCalculation(-40))
- assertEquals("Pass", gradeCalculation(50))
- }
-
- @Test
- fun whenUsingReturnStatementLambda_thenCalculateGrade() {
- val gradeCalculation: Int.() -> String = getCalculationLambdaWithReturn()
-
- assertEquals("Distinction", 80.gradeCalculation())
- assertEquals("Error", 244_234_324.gradeCalculation())
- }
-
- @Test
- fun whenUsingAnonymousFunction_thenCalculateGrade() {
- val gradeCalculation = getCalculationAnonymousFunction()
-
- assertEquals("Error", gradeCalculation(244_234_324))
- assertEquals("Pass", gradeCalculation(50))
- }
-
- @Test
- fun whenPassingAFunctionReference_thenCallTriggerLambda() {
- val reference = Double::isFinite
- val result = invokeLambda(reference)
-
- assertTrue(result)
- }
-
- @Test
- fun givenArray_whenMappingArray_thenPerformCalculationOnAllElements() {
- val expected = listOf("100", "200", "300", "400", "500")
- val actual = manyLambda(arrayOf(1, 2, 3, 4, 5))
-
- assertEquals(expected, actual)
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt
deleted file mode 100644
index c99e438742..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/late/LateInitUnitTest.kt
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.baeldung.late
-
-import org.junit.Test
-import kotlin.test.assertFalse
-import kotlin.test.assertTrue
-
-class LateInitUnitTest {
-
- private lateinit var answer: String
-
- @Test(expected = UninitializedPropertyAccessException::class)
- fun givenLateInit_WhenNotInitialized_ShouldThrowAnException() {
- answer.length
- }
-
- @Test
- fun givenLateInit_TheIsInitialized_ReturnsTheInitializationStatus() {
- assertFalse { this::answer.isInitialized }
- answer = "42"
- assertTrue { this::answer.isInitialized }
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt
deleted file mode 100644
index b9b21ed4d9..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/lazy/LazyUnitTest.kt
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.baeldung.lazy
-
-import org.junit.Test
-import java.util.concurrent.CountDownLatch
-import java.util.concurrent.Executors
-import java.util.concurrent.TimeUnit
-import java.util.concurrent.atomic.AtomicInteger
-import kotlin.test.assertEquals
-
-class LazyUnitTest {
- @Test
- fun givenLazyValue_whenGetIt_thenShouldInitializeItOnlyOnce() {
- //given
- val numberOfInitializations: AtomicInteger = AtomicInteger()
- val lazyValue: ClassWithHeavyInitialization by lazy {
- numberOfInitializations.incrementAndGet()
- ClassWithHeavyInitialization()
- }
- //when
- println(lazyValue)
- println(lazyValue)
-
- //then
- assertEquals(numberOfInitializations.get(), 1)
- }
-
- @Test
- fun givenLazyValue_whenGetItUsingPublication_thenCouldInitializeItMoreThanOnce() {
- //given
- val numberOfInitializations: AtomicInteger = AtomicInteger()
- val lazyValue: ClassWithHeavyInitialization by lazy(LazyThreadSafetyMode.PUBLICATION) {
- numberOfInitializations.incrementAndGet()
- ClassWithHeavyInitialization()
- }
- val executorService = Executors.newFixedThreadPool(2)
- val countDownLatch = CountDownLatch(1)
- //when
- executorService.submit { countDownLatch.await(); println(lazyValue) }
- executorService.submit { countDownLatch.await(); println(lazyValue) }
- countDownLatch.countDown()
-
- //then
- executorService.shutdown()
- executorService.awaitTermination(5, TimeUnit.SECONDS)
- //assertEquals(numberOfInitializations.get(), 2)
- }
-
- class ClassWithHeavyInitialization {
-
- }
-
-
- lateinit var a: String
- @Test
- fun givenLateInitProperty_whenAccessItAfterInit_thenPass() {
- //when
- a = "it"
- println(a)
-
- //then not throw
- }
-
- @Test(expected = UninitializedPropertyAccessException::class)
- fun givenLateInitProperty_whenAccessItWithoutInit_thenThrow() {
- //when
- println(a)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt
deleted file mode 100644
index 66fc043581..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/nullsafety/NullSafetyTest.kt
+++ /dev/null
@@ -1,161 +0,0 @@
-package com.baeldung.nullsafety
-
-import org.junit.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertFailsWith
-import kotlin.test.assertNull
-import kotlin.test.assertTrue
-
-
-class NullSafetyTest {
-
- @Test
- fun givenNonNullableField_whenAssignValueToIt_thenNotNeedToCheckAgainstNull() {
- //given
- var a: String = "value"
- //a = null compilation error
-
- //then
- assertEquals(a.length, 5)
- }
-
- @Test
- fun givenNullableField_whenReadValue_thenNeedToCheckAgainstNull() {
- //given
- var b: String? = "value"
- b = null
-
- //when
- if (b != null) {
-
- } else {
- assertNull(b)
- }
- }
-
- @Test
- fun givenComplexObject_whenUseSafeCall_thenShouldChainCallsResultingWithValue() {
- //given
- val p: Person? = Person(Country("ENG"))
-
- //when
- val res = p?.country?.code
-
- //then
- assertEquals(res, "ENG")
- }
-
- @Test
- fun givenComplexObject_whenUseSafeCall_thenShouldChainCallsResultingWithNull() {
- //given
- val p: Person? = Person(Country(null))
-
- //when
- val res = p?.country?.code
-
- //then
- assertNull(res)
- }
-
- @Test
- fun givenCollectionOfObjects_whenUseLetOperator_thenShouldApplyActionOnlyOnNonNullValue() {
- //given
- val firstName = "Tom"
- val secondName = "Michael"
- val names: List = listOf(firstName, null, secondName)
-
- //when
- var res = listOf()
- for (item in names) {
- item?.let { res = res.plus(it); it }
- ?.also{it -> println("non nullable value: $it")}
- }
-
- //then
- assertEquals(2, res.size)
- assertTrue { res.contains(firstName) }
- assertTrue { res.contains(secondName) }
- }
-
- @Test
- fun fivenCollectionOfObject_whenUseRunOperator_thenExecuteActionOnNonNullValue(){
- //given
- val firstName = "Tom"
- val secondName = "Michael"
- val names: List = listOf(firstName, null, secondName)
-
- //when
- var res = listOf()
- for (item in names) {
- item?.run{res = res.plus(this)}
- }
-
- //then
- assertEquals(2, res.size)
- assertTrue { res.contains(firstName) }
- assertTrue { res.contains(secondName) }
- }
-
- @Test
- fun givenNullableReference_whenUseElvisOperator_thenShouldReturnValueIfReferenceIsNotNull() {
- //given
- val value: String? = "name"
-
- //when
- val res = value?.length ?: -1
-
- //then
- assertEquals(res, 4)
- }
-
- @Test
- fun givenNullableReference_whenUseElvisOperator_thenShouldReturnDefaultValueIfReferenceIsNull() {
- //given
- val value: String? = null
-
- //when
- val res = value?.length ?: -1
-
- //then
- assertEquals(res, -1)
- }
-
- @Test
- fun givenNullableField_whenUsingDoubleExclamationMarkOperatorOnNull_thenThrowNPE() {
- //given
- var b: String? = "value"
- b = null
-
- //when
- assertFailsWith {
- b!!.length
- }
- }
-
- @Test
- fun givenNullableField_whenUsingDoubleExclamationMarkOperatorOnNotNull_thenReturnValue() {
- //given
- val b: String? = "value"
-
- //then
- assertEquals(b!!.length, 5)
- }
-
- @Test
- fun givenNullableList_whenUseFilterNotNullMethod_thenRemoveALlNullValues() {
- //given
- val list: List = listOf("a", null, "b")
-
- //when
- val res = list.filterNotNull()
-
- //then
- assertEquals(res.size, 2)
- assertTrue { res.contains("a") }
- assertTrue { res.contains("b") }
- }
-}
-
-data class Person(val country: Country?)
-
-data class Country(val code: String?)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt
deleted file mode 100644
index cb3ed98006..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/scope/ScopeFunctionsUnitTest.kt
+++ /dev/null
@@ -1,143 +0,0 @@
-package com.baeldung.scope
-
-import org.junit.Test
-import kotlin.test.assertTrue
-
-
-class ScopeFunctionsUnitTest {
-
- class Logger {
-
- var called : Boolean = false
-
- fun info(message: String) {
- called = true
- }
-
- fun wasCalled() = called
- }
-
- @Test
- fun shouldTransformWhenLetFunctionUsed() {
- val stringBuider = StringBuilder()
- val numberOfCharacters = stringBuider.let {
- it.append("This is a transformation function.")
- it.append("It takes a StringBuilder instance and returns the number of characters in the generated String")
- it.length
- }
-
- assertTrue {
- numberOfCharacters == 128
- }
- }
-
- @Test
- fun shouldHandleNullabilityWhenLetFunctionUsed() {
-
- val message: String? = "hello there!"
- val charactersInMessage = message?.let {
- "At this point is safe to reference the variable. Let's print the message: $it"
- } ?: "default value"
-
- assertTrue {
- charactersInMessage.equals("At this point is safe to reference the variable. Let's print the message: hello there!")
- }
-
- val aNullMessage = null
- val thisIsNull = aNullMessage?.let {
- "At this point it would be safe to reference the variable. But it will not really happen because it is null. Let's reference: $it"
- } ?: "default value"
-
- assertTrue {
- thisIsNull.equals("default value")
- }
- }
-
- @Test
- fun shouldInitializeObjectWhenUsingApply() {
- val aStudent = Student().apply {
- studentId = "1234567"
- name = "Mary"
- surname = "Smith"
- }
-
- assertTrue {
- aStudent.name.equals("Mary")
- }
- }
-
- @Test
- fun shouldAllowBuilderStyleObjectDesignWhenApplyUsedInClassMethods() {
- val teacher = Teacher()
- .setId(1000)
- .setName("Martha")
- .setSurname("Spector")
-
- assertTrue {
- teacher.surname.equals("Spector")
- }
- }
-
- @Test
- fun shouldAllowSideEffectWhenUsingAlso() {
- val restClient = RestClient("http://www.someurl.com")
-
- val logger = Logger()
-
- val headers = restClient
- .getResponse()
- .also { logger.info(it.toString()) }
- .headers
-
- assertTrue {
- logger.wasCalled() && headers.headerInfo.equals("some header info")
- }
-
- }
-
- @Test
- fun shouldInitializeFieldWhenAlsoUsed() {
- val aStudent = Student().also { it.name = "John"}
-
- assertTrue {
- aStudent.name.equals("John")
- }
- }
-
- @Test
- fun shouldLogicallyGroupObjectCallsWhenUsingWith() {
- val bankAccount = BankAccount(1000)
- with (bankAccount) {
- checkAuthorization("someone")
- addPayee("some payee")
- makePayment("payment information")
- }
- }
-
- @Test
- fun shouldConvertObjectWhenRunUsed() {
- val stringBuider = StringBuilder()
- val numberOfCharacters = stringBuider.run {
- append("This is a transformation function.")
- append("It takes a StringBuilder instance and returns the number of characters in the generated String")
- length
- }
-
- assertTrue {
- numberOfCharacters == 128
- }
- }
-
- @Test
- fun shouldHandleNullabilityWhenRunIsUsed() {
- val message: String? = "hello there!"
- val charactersInMessage = message?.run {
- "At this point is safe to reference the variable. Let's print the message: $this"
- } ?: "default value"
-
- assertTrue {
- charactersInMessage.equals("At this point is safe to reference the variable. Let's print the message: hello there!")
- }
- }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt
deleted file mode 100644
index 88011ab396..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-2/src/test/kotlin/com/baeldung/structuraljump/StructuralJumpUnitTest.kt
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.baeldung.structuraljump
-
-import org.junit.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertFalse
-
-class StructuralJumpUnitTest {
-
- @Test
- fun givenLoop_whenBreak_thenComplete() {
- var value = ""
- for (i in "hello_world") {
- if (i == '_')
- break
- value += i.toString()
- }
- assertEquals("hello", value)
- }
- @Test
- fun givenLoop_whenBreakWithLabel_thenComplete() {
- var value = ""
- outer_loop@ for (i in 'a'..'d') {
- for (j in 1..3) {
- value += "" + i + j
- if (i == 'b' && j == 1)
- break@outer_loop
- }
- }
- assertEquals("a1a2a3b1", value)
- }
-
- @Test
- fun givenLoop_whenContinue_thenComplete() {
- var result = ""
- for (i in "hello_world") {
- if (i == '_')
- continue
- result += i
- }
- assertEquals("helloworld", result)
- }
- @Test
- fun givenLoop_whenContinueWithLabel_thenComplete() {
- var result = ""
- outer_loop@ for (i in 'a'..'c') {
- for (j in 1..3) {
- if (i == 'b')
- continue@outer_loop
- result += "" + i + j
- }
- }
- assertEquals("a1a2a3c1c2c3", result)
- }
-
- @Test
- fun givenLambda_whenReturn_thenComplete() {
- var result = returnInLambda();
- assertEquals("hello", result)
- }
-
- private fun returnInLambda(): String {
- var result = ""
- "hello_world".forEach {
- // non-local return directly to the caller
- if (it == '_') return result
- result += it.toString()
- }
- //this line won't be reached
- return result;
- }
-
- @Test
- fun givenLambda_whenReturnWithExplicitLabel_thenComplete() {
- var result = ""
- "hello_world".forEach lit@{
- if (it == '_') {
- // local return to the caller of the lambda, i.e. the forEach loop
- return@lit
- }
- result += it.toString()
- }
- assertEquals("helloworld", result)
- }
-
- @Test
- fun givenLambda_whenReturnWithImplicitLabel_thenComplete() {
- var result = ""
- "hello_world".forEach {
- if (it == '_') {
- // local return to the caller of the lambda, i.e. the forEach loop
- return@forEach
- }
- result += it.toString()
- }
- assertEquals("helloworld", result)
- }
-
- @Test
- fun givenAnonymousFunction_return_thenComplete() {
- var result = ""
- "hello_world".forEach(fun(element) {
- // local return to the caller of the anonymous fun, i.e. the forEach loop
- if (element == '_') return
- result += element.toString()
- })
- assertEquals("helloworld", result)
- }
-
- @Test
- fun givenAnonymousFunction_returnToLabel_thenComplete() {
- var result = ""
- run loop@{
- "hello_world".forEach {
- // non-local return from the lambda passed to run
- if (it == '_') return@loop
- result += it.toString()
- }
- }
- assertEquals("hello", result)
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md b/core-kotlin-modules/core-kotlin-lang-oop-2/README.md
deleted file mode 100644
index 27536273dc..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/README.md
+++ /dev/null
@@ -1,10 +0,0 @@
-## Core Kotlin Lang OOP
-
-This module contains articles about Object-Oriented Programming in Kotlin
-
-### Relevant articles:
-
-- [Generics in Kotlin](https://www.baeldung.com/kotlin-generics)
-- [Delegated Properties in Kotlin](https://www.baeldung.com/kotlin-delegated-properties)
-- [Delegation Pattern in Kotlin](https://www.baeldung.com/kotlin-delegation-pattern)
-- [[<-- Prev]](/core-kotlin-modules/core-kotlin-lang-oop)
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml b/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml
deleted file mode 100644
index f0adea121e..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/pom.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
- 4.0.0
- core-kotlin-lang-oop-2
- core-kotlin-lang-oop-2
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt
deleted file mode 100644
index 37a632fe41..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/generic/Reified.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-inline fun Iterable<*>.filterIsInstance() = filter { it is T }
-
-fun main(args: Array) {
- val set = setOf("1984", 2, 3, "Brave new world", 11)
- println(set.filterIsInstance())
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt
deleted file mode 100644
index 9ea9f027fc..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/Database.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-package com.baeldung.kotlin.delegates
-
-val data = arrayOf>(
- mutableMapOf(
- "id" to 1,
- "name" to "George",
- "age" to 4
- ),
- mutableMapOf(
- "id" to 2,
- "name" to "Charlotte",
- "age" to 2
- )
-)
-
-class NoRecordFoundException(id: Int) : Exception("No record found for id $id") {
- init {
- println("No record found for ID $id")
- }
-}
-
-fun queryForValue(field: String, id: Int): Any {
- println("Loading record $id from the fake database")
- val value = data.firstOrNull { it["id"] == id }
- ?.get(field) ?: throw NoRecordFoundException(id)
- println("Loaded value $value for field $field of record $id")
- return value
-}
-
-fun update(field: String, id: Int, value: Any?) {
- println("Updating field $field of record $id to value $value in the fake database")
- data.firstOrNull { it["id"] == id }
- ?.put(field, value)
- ?: throw NoRecordFoundException(id)
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt
deleted file mode 100644
index c1c0f8823c..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegate.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.kotlin.delegates
-
-import kotlin.properties.ReadWriteProperty
-import kotlin.reflect.KProperty
-
-class DatabaseDelegate(private val field: String, private val id: Int) : ReadWriteProperty {
- override fun getValue(thisRef: R, property: KProperty<*>): T =
- queryForValue(field, id) as T
-
- override fun setValue(thisRef: R, property: KProperty<*>, value: T) {
- update(field, id, value)
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt
deleted file mode 100644
index 8e261aacf2..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegation.kt
+++ /dev/null
@@ -1,64 +0,0 @@
-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
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt
deleted file mode 100644
index 7788305ea1..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/main/kotlin/com/baeldung/kotlin/delegates/User.kt
+++ /dev/null
@@ -1,6 +0,0 @@
-package com.baeldung.kotlin.delegates
-
-class User(val id: Int) {
- var name: String by DatabaseDelegate("name", id)
- var age: Int by DatabaseDelegate("age", id)
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt
deleted file mode 100644
index b189d0f483..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/GenericsTest.kt
+++ /dev/null
@@ -1,143 +0,0 @@
-package com.baeldung.kotlin
-
-import org.junit.Test
-import kotlin.test.assertEquals
-import kotlin.test.assertTrue
-
-class GenericsTest {
-
- @Test
- fun givenParametrizeClass_whenInitializeItWithSpecificType_thenShouldBeParameterized() {
- //given
- val parameterizedClass = ParameterizedClass("string-value")
-
- //when
- val res = parameterizedClass.getValue()
-
- //then
- assertTrue(res is String)
- }
-
- @Test
- fun givenParametrizeClass_whenInitializeIt_thenShouldBeParameterizedByInferredType() {
- //given
- val parameterizedClass = ParameterizedClass("string-value")
-
- //when
- val res = parameterizedClass.getValue()
-
- //then
- assertTrue(res is String)
- }
-
- @Test
- fun givenParameterizedProducerByOutKeyword_whenGetValue_thenCanAssignItToSuperType() {
- //given
- val parameterizedProducer = ParameterizedProducer("string")
-
- //when
- val ref: ParameterizedProducer = parameterizedProducer
-
- //then
- assertTrue(ref is ParameterizedProducer)
- }
-
- @Test
- fun givenParameterizedConsumerByInKeyword_whenGetValue_thenCanAssignItToSubType() {
- //given
- val parameterizedConsumer = ParameterizedConsumer()
-
- //when
- val ref: ParameterizedConsumer = parameterizedConsumer
-
- //then
- assertTrue(ref is ParameterizedConsumer)
- }
-
- @Test
- fun givenTypeProjections_whenOperateOnTwoList_thenCanAcceptListOfSubtypes() {
- //given
- val ints: Array = arrayOf(1, 2, 3)
- val any: Array = arrayOfNulls(3)
-
- //when
- copy(ints, any)
-
- //then
- assertEquals(any[0], 1)
- assertEquals(any[1], 2)
- assertEquals(any[2], 3)
-
- }
-
- fun copy(from: Array, to: Array) {
- assert(from.size == to.size)
- for (i in from.indices)
- to[i] = from[i]
- }
-
- @Test
- fun givenTypeProjection_whenHaveArrayOfIn_thenShouldAddElementsOfSubtypesToIt() {
- //given
- val objects: Array = arrayOfNulls(1)
-
- //when
- fill(objects, 1)
-
- //then
- assertEquals(objects[0], 1)
- }
-
- fun fill(dest: Array, value: Int) {
- dest[0] = value
- }
-
- @Test
- fun givenStartProjection_whenPassAnyType_thenCompile() {
- //given
- val array = arrayOf(1,2,3)
-
- //then
- printArray(array)
-
- }
-
- fun printArray(array: Array<*>) {
- array.forEach { println(it) }
- }
-
- @Test
- fun givenFunctionWithDefinedGenericConstraints_whenCallWithProperType_thenCompile(){
- //given
- val listOfInts = listOf(5,2,3,4,1)
-
- //when
- val sorted = sort(listOfInts)
-
- //then
- assertEquals(sorted, listOf(1,2,3,4,5))
- }
-
- fun > sort(list: List): List{
- return list.sorted()
- }
-
- class ParameterizedClass(private val value: A) {
-
- fun getValue(): A {
- return value
- }
- }
-
- class ParameterizedProducer(private val value: T) {
- fun get(): T {
- return value
- }
- }
-
- class ParameterizedConsumer {
- fun toString(value: T): String {
- return value.toString()
- }
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt
deleted file mode 100644
index fc50730dfa..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/DatabaseDelegatesTest.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baeldung.kotlin.delegates
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-class DatabaseDelegatesTest {
- @Test
- fun testGetKnownFields() {
- val user = User(1)
- assertEquals("George", user.name)
- assertEquals(4, user.age)
- }
-
- @Test
- fun testSetKnownFields() {
- val user = User(2)
- user.age = 3
- assertEquals(3, user.age)
- }
-
- @Test(expected = NoRecordFoundException::class)
- fun testGetKnownField() {
- val user = User(3)
- user.name
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt b/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt
deleted file mode 100644
index e65032acd4..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop-2/src/test/kotlin/com/baeldung/kotlin/delegates/InterfaceDelegationTest.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-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)
- }
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/README.md b/core-kotlin-modules/core-kotlin-lang-oop/README.md
deleted file mode 100644
index 0c1aeb7850..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/README.md
+++ /dev/null
@@ -1,17 +0,0 @@
-## Core Kotlin Lang OOP
-
-This module contains articles about Object-Oriented Programming in Kotlin
-
-### Relevant articles:
-
-- [Data Classes in Kotlin](https://www.baeldung.com/kotlin-data-classes)
-- [Sealed Classes in Kotlin](https://www.baeldung.com/kotlin-sealed-classes)
-- [Extension Methods in Kotlin](https://www.baeldung.com/kotlin-extension-methods)
-- [Objects in Kotlin](https://www.baeldung.com/kotlin-objects)
-- [Working with Enums in Kotlin](https://www.baeldung.com/kotlin-enum)
-- [Kotlin Constructors](https://www.baeldung.com/kotlin-constructors)
-- [Kotlin Nested and Inner Classes](https://www.baeldung.com/kotlin-inner-classes)
-- [Guide to Kotlin Interfaces](https://www.baeldung.com/kotlin-interfaces)
-- [Inline Classes in Kotlin](https://www.baeldung.com/kotlin-inline-classes)
-- [Static Methods Behavior in Kotlin](https://www.baeldung.com/kotlin-static-methods)
-- More articles: [[next -->]](/core-kotlin-modules/core-kotlin-lang-oop-2)
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/pom.xml b/core-kotlin-modules/core-kotlin-lang-oop/pom.xml
deleted file mode 100644
index 03fc80f07d..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/pom.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
- 4.0.0
- core-kotlin-lang-oop
- core-kotlin-lang-oop
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
-
- org.assertj
- assertj-core
- ${assertj.version}
- test
-
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt
deleted file mode 100644
index 72b8d330e8..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Car.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baeldung.constructor
-
-class Car {
- val id: String
- val type: String
-
- constructor(id: String, type: String) {
- this.id = id
- this.type = type
- }
-
-}
-
-fun main(args: Array) {
- val car = Car("1", "sport")
- val s= Car("2", "suv")
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt
deleted file mode 100644
index 4483bfcf08..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Employee.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.constructor
-
-class Employee(name: String, val salary: Int): Person(name)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java
deleted file mode 100644
index 57911b24ee..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/constructor/Person.java
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.constructor;
-
-class PersonJava {
- final String name;
- final String surname;
- final Integer age;
-
- public PersonJava(String name, String surname) {
- this.name = name;
- this.surname = surname;
- this.age = null;
- }
-
- public PersonJava(String name, String surname, Integer age) {
- this.name = name;
- this.surname = surname;
- this.age = age;
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java b/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java
deleted file mode 100644
index 7eac98fe2a..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/java/com/baeldung/dataclass/Movie.java
+++ /dev/null
@@ -1,88 +0,0 @@
-package com.baeldung.dataclass;
-
-public class Movie {
-
- private String name;
- private String studio;
- private float rating;
-
- public Movie(String name, String studio, float rating) {
- this.name = name;
- this.studio = studio;
- this.rating = rating;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getStudio() {
- return studio;
- }
-
- public void setStudio(String studio) {
- this.studio = studio;
- }
-
- public float getRating() {
- return rating;
- }
-
- public void setRating(float rating) {
- this.rating = rating;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- result = prime * result + Float.floatToIntBits(rating);
- result = prime * result + ((studio == null) ? 0 : studio.hashCode());
-
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
-
- if (obj == null)
- return false;
-
- if (getClass() != obj.getClass())
- return false;
-
- Movie other = (Movie) obj;
-
- if (name == null) {
- if (other.name != null)
- return false;
-
- } else if (!name.equals(other.name))
- return false;
-
- if (Float.floatToIntBits(rating) != Float.floatToIntBits(other.rating))
- return false;
-
- if (studio == null) {
- if (other.studio != null)
- return false;
-
- } else if (!studio.equals(other.studio))
- return false;
-
- return true;
- }
-
- @Override
- public String toString() {
- return "Movie [name=" + name + ", studio=" + studio + ", rating=" + rating + "]";
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt
deleted file mode 100644
index 3779d74541..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/constructor/Person.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baeldung.constructor
-
-open class Person(
- val name: String,
- val age: Int? = null
-) {
- val upperCaseName: String = name.toUpperCase()
-
- init {
- println("Hello, I'm $name")
-
- if (age != null && age < 0) {
- throw IllegalArgumentException("Age cannot be less than zero!")
- }
- }
-
- init {
- println("upperCaseName is $upperCaseName")
- }
-
-}
-
-fun main(args: Array) {
- val person = Person("John")
- val personWithAge = Person("John", 22)
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt
deleted file mode 100644
index c0c15b2516..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Movie.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.dataclass
-
-data class Movie(val name: String, val studio: String, var rating: Float)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt
deleted file mode 100644
index d47909bf29..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/dataclass/Sandbox.kt
+++ /dev/null
@@ -1,26 +0,0 @@
-package com.baeldung.dataclass
-
-fun main(args: Array) {
-
- val movie = Movie("Whiplash", "Sony Pictures", 8.5F)
-
- println(movie.name) //Whiplash
- println(movie.studio) //Sony Pictures
- println(movie.rating) //8.5
-
- movie.rating = 9F
-
- println(movie.toString()) //Movie(name=Whiplash, studio=Sony Pictures, rating=9.0)
-
- val betterRating = movie.copy(rating = 9.5F)
- println(betterRating.toString()) //Movie(name=Whiplash, studio=Sony Pictures, rating=9.5)
-
- movie.component1() //name
- movie.component2() //studio
- movie.component3() //rating
-
- val(name, studio, rating) = movie
-
- fun getMovieInfo() = movie
- val(namef, studiof, ratingf) = getMovieInfo()
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt
deleted file mode 100644
index 69cfce5601..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/CardType.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.enums
-
-enum class CardType(val color: String) : ICardLimit {
- SILVER("gray") {
- override fun getCreditLimit() = 100000
- override fun calculateCashbackPercent() = 0.25f
- },
- GOLD("yellow") {
- override fun getCreditLimit() = 200000
- override fun calculateCashbackPercent(): Float = 0.5f
- },
- PLATINUM("black") {
- override fun getCreditLimit() = 300000
- override fun calculateCashbackPercent() = 0.75f
- };
-
- companion object {
- fun getCardTypeByColor(color: String) = values().firstOrNull { it.color == color }
- fun getCardTypeByName(name: String) = valueOf(name.toUpperCase())
- }
-
- abstract fun calculateCashbackPercent(): Float
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt
deleted file mode 100644
index 7994822a52..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/enums/ICardLimit.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.enums
-
-interface ICardLimit {
- fun getCreditLimit(): Int
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt
deleted file mode 100644
index 5b46b9570f..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.baeldung.inline.classes
-
-interface Drawable {
- fun draw()
-}
-
-inline class CircleRadius(private val circleRadius : Double) : Drawable {
- val diameterOfCircle get() = 2 * circleRadius
- fun areaOfCircle() = 3.14 * circleRadius * circleRadius
-
- override fun draw() {
- println("Draw my circle")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt
deleted file mode 100644
index 430fa509da..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.inline.classes
-
-inline class InlineDoubleWrapper(val doubleValue : Double)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt
deleted file mode 100644
index 630afbdae7..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/ConflictingInterfaces.kt
+++ /dev/null
@@ -1,23 +0,0 @@
-package com.baeldung.interfaces
-
-interface BaseInterface {
- fun someMethod(): String
-}
-
-interface FirstChildInterface : BaseInterface {
- override fun someMethod(): String {
- return("Hello, from someMethod in FirstChildInterface")
- }
-}
-
-interface SecondChildInterface : BaseInterface {
- override fun someMethod(): String {
- return("Hello, from someMethod in SecondChildInterface")
- }
-}
-
-class ChildClass : FirstChildInterface, SecondChildInterface {
- override fun someMethod(): String {
- return super.someMethod()
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt
deleted file mode 100644
index 591fde0689..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/InterfaceDelegation.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.interfaces
-
-interface MyInterface {
- fun someMethod(): String
-}
-
-class MyClass() : MyInterface {
- override fun someMethod(): String {
- return("Hello, World!")
- }
-}
-
-class MyDerivedClass(myInterface: MyInterface) : MyInterface by myInterface
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt
deleted file mode 100644
index 105a85cbb3..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/MultipleInterfaces.kt
+++ /dev/null
@@ -1,29 +0,0 @@
-package com.baeldung.interfaces
-
-interface FirstInterface {
- fun someMethod(): String
-
- fun anotherMethod(): String {
- return("Hello, from anotherMethod in FirstInterface")
- }
-}
-
-interface SecondInterface {
- fun someMethod(): String {
- return("Hello, from someMethod in SecondInterface")
- }
-
- fun anotherMethod(): String {
- return("Hello, from anotherMethod in SecondInterface")
- }
-}
-
-class SomeClass: FirstInterface, SecondInterface {
- override fun someMethod(): String {
- return("Hello, from someMethod in SomeClass")
- }
-
- override fun anotherMethod(): String {
- return("Hello, from anotherMethod in SomeClass")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt
deleted file mode 100644
index 0758549dde..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/interfaces/SimpleInterface.kt
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.baeldung.interfaces
-
-interface SimpleInterface {
- val firstProp: String
- val secondProp: String
- get() = "Second Property"
- fun firstMethod(): String
- fun secondMethod(): String {
- println("Hello, from: " + secondProp)
- return ""
- }
-}
-
-class SimpleClass: SimpleInterface {
- override val firstProp: String = "First Property"
- override val secondProp: String
- get() = "Second Property, Overridden!"
- override fun firstMethod(): String {
- return("Hello, from: " + firstProp)
- }
- override fun secondMethod(): String {
- return("Hello, from: " + secondProp + firstProp)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt
deleted file mode 100644
index 96e54716b3..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/Sealed.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.kotlin
-
-sealed class Result {
- abstract fun map(func: (S) -> R) : Result
- abstract fun mapFailure(func: (F) -> R) : Result
- abstract fun get() : S?
-}
-
-data class Success(val success: S) : Result() {
- override fun map(func: (S) -> R) : Result = Success(func(success))
- override fun mapFailure(func: (F) -> R): Result = Success(success)
- override fun get(): S? = success
-}
-
-data class Failure(val failure: F) : Result() {
- override fun map(func: (S) -> R) : Result = Failure(failure)
- override fun mapFailure(func: (F) -> R): Result = Failure(func(failure))
- override fun get(): S? = null
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt
deleted file mode 100644
index ca57b2965e..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/kotlin/StringUtil.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-@file:JvmName("Strings")
-package com.baeldung.kotlin
-
-fun String.escapeForXml() : String {
- return this
- .replace("&", "&")
- .replace("<", "<")
- .replace(">", ">")
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt
deleted file mode 100644
index ee01c06646..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/nested/Computer.kt
+++ /dev/null
@@ -1,75 +0,0 @@
-package com.baeldung.nested
-
-import org.slf4j.Logger
-import org.slf4j.LoggerFactory
-
-class Computer(val model: String) {
-
- companion object {
- const val originCountry = "China"
- fun getBuiltDate(): String {
- return "2018-05-23"
- }
-
- val log: Logger = LoggerFactory.getLogger(Computer::class.java)
- }
-
- //Nested class
- class MotherBoard(val manufacturer: String) {
- fun getInfo() = "Made by $manufacturer installed in $originCountry - ${getBuiltDate()}"
- }
-
- //Inner class
- inner class HardDisk(val sizeInGb: Int) {
- fun getInfo() = "Installed on ${this@Computer} with $sizeInGb GB"
- }
-
- interface Switcher {
- fun on(): String
- }
-
- interface Protector {
- fun smart()
- }
-
- fun powerOn(): String {
- //Local class
- var defaultColor = "Blue"
-
- class Led(val color: String) {
- fun blink(): String {
- return "blinking $color"
- }
-
- fun changeDefaultPowerOnColor() {
- defaultColor = "Violet"
- }
- }
-
- val powerLed = Led("Green")
- log.debug("defaultColor is $defaultColor")
- powerLed.changeDefaultPowerOnColor()
- log.debug("defaultColor changed inside Led class to $defaultColor")
- //Anonymous object
- val powerSwitch = object : Switcher, Protector {
- override fun on(): String {
- return powerLed.blink()
- }
-
- override fun smart() {
- log.debug("Smart protection is implemented")
- }
-
- fun changeDefaultPowerOnColor() {
- defaultColor = "Yellow"
- }
- }
- powerSwitch.changeDefaultPowerOnColor()
- log.debug("defaultColor changed inside powerSwitch anonymous object to $defaultColor")
- return powerSwitch.on()
- }
-
- override fun toString(): String {
- return "Computer(model=$model)"
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt
deleted file mode 100644
index 23c7cfb11a..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/ConsoleUtils.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.static
-
-class ConsoleUtils {
- companion object {
- @JvmStatic
- fun debug(debugMessage : String) {
- println("[DEBUG] $debugMessage")
- }
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt
deleted file mode 100644
index e67addc9ea..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/main/kotlin/com/baeldung/static/LoggingUtils.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.static
-
-fun debug(debugMessage : String) {
- println("[DEBUG] $debugMessage")
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java b/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java
deleted file mode 100644
index c7ef18b879..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/java/com/baeldung/kotlin/StringUtilUnitTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.baeldung.kotlin;
-
-import kotlin.text.StringsKt;
-import org.junit.Assert;
-import org.junit.Test;
-
-import static com.baeldung.kotlin.Strings.*;
-
-
-public class StringUtilUnitTest {
-
- @Test
- public void shouldEscapeXmlTagsInString() {
- String xml = "hi";
-
- String escapedXml = escapeForXml(xml);
-
- Assert.assertEquals("<a>hi</a>", escapedXml);
- }
-
- @Test
- public void callingBuiltInKotlinExtensionMethod() {
- String name = "john";
-
- String capitalizedName = StringsKt.capitalize(name);
-
- Assert.assertEquals("John", capitalizedName);
- }
-
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt
deleted file mode 100644
index 525faebd55..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/enums/CardTypeUnitTest.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.baeldung.enums
-
-import org.junit.jupiter.api.Assertions
-import org.junit.jupiter.api.Assertions.assertEquals
-import org.junit.jupiter.api.Test
-
-internal class CardTypeUnitTest {
-
- @Test
- fun givenSilverCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
- assertEquals(0.25f, CardType.SILVER.calculateCashbackPercent())
- }
-
- @Test
- fun givenGoldCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
- assertEquals(0.5f, CardType.GOLD.calculateCashbackPercent())
- }
-
- @Test
- fun givenPlatinumCardType_whenCalculateCashbackPercent_thenReturnCashbackValue() {
- assertEquals(0.75f, CardType.PLATINUM.calculateCashbackPercent())
- }
-
- @Test
- fun givenSilverCardType_whenGetCreditLimit_thenReturnCreditLimit() {
- assertEquals(100000, CardType.SILVER.getCreditLimit())
- }
-
- @Test
- fun givenGoldCardType_whenGetCreditLimit_thenReturnCreditLimit() {
- assertEquals(200000, CardType.GOLD.getCreditLimit())
- }
-
- @Test
- fun givenPlatinumCardType_whenGetCreditLimit_thenReturnCreditLimit() {
- assertEquals(300000, CardType.PLATINUM.getCreditLimit())
- }
-
- @Test
- fun givenSilverCardType_whenCheckColor_thenReturnColor() {
- assertEquals("gray", CardType.SILVER.color)
- }
-
- @Test
- fun givenGoldCardType_whenCheckColor_thenReturnColor() {
- assertEquals("yellow", CardType.GOLD.color)
- }
-
- @Test
- fun givenPlatinumCardType_whenCheckColor_thenReturnColor() {
- assertEquals("black", CardType.PLATINUM.color)
- }
-
- @Test
- fun whenGetCardTypeByColor_thenSilverCardType() {
- Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByColor("gray"))
- }
-
- @Test
- fun whenGetCardTypeByColor_thenGoldCardType() {
- Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByColor("yellow"))
- }
-
- @Test
- fun whenGetCardTypeByColor_thenPlatinumCardType() {
- Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByColor("black"))
- }
-
- @Test
- fun whenGetCardTypeByName_thenSilverCardType() {
- Assertions.assertEquals(CardType.SILVER, CardType.getCardTypeByName("silver"))
- }
-
- @Test
- fun whenGetCardTypeByName_thenGoldCardType() {
- Assertions.assertEquals(CardType.GOLD, CardType.getCardTypeByName("gold"))
- }
-
- @Test
- fun whenGetCardTypeByName_thenPlatinumCardType() {
- Assertions.assertEquals(CardType.PLATINUM, CardType.getCardTypeByName("platinum"))
- }
-
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt
deleted file mode 100644
index 8de378b6dd..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package com.baeldung.inline.classes
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-class CircleRadiusTest {
-
- @Test
- fun givenRadius_ThenDiameterIsCorrectlyCalculated() {
- val radius = CircleRadius(5.0)
- assertEquals(10.0, radius.diameterOfCircle)
- }
-
- @Test
- fun givenRadius_ThenAreaIsCorrectlyCalculated() {
- val radius = CircleRadius(5.0)
- assertEquals(78.5, radius.areaOfCircle())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt
deleted file mode 100644
index 349c90d6f4..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.baeldung.inline.classes
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-class InlineDoubleWrapperTest {
-
- @Test
- fun whenInclineClassIsUsed_ThenPropertyIsReadCorrectly() {
- val piDoubleValue = InlineDoubleWrapper(3.14)
- assertEquals(3.14, piDoubleValue.doubleValue)
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt
deleted file mode 100644
index 96b99948b7..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/interfaces/InterfaceExamplesUnitTest.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package com.baeldung.interfaces
-
-import org.junit.Test
-import kotlin.test.assertEquals
-
-class InterfaceExamplesUnitTest {
- @Test
- fun givenAnInterface_whenImplemented_thenBehavesAsOverridden() {
- val simpleClass = SimpleClass()
- assertEquals("Hello, from: First Property", simpleClass.firstMethod())
- assertEquals("Hello, from: Second Property, Overridden!First Property", simpleClass.secondMethod())
- }
-
- @Test
- fun givenMultipleInterfaces_whenImplemented_thenBehavesAsOverridden() {
- val someClass = SomeClass()
- assertEquals("Hello, from someMethod in SomeClass", someClass.someMethod())
- assertEquals("Hello, from anotherMethod in SomeClass", someClass.anotherMethod())
- }
-
- @Test
- fun givenConflictingInterfaces_whenImplemented_thenBehavesAsOverridden() {
- val childClass = ChildClass()
- assertEquals("Hello, from someMethod in SecondChildInterface", childClass.someMethod())
- }
-
- @Test
- fun givenAnInterface_whenImplemented_thenBehavesAsDelegated() {
- val myClass = MyClass()
- assertEquals("Hello, World!", MyDerivedClass(myClass).someMethod())
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt
deleted file mode 100644
index 44c5cd0ece..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/ExtensionMethods.kt
+++ /dev/null
@@ -1,44 +0,0 @@
-package com.baeldung.kotlin
-
-import org.junit.Assert
-import org.junit.Test
-
-class ExtensionMethods {
- @Test
- fun simpleExtensionMethod() {
- Assert.assertEquals("Nothing", "Nothing".escapeForXml())
- Assert.assertEquals("<Tag>", "".escapeForXml())
- Assert.assertEquals("a&b", "a&b".escapeForXml())
- }
-
- @Test
- fun genericExtensionMethod() {
- fun T.concatAsString(b: T) : String {
- return this.toString() + b.toString()
- }
-
- Assert.assertEquals("12", "1".concatAsString("2"))
- Assert.assertEquals("12", 1.concatAsString(2))
- // This doesn't compile
- // Assert.assertEquals("12", 1.concatAsString(2.0))
- }
-
- @Test
- fun infixExtensionMethod() {
- infix fun Number.toPowerOf(exponent: Number): Double {
- return Math.pow(this.toDouble(), exponent.toDouble())
- }
-
- Assert.assertEquals(9.0, 3 toPowerOf 2, 0.1)
- Assert.assertEquals(3.0, 9 toPowerOf 0.5, 0.1)
- }
-
- @Test
- fun operatorExtensionMethod() {
- operator fun List.times(by: Int): List {
- return this.map { it * by }
- }
-
- Assert.assertEquals(listOf(2, 4, 6), listOf(1, 2, 3) * 2)
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt
deleted file mode 100644
index 8c7509f653..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/SealedTest.kt
+++ /dev/null
@@ -1,84 +0,0 @@
-package com.baeldung.kotlin
-
-import org.junit.Assert
-import org.junit.Test
-
-class SealedTest {
- fun divide(a: Int, b: Int) : Result = when (b) {
- 0 -> Failure("Division by zero")
- else -> Success(a.toFloat() / b)
- }
-
- @Test
- fun testSuccess() {
- val result = divide(10, 5)
- Assert.assertEquals(Success(2.0f), result)
- }
-
- @Test
- fun testError() {
- val result = divide(10, 0)
- Assert.assertEquals(Failure("Division by zero"), result)
- }
-
- @Test
- fun testMatchOnSuccess() {
- val result = divide(10, 5)
- when (result) {
- is Success -> {
- // Expected
- }
- is Failure -> Assert.fail("Expected Success")
- }
- }
-
- @Test
- fun testMatchOnError() {
- val result = divide(10, 0)
- when (result) {
- is Failure -> {
- // Expected
- }
- }
- }
-
- @Test
- fun testGetSuccess() {
- val result = divide(10, 5)
- Assert.assertEquals(2.0f, result.get())
- }
-
- @Test
- fun testGetError() {
- val result = divide(10, 0)
- Assert.assertNull(result.get())
- }
-
- @Test
- fun testMapOnSuccess() {
- val result = divide(10, 5)
- .map { "Result: $it" }
- Assert.assertEquals(Success("Result: 2.0"), result)
- }
-
- @Test
- fun testMapOnError() {
- val result = divide(10, 0)
- .map { "Result: $it" }
- Assert.assertEquals(Failure("Division by zero"), result)
- }
-
- @Test
- fun testMapFailureOnSuccess() {
- val result = divide(10, 5)
- .mapFailure { "Failure: $it" }
- Assert.assertEquals(Success(2.0f), result)
- }
-
- @Test
- fun testMapFailureOnError() {
- val result = divide(10, 0)
- .mapFailure { "Failure: $it" }
- Assert.assertEquals(Failure("Failure: Division by zero"), result)
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt
deleted file mode 100644
index 46ba42e1e5..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/Counter.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package com.baeldung.kotlin.objects
-
-object Counter {
- private var count: Int = 0
-
- fun currentCount() = count
-
- fun increment() {
- ++count
- }
-
- fun decrement() {
- --count
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt
deleted file mode 100644
index 0bbb1c741d..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ObjectsTest.kt
+++ /dev/null
@@ -1,36 +0,0 @@
-package com.baeldung.kotlin.objects
-
-import org.junit.Assert
-import org.junit.Test
-
-class ObjectsTest {
- @Test
- fun singleton() {
-
- Assert.assertEquals(42, SimpleSingleton.answer)
- Assert.assertEquals("Hello, world!", SimpleSingleton.greet("world"))
- }
-
- @Test
- fun counter() {
- Assert.assertEquals(0, Counter.currentCount())
- Counter.increment()
- Assert.assertEquals(1, Counter.currentCount())
- Counter.decrement()
- Assert.assertEquals(0, Counter.currentCount())
- }
-
- @Test
- fun comparator() {
- val strings = listOf("Hello", "World")
- val sortedStrings = strings.sortedWith(ReverseStringComparator)
-
- Assert.assertEquals(listOf("World", "Hello"), sortedStrings)
- }
-
- @Test
- fun companion() {
- Assert.assertEquals("You can see me", OuterClass.public)
- // Assert.assertEquals("You can't see me", OuterClass.secret) // Cannot access 'secret'
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt
deleted file mode 100644
index 4abb7a668d..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/OuterClass.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.kotlin.objects
-
-class OuterClass {
- companion object {
- private val secret = "You can't see me"
- val public = "You can see me"
- }
-
- fun getSecretValue() = secret
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt
deleted file mode 100644
index 20dc2d8c5b..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/ReverseStringComparator.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.baeldung.kotlin.objects
-
-object ReverseStringComparator : Comparator {
- override fun compare(o1: String, o2: String) = o1.reversed().compareTo(o2.reversed())
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt
deleted file mode 100644
index bfafd8183f..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/SimpleSingleton.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package com.baeldung.kotlin.objects
-
-object SimpleSingleton {
- val answer = 42;
-
- fun greet(name: String) = "Hello, $name!"
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt
deleted file mode 100644
index 36cd476110..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/kotlin/objects/StaticClass.kt
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.baeldung.kotlin.objects
-
-class StaticClass {
- companion object {
- @JvmStatic
- val staticField = 42
- }
-}
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt
deleted file mode 100644
index 7882d85b3c..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/nested/ComputerUnitTest.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.baeldung.nested
-
-import org.assertj.core.api.Assertions.assertThat
-import org.junit.jupiter.api.Test
-
-class ComputerUnitTest {
-
- @Test
- fun givenComputer_whenPowerOn_thenBlink() {
- val computer = Computer("Desktop")
-
- assertThat(computer.powerOn()).isEqualTo("blinking Green")
- }
-
- @Test
- fun givenMotherboard_whenGetInfo_thenGetInstalledAndBuiltDetails() {
- val motherBoard = Computer.MotherBoard("MotherBoard Inc.")
-
- assertThat(motherBoard.getInfo()).isEqualTo("Made by MotherBoard Inc. installed in China - 2018-05-23")
- }
-
- @Test
- fun givenHardDisk_whenGetInfo_thenGetComputerModelAndDiskSizeInGb() {
- val hardDisk = Computer("Desktop").HardDisk(1000)
-
- assertThat(hardDisk.getInfo()).isEqualTo("Installed on Computer(model=Desktop) with 1000 GB")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt
deleted file mode 100644
index 8abed144eb..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/ConsoleUtilsUnitTest.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.static
-
-import org.junit.Test
-
-class ConsoleUtilsUnitTest {
- @Test
- fun givenAStaticMethod_whenCalled_thenNoErrorIsThrown() {
- ConsoleUtils.debug("test message")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt b/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt
deleted file mode 100644
index 59587ff009..0000000000
--- a/core-kotlin-modules/core-kotlin-lang-oop/src/test/kotlin/com/baeldung/static/LoggingUtilsUnitTest.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.baeldung.static
-
-import org.junit.Test
-
-class LoggingUtilsUnitTest {
- @Test
- fun givenAPackageMethod_whenCalled_thenNoErrorIsThrown() {
- debug("test message")
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/README.md b/core-kotlin-modules/core-kotlin-lang/README.md
deleted file mode 100644
index eaeae76854..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/README.md
+++ /dev/null
@@ -1,16 +0,0 @@
-## Core Kotlin Lang
-
-This module contains articles about core features in the Kotlin language.
-
-### Relevant articles:
-- [Guide to the “when{}” Block in Kotlin](https://www.baeldung.com/kotlin-when)
-- [Difference Between “==” and “===” Operators in Kotlin](https://www.baeldung.com/kotlin-equality-operators)
-- [Nested forEach in Kotlin](https://www.baeldung.com/kotlin-nested-foreach)
-- [Destructuring Declarations in Kotlin](https://www.baeldung.com/kotlin-destructuring-declarations)
-- [Try-with-resources in Kotlin](https://www.baeldung.com/kotlin-try-with-resources)
-- [Operator Overloading in Kotlin](https://www.baeldung.com/kotlin-operator-overloading)
-- [Inline Functions in Kotlin](https://www.baeldung.com/kotlin-inline-functions)
-- [Void Type in Kotlin](https://www.baeldung.com/kotlin-void-type)
-- [How to use Kotlin Range Expressions](https://www.baeldung.com/kotlin-ranges)
-- [Creating a Kotlin Range Iterator on a Custom Object](https://www.baeldung.com/kotlin-custom-range-iterator)
-- [[More --> ]](/core-kotlin-modules/core-kotlin-lang-2)
diff --git a/core-kotlin-modules/core-kotlin-lang/pom.xml b/core-kotlin-modules/core-kotlin-lang/pom.xml
deleted file mode 100644
index d3ac7f690c..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/pom.xml
+++ /dev/null
@@ -1,16 +0,0 @@
-
-
- 4.0.0
- core-kotlin-lang
- core-kotlin-lang
- jar
-
-
- com.baeldung.core-kotlin-modules
- core-kotlin-modules
- 1.0.0-SNAPSHOT
-
-
-
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt
deleted file mode 100644
index d3167ce033..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Person.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.destructuringdeclarations
-
-data class Person(var id: Int, var name: String, var age: Int)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt
deleted file mode 100644
index e3da9b46a4..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Result.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.destructuringdeclarations
-
-data class Result(val result: Int, val status: String)
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt
deleted file mode 100644
index f845d01539..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/destructuringdeclarations/Sandbox.kt
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.baeldung.destructuringdeclarations
-
-fun main(args: Array) {
-
- //2.1. Objects
- val person = Person(1, "Jon Snow", 20)
- val(id, name, age) = person
-
- println(id) //1
- println(name) //Jon Snow
- println(age) //20
-
- //2.2. Functions
- fun getPersonInfo() = Person(2, "Ned Stark", 45)
- val(idf, namef, agef) = getPersonInfo()
-
- fun twoValuesReturn(): Pair {
-
- // needed code
-
- return Pair(1, "success")
- }
-
- // Now, to use this function:
- val (result, status) = twoValuesReturn()
-
- //2.3. Collections and For-loops
- var map: HashMap = HashMap()
- map.put(1, person)
-
- for((key, value) in map){
- println("Key: $key, Value: $value")
- }
-
- //2.4. Underscore and Destructuring in Lambdas
- val (_, name2, age2) = person
- val (id3, name3) = person
-
- map.mapValues { entry -> "${entry.value}!" }
- map.mapValues { (key, value) -> "$value!" }
-
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt
deleted file mode 100644
index 030169bb8a..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/equalityoperators/User.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package com.baeldung.equalityoperators
-
-data class User(val name: String, val age: Int, val hobbies: List)
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt
deleted file mode 100644
index 20eda4e64f..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/forEach/forEach.kt
+++ /dev/null
@@ -1,87 +0,0 @@
-package com.baeldung.forEach
-
-
-class Country(val name : String, val cities : List)
-
-class City(val name : String, val streets : List)
-
-fun City.getStreetsWithCityName() : List {
- return streets.map { "$name, $it" }.toList()
-}
-
-fun Country.getCitiesWithCountryName() : List {
- return cities.flatMap { it.getStreetsWithCityName() }
- .map { "$name, $it" }
-}
-
-class World {
-
- private val streetsOfAmsterdam = listOf("Herengracht", "Prinsengracht")
- private val streetsOfBerlin = listOf("Unter den Linden","Tiergarten")
- private val streetsOfMaastricht = listOf("Grote Gracht", "Vrijthof")
- private val countries = listOf(
- Country("Netherlands", listOf(City("Maastricht", streetsOfMaastricht),
- City("Amsterdam", streetsOfAmsterdam))),
- Country("Germany", listOf(City("Berlin", streetsOfBerlin))))
-
- fun allCountriesIt() {
- countries.forEach { println(it.name) }
- }
-
- fun allCountriesItExplicit() {
- countries.forEach { it -> println(it.name) }
- }
-
- //here we cannot refer to 'it' anymore inside the forEach
- fun allCountriesExplicit() {
- countries.forEach { c -> println(c.name) }
- }
-
- fun allNested() {
- countries.forEach {
- println(it.name)
- it.cities.forEach {
- println(" ${it.name}")
- it.streets.forEach { println(" $it") }
- }
- }
- }
-
- fun allTable() {
- countries.forEach { c ->
- c.cities.forEach { p ->
- p.streets.forEach { println("${c.name} ${p.name} $it") }
- }
- }
- }
-
- fun allStreetsFlatMap() {
-
- countries.flatMap { it.cities}
- .flatMap { it.streets}
- .forEach { println(it) }
- }
-
- fun allFlatMapTable() {
-
- countries.flatMap { it.getCitiesWithCountryName() }
- .forEach { println(it) }
- }
-}
-
-fun main(args : Array) {
-
- val world = World()
-
- world.allCountriesExplicit()
-
- world.allNested()
-
- world.allTable()
-
- world.allStreetsFlatMap()
-
- world.allFlatMapTable()
-}
-
-
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt
deleted file mode 100644
index 3b179642ba..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/inline/Inline.kt
+++ /dev/null
@@ -1,28 +0,0 @@
-package com.baeldung.inline
-
-import kotlin.random.Random
-
-/**
- * An extension function on all collections to apply a function to all collection
- * elements.
- */
-fun Collection.each(block: (T) -> Unit) {
- for (e in this) block(e)
-}
-
-/**
- * In order to see the the JVM bytecode:
- * 1. Compile the Kotlin file using `kotlinc Inline.kt`
- * 2. Take a peek at the bytecode using the `javap -c InlineKt`
- */
-fun main() {
- val numbers = listOf(1, 2, 3, 4, 5)
- val random = random()
-
- numbers.each { println(random * it) } // capturing the random variable
-}
-
-/**
- * Generates a random number.
- */
-private fun random(): Int = Random.nextInt()
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt
deleted file mode 100644
index 93eb78c5b6..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Money.kt
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.baeldung.operators
-
-import java.math.BigDecimal
-
-enum class Currency {
- DOLLARS, EURO
-}
-
-class Money(val amount: BigDecimal, val currency: Currency) : Comparable {
-
- override fun compareTo(other: Money): Int =
- convert(Currency.DOLLARS).compareTo(other.convert(Currency.DOLLARS))
-
- fun convert(currency: Currency): BigDecimal = TODO()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) return true
- if (other !is Money) return false
-
- if (amount != other.amount) return false
- if (currency != other.currency) return false
-
- return true
- }
-
- override fun hashCode(): Int {
- var result = amount.hashCode()
- result = 31 * result + currency.hashCode()
- return result
- }
-}
\ No newline at end of file
diff --git a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt b/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt
deleted file mode 100644
index 8a0ee48a36..0000000000
--- a/core-kotlin-modules/core-kotlin-lang/src/main/kotlin/com/baeldung/operators/Page.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package com.baeldung.operators
-
-interface Page {
- fun pageNumber(): Int
- fun pageSize(): Int
- fun elements(): MutableList
-}
-
-operator fun Page.invoke(index: Int): T = elements()[index]
-operator fun Page.get(index: Int): T = elements()[index]
-operator fun Page.get(start: Int, endExclusive: Int): List