Skip to content

Commit 104b41c

Browse files
authored
Merge branch 'master' into master
2 parents 3b08798 + 18c6a1a commit 104b41c

File tree

121 files changed

+1222
-1145
lines changed

Some content is hidden

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

121 files changed

+1222
-1145
lines changed

code-generation/pom.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@
1212
</parent>
1313

1414
<dependencies>
15+
<dependency>
16+
<groupId>com.google.auto.value</groupId>
17+
<artifactId>auto-value-annotations</artifactId>
18+
<version>${auto-value.version}</version>
19+
</dependency>
1520
<dependency>
1621
<groupId>com.google.auto.value</groupId>
1722
<artifactId>auto-value</artifactId>
1823
<version>${auto-value.version}</version>
24+
<scope>provided</scope>
1925
</dependency>
2026
<dependency>
2127
<groupId>com.google.auto.factory</groupId>
@@ -43,9 +49,9 @@
4349
</dependencies>
4450

4551
<properties>
46-
<auto-value.version>1.3</auto-value.version>
47-
<auto-factory.version>1.0-beta5</auto-factory.version>
48-
<auto-service.version>1.0-rc5</auto-service.version>
52+
<auto-value.version>1.6.6</auto-value.version>
53+
<auto-factory.version>1.0-beta6</auto-factory.version>
54+
<auto-service.version>1.0-rc6</auto-service.version>
4955
<guice.version>4.2.0</guice.version>
5056
</properties>
5157

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.baeldung.autovalue;
2+
3+
import java.util.ArrayList;
4+
import java.util.Collections;
5+
import java.util.List;
6+
7+
import com.google.auto.value.AutoValue;
8+
9+
@AutoValue
10+
public abstract class Person {
11+
12+
public abstract String name();
13+
14+
public abstract List<String> favoriteMovies();
15+
16+
public static Builder builder() {
17+
return new AutoValue_Person.Builder();
18+
}
19+
20+
@AutoValue.Builder
21+
public static abstract class Builder {
22+
23+
public abstract Builder name(String value);
24+
25+
public abstract Builder favoriteMovies(List<String> value);
26+
27+
abstract List<String> favoriteMovies();
28+
29+
abstract Person autoBuild();
30+
31+
public Person build() {
32+
List<String> favoriteMovies = favoriteMovies();
33+
List<String> copy = Collections.unmodifiableList(new ArrayList<>(favoriteMovies));
34+
favoriteMovies(copy);
35+
return autoBuild();
36+
}
37+
}
38+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.autovalue;
2+
3+
import static org.junit.Assert.assertEquals;
4+
import static org.junit.Assert.assertFalse;
5+
6+
import java.util.ArrayList;
7+
import java.util.List;
8+
9+
import org.junit.Test;
10+
11+
/**
12+
* Unit Test which verifies that the {@link Person} value object creates defensive copies of its favoriteMovies list.
13+
*/
14+
public class PersonUnitTest {
15+
16+
@Test
17+
public void givenNewPerson_whenModifyOriginalList_thenValueObjectIsNotAlsoModified() {
18+
// GIVEN new Person
19+
List<String> originalFavoriteMoviesList = new ArrayList<String>();
20+
originalFavoriteMoviesList.add("Training Day");
21+
originalFavoriteMoviesList.add("Fast and the Furious");
22+
Person person = Person.builder()
23+
.name("Dan")
24+
.favoriteMovies(originalFavoriteMoviesList)
25+
.build();
26+
27+
// WHEN modify original list
28+
originalFavoriteMoviesList.add("Friday");
29+
30+
// THEN Person remains unaffected
31+
assertFalse(person.favoriteMovies()
32+
.contains("Friday"));
33+
assertEquals(2, person.favoriteMovies()
34+
.size());
35+
}
36+
37+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
## Core Java 9 streams
2+
3+
This module contains articles about Java 9 streams
4+
5+
### Relevant Articles:
6+
- [How to Break from Java Stream forEach](https://www.baeldung.com/java-break-stream-foreach)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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-9-streams</artifactId>
5+
<version>0.1.0-SNAPSHOT</version>
6+
<name>core-java-9-streams</name>
7+
<packaging>jar</packaging>
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+
</dependencies>
18+
19+
<build>
20+
<finalName>core-java-9-streams</finalName>
21+
<resources>
22+
<resource>
23+
<directory>src/main/resources</directory>
24+
<filtering>true</filtering>
25+
</resource>
26+
</resources>
27+
</build>
28+
29+
<properties>
30+
</properties>
31+
</project>

java-streams-2/src/main/java/com/baeldung/breakforeach/CustomForEach.java renamed to core-java-modules/core-java-9-streams/src/main/java/com/baeldung/streams/breakforeach/CustomForEach.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.breakforeach;
1+
package com.baeldung.streams.breakforeach;
22

33
import java.util.Spliterator;
44
import java.util.function.BiConsumer;

java-streams-2/src/main/java/com/baeldung/breakforeach/CustomSpliterator.java renamed to core-java-modules/core-java-9-streams/src/main/java/com/baeldung/streams/breakforeach/CustomSpliterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.breakforeach;
1+
package com.baeldung.streams.breakforeach;
22

33
import java.util.Spliterator;
44
import java.util.Spliterators;

java-streams-2/src/main/java/com/baeldung/breakforeach/CustomTakeWhile.java renamed to core-java-modules/core-java-9-streams/src/main/java/com/baeldung/streams/breakforeach/CustomTakeWhile.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.breakforeach;
1+
package com.baeldung.streams.breakforeach;
22

33
import java.util.function.Predicate;
44
import java.util.stream.Stream;

java-streams-2/src/main/java/com/baeldung/breakforeach/TakeWhileExample.java renamed to core-java-modules/core-java-9-streams/src/main/java/com/baeldung/streams/breakforeach/TakeWhileExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.breakforeach;
1+
package com.baeldung.streams.breakforeach;
22

33
import java.util.List;
44
import java.util.stream.Stream;

java-streams-2/src/test/java/com/baeldung/breakforeach/BreakFromStreamForEachUnitTest.java renamed to core-java-modules/core-java-9-streams/src/test/java/com/baeldung/streams/breakforeach/BreakFromStreamForEachUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.baeldung.breakforeach;
1+
package com.baeldung.streams.breakforeach;
22

33
import org.junit.Test;
44

0 commit comments

Comments
 (0)