Merge branch 'master' into BAEL-16646

This commit is contained in:
Alessio Stalla
2019-10-02 17:13:32 +02:00
committed by GitHub
894 changed files with 7349 additions and 2067 deletions

View File

@@ -1,6 +1,6 @@
## Relevant articles:
- [Dijkstra Algorithm in Java](https://www.baeldung.com/java-dijkstra)
- [Dijkstra Shortest Path Algorithm in Java](https://www.baeldung.com/java-dijkstra)
- [Introduction to Cobertura](https://www.baeldung.com/cobertura)
- [Test a Linked List for Cyclicity](https://www.baeldung.com/java-linked-list-cyclicity)
- [Introduction to JGraphT](https://www.baeldung.com/jgrapht)

View File

@@ -8,3 +8,4 @@
- [Checking if a Java Graph has a Cycle](https://www.baeldung.com/java-graph-has-a-cycle)
- [A Guide to the Folding Technique in Java](https://www.baeldung.com/folding-hashing-technique)
- [Creating a Triangle with for Loops in Java](https://www.baeldung.com/java-print-triangle)
- [Efficient Word Frequency Calculator in Java](https://www.baeldung.com/java-word-frequency)

View File

@@ -54,6 +54,21 @@
<version>1.1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-bytecode</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
</dependencies>
<build>
@@ -73,5 +88,7 @@
<commons-collections4.version>4.3</commons-collections4.version>
<guava.version>28.0-jre</guava.version>
<retrofit.version>2.6.0</retrofit.version>
<jmh-core.version>1.19</jmh-core.version>
<jmh-generator.version>1.19</jmh-generator.version>
</properties>
</project>

View File

@@ -7,3 +7,4 @@
- [Heap Sort in Java](https://www.baeldung.com/java-heap-sort)
- [Shell Sort in Java](https://www.baeldung.com/java-shell-sort)
- [Counting Sort in Java](https://www.baeldung.com/java-counting-sort)
- [Sorting Strings by Contained Numbers in Java](https://www.baeldung.com/java-sort-strings-contained-numbers)

View File

@@ -1,3 +1,4 @@
## Relevant articles:
- [OData Protocol Guide](https://www.baeldung.com/odata)
- [Intro to OData with Olingo](https://www.baeldung.com/olingo)

View File

@@ -1,6 +1,7 @@
package com.baeldung.cdi.cdi2observers.application;
package com.baeldung.cdi2observers.application;
import com.baeldung.cdi2observers.events.ExampleEvent;
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.se.SeContainerInitializer;

View File

@@ -1,4 +1,4 @@
package com.baeldung.cdi.cdi2observers.events;
package com.baeldung.cdi2observers.events;
public class ExampleEvent {

View File

@@ -1,4 +1,4 @@
package com.baeldung.cdi.cdi2observers.events;
package com.baeldung.cdi2observers.events;
import javax.enterprise.event.Event;
import javax.inject.Inject;

View File

@@ -1,6 +1,7 @@
package com.baeldung.cdi.cdi2observers.observers;
package com.baeldung.cdi2observers.observers;
import com.baeldung.cdi2observers.events.ExampleEvent;
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
import javax.annotation.Priority;
import javax.enterprise.event.Observes;

View File

@@ -1,7 +1,7 @@
package com.baeldung.cdi.cdi2observers.observers;
package com.baeldung.cdi2observers.observers;
import com.baeldung.cdi.cdi2observers.events.ExampleEvent;
import com.baeldung.cdi.cdi2observers.services.TextService;
import com.baeldung.cdi2observers.events.ExampleEvent;
import com.baeldung.cdi2observers.services.TextService;
import javax.annotation.Priority;
import javax.enterprise.event.Observes;

View File

@@ -1,4 +1,4 @@
package com.baeldung.cdi.cdi2observers.services;
package com.baeldung.cdi2observers.services;
public class TextService {

View File

@@ -1,7 +1,8 @@
<beans xmlns="http://java.sun.com/xml/ns/javaee"
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/beans_1_2.xsd">
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">
<interceptors>
<class>com.baeldung.interceptor.AuditedInterceptor</class>
</interceptors>

View File

@@ -1,9 +1,10 @@
package com.baeldung.cdi.cdi2observers.tests;
package com.baeldung.test.cdi2observers.tests;
import com.baeldung.cdi.cdi2observers.services.TextService;
import static org.assertj.core.api.Assertions.assertThat;
import com.baeldung.cdi2observers.services.TextService;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TextServiceUnitTest {
@Test

View File

@@ -6,7 +6,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class TimeLoggerFactoryUnitTest {
@Test
public void givenTimeLoggerFactory_whenCalledgetTimeLogger_thenOneAssertion() {
TimeLoggerFactory timeLoggerFactory = new TimeLoggerFactory();

View File

@@ -9,3 +9,4 @@
- [Working with XML in Groovy](https://www.baeldung.com/groovy-xml)
- [Integrating Groovy into Java Applications](https://www.baeldung.com/groovy-java-applications)
- [Concatenate Strings with Groovy](https://www.baeldung.com/groovy-concatenate-strings)
- [Metaprogramming in Groovy](https://www.baeldung.com/groovy-metaprogramming)

View File

@@ -0,0 +1,17 @@
package com.baeldung.category;
class BaeldungCategory {
public static String capitalize(String self) {
String capitalizedStr = self;
if (self.size() > 0) {
capitalizedStr = self.substring(0, 1).toUpperCase() + self.substring(1);
}
return capitalizedStr
}
public static double toThePower(Number self, Number exponent) {
return Math.pow(self, exponent);
}
}

View File

@@ -0,0 +1,17 @@
package com.baeldung.category;
import groovy.lang.Category
@Category(Number)
class NumberCategory {
public Number cube() {
return this*this*this
}
public int divideWithRoundUp(BigDecimal divisor, boolean isRoundUp) {
def mathRound = isRoundUp ? BigDecimal.ROUND_UP : BigDecimal.ROUND_DOWN
return (int)new BigDecimal(this).divide(divisor, 0, mathRound)
}
}

View File

@@ -0,0 +1,101 @@
package com.baeldung.category
import groovy.time.*
import java.text.SimpleDateFormat
import groovy.xml.*
import groovy.xml.dom.*
import com.baeldung.category.BaeldungCategory
import com.baeldung.category.NumberCategory
class CategoryUnitTest extends GroovyTestCase {
void test_whenUsingTimeCategory_thenOperationOnDate() {
def jan_1_2019 = new Date("01/01/2019")
use (TimeCategory) {
assert jan_1_2019 + 10.seconds == new Date("01/01/2019 00:00:10")
assert jan_1_2019 + 20.minutes == new Date("01/01/2019 00:20:00")
assert jan_1_2019 + 2.hours == new Date("01/01/2019 02:00:00")
assert jan_1_2019 - 1.day == new Date("12/31/2018")
assert jan_1_2019 + 2.weeks == new Date("01/15/2019")
assert jan_1_2019 - 2.months == new Date("11/01/2018")
assert jan_1_2019 + 3.years == new Date("01/01/2022")
}
}
void test_whenUsingTimeCategory_thenOperationOnNumber() {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy")
use (TimeCategory) {
assert sdf.format(5.days.from.now) == sdf.format(new Date() + 5.days)
sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss")
assert sdf.format(10.minutes.from.now) == sdf.format(new Date() + 10.minutes)
assert sdf.format(2.hours.ago) == sdf.format(new Date() - 2.hours)
}
}
void test_whenUsingDOMCategory_thenOperationOnXML() {
def baeldungArticlesText = """
<articles>
<article core-java="true">
<title>An Intro to the Java Debug Interface (JDI)</title>
<desc>A quick and practical overview of Java Debug Interface.</desc>
</article>
<article core-java="false">
<title>A Quick Guide to Working with Web Services in Groovy</title>
<desc>Learn how to work with Web Services in Groovy.</desc>
</article>
</articles>
"""
def baeldungArticlesDom = DOMBuilder.newInstance().parseText(baeldungArticlesText)
def root = baeldungArticlesDom.documentElement
use (DOMCategory) {
assert root.article.size() == 2
def articles = root.article
assert articles[0].title.text() == "An Intro to the Java Debug Interface (JDI)"
assert articles[1].desc.text() == "Learn how to work with Web Services in Groovy."
def articleNode3 = root.appendNode(new QName("article"), ["core-java": "false"])
articleNode3.appendNode("title", "Metaprogramming in Groovy")
articleNode3.appendNode("desc", "Explore the concept of runtime and compile-time metaprogramming in Groovy")
assert root.article.size() == 3
assert root.article[2].title.text() == "Metaprogramming in Groovy"
}
}
void test_whenUsingBaeldungCategory_thenCapitalizeString() {
use (BaeldungCategory) {
assert "norman".capitalize() == "Norman"
}
}
void test_whenUsingBaeldungCategory_thenOperationsOnNumber() {
use (BaeldungCategory) {
assert 50.toThePower(2) == 2500
assert 2.4.toThePower(4) == 33.1776
}
}
void test_whenUsingNumberCategory_thenOperationsOnNumber() {
use (NumberCategory) {
assert 3.cube() == 27
assert 25.divideWithRoundUp(6, true) == 5
assert 120.23.divideWithRoundUp(6.1, true) == 20
assert 150.9.divideWithRoundUp(12.1, false) == 12
}
}
}

View File

@@ -5,6 +5,6 @@
### Relevant Articles:
- [Anonymous Classes in Java](http://www.baeldung.com/)
- [How to Delay Code Execution in Java](https://www.baeldung.com/java-delay-code-execution)
- [Run JAR Application With Command Line Arguments](https://www.baeldung.com/java-run-jar-with-arguments)
- [Run a Java Application from the Command Line](https://www.baeldung.com/java-run-jar-with-arguments)
- [Java 8 Stream skip() vs limit()](https://www.baeldung.com/java-stream-skip-vs-limit)
- [Guide to Java BiFunction Interface](https://www.baeldung.com/java-bifunction-interface)

View File

@@ -3,35 +3,12 @@
## Core Java 8 Cookbooks and Examples
### Relevant Articles:
- [Guide to Java 8s Collectors](http://www.baeldung.com/java-8-collectors)
- [New Features in Java 8](http://www.baeldung.com/java-8-new-features)
- [The Double Colon Operator in Java 8](http://www.baeldung.com/java-8-double-colon-operator)
- [Guide to Java 8 groupingBy Collector](http://www.baeldung.com/java-groupingby-collector)
- [Strategy Design Pattern in Java 8](http://www.baeldung.com/java-strategy-pattern)
- [Guide to Java 8 Comparator.comparing()](http://www.baeldung.com/java-8-comparator-comparing)
- [Guide To Java 8 Optional](http://www.baeldung.com/java-optional)
- [Guide to the Java 8 forEach](http://www.baeldung.com/foreach-java)
- [The Difference Between map() and flatMap()](http://www.baeldung.com/java-difference-map-and-flatmap)
- [Static and Default Methods in Interfaces in Java](http://www.baeldung.com/java-static-default-methods)
- [Efficient Word Frequency Calculator in Java](http://www.baeldung.com/java-word-frequency)
- [Introduction to Spliterator in Java](http://www.baeldung.com/java-spliterator)
- [Java 8 Math New Methods](http://www.baeldung.com/java-8-math)
- [Overview of Java Built-in Annotations](http://www.baeldung.com/java-default-annotations)
- [Finding Min/Max in an Array with Java](http://www.baeldung.com/java-array-min-max)
- [Internationalization and Localization in Java 8](http://www.baeldung.com/java-8-localization)
- [Java Optional orElse() vs orElseGet()](http://www.baeldung.com/java-optional-or-else-vs-or-else-get)
- [Java 8 Unsigned Arithmetic Support](http://www.baeldung.com/java-unsigned-arithmetic)
- [Generalized Target-Type Inference in Java](http://www.baeldung.com/java-generalized-target-type-inference)
- [Overriding System Time for Testing in Java](http://www.baeldung.com/java-override-system-time)
- [Set the Time Zone of a Date in Java](https://www.baeldung.com/java-set-date-time-zone)
- [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance)
- [Java Primitives versus Objects](https://www.baeldung.com/java-primitives-vs-objects)
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
- [How to Replace Many if Statements in Java](https://www.baeldung.com/java-replace-if-statements)
- [Java @Override Annotation](https://www.baeldung.com/java-override)
- [Java @SuppressWarnings Annotation](https://www.baeldung.com/java-suppresswarnings)
- [Java @SafeVarargs Annotation](https://www.baeldung.com/java-safevarargs)
- [Java @Deprecated Annotation](https://www.baeldung.com/java-deprecated)
- [Java 8 Predicate Chain](https://www.baeldung.com/java-predicate-chain)
- [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation)
- [The Difference Between Collection.stream().forEach() and Collection.forEach()](https://www.baeldung.com/java-collection-stream-foreach)
- [New Features in Java 8](https://www.baeldung.com/java-8-new-features)
- [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector)
- [Strategy Design Pattern in Java 8](https://www.baeldung.com/java-strategy-pattern)
- [Guide to Java 8 Comparator.comparing()](https://www.baeldung.com/java-8-comparator-comparing)
- [Guide to the Java 8 forEach](https://www.baeldung.com/foreach-java)
- [Introduction to Spliterator in Java](https://www.baeldung.com/java-spliterator)
- [Finding Min/Max in an Array with Java](https://www.baeldung.com/java-array-min-max)
- [Internationalization and Localization in Java 8](https://www.baeldung.com/java-8-localization)
- [Generalized Target-Type Inference in Java](https://www.baeldung.com/java-generalized-target-type-inference)

View File

@@ -116,12 +116,6 @@
<version>${powermock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>${jmockit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@@ -150,16 +144,6 @@
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<argLine>
-javaagent:${settings.localRepository}/org/jmockit/jmockit/${jmockit.version}/jmockit-${jmockit.version}.jar
</argLine>
<disableXmlReport>true</disableXmlReport>
</configuration>
</plugin>
</plugins>
</build>
@@ -176,7 +160,6 @@
<assertj.version>3.6.1</assertj.version>
<asspectj.version>1.8.9</asspectj.version>
<powermock.version>2.0.0-RC.4</powermock.version>
<jmockit.version>1.44</jmockit.version>
<avaitility.version>1.7.0</avaitility.version>
<jmh-core.version>1.19</jmh-core.version>
<jmh-generator.version>1.19</jmh-generator.version>

View File

@@ -0,0 +1,11 @@
=========
## Core Java 8 Cookbooks and Examples
### Relevant Articles:
- [Java @Override Annotation](https://www.baeldung.com/java-override)
- [Java @SuppressWarnings Annotation](https://www.baeldung.com/java-suppresswarnings)
- [Java @SafeVarargs Annotation](https://www.baeldung.com/java-safevarargs)
- [Java @Deprecated Annotation](https://www.baeldung.com/java-deprecated)
- [Overview of Java Built-in Annotations](https://www.baeldung.com/java-default-annotations)
- [Creating a Custom Annotation in Java](https://www.baeldung.com/java-custom-annotation)

View File

@@ -0,0 +1,72 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung</groupId>
<artifactId>core-java-annotations</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-annotations</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
<!-- test scoped -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh-core.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-bytecode</artifactId>
<version>${jmh-generator.version}</version>
</dependency>
</dependencies>
<build>
<finalName>core-java-annotations</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<properties>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<asspectj.version>1.8.9</asspectj.version>
<jmh-core.version>1.19</jmh-core.version>
<jmh-generator.version>1.19</jmh-generator.version>
<!-- plugins -->
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
</properties>
</project>

View File

@@ -1,25 +0,0 @@
*.class
0.*
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
.resourceCache
# Packaged files #
*.jar
*.war
*.ear
# Files generated by integration tests
backup-pom.xml
/bin/
/temp
#IntelliJ specific
.idea/
*.iml

View File

@@ -1,5 +1,10 @@
## Relevant Articles
- [Extending an Arrays Length](https://www.baeldung.com/java-array-add-element-at-the-end)
- [Checking If an Array Is Sorted in Java](https://www.baeldung.com/java-check-sorted-array)
- [Looping Diagonally Through a 2d Java Array](https://www.baeldung.com/java-loop-diagonal-array)
- [Converting Between Stream and Array in Java](https://www.baeldung.com/java-stream-to-array)
- [Convert a Float to a Byte Array in Java](https://www.baeldung.com/java-convert-float-to-byte-array)
- [Array Operations in Java](https://www.baeldung.com/java-common-array-operations)
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)
- [Removing an Element from an Array in Java](https://www.baeldung.com/java-array-remove-element)
- [Removing the First Element of an Array](https://www.baeldung.com/java-array-remove-first-element)

View File

@@ -1,19 +1,14 @@
package com.baeldung.array.operations;
import org.apache.commons.lang3.ArrayUtils;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Random;
import java.util.Set;
import java.util.*;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.apache.commons.lang3.ArrayUtils;
public class ArrayOperations {
// Get the first and last item of an array

View File

@@ -1,13 +1,10 @@
package com.baeldung.array;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.lang3.ArrayUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class RemoveElementFromAnArrayUnitTest {
private final RemoveElementFromAnArray sut = new RemoveElementFromAnArray();

View File

@@ -1,12 +1,10 @@
package com.baeldung.array.conversions;
import static com.baeldung.array.conversions.FloatToByteArray.byteArrayToFloat;
import static com.baeldung.array.conversions.FloatToByteArray.byteArrayToFloatWithByteBuffer;
import static com.baeldung.array.conversions.FloatToByteArray.floatToByteArray;
import static com.baeldung.array.conversions.FloatToByteArray.floatToByteArrayWithByteBuffer;
import org.junit.Test;
import static com.baeldung.array.conversions.FloatToByteArray.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class FloatToByteArrayUnitTest {

View File

@@ -1,13 +1,13 @@
package com.baeldung.array.operations;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Arrays;
import org.assertj.core.api.Condition;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import static org.assertj.core.api.Assertions.assertThat;
public class ArrayOperationsUnitTest {
private Integer[] defaultObjectArray;

View File

@@ -2,9 +2,7 @@ package com.baeldung.array.operations;
import org.junit.jupiter.api.Test;
import static com.baeldung.array.operations.ArrayOperations.intersectionMultiSet;
import static com.baeldung.array.operations.ArrayOperations.intersectionSet;
import static com.baeldung.array.operations.ArrayOperations.intersectionSimple;
import static com.baeldung.array.operations.ArrayOperations.*;
import static org.assertj.core.api.Assertions.assertThat;
class IntersectionUnitTest {

View File

@@ -1,4 +1,4 @@
package com.baeldung.list.removefirst;
package com.baeldung.array.removefirst;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

View File

@@ -1,25 +0,0 @@
*.class
0.*
#folders#
/target
/neoDb*
/data
/src/main/webapp/WEB-INF/classes
*/META-INF/*
.resourceCache
# Packaged files #
*.jar
*.war
*.ear
# Files generated by integration tests
backup-pom.xml
/bin/
/temp
#IntelliJ specific
.idea/
*.iml

View File

@@ -3,17 +3,14 @@
## Core Java Arrays Cookbooks and Examples
### Relevant Articles:
- [How to Copy an Array in Java](http://www.baeldung.com/java-array-copy)
- [Check if a Java Array Contains a Value](http://www.baeldung.com/java-array-contains-value)
- [Initializing Arrays in Java](http://www.baeldung.com/java-initialize-array)
- [Guide to the java.util.Arrays Class](http://www.baeldung.com/java-util-arrays)
- [Multi-Dimensional Arrays In Java](http://www.baeldung.com/java-jagged-arrays)
- [Find Sum and Average in a Java Array](http://www.baeldung.com/java-array-sum-average)
- [How to Copy an Array in Java](https://www.baeldung.com/java-array-copy)
- [Check if a Java Array Contains a Value](https://www.baeldung.com/java-array-contains-value)
- [Initializing Arrays in Java](https://www.baeldung.com/java-initialize-array)
- [Guide to the java.util.Arrays Class](https://www.baeldung.com/java-util-arrays)
- [Multi-Dimensional Arrays In Java](https://www.baeldung.com/java-jagged-arrays)
- [Find Sum and Average in a Java Array](https://www.baeldung.com/java-array-sum-average)
- [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide)
- [How to Invert an Array in Java](http://www.baeldung.com/java-invert-array)
- [Array Operations in Java](http://www.baeldung.com/java-common-array-operations)
- [Intersection Between two Integer Arrays](https://www.baeldung.com/java-array-intersection)
- [Read and Write User Input in Java](https://www.baeldung.com/java-console-input-output)
- [How to Reverse an Array in Java](http://www.baeldung.com/java-invert-array)
- [Sorting Arrays in Java](https://www.baeldung.com/java-sorting-arrays)
- [Convert a Float to a Byte Array in Java](https://www.baeldung.com/java-convert-float-to-byte-array)
- [Converting Between Stream and Array in Java](https://www.baeldung.com/java-stream-to-array)
- [Removing an Element from an Array in Java](https://www.baeldung.com/java-array-remove-element)
- [Checking If an Array Is Sorted in Java](https://www.baeldung.com/java-check-sorted-array)

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;

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