Skip to content

Commit 1fecf62

Browse files
committed
feat(collections): 🎸 merge map, translated
Refers: #10
1 parent 731a4ad commit 1fecf62

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed
Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
:java-package: src/org/j6toj8/collections
22
:section-java-package: ../../../{java-package}
33

4-
=== Maps e Streams
4+
=== Maps and Streams
55

6-
.Objetivo
6+
.Objective
77
--------------------------------------------------
88
Develop code that uses the merge(), flatMap(), and map() methods on Java Streams
9-
-
10-
Desenvolver código que usa os métodos merge(), flatMap(), e map() em Streams Java.
119
--------------------------------------------------
1210

13-
Dos objetivos desta seção, apenas o método `merge` ainda não foi apresentado em outras seções.
11+
About the objectives of this section, only the `merge` method has not yet been introduced in other sections.
1412

15-
. É possível colocar um novo valor em um mapa, ou alterar o valor que já estava presente, utilizando o método `merge`.
13+
. You can put a new value on a map, or change the value that was already present using the `merge` method.
1614
+
1715
[source,java,indent=0]
1816
.{java-package}/mergemap/Collections_Merge.java
1917
----
2018
include::{section-java-package}/mergemap/Collections_Merge.java[tag=code]
2119
----
2220
+
23-
.Saída no console
21+
.console output
2422
[source,console]
2523
----
26-
Map antes do merge: {1=String1-, 2=String2-}
27-
Map depois do merge: {1=String1-StringA, 2=String2-StringB, 3=StringC, 4=StringD}
24+
Map before merge: {1=String1-, 2=String2-}
25+
Map after merge: {1=String1-StringA, 2=String2-StringB, 3=StringC, 4=StringD}
2826
----
2927
+
30-
Perceba que, para as chaves que já estavam presentes no `Map`, foi aplicada a função lambda. Para as chaves que ainda não estavam presentes, foi apenas inserida a `String` passada como valor.
28+
Note that for keys that were already present in `Map`, the lambda function was applied. For keys that were not already present, only the `String` passed as value was entered.
3129

32-
. É possível transformar valores em uma coleção com o método `map`.
30+
. You can transform values into a collection with the `map` method.
3331
+
3432
[source,java,indent=0]
3533
.{java-package}/mergemap/Collections_Map.java
3634
----
3735
include::{section-java-package}/mergemap/Collections_Map.java[tag=code]
3836
----
3937
+
40-
.Saída no console
38+
.console output
4139
[source,console]
4240
----
4341
2
@@ -51,21 +49,21 @@ include::{section-java-package}/mergemap/Collections_Map.java[tag=code]
5149
18
5250
----
5351

54-
. É possível percorrer outro Stream, em sequência com o Stream atual, utilizando o método `flatMap`.
52+
. You can traverse another Stream in sequence with the current Stream using the `flatMap` method.
5553
+
5654
[source,java,indent=0]
5755
.{java-package}/mergemap/Collections_FlatMap.java
5856
----
5957
include::{section-java-package}/mergemap/Collections_FlatMap.java[tag=code]
6058
----
6159
+
62-
.Saída no console
60+
.console output
6361
[source,console]
6462
----
65-
Com map:
66-
java.util.stream.ReferencePipeline$Head@e9e54c2
63+
With map:
64+
java.util.stream.ReferencePipeline$Head@5f184fc6
6765
68-
Com flatMap:
66+
With flatMap:
6967
M
7068
a
7169
n
@@ -74,20 +72,21 @@ e
7472
l
7573
----
7674
+
77-
Perceba que uma transformação que resulta em outro Stream é percorrida como se fosse o próprio Stream original.
75+
Note that a transformation that results in another Stream is traversed as if it were the original Stream itself.
7876

77+
.References
7978
****
8079
8180
* Additions in Java 8
8281
+
83-
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 152). Wiley. Edição do Kindle.
82+
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 152). Wiley. Kindle Edition.
8483
8584
* Using Streams
8685
+
87-
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Edição do Kindle.
86+
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Kindle Edition.
8887
8988
* https://www.baeldung.com/java-8-streams[The Java 8 Stream API Tutorial.]
9089
9190
* https://www.baeldung.com/java-merge-maps[Merging Two Maps with Java 8.]
9291
93-
****
92+
****

src/org/j6toj8/collections/mergemap/Collections_FlatMap.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ public static void main(String[] args) {
99
// tag::code[]
1010
List<String> list = Arrays.asList("Manoel");
1111

12-
System.out.println("\n Com map: ");
13-
// com map - as letras da String viram
14-
// um Stream dentro de outro Stream
12+
System.out.println("\n With map: ");
13+
// com map - String letters become Stream within Stream
1514
list.stream()
1615
.map(s -> Arrays.stream(s.split("")))
1716
.forEach(System.out::println);
1817

19-
System.out.println("\n Com flatMap: ");
20-
// com flatMap - as letras da String viram dados
21-
// do próprio Stream
18+
System.out.println("\n With flatMap: ");
19+
// with flatMap - String letters become data of the Stream
2220
list.stream()
2321
.flatMap(s -> Arrays.stream(s.split("")))
2422
.forEach(System.out::println);

src/org/j6toj8/collections/mergemap/Collections_Merge.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ public static void main(String[] args) {
1010
map.put(1, "String1-");
1111
map.put(2, "String2-");
1212

13-
System.out.println("Map antes do merge: " + map);
13+
System.out.println("Map before merge: " + map);
1414
map.merge(1, "StringA", (v1, v2) -> v1.concat(v2));
1515
map.merge(2, "StringB", (v1, v2) -> v1.concat(v2));
1616
map.merge(3, "StringC", (v1, v2) -> v1.concat(v2));
1717
map.merge(4, "StringD", (v1, v2) -> v1.concat(v2));
18-
System.out.println("Map depois do merge: " + map);
18+
System.out.println("Map after merge: " + map);
1919
// end::code[]
2020
}
2121
}

0 commit comments

Comments
 (0)