Skip to content

Commit e9fa785

Browse files
committed
[BAEL-9712] - Fixed conflicts
2 parents 96d121b + 80566a8 commit e9fa785

101 files changed

Lines changed: 3500 additions & 705 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@
5050
- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality)
5151
- [Java List Initialization in One Line](https://www.baeldung.com/java-init-list-one-line)
5252
- [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-io/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
- [Read a File into an ArrayList](https://www.baeldung.com/java-file-to-arraylist)
3535
- [Guide to Java OutputStream](https://www.baeldung.com/java-outputstream)
3636
- [Reading a CSV File into an Array](https://www.baeldung.com/java-csv-file-array)
37+
- [Guide to BufferedReader](https://www.baeldung.com/java-buffered-reader)

‎core-java-lang/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@
5656
- [How to Separate Double into Integer and Decimal Parts](https://www.baeldung.com/java-separate-double-into-integer-decimal-parts)
5757
- [“Sneaky Throws” in Java](http://www.baeldung.com/java-sneaky-throws)
5858
- [Inheritance and Composition (Is-a vs Has-a relationship) in Java](http://www.baeldung.com/java-inheritance-composition)
59+
- [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors)
5960

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.baeldung.constructors;
2+
3+
import java.time.LocalDateTime;
4+
5+
class BankAccount {
6+
String name;
7+
LocalDateTime opened;
8+
double balance;
9+
10+
@Override
11+
public String toString() {
12+
return String.format("%s, %s, %f", this.name, this.opened.toString(), this.balance);
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public LocalDateTime getOpened() {
20+
return opened;
21+
}
22+
23+
public double getBalance() {
24+
return this.balance;
25+
}
26+
}
27+
28+
class BankAccountEmptyConstructor extends BankAccount {
29+
public BankAccountEmptyConstructor() {
30+
this.name = "";
31+
this.opened = LocalDateTime.now();
32+
this.balance = 0.0d;
33+
}
34+
}
35+
36+
class BankAccountParameterizedConstructor extends BankAccount {
37+
public BankAccountParameterizedConstructor(String name, LocalDateTime opened, double balance) {
38+
this.name = name;
39+
this.opened = opened;
40+
this.balance = balance;
41+
}
42+
}
43+
44+
class BankAccountCopyConstructor extends BankAccount {
45+
public BankAccountCopyConstructor(String name, LocalDateTime opened, double balance) {
46+
this.name = name;
47+
this.opened = opened;
48+
this.balance = balance;
49+
}
50+
51+
public BankAccountCopyConstructor(BankAccount other) {
52+
this.name = other.name;
53+
this.opened = LocalDateTime.now();
54+
this.balance = 0.0f;
55+
}
56+
}

0 commit comments

Comments
 (0)