Skip to content

Commit 731a4ad

Browse files
committed
feat(collections): 🎸 collection improvements, translated
Refers: #10
1 parent da1b2c7 commit 731a4ad

File tree

5 files changed

+32
-33
lines changed

5 files changed

+32
-33
lines changed
Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,82 @@
11
:java-package: src/org/j6toj8/collections
22
:section-java-package: ../../../{java-package}
33

4-
=== Melhorias de Java 8 em Coleções
4+
=== Java 8 collection improvements
55

6-
.Objetivo
6+
.Objective
77
--------------------------------------------------
88
Develop code that uses Java SE 8 collection improvements, including the Collection.removeIf(), List.replaceAll(), Map.computeIfAbsent(), and Map.computeIfPresent() methods
9-
-
10-
Desenvolver código que use as melhorias em coleções do Java SE 8, incluindo os métodos Collection.removeIf(), List.replaceAll(), Map.computeIfAbsent(), e Map.computeIfPresent()
119
--------------------------------------------------
1210

13-
O Java 8 trouxe vários métodos em Collections que utilizam como argumento uma função lambda, facilitando algumas operações. Serão apresentados exemplos dos 4 métodos relacionados a esse objetivo.
11+
Java 8 has introduced several methods in Collections that use a lambda function as argument, making some operations easier. Examples of the 4 methods related to this objective will be presented.
1412

15-
. É possível remover um item de uma coleção condicionalmente com uma função lambda.
13+
. You can conditionally remove an item from a collection with a lambda function.
1614
+
1715
[source,java,indent=0]
1816
.{java-package}/improvements/Collections_RemoveIf.java
1917
----
2018
include::{section-java-package}/improvements/Collections_RemoveIf.java[tag=code]
2119
----
2220
+
23-
.Saída no console
21+
.console output
2422
[source,console]
2523
----
26-
Lista antes do removeIf: [1, 2, 3, 4, 5, 6, 7, 8, 9]
27-
Lista depois do removeIf: [1, 3, 5, 7, 9]
24+
List before removeIf: [1, 2, 3, 4, 5, 6, 7, 8, 9]
25+
List after removeIf: [1, 3, 5, 7, 9]
2826
----
2927

30-
. É possível modificar todos os elementos da coleção de acordo com uma operação lambda.
28+
. You can modify all elements of the collection according to a lambda operation.
3129
+
3230
[source,java,indent=0]
3331
.{java-package}/improvements/Collections_ReplaceAll.java
3432
----
3533
include::{section-java-package}/improvements/Collections_ReplaceAll.java[tag=code]
3634
----
3735
+
38-
.Saída no console
36+
.console output
3937
[source,console]
4038
----
41-
Lista antes do replaceAll: [1, 2, 3, 4, 5, 6, 7, 8, 9]
42-
Lista depois do replaceAll: [2, 4, 6, 8, 10, 12, 14, 16, 18]
39+
List before replaceAll: [1, 2, 3, 4, 5, 6, 7, 8, 9]
40+
List after replaceAll: [2, 4, 6, 8, 10, 12, 14, 16, 18]
4341
----
4442

45-
. É possível colocar valores em um `Map` a partir de uma função lambda, apenas se a chave *não* estiver presente no `Map`.
43+
. You can put values in a `Map` from a lambda function only if the *key* is not present in `Map`.
4644
+
4745
[source,java,indent=0]
4846
.{java-package}/improvements/Collections_ComputeIfAbsent.java
4947
----
5048
include::{section-java-package}/improvements/Collections_ComputeIfAbsent.java[tag=code]
5149
----
5250
+
53-
.Saída no console
51+
.console output
5452
[source,console]
5553
----
56-
Map antes do computeIfAbsent: {A=65, B=66}
57-
Map depois do computeIfAbsent: {A=65, B=66, C=67}
54+
Map before computeIfAbsent: {A=65, B=66}
55+
Map after computeIfAbsent: {A=65, B=66, C=67}
5856
----
5957

60-
. É possível alterar valores em um `Map` a partir de uma função lambda, apenas se a chave estiver presente no `Map`.
58+
. You can change values in a `Map` from a lambda function only if the key is present in `Map`.
6159
+
6260
[source,java,indent=0]
6361
.{java-package}/improvements/Collections_ComputeIfPresent.java
6462
----
6563
include::{section-java-package}/improvements/Collections_ComputeIfPresent.java[tag=code]
6664
----
6765
+
68-
.Saída no console
66+
.console output
6967
[source,console]
7068
----
71-
Map antes do computeIfPresent: {A=65, B=66}
72-
Map depois do computeIfPresent: {A=4225, B=4356}
69+
Map before computeIfPresent: {A=65, B=66}
70+
Map after computeIfPresent: {A=4225, B=4356}
7371
----
7472

73+
.References
7574
****
7675
7776
* Using Streams
7877
+
79-
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Edição do Kindle.
78+
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Kindle Edition.
8079
8180
* https://www.baeldung.com/java-8-streams[The Java 8 Stream API Tutorial.]
8281
83-
****
82+
****

src/org/j6toj8/collections/improvements/Collections_ComputeIfAbsent.java

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

13-
System.out.println("Map antes do computeIfAbsent: " + map);
13+
System.out.println("Map before computeIfAbsent: " + map);
1414
map.computeIfAbsent("A", k -> k.hashCode());
1515
map.computeIfAbsent("C", k -> k.hashCode());
16-
System.out.println("Map depois do computeIfAbsent: " + map);
16+
System.out.println("Map after computeIfAbsent: " + map);
1717
// end::code[]
1818
}
1919
}

src/org/j6toj8/collections/improvements/Collections_ComputeIfPresent.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("A", "A".hashCode());
1111
map.put("B", "B".hashCode());
1212

13-
System.out.println("Map antes do computeIfPresent: " + map);
13+
System.out.println("Map before computeIfPresent: " + map);
1414
// k = chave; v = valor
1515
map.computeIfPresent("A", (k, v) -> k.hashCode() * v);
1616
map.computeIfPresent("B", (k, v) -> k.hashCode() * v);
1717
map.computeIfPresent("C", (k, v) -> k.hashCode() * v);
18-
System.out.println("Map depois do computeIfPresent: " + map);
18+
System.out.println("Map after computeIfPresent: " + map);
1919
// end::code[]
2020
}
2121
}

src/org/j6toj8/collections/improvements/Collections_RemoveIf.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public static void main(String[] args) {
1010
// tag::code[]
1111
List<Integer> list = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9));
1212

13-
System.out.println("Lista antes do removeIf: " + list);
14-
list.removeIf(n -> n % 2 == 0); // remove números pares
15-
System.out.println("Lista depois do removeIf: " + list);
13+
System.out.println("List before removeIf: " + list);
14+
list.removeIf(n -> n % 2 == 0); // remove even numbers
15+
System.out.println("List after removeIf: " + list);
1616
// end::code[]
1717
}
1818
}

src/org/j6toj8/collections/improvements/Collections_ReplaceAll.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public static void main(String[] args) {
1010
// tag::code[]
1111
List<Integer> list = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8,9));
1212

13-
System.out.println("Lista antes do replaceAll: " + list);
14-
list.replaceAll(n -> n * 2); // multiplica todos os elementos por 2
15-
System.out.println("Lista depois do replaceAll: " + list);
13+
System.out.println("List before replaceAll: " + list);
14+
list.replaceAll(n -> n * 2); // multiply all elements by 2
15+
System.out.println("List after replaceAll: " + list);
1616
// end::code[]
1717
}
1818
}

0 commit comments

Comments
 (0)