File tree Expand file tree Collapse file tree
modules/src/main/java/com/platzi/functional_student_practice Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33import com .platzi .functional_teacher_theory ._06_reference_operator .NombresUtils ;
44
5+ import java .util .Arrays ;
56import java .util .List ;
67import java .util .function .BiFunction ;
78import java .util .function .Predicate ;
@@ -10,7 +11,7 @@ public class Syntax {
1011 public static void main (String [] args ) {
1112
1213 System .out .println ("////////////////////////////////////////////////////////////////////////////////////" );
13- System .out .println ("\n CLASS 17 \n " );
14+ System .out .println ("\n CLASS 18 \n " );
1415
1516 // 1 input, no return
1617 List <String > cursos = NombresUtils .getList ("Java" , "Functional" );
Original file line number Diff line number Diff line change 1+ package com .platzi .functional_student_practice ._09_defaults ;
2+
3+ public class StringFunctions {
4+ public static void main (String [] args ) {
5+ System .out .println ("////////////////////////////////////////////////////////////////////////////////////" );
6+ System .out .println ("\n CLASS 19\n " );
7+
8+ StringOperation six = () -> 6 ;
9+ // 1b. Execution of default method
10+ six .operate ("Alumno" );
11+ // 2b. Execution of concatenated default methods
12+ six .reduceAmount (2 ).operate ("Profesor" );
13+
14+ // 3. Execution of .functionSaved() method
15+ DoOperation operateFive = text -> System .out .println (text );
16+ // 4. Execution of saved function 5 times with "Platzi" String
17+ operateFive .execute (5 , "Platzi" );
18+ }
19+
20+ @ FunctionalInterface
21+ interface StringOperation {
22+ int getAmount ();
23+
24+ // 1. Default method. Functional Interfaces require 1 and only 1 abstract method, but you can add any amount of default methods
25+ default void operate (String text ) {
26+ int x = getAmount ();
27+ while (x -- > 0 ) {
28+ System .out .println (text );
29+ }
30+ }
31+
32+ // 2. Extra default method, wich return another StringOperation Object that can be called operate with a modificed Amount
33+ default StringOperation reduceAmount (int x ) {
34+ int old = getAmount ();
35+ return () -> old - x ;
36+ }
37+ }
38+
39+ @ FunctionalInterface
40+ interface DoOperation {
41+ void functionSaved (String text );
42+
43+ default void execute (int x , String text ) {
44+ while (x -- > 0 ) {
45+ functionSaved (text );
46+ }
47+ }
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments