Skip to content

Commit 5aef6d9

Browse files
committed
Merge branch 'master' of github.com:eugenp/tutorials
2 parents 852762f + a6c9c58 commit 5aef6d9

145 files changed

Lines changed: 3785 additions & 925 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.

‎.travis.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ before_install:
44
- echo "MAVEN_OPTS='-Xmx2048M -Xss128M -XX:+CMSClassUnloadingEnabled -XX:+UseG1GC -XX:-UseGCOverheadLimit'" > ~/.mavenrc
55

66
install: skip
7-
script: travis_wait 60 mvn -q install -Pdefault-first,default-second
7+
script: travis_wait 60 mvn -q install -Pdefault-first,default-second -Dgib.enabled=true
88

99
sudo: required
1010

‎algorithms-miscellaneous-2/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred)
1818
- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage)
1919
- [Converting Between Byte Arrays and Hexadecimal Strings in Java](https://www.baeldung.com/java-byte-arrays-hex-strings)
20+
- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude)

‎core-java-10/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
- [Java 10 LocalVariable Type-Inference](http://www.baeldung.com/java-10-local-variable-type-inference)
55
- [Guide to Java 10](http://www.baeldung.com/java-10-overview)
66
- [Copy a List to Another List in Java](http://www.baeldung.com/java-copy-list-to-another)
7+
- [Deep Dive Into the New Java JIT Compiler – Graal](https://www.baeldung.com/graal-java-jit-compiler)

‎core-java-8/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
- [An Overview of Regular Expressions Performance in Java](https://www.baeldung.com/java-regex-performance)
3434
- [Java Primitives versus Objects](https://www.baeldung.com/java-primitives-vs-objects)
3535
- [How to Use if/else Logic in Java 8 Streams](https://www.baeldung.com/java-8-streams-if-else-logic)
36+
- [How to Replace Many if Statements in Java](https://www.baeldung.com/java-replace-if-statements)

‎core-java-arrays/src/main/java/com/baeldung/array/operations/ArrayOperations.java‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
import java.util.Arrays;
55
import java.util.HashSet;
66
import java.util.LinkedHashSet;
7+
import java.util.LinkedList;
78
import java.util.Random;
89
import java.util.Set;
910
import java.util.function.Function;
1011
import java.util.function.IntPredicate;
1112
import java.util.function.Predicate;
13+
import java.util.stream.Stream;
1214

1315
import org.apache.commons.lang3.ArrayUtils;
1416

@@ -194,4 +196,16 @@ public static int getRandomFromIntArray(int[] array) {
194196
public static <T> T getRandomFromObjectArray(T[] array) {
195197
return array[new Random().nextInt(array.length)];
196198
}
199+
200+
public static Integer[] intersectionSimple(final Integer[] a, final Integer[] b){
201+
return Stream.of(a).filter(Arrays.asList(b)::contains).toArray(Integer[]::new);
202+
}
203+
204+
public static Integer[] intersectionSet(final Integer[] a, final Integer[] b){
205+
return Stream.of(a).filter(Arrays.asList(b)::contains).distinct().toArray(Integer[]::new);
206+
}
207+
208+
public static Integer[] intersectionMultiSet(final Integer[] a, final Integer[] b){
209+
return Stream.of(a).filter(new LinkedList<>(Arrays.asList(b))::remove).toArray(Integer[]::new);
210+
}
197211
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.baeldung.array.operations;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static com.baeldung.array.operations.ArrayOperations.intersectionMultiSet;
6+
import static com.baeldung.array.operations.ArrayOperations.intersectionSet;
7+
import static com.baeldung.array.operations.ArrayOperations.intersectionSimple;
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
class IntersectionUnitTest {
11+
private static final Integer[] a = { 1, 3, 2 };
12+
private static final Integer[] b = { 4, 3, 2, 4, 2, 3, 4, 4, 3 };
13+
private static final Integer[] c = { 1, 3, 2, 3, 3, 2 };
14+
15+
@Test
16+
void whenIntersectionSimpleIsUsed_thenCommonEntriesAreInTheResult() {
17+
assertThat(intersectionSimple(a, b)).isEqualTo(new Integer[] { 3, 2 });
18+
assertThat(intersectionSimple(b, a)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 });
19+
}
20+
21+
@Test
22+
void whenIntersectionSimpleIsUsedWithAnArrayAndItself_thenTheResultIsTheIdentity() {
23+
assertThat(intersectionSimple(b, b)).isEqualTo(b);
24+
assertThat(intersectionSimple(a, a)).isEqualTo(a);
25+
}
26+
27+
@Test
28+
void whenIntersectionSetIsUsed_thenCommonEntriesAreInTheResult() {
29+
assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 });
30+
}
31+
32+
@Test
33+
void whenIntersectionSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() {
34+
assertThat(intersectionSet(a, b)).isEqualTo(new Integer[] { 3, 2 });
35+
assertThat(intersectionSet(b, a)).isEqualTo(new Integer[] { 3, 2 });
36+
}
37+
38+
@Test
39+
void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasNoDuplicateEntries_ThenTheResultIsTheIdentity() {
40+
assertThat(intersectionSet(a, a)).isEqualTo(a);
41+
}
42+
43+
@Test
44+
void whenIntersectionSetIsUsedWithAnArrayAndWithItself_andTheInputHasDuplicateEntries_ThenTheResultIsNotTheIdentity() {
45+
assertThat(intersectionSet(b, b)).isNotEqualTo(b);
46+
}
47+
48+
@Test
49+
void whenMultiSetIsUsed_thenCommonEntriesAreInTheResult() {
50+
assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 });
51+
}
52+
53+
@Test
54+
void whenIntersectionMultiSetIsUsed_thenTheNumberOfEntriesDoesNotChangeWithTheParameterOrder() {
55+
assertThat(intersectionMultiSet(a, b)).isEqualTo(new Integer[] { 3, 2 });
56+
assertThat(intersectionMultiSet(b, a)).isEqualTo(new Integer[] { 3, 2 });
57+
assertThat(intersectionMultiSet(b, c)).isEqualTo(new Integer[] { 3, 2, 2, 3, 3 });
58+
assertThat(intersectionMultiSet(c, b)).isEqualTo(new Integer[] { 3, 2, 3, 3, 2 });
59+
}
60+
61+
@Test
62+
void whenIntersectionMultiSetIsUsedWithAnArrayAndWithItself_ThenTheResultIsTheIdentity() {
63+
assertThat(intersectionMultiSet(b, b)).isEqualTo(b);
64+
assertThat(intersectionMultiSet(a, a)).isEqualTo(a);
65+
}
66+
}

‎core-java-collections/README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,11 @@
4343
- [Converting a Collection to ArrayList in Java](https://www.baeldung.com/java-convert-collection-arraylist)
4444
- [Java 8 Streams: Find Items From One List Based On Values From Another List](https://www.baeldung.com/java-streams-find-list-items)
4545
- [Combining Different Types of Collections in Java](https://www.baeldung.com/java-combine-collections)
46+
- [Sorting in Java](http://www.baeldung.com/java-sorting)
47+
- [A Guide to the Java LinkedList](http://www.baeldung.com/java-linkedlist)
48+
- [Java List UnsupportedOperationException](http://www.baeldung.com/java-list-unsupported-operation-exception)
49+
- [Join and Split Arrays and Collections in Java](http://www.baeldung.com/java-join-and-split)
50+
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
51+
- [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line)
52+
- [ClassCastException: Arrays$ArrayList cannot be cast to ArrayList](https://www.baeldung.com/java-classcastexception-arrays-arraylist)
53+
- [A Guide to EnumMap](https://www.baeldung.com/java-enum-map)

‎core-java-collections/pom.xml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@
5656
<artifactId>commons-exec</artifactId>
5757
<version>1.3</version>
5858
</dependency>
59+
<dependency>
60+
<groupId>org.projectlombok</groupId>
61+
<artifactId>lombok</artifactId>
62+
<version>${lombok.version}</version>
63+
<scope>provided</scope>
64+
</dependency>
5965
</dependencies>
6066

6167
<properties>
@@ -67,5 +73,6 @@
6773
<avaitility.version>1.7.0</avaitility.version>
6874
<assertj.version>3.11.1</assertj.version>
6975
<eclipse.collections.version>7.1.0</eclipse.collections.version>
76+
<lombok.version>1.16.12</lombok.version>
7077
</properties>
7178
</project>

core-java/src/main/java/com/baeldung/classcastexception/ClassCastException.java renamed to core-java-collections/src/main/java/com/baeldung/classcastexception/ClassCastException.java

File renamed without changes.

core-java/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java renamed to core-java-collections/src/test/java/com/baeldung/java/listInitialization/ListInitializationUnitTest.java

File renamed without changes.

0 commit comments

Comments
 (0)