Skip to content

Commit 9369b16

Browse files
committed
#21 - Java
1 parent cb6d48e commit 9369b16

File tree

1 file changed

+45
-41
lines changed

1 file changed

+45
-41
lines changed

Roadmap/21 - CALLBACKS/java/JimsimroDev.java

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@
1616
*/
1717

1818
public class JimsimroDev {
19-
private static final String DIV_LINE =":::::::::::::::::::::::::";
19+
private static final String DIV_LINE = ":::::::::::::::::::::::::";
2020
private static final int MIN = 1000;
2121
private static final int MAX = 10000;
2222

2323
interface Noficar {
2424
void notificacion(String mensaje);
2525
}
2626

27+
interface Confirmado {
28+
void confirmarPedidos(String mensaje);
29+
}
30+
31+
interface Listo {
32+
void pedidoListo(String mensaje);
33+
}
34+
35+
interface Entregado {
36+
void entregarPedidos(String mensaje);
37+
}
38+
2739
static void notificacionEnviada(String proceso, Noficar callback) {
2840
try {
2941
System.out.println("Iniciando proceso...");
@@ -35,60 +47,52 @@ static void notificacionEnviada(String proceso, Noficar callback) {
3547

3648
}
3749

38-
interface Callback {
39-
void notificar(String mensaje);
40-
}
41-
4250
static int ramdon() {
4351
return (int) (Math.random() * (MAX - MIN + 1)) + MIN;
4452
}
4553

46-
static void procesarPedidos(String plato, Callback callback) {
47-
try {
48-
print(DIV_LINE);
49-
print("Iniciando pedido....");
50-
Thread.sleep(ramdon());
51-
callback.notificar(plato + " Confirmado");
54+
static void procesarPedidos(String plato, Confirmado confirmado, Listo listo, Entregado entregado) {
55+
Thread hacerPedido = new Thread(() -> {
56+
try {
5257

53-
print(DIV_LINE);
54-
print("Preparando pedido....");
55-
Thread.sleep(ramdon());
56-
callback.notificar(plato + " Listo");
58+
print("Iniciando pedido " + plato +"....");
59+
Thread.sleep(ramdon());
60+
confirmado.confirmarPedidos(plato + " Confirmado");
5761

58-
print(DIV_LINE);
59-
print("Entregando el plato", plato);
60-
Thread.sleep(ramdon());
61-
callback.notificar(plato + " Entregado");
62+
print("Preparando pedido " + plato + "....");
63+
print(DIV_LINE);
64+
Thread.sleep(ramdon());
65+
listo.pedidoListo(plato + " Listo");
6266

63-
} catch (InterruptedException e) {
64-
print("Erro no pedido" + e);
65-
}
66-
}
67+
print("Entregando el plato "+plato);
68+
print(DIV_LINE);
69+
Thread.sleep(ramdon());
70+
entregado.entregarPedidos(plato + " Entregado");
6771

68-
static void hacerOrden(String plato) {
69-
procesarPedidos(plato, new Callback() {
70-
71-
@Override
72-
public void notificar(String mensaje) {
73-
System.out.println(mensaje);
72+
} catch (InterruptedException e) {
73+
print("Erro no pedido" + e);
7474
}
7575
});
76+
hacerPedido.start();
7677
}
77-
static void print(Object... args){
78-
for (Object s : args){
79-
System.out.print(s + " ");
80-
}
81-
System.out.println();
78+
79+
static void hacerOrden(String plato) {
80+
procesarPedidos(
81+
plato,
82+
JimsimroDev::print,
83+
JimsimroDev::print,
84+
JimsimroDev::print);
8285
}
8386

84-
public static void main(String[] args) {
85-
notificacionEnviada("Enviando SMS ", new Noficar() {
87+
static void print(Object... args) {
88+
for (Object s : args) {
89+
System.out.print(s + " ");
90+
}
91+
System.out.println();
92+
}
8693

87-
@Override
88-
public void notificacion(String mensaje) {
89-
System.out.println(mensaje);
90-
}
91-
});
94+
public static void main(String[] args) {
95+
notificacionEnviada("Enviando SMS ", System.out::println);
9296

9397
// EXTRA
9498
hacerOrden("Bandeja Paisa");

0 commit comments

Comments
 (0)