Skip to content

Commit da1b2c7

Browse files
committed
feat(collections): 🎸 calculations, translated
Refers: #10
1 parent 2bc320e commit da1b2c7

File tree

5 files changed

+27
-28
lines changed

5 files changed

+27
-28
lines changed
Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,92 @@
11
:java-package: src/org/j6toj8/collections
22
:section-java-package: ../../../{java-package}
33

4-
=== Fazendo cálculos e coletando resultados de Streams
4+
=== Perform Calculations and Collecting Streams Results
55

6-
.Objetivo
6+
.Objective
77
--------------------------------------------------
88
Perform calculations on Java Streams by using count, max, min, average, and sum methods and save results to a collection by using the collect method and Collector class, including the averagingDouble, groupingBy, joining, partitioningBy methods
9-
-
10-
Realizar cálculos em Streams usando os métodos count, max, min, average, e sum e salvar resultados em uma coleção usando o método collect e a classe Collector, incluindo os métodos averagingDouble, groupingBy, joining, partitioningBy
119
--------------------------------------------------
1210

13-
. É possível pegar o maior ou menor valor, ou a quantidade de elementos da coleção.
11+
. You can get the largest or smallest value, or the number of elements in the collection.
1412
+
1513
[source,java,indent=0]
1614
.{java-package}/calculations/Collections_MaxMinCount.java
1715
----
1816
include::{section-java-package}/calculations/Collections_MaxMinCount.java[tag=code]
1917
----
2018
+
21-
.Saída no console
19+
.console output
2220
[source,console]
2321
----
2422
Max: 9
2523
Min: 1
2624
Count: 9
2725
----
2826

29-
. É possível pegar a média dos valores da coleção.
27+
. You can take the average of the collection values.
3028
+
3129
[source,java,indent=0]
3230
.{java-package}/calculations/Collections_AveragingDouble.java
3331
----
3432
include::{section-java-package}/calculations/Collections_AveragingDouble.java[tag=code]
3533
----
3634
+
37-
.Saída no console
35+
.console output
3836
[source,console]
3937
----
4038
Média: 5.0
4139
----
4240

43-
. É possível agrupar os valores da coleção por uma regra específica.
41+
. You can group collection values by a specific rule.
4442
+
4543
[source,java,indent=0]
4644
.{java-package}/calculations/Collections_GroupingBy.java
4745
----
4846
include::{section-java-package}/calculations/Collections_GroupingBy.java[tag=code]
4947
----
5048
+
51-
.Saída no console
49+
.console output
5250
[source,console]
5351
----
54-
Mapa de resto da divisão por 3: {0=[3, 6, 9], 1=[1, 4, 7], 2=[2, 5, 8]}
52+
Map of rest of division by 3: {0=[3, 6, 9], 1=[1, 4, 7], 2=[2, 5, 8]}
5553
----
5654

57-
. É possível concatenar os valores da coleção.
55+
. You can concatenate the collection values.
5856
+
5957
[source,java,indent=0]
6058
.{java-package}/calculations/Collections_Joining.java
6159
----
6260
include::{section-java-package}/calculations/Collections_Joining.java[tag=code]
6361
----
6462
+
65-
.Saída no console
63+
.console output
6664
[source,console]
6765
----
68-
Junção dos valores como String: 123456789
66+
Join values as String: 123456789
6967
----
7068

71-
. É possível separar os valores da coleção em um mapa com chaves `true` e `false`, de acordo com uma função lambda.
69+
. You can separate collection values in a map with `true` and `false` keys, according to a lambda function.
7270
+
7371
[source,java,indent=0]
7472
.{java-package}/calculations/Collections_PartitioningBy.java
7573
----
7674
include::{section-java-package}/calculations/Collections_PartitioningBy.java[tag=code]
7775
----
7876
+
79-
.Saída no console
77+
.console output
8078
[source,console]
8179
----
82-
Mapa de pares e ímpares: {false=[1, 3, 5, 7, 9], true=[2, 4, 6, 8]}
80+
Even and odd map: {false=[1, 3, 5, 7, 9], true=[2, 4, 6, 8]}
8381
----
8482

83+
.References
8584
****
8685
8786
* Using Streams
8887
+
89-
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Edição do Kindle.
88+
Boyarsky, Jeanne; Selikoff, Scott. OCP: Oracle Certified Professional Java SE 8 Programmer II Study Guide (p. 185). Wiley. Kindle Edition.
9089
9190
* https://www.baeldung.com/java-8-streams[The Java 8 Stream API Tutorial.]
9291
93-
****
92+
****

src/org/j6toj8/collections/calculations/Collections_GroupingBy.java

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

14-
Map<Integer, List<Integer>> mapaDivisaoPor3 = list.stream()
14+
Map<Integer, List<Integer>> mapDivisionBy3 = list.stream()
1515
.collect(Collectors.groupingBy(n -> n % 3));
1616

17-
System.out.println("Mapa de resto da divisão por 3: " + mapaDivisaoPor3);
17+
System.out.println("Map of rest of division by 3: " + mapDivisionBy3);
1818
// end::code[]
1919
}
2020
}

src/org/j6toj8/collections/calculations/Collections_Joining.java

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

13-
String juncao = list.stream()
13+
String join = list.stream()
1414
.map(n -> n.toString())
1515
.collect(Collectors.joining());
1616

17-
System.out.println("Junção dos valores como String: " + juncao);
17+
System.out.println("Join values as String: " + join);
1818
// end::code[]
1919
}
2020
}

src/org/j6toj8/collections/calculations/Collections_MaxMinCount.java

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

1313
OptionalInt max = list.stream()
14-
.mapToInt(Integer::intValue) // transforma para int
14+
.mapToInt(Integer::intValue) // transform to int
1515
.max();
1616
System.out.println("Max: " + max.getAsInt());
1717

1818
OptionalInt min = list.stream()
19-
.mapToInt(Integer::intValue) // transforma para int
19+
.mapToInt(Integer::intValue) // transform to int
2020
.min();
2121
System.out.println("Min: " + min.getAsInt());
2222

2323
long count = list.stream()
24-
.mapToInt(Integer::intValue) // transforma para int
24+
.mapToInt(Integer::intValue) // transform to int
2525
.count();
2626
System.out.println("Count: " + count);
2727
// end::code[]

src/org/j6toj8/collections/calculations/Collections_PartitioningBy.java

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

14-
Map<Boolean, List<Integer>> mapaParImpar = list.stream()
14+
Map<Boolean, List<Integer>> mapEvenOdd = list.stream()
1515
.collect(Collectors.partitioningBy(n -> n % 2 == 0));
1616

17-
System.out.println("Mapa de pares e ímpares: " + mapaParImpar);
17+
System.out.println("Even and odd map: " + mapEvenOdd);
1818
// end::code[]
1919
}
2020
}

0 commit comments

Comments
 (0)