Skip to content

Commit a295224

Browse files
committed
Merge remote-tracking branch 'eugenp/master'
2 parents ee1e3ee + 15b7eac commit a295224

75 files changed

Lines changed: 2405 additions & 405 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,5 @@ jmeter/src/main/resources/*-JMeter.csv
6262
**/dist
6363
**/tmp
6464
**/out-tsc
65+
**/nbproject/
66+
**/nb-configuration.xml

‎README.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ In additional to Spring, the following technologies are in focus: `core Java`, `
2121
Building the project
2222
====================
2323
To do the full build, do: `mvn install -Pdefault -Dgib.enabled=false`
24+
25+
26+
Building a single module
27+
====================
28+
To build a specific module run the command: `mvn clean install -Dgib.enabled=false` in the module directory
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.baeldung.algorithms.insertionsort;
2+
3+
public class InsertionSort {
4+
5+
public static void insertionSortImperative(int[] input) {
6+
for (int i = 1; i < input.length; i++) {
7+
int key = input[i];
8+
int j = i - 1;
9+
while (j >= 0 && input[j] > key) {
10+
input[j + 1] = input[j];
11+
j = j - 1;
12+
}
13+
input[j + 1] = key;
14+
}
15+
}
16+
17+
public static void insertionSortRecursive(int[] input) {
18+
insertionSortRecursive(input, input.length);
19+
}
20+
21+
private static void insertionSortRecursive(int[] input, int i) {
22+
// base case
23+
if (i <= 1) {
24+
return;
25+
}
26+
27+
// sort the first i - 1 elements of the array
28+
insertionSortRecursive(input, i - 1);
29+
30+
// then find the correct position of the element at position i
31+
int key = input[i - 1];
32+
int j = i - 2;
33+
// shifting the elements from their position by 1
34+
while (j >= 0 && input[j] > key) {
35+
input[j + 1] = input[j];
36+
j = j - 1;
37+
}
38+
// inserting the key at the appropriate position
39+
input[j + 1] = key;
40+
}
41+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.baeldung.algorithms.insertionsort;
2+
3+
import com.baeldung.algorithms.insertionsort.InsertionSort;
4+
import org.junit.Test;
5+
6+
import static org.junit.Assert.assertArrayEquals;
7+
8+
public class InsertionSortUnitTest {
9+
10+
@Test
11+
public void givenUnsortedArray_whenInsertionSortImperative_thenSortedAsc() {
12+
int[] input = {6, 2, 3, 4, 5, 1};
13+
InsertionSort.insertionSortImperative(input);
14+
int[] expected = {1, 2, 3, 4, 5, 6};
15+
assertArrayEquals("the two arrays are not equal", expected, input);
16+
}
17+
18+
@Test
19+
public void givenUnsortedArray_whenInsertionSortRecursive_thenSortedAsc() {
20+
int[] input = {6, 4, 5, 2, 3, 1};
21+
InsertionSort.insertionSortRecursive(input);
22+
int[] expected = {1, 2, 3, 4, 5, 6};
23+
assertArrayEquals("the two arrays are not equal", expected, input);
24+
}
25+
}

‎core-java-8/src/test/java/com/baeldung/internationalization/DateTimeFormatterUnitTest.java‎

Lines changed: 0 additions & 46 deletions
This file was deleted.

‎core-java-collections/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
- [Thread Safe LIFO Data Structure Implementations](https://www.baeldung.com/java-lifo-thread-safe)
4949
- [Collections.emptyList() vs. New List Instance](https://www.baeldung.com/java-collections-emptylist-new-list)
5050
- [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap)
51+
- [Differences Between Collection.clear() and Collection.removeAll()](https://www.baeldung.com/java-collection-clear-vs-removeall)
5152
- [Performance of contains() in a HashSet vs ArrayList](https://www.baeldung.com/java-hashset-arraylist-contains-performance)
5253
- [Get the Key for a Value from a Java Map](https://www.baeldung.com/java-map-key-from-value)
5354
- [Time Complexity of Java Collections](https://www.baeldung.com/java-collections-complexity)

‎core-java-collections/pom.xml‎

Lines changed: 88 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,88 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3-
<modelVersion>4.0.0</modelVersion>
4-
<groupId>com.baeldung</groupId>
5-
<artifactId>core-java-collections</artifactId>
6-
<version>0.1.0-SNAPSHOT</version>
7-
<packaging>jar</packaging>
8-
<name>core-java-collections</name>
9-
10-
<parent>
11-
<groupId>com.baeldung</groupId>
12-
<artifactId>parent-java</artifactId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<relativePath>../parent-java</relativePath>
15-
</parent>
16-
17-
<dependencies>
18-
<dependency>
19-
<groupId>net.sourceforge.collections</groupId>
20-
<artifactId>collections-generic</artifactId>
21-
<version>${collections-generic.version}</version>
22-
</dependency>
23-
<dependency>
24-
<groupId>org.apache.commons</groupId>
25-
<artifactId>commons-collections4</artifactId>
26-
<version>${commons-collections4.version}</version>
27-
</dependency>
28-
<dependency>
29-
<groupId>com.jayway.awaitility</groupId>
30-
<artifactId>awaitility</artifactId>
31-
<version>${avaitility.version}</version>
32-
<scope>test</scope>
33-
</dependency>
34-
<dependency>
35-
<groupId>org.apache.commons</groupId>
36-
<artifactId>commons-lang3</artifactId>
37-
<version>${commons-lang3.version}</version>
38-
</dependency>
39-
<dependency>
40-
<groupId>org.eclipse.collections</groupId>
41-
<artifactId>eclipse-collections</artifactId>
42-
<version>${eclipse.collections.version}</version>
43-
</dependency>
44-
<dependency>
45-
<groupId>org.assertj</groupId>
46-
<artifactId>assertj-core</artifactId>
47-
<version>${assertj.version}</version>
48-
<scope>test</scope>
49-
</dependency>
50-
<dependency>
51-
<groupId>org.junit.platform</groupId>
52-
<artifactId>junit-platform-runner</artifactId>
53-
<version>${junit.platform.version}</version>
54-
<scope>test</scope>
55-
</dependency>
56-
<dependency>
57-
<groupId>org.openjdk.jmh</groupId>
58-
<artifactId>jmh-core</artifactId>
59-
<version>${openjdk.jmh.version}</version>
60-
</dependency>
61-
<dependency>
62-
<groupId>org.openjdk.jmh</groupId>
63-
<artifactId>jmh-generator-annprocess</artifactId>
64-
<version>${openjdk.jmh.version}</version>
65-
</dependency>
66-
<dependency>
67-
<groupId>org.apache.commons</groupId>
68-
<artifactId>commons-exec</artifactId>
69-
<version>1.3</version>
70-
</dependency>
71-
<dependency>
72-
<groupId>one.util</groupId>
73-
<artifactId>streamex</artifactId>
74-
<version>0.6.5</version>
75-
</dependency>
76-
77-
</dependencies>
78-
79-
80-
<properties>
81-
<openjdk.jmh.version>1.19</openjdk.jmh.version>
82-
<junit.platform.version>1.2.0</junit.platform.version>
83-
<commons-lang3.version>3.5</commons-lang3.version>
84-
<commons-collections4.version>4.1</commons-collections4.version>
85-
<collections-generic.version>4.01</collections-generic.version>
86-
<avaitility.version>1.7.0</avaitility.version>
87-
<assertj.version>3.6.1</assertj.version>
88-
<eclipse.collections.version>7.1.0</eclipse.collections.version>
89-
</properties>
90-
</project>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<artifactId>core-java-collections</artifactId>
5+
<version>0.1.0-SNAPSHOT</version>
6+
<packaging>jar</packaging>
7+
<name>core-java-collections</name>
8+
9+
<parent>
10+
<groupId>com.baeldung</groupId>
11+
<artifactId>parent-java</artifactId>
12+
<version>0.0.1-SNAPSHOT</version>
13+
<relativePath>../parent-java</relativePath>
14+
</parent>
15+
16+
<dependencies>
17+
<dependency>
18+
<groupId>net.sourceforge.collections</groupId>
19+
<artifactId>collections-generic</artifactId>
20+
<version>${collections-generic.version}</version>
21+
</dependency>
22+
<dependency>
23+
<groupId>org.apache.commons</groupId>
24+
<artifactId>commons-collections4</artifactId>
25+
<version>${commons-collections4.version}</version>
26+
</dependency>
27+
<dependency>
28+
<groupId>com.jayway.awaitility</groupId>
29+
<artifactId>awaitility</artifactId>
30+
<version>${avaitility.version}</version>
31+
<scope>test</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.apache.commons</groupId>
35+
<artifactId>commons-lang3</artifactId>
36+
<version>${commons-lang3.version}</version>
37+
</dependency>
38+
<dependency>
39+
<groupId>org.eclipse.collections</groupId>
40+
<artifactId>eclipse-collections</artifactId>
41+
<version>${eclipse.collections.version}</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.assertj</groupId>
45+
<artifactId>assertj-core</artifactId>
46+
<version>${assertj.version}</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.platform</groupId>
51+
<artifactId>junit-platform-runner</artifactId>
52+
<version>${junit.platform.version}</version>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.openjdk.jmh</groupId>
57+
<artifactId>jmh-core</artifactId>
58+
<version>${openjdk.jmh.version}</version>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.openjdk.jmh</groupId>
62+
<artifactId>jmh-generator-annprocess</artifactId>
63+
<version>${openjdk.jmh.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.apache.commons</groupId>
67+
<artifactId>commons-exec</artifactId>
68+
<version>1.3</version>
69+
</dependency>
70+
71+
<dependency>
72+
<groupId>one.util</groupId>
73+
<artifactId>streamex</artifactId>
74+
<version>0.6.5</version>
75+
</dependency>
76+
</dependencies>
77+
78+
<properties>
79+
<openjdk.jmh.version>1.19</openjdk.jmh.version>
80+
<junit.platform.version>1.2.0</junit.platform.version>
81+
<commons-lang3.version>3.5</commons-lang3.version>
82+
<commons-collections4.version>4.1</commons-collections4.version>
83+
<collections-generic.version>4.01</collections-generic.version>
84+
<avaitility.version>1.7.0</avaitility.version>
85+
<assertj.version>3.6.1</assertj.version>
86+
<eclipse.collections.version>7.1.0</eclipse.collections.version>
87+
</properties>
88+
</project>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung.convertcollectiontoarraylist;
2+
3+
/**
4+
* This POJO is the element type of our collection. It has a deepCopy() method.
5+
*
6+
* @author chris
7+
*/
8+
public class Foo {
9+
10+
private int id;
11+
private String name;
12+
private Foo parent;
13+
14+
public Foo() {
15+
}
16+
17+
public Foo(int id, String name, Foo parent) {
18+
this.id = id;
19+
this.name = name;
20+
this.parent = parent;
21+
}
22+
23+
public int getId() {
24+
return id;
25+
}
26+
27+
public void setId(int id) {
28+
this.id = id;
29+
}
30+
31+
public String getName() {
32+
return name;
33+
}
34+
35+
public void setName(String name) {
36+
this.name = name;
37+
}
38+
39+
public Foo getParent() {
40+
return parent;
41+
}
42+
43+
public void setParent(Foo parent) {
44+
this.parent = parent;
45+
}
46+
47+
public Foo deepCopy() {
48+
return new Foo(
49+
this.id, this.name, this.parent != null ? this.parent.deepCopy() : null);
50+
}
51+
52+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.synchronizedcollections.application;
2+
3+
import java.util.Arrays;
4+
import java.util.Collections;
5+
import java.util.List;
6+
import java.util.logging.Logger;
7+
8+
public class Application {
9+
10+
private static final Logger LOGGER = Logger.getLogger(Application.class.getName());
11+
12+
public static void main(String[] args) throws InterruptedException {
13+
List<Integer> syncCollection = Collections.synchronizedList(Arrays.asList(1, 2, 3, 4, 5, 6));
14+
synchronized (syncCollection) {
15+
syncCollection.forEach((e) -> {LOGGER.info(e.toString());});
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)