Java 16961 (#13236)

* [JAVA-16961] Moved code for article "Create an Empty Map in Java"

* [JAVA-16961] Alter README.md

* [JAVA-16961] Moved code for article "Sorting a Hashset in Java"

* [JAVA-16961] Added links to README.md files

* [JAVA-16961] Revert link changes

* [JAVA-16961] Replaced junit4 with junit5 annotations

* [JAVA-16961] test build

* [JAVA-16961] Added junit annotations

* [JAVA-16961] Added links

Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
panos-kakos 2023-01-13 14:37:27 +00:00 committed by GitHub
parent 4723349f37
commit 13097b458f
15 changed files with 44 additions and 22 deletions

View File

@ -13,3 +13,4 @@
- [Getting the Size of an Iterable in Java](https://www.baeldung.com/java-iterable-size) - [Getting the Size of an Iterable in Java](https://www.baeldung.com/java-iterable-size)
- [Java Null-Safe Streams from Collections](https://www.baeldung.com/java-null-safe-streams-from-collections) - [Java Null-Safe Streams from Collections](https://www.baeldung.com/java-null-safe-streams-from-collections)
- [Differences Between Iterator and Iterable and How to Use Them?](https://www.baeldung.com/java-iterator-vs-iterable) - [Differences Between Iterator and Iterable and How to Use Them?](https://www.baeldung.com/java-iterator-vs-iterable)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-1) [[next -->]](/core-java-modules/core-java-collections-3)

View File

@ -7,7 +7,6 @@
- [ArrayList vs. LinkedList vs. HashMap in Java](https://www.baeldung.com/java-arraylist-vs-linkedlist-vs-hashmap) - [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) - [Java Deque vs. Stack](https://www.baeldung.com/java-deque-vs-stack)
- [Collection.toArray(new T[0]) or .toArray(new T[size])](https://www.baeldung.com/java-collection-toarray-methods) - [Collection.toArray(new T[0]) or .toArray(new T[size])](https://www.baeldung.com/java-collection-toarray-methods)
- [Create an Empty Map in Java](https://www.baeldung.com/java-create-empty-map)
- [Sorting Objects in a List by Date](https://www.baeldung.com/java-sort-list-by-date) - [Sorting Objects in a List by Date](https://www.baeldung.com/java-sort-list-by-date)
- [Fixed Size Queue Implementations in Java](https://www.baeldung.com/java-fixed-size-queue) - [Fixed Size Queue Implementations in Java](https://www.baeldung.com/java-fixed-size-queue)
- [Difference Between Java Enumeration and Iterator](https://www.baeldung.com/java-enumeration-vs-iterator) - [Difference Between Java Enumeration and Iterator](https://www.baeldung.com/java-enumeration-vs-iterator)
@ -15,4 +14,4 @@
- [Guide to Java PriorityQueue](https://www.baeldung.com/java-priorityqueue) - [Guide to Java PriorityQueue](https://www.baeldung.com/java-priorityqueue)
- [Java Generics PECS Producer Extends Consumer Super](https://www.baeldung.com/java-generics-pecs) - [Java Generics PECS Producer Extends Consumer Super](https://www.baeldung.com/java-generics-pecs)
- [Reversing a Stack in Java](https://www.baeldung.com/java-reversing-a-stack) - [Reversing a Stack in Java](https://www.baeldung.com/java-reversing-a-stack)
- [Sorting a HashSet in Java](https://www.baeldung.com/java-sort-hashset) - More articles: [[<-- prev]](/core-java-modules/core-java-collections-3)

View File

@ -25,6 +25,12 @@
<artifactId>commons-lang3</artifactId> <artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version> <version>${commons-lang3.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>

View File

@ -2,9 +2,7 @@ package com.baeldung.collections.comparation;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map; import java.util.Map;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@ -2,10 +2,8 @@ package com.baeldung.collections.comparation;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;

View File

@ -10,7 +10,7 @@ import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.jupiter.api.Test;
public class EmployeeSortingByDateUnitTest { public class EmployeeSortingByDateUnitTest {

View File

@ -5,8 +5,9 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class ComparatorsUnitTest { public class ComparatorsUnitTest {
@Test @Test

View File

@ -1,10 +1,12 @@
package com.baeldung.stackreversal; package com.baeldung.stackreversal;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.baeldung.collections.sorting.Employee; import com.baeldung.collections.sorting.Employee;
import com.baeldung.collections.stackreversal.ReverseStackUsingQueue; import com.baeldung.collections.stackreversal.ReverseStackUsingQueue;
import com.baeldung.collections.stackreversal.ReverseStackUsingRecursion; import com.baeldung.collections.stackreversal.ReverseStackUsingRecursion;
import org.junit.Assert;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -15,7 +17,7 @@ public class StackReversalUnitTest {
ReverseStackUsingQueue reverseStack = new ReverseStackUsingQueue(); ReverseStackUsingQueue reverseStack = new ReverseStackUsingQueue();
Stack<Integer> originalStack = generateStackFromGivenList(Arrays.stream(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).boxed().collect(Collectors.toList()), new Stack<Integer>()); Stack<Integer> originalStack = generateStackFromGivenList(Arrays.stream(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).boxed().collect(Collectors.toList()), new Stack<Integer>());
Stack<Integer> reverseList = generateStackFromGivenList(Arrays.stream(new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}).boxed().collect(Collectors.toList()), new Stack<Integer>()); Stack<Integer> reverseList = generateStackFromGivenList(Arrays.stream(new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}).boxed().collect(Collectors.toList()), new Stack<Integer>());
Assert.assertEquals(reverseStack.reverseIntegerStack(originalStack), reverseList); assertEquals(reverseStack.reverseIntegerStack(originalStack), reverseList);
} }
@Test @Test
@ -26,7 +28,7 @@ public class StackReversalUnitTest {
Collections.reverse(listOfWordsReversed); Collections.reverse(listOfWordsReversed);
Stack<String> originalStack = generateStackFromGivenList(listOfWords, new Stack<String>()); Stack<String> originalStack = generateStackFromGivenList(listOfWords, new Stack<String>());
Stack<String> reversedStack = generateStackFromGivenList(listOfWordsReversed, new Stack<String>()); Stack<String> reversedStack = generateStackFromGivenList(listOfWordsReversed, new Stack<String>());
Assert.assertEquals(stackReversal.reverseStringStack(originalStack), reversedStack); assertEquals(stackReversal.reverseStringStack(originalStack), reversedStack);
} }
@Test @Test
@ -43,7 +45,7 @@ public class StackReversalUnitTest {
Collections.reverse(employeeReversed); Collections.reverse(employeeReversed);
Stack<Employee> originalStack = generateStackFromGivenList(employeeList, new Stack<Employee>()); Stack<Employee> originalStack = generateStackFromGivenList(employeeList, new Stack<Employee>());
Stack<Employee> reverseStack = generateStackFromGivenList(employeeReversed, new Stack<Employee>()); Stack<Employee> reverseStack = generateStackFromGivenList(employeeReversed, new Stack<Employee>());
Assert.assertEquals(stackReversal.reverseEmployeeStack(originalStack), reverseStack); assertEquals(stackReversal.reverseEmployeeStack(originalStack), reverseStack);
} }
@Test @Test
@ -51,7 +53,7 @@ public class StackReversalUnitTest {
ReverseStackUsingRecursion reverseStack = new ReverseStackUsingRecursion(); ReverseStackUsingRecursion reverseStack = new ReverseStackUsingRecursion();
Stack<Integer> originalStack = generateStackFromGivenList(Arrays.stream(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).boxed().collect(Collectors.toList()), new Stack<Integer>()); Stack<Integer> originalStack = generateStackFromGivenList(Arrays.stream(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}).boxed().collect(Collectors.toList()), new Stack<Integer>());
Stack<Integer> reversedStack = generateStackFromGivenList(Arrays.stream(new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}).boxed().collect(Collectors.toList()), new Stack<Integer>()); Stack<Integer> reversedStack = generateStackFromGivenList(Arrays.stream(new int[]{10, 9, 8, 7, 6, 5, 4, 3, 2, 1}).boxed().collect(Collectors.toList()), new Stack<Integer>());
Assert.assertEquals(reverseStack.reverseIntegerStack(originalStack), reversedStack); assertEquals(reverseStack.reverseIntegerStack(originalStack), reversedStack);
} }
private Stack generateStackFromGivenList(List elements, Stack stack){ private Stack generateStackFromGivenList(List elements, Stack stack){

View File

@ -12,4 +12,5 @@ This module contains articles about Map data structures in Java.
- [Immutable Map Implementations in Java](https://www.baeldung.com/java-immutable-maps) - [Immutable Map Implementations in Java](https://www.baeldung.com/java-immutable-maps)
- [Guide to Apache Commons MultiValuedMap](https://www.baeldung.com/apache-commons-multi-valued-map) - [Guide to Apache Commons MultiValuedMap](https://www.baeldung.com/apache-commons-multi-valued-map)
- [The Java HashMap Under the Hood](https://www.baeldung.com/java-hashmap-advanced) - [The Java HashMap Under the Hood](https://www.baeldung.com/java-hashmap-advanced)
- [Create an Empty Map in Java](https://www.baeldung.com/java-create-empty-map)
- More articles: [[next -->]](/core-java-modules/core-java-collections-maps-2) - More articles: [[next -->]](/core-java-modules/core-java-collections-maps-2)

View File

@ -20,6 +20,12 @@
<artifactId>commons-collections4</artifactId> <artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version> <version>${commons-collections4.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,7 +1,5 @@
package com.baeldung.maps.initialize; package com.baeldung.map;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
@ -10,6 +8,9 @@ import java.util.NavigableMap;
import java.util.SortedMap; import java.util.SortedMap;
import java.util.TreeMap; import java.util.TreeMap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
public class EmptyMapInitializer { public class EmptyMapInitializer {
public static Map<String, String> articleMap; public static Map<String, String> articleMap;

View File

@ -1,11 +1,12 @@
package com.baeldung.maps.initialize; package com.baeldung.map;
import java.util.Map;
import org.junit.Test;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
import org.junit.Test;
public class EmptyMapInitializerUnitTest { public class EmptyMapInitializerUnitTest {
@Test(expected=UnsupportedOperationException.class) @Test(expected=UnsupportedOperationException.class)

View File

@ -2,3 +2,5 @@
- [Using Streams to Collect Into a TreeSet](https://www.baeldung.com/java-stream-collect-into-treeset) - [Using Streams to Collect Into a TreeSet](https://www.baeldung.com/java-stream-collect-into-treeset)
- [A Guide to LinkedHashSet in Java](https://www.baeldung.com/java-linkedhashset) - [A Guide to LinkedHashSet in Java](https://www.baeldung.com/java-linkedhashset)
- [Sorting a HashSet in Java](https://www.baeldung.com/java-sort-hashset)
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-set)

View File

@ -15,6 +15,12 @@
</parent> </parent>
<dependencies> <dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<build> <build>

View File

@ -1,4 +1,4 @@
package com.baeldung.collections.sorting; package com.baeldung.hashset.sorting;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;