Split or move core-java-collections module (#7842)

This commit is contained in:
Catalin Burcea 2019-09-27 16:31:36 +03:00 committed by Josh Cummings
parent 957ad4587c
commit 0677a06271
60 changed files with 292 additions and 194 deletions

View File

@ -0,0 +1,15 @@
=========
## Core Java Collections Cookbooks and Examples
### Relevant Articles:
- [Removing Elements from Java Collections](https://www.baeldung.com/java-collection-remove-elements)
- [How to Filter a Collection in Java](https://www.baeldung.com/java-collection-filtering)
- [Join and Split Arrays and Collections in Java](https://www.baeldung.com/java-join-and-split)
- [Java Combine Multiple Collections](https://www.baeldung.com/java-combine-multiple-collections)
- [Combining Different Types of Collections in Java](https://www.baeldung.com/java-combine-collections)
- [Shuffling Collections In Java](https://www.baeldung.com/java-shuffle-collection)
- [Sorting in Java](https://www.baeldung.com/java-sorting)
- [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)

View File

@ -0,0 +1,58 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-collections-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>core-java-collections-2</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>${eclipse.collections.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>${commons-exec.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<eclipse.collections.version>7.1.0</eclipse.collections.version>
<commons-collections4.version>4.1</commons-collections4.version>
<assertj.version>3.11.1</assertj.version>
<junit.platform.version>1.2.0</junit.platform.version>
<commons-exec.version>1.3</commons-exec.version>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import java.util.Arrays;
import java.util.stream.Stream;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import java.util.Collection;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import java.util.Collection;
import java.util.HashSet;

View File

@ -1,4 +1,4 @@
package com.baeldung.java.filtering;
package com.baeldung.collections.filtering;
import java.util.Collection;
import java.util.function.Predicate;

View File

@ -1,4 +1,4 @@
package com.baeldung.java.iterable;
package com.baeldung.collections.iterablesize;
import java.util.Collection;
import java.util.stream.StreamSupport;

View File

@ -1,4 +1,4 @@
package com.baeldung.removal;
package com.baeldung.collections.removal;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.baeldung.removal;
package com.baeldung.collections.removal;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.baeldung.removal;
package com.baeldung.collections.removal;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.baeldung.removal;
package com.baeldung.collections.removal;
import java.util.ArrayList;
import java.util.Collection;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import static org.junit.Assert.*;
import org.junit.Test;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

View File

@ -1,4 +1,4 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

View File

@ -1,5 +1,5 @@
package com.baeldung.combiningcollections;
package com.baeldung.collections.combiningcollections;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

View File

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

View File

@ -1,4 +1,4 @@
package com.baeldung.java.iterable;
package com.baeldung.collections.iterablesize;
import static org.junit.Assert.assertEquals;

View File

@ -1,4 +1,4 @@
package org.baeldung.java.collections;
package com.baeldung.collections.joinsplit;
import java.util.ArrayList;
import java.util.Collections;

View File

@ -1,4 +1,4 @@
package org.baeldung.java.collections;
package com.baeldung.collections.multiplecollections;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
@ -14,7 +14,7 @@ import java.util.stream.Stream;
import static java.util.Arrays.asList;
public class CollectionsConcatenateUnitTest {
public class CombineMultipleCollectionsUnitTest {
@Test
public void givenUsingJava8_whenConcatenatingUsingConcat_thenCorrect() {

View File

@ -1,4 +1,4 @@
package com.baeldung.removal;
package com.baeldung.collections.removal;
import org.junit.Before;
import org.junit.Test;

View File

@ -1,4 +1,4 @@
package org.baeldung.java.sorting;
package com.baeldung.collections.sorting;
public class Employee implements Comparable {

View File

@ -1,4 +1,4 @@
package org.baeldung.java.sorting;
package com.baeldung.collections.sorting;
import com.google.common.primitives.Ints;
import org.apache.commons.lang3.ArrayUtils;

View File

@ -0,0 +1,11 @@
=========
## 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)
- [Differences Between Collection.clear() and Collection.removeAll()](https://www.baeldung.com/java-collection-clear-vs-removeall)
- [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)

View File

@ -0,0 +1,34 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-collections-3</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-collections-3</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${openjdk.jmh.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<openjdk.jmh.version>1.19</openjdk.jmh.version>
<assertj.version>3.11.1</assertj.version>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package com.baeldung.performance;
package com.baeldung.collections.arraylistvsvector;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;

View File

@ -0,0 +1,55 @@
package com.baeldung.collections.arraylistvsvector;
public class Employee {
private Long id;
private String name;
public Employee(Long id, String name) {
this.name = name;
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
if (!id.equals(employee.id)) return false;
return name.equals(employee.name);
}
@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + name.hashCode();
return result;
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.java.list;
package com.baeldung.collections.arraylistvsvector;
import java.util.Enumeration;
import java.util.Iterator;

View File

@ -1,4 +1,4 @@
package com.baeldung.performance;
package com.baeldung.collections.containsperformance;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.runner.Runner;

View File

@ -0,0 +1,55 @@
package com.baeldung.collections.containsperformance;
public class Employee {
private Long id;
private String name;
public Employee(Long id, String name) {
this.name = name;
this.id = id;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
if (!id.equals(employee.id)) return false;
return name.equals(employee.name);
}
@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + name.hashCode();
return result;
}
@Override
public String toString() {
return "Employee{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.iterators;
package com.baeldung.collections.iterators;
import java.util.ArrayList;
import java.util.Iterator;

View File

@ -1,4 +1,4 @@
package com.baeldung.performance;
package com.baeldung.collections.sortingcomparison;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

View File

@ -1,4 +1,4 @@
package com.baeldung.java.sort;
package com.baeldung.collections.sortingcomparison;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,8 +1,8 @@
package com.baeldung.iterators;
package com.baeldung.collections.iterators;
import static com.baeldung.iterators.Iterators.failFast1;
import static com.baeldung.iterators.Iterators.failFast2;
import static com.baeldung.iterators.Iterators.failSafe1;
import static com.baeldung.collections.iterators.Iterators.failFast1;
import static com.baeldung.collections.iterators.Iterators.failFast2;
import static com.baeldung.collections.iterators.Iterators.failSafe1;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

View File

@ -12,3 +12,4 @@
- [How to Find an Element in a List with Java](http://www.baeldung.com/find-list-element-java)
- [Finding Max/Min of a List or Collection](http://www.baeldung.com/java-collection-min-max)
- [Remove All Occurrences of a Specific Value from a List](https://www.baeldung.com/java-remove-value-from-list)
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)

View File

@ -3,29 +3,13 @@
## Core Java Collections Cookbooks and Examples
### Relevant Articles:
- [Java Combine Multiple Collections](http://www.baeldung.com/java-combine-multiple-collections)
- [Collect a Java Stream to an Immutable Collection](http://www.baeldung.com/java-stream-immutable-collection)
- [Introduction to the Java ArrayDeque](http://www.baeldung.com/java-array-deque)
- [Getting the Size of an Iterable in Java](http://www.baeldung.com/java-iterable-size)
- [How to Filter a Collection in Java](http://www.baeldung.com/java-collection-filtering)
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)
- [Fail-Safe Iterator vs Fail-Fast Iterator](http://www.baeldung.com/java-fail-safe-vs-fail-fast-iterator)
- [Shuffling Collections In Java](http://www.baeldung.com/java-shuffle-collection)
- [An Introduction to Java.util.Hashtable Class](http://www.baeldung.com/java-hash-table)
- [Java Null-Safe Streams from Collections](https://www.baeldung.com/java-null-safe-streams-from-collections)
- [Collect a Java Stream to an Immutable Collection](https://www.baeldung.com/java-stream-immutable-collection)
- [Introduction to the Java ArrayDeque](https://www.baeldung.com/java-array-deque)
- [An Introduction to Java.util.Hashtable Class](https://www.baeldung.com/java-hash-table)
- [Thread Safe LIFO Data Structure Implementations](https://www.baeldung.com/java-lifo-thread-safe)
- [Differences Between Collection.clear() and Collection.removeAll()](https://www.baeldung.com/java-collection-clear-vs-removeall)
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
- [Time Complexity of Java Collections](https://www.baeldung.com/java-collections-complexity)
- [Operating on and Removing an Item from Stream](https://www.baeldung.com/java-use-remove-item-stream)
- [An Introduction to Synchronized Java Collections](https://www.baeldung.com/java-synchronized-collections)
- [Removing Elements from Java Collections](https://www.baeldung.com/java-collection-remove-elements)
- [Combining Different Types of Collections in Java](https://www.baeldung.com/java-combine-collections)
- [Sorting in Java](http://www.baeldung.com/java-sorting)
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map)
- [A Guide to Iterator in Java](http://www.baeldung.com/java-iterator)
- [Differences Between HashMap and Hashtable](https://www.baeldung.com/hashmap-hashtable-differences)
- [Java ArrayList vs Vector](https://www.baeldung.com/java-arraylist-vs-vector)
- [A Guide to Iterator in Java](https://www.baeldung.com/java-iterator)
- [Defining a Char Stack in Java](https://www.baeldung.com/java-char-stack)
- [Time Comparison of Arrays.sort(Object[]) and Arrays.sort(int[])](https://www.baeldung.com/arrays-sortobject-vs-sortint)
- [Guide to the Java Queue Interface](https://www.baeldung.com/java-queue)
- [An Introduction to Synchronized Java Collections](https://www.baeldung.com/java-synchronized-collections)

View File

@ -14,33 +14,12 @@
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>${eclipse.collections.version}</version>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
@ -51,11 +30,6 @@
<artifactId>jmh-generator-annprocess</artifactId>
<version>${openjdk.jmh.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-exec</artifactId>
<version>${commons-exec.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -66,13 +40,6 @@
<properties>
<openjdk.jmh.version>1.19</openjdk.jmh.version>
<junit.platform.version>1.2.0</junit.platform.version>
<commons-lang3.version>3.8.1</commons-lang3.version>
<commons-collections4.version>4.1</commons-collections4.version>
<collections-generic.version>4.01</collections-generic.version>
<avaitility.version>1.7.0</avaitility.version>
<assertj.version>3.11.1</assertj.version>
<eclipse.collections.version>7.1.0</eclipse.collections.version>
<commons-exec.version>1.3</commons-exec.version>
</properties>
</project>

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.application;
package com.baeldung.synchronizedcollections;
import java.util.Arrays;
import java.util.Collections;

View File

@ -1,83 +0,0 @@
package com.baeldung.java.collections;
import org.junit.Test;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
public class ConcurrentModificationExceptionUnitTest {
@Test
public void changingContentWithSetDoesNotThrowConcurrentModificationException() throws Exception {
ArrayList<Object> array = new ArrayList<>(asList(0, "one", 2, "three"));
for (Object item : array) {
array.set(3, 3);
}
}
@Test
public void removingElementUsingIteratorAPI() throws Exception {
List<String> originalList = new ArrayList<>(asList("zero", "one", "two", "three"));
Iterator<String> iterator = originalList.iterator();
while (iterator.hasNext()) {
String next = iterator.next();
if (Objects.equals(next, "one")) iterator.remove();
}
assertEquals(originalList, asList("zero", "two", "three"));
}
@Test
public void modifyingContentAndIteratingUsingListIteratorAPI() throws Exception {
List<String> originalList = new ArrayList<>(asList("zero", "one", "two", "three"));
ListIterator<String> iterator = originalList.listIterator();
while (iterator.hasNext()) {
String next = iterator.next();
if (Objects.equals(next, "one")) {
iterator.set("another");
}
if (Objects.equals(next, "two")) {
iterator.remove();
}
if (Objects.equals(next, "three")) {
iterator.add("four");
}
}
assertEquals(originalList, asList("zero", "another", "three", "four"));
}
@Test
public void removingElementUsingCopyAndListAPI() throws Exception {
List<String> originalList = new ArrayList<>(asList("zero", "one", "two", "three"));
List<String> listCopy = new ArrayList<>(originalList);
for (String next : listCopy) {
if (Objects.equals(next, "one")) originalList.remove(originalList.indexOf(next) - 1);
}
assertEquals(originalList, asList("one", "two", "three"));
}
@Test
public void copyOnWriteList() throws Exception {
List<String> originalList = new CopyOnWriteArrayList<>(asList("zero", "one", "two", "three"));
for (String next : originalList) {
if (Objects.equals(next, "one")) originalList.remove(originalList.indexOf(next) - 1);
}
assertEquals(originalList, asList("one", "two", "three"));
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.ArrayList;
import java.util.Arrays;

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.Collections;
import java.util.HashMap;

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.Arrays;
import java.util.Collections;

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.Collections;
import java.util.Map;

View File

@ -1,4 +1,4 @@
package com.baeldung.synchronizedcollections.test;
package com.baeldung.synchronizedcollections;
import java.util.Arrays;
import java.util.Collections;

View File

@ -1,3 +0,0 @@
### Relevant Articles:
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
- [Introduction to Java Servlets](http://www.baeldung.com/intro-to-servlets)

View File

@ -401,6 +401,8 @@
<module>core-java-modules/core-java-arrays</module>
<module>core-java-modules/core-java-arrays-2</module>
<module>core-java-modules/core-java-collections</module>
<module>core-java-modules/core-java-collections-2</module>
<module>core-java-modules/core-java-collections-3</module>
<module>core-java-modules/core-java-collections-list</module>
<module>core-java-modules/core-java-collections-list-2</module>
<module>core-java-modules/core-java-collections-list-3</module>
@ -1141,6 +1143,8 @@
<module>core-java-modules/core-java-arrays</module>
<module>core-java-modules/core-java-arrays-2</module>
<module>core-java-modules/core-java-collections</module>
<module>core-java-modules/core-java-collections-2</module>
<module>core-java-modules/core-java-collections-3</module>
<module>core-java-modules/core-java-collections-list</module>
<module>core-java-modules/core-java-collections-list-2</module>
<module>core-java-modules/core-java-collections-list-3</module>