File tree 6 files changed +36
-26
lines changed
callback/src/main/java/com/iluwatar/callback
6 files changed +36
-26
lines changed Original file line number Diff line number Diff line change 24
24
package com .iluwatar .callback ;
25
25
26
26
import org .slf4j .Logger ;
27
- import org .slf4j .LoggerFactory ;
27
+
28
+ import static org .slf4j .LoggerFactory .getLogger ;
28
29
29
30
/**
30
- *
31
- * Callback pattern is more native for functional languages where functions are treated as
32
- * first-class citizens. Prior to Java 8 callbacks can be simulated using simple (alike command)
33
- * interfaces.
34
- *
31
+ *
32
+ * Callback pattern is more native for functional languages where functions are
33
+ * treated as first-class citizens. Prior to Java 8 callbacks can be simulated
34
+ * using simple (alike command) interfaces.
35
+ *
35
36
*/
36
- public class App {
37
+ public final class App {
37
38
38
- private static final Logger LOGGER = LoggerFactory .getLogger (App .class );
39
+ private static final Logger LOGGER = getLogger (App .class );
40
+
41
+ private App () {
42
+ }
39
43
40
44
/**
41
45
* Program entry point
42
46
*/
43
- public static void main (String [] args ) {
47
+ public static void main (final String [] args ) {
44
48
Task task = new SimpleTask ();
45
49
Callback callback = () -> LOGGER .info ("I'm done now." );
46
50
task .executeWith (callback );
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .callback ;
25
25
26
26
/**
27
- *
27
+ *
28
28
* Callback interface
29
- *
29
+ *
30
30
*/
31
31
public interface Callback {
32
32
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .callback ;
25
25
26
26
import org .slf4j .Logger ;
27
- import org .slf4j .LoggerFactory ;
27
+
28
+ import static org .slf4j .LoggerFactory .getLogger ;
28
29
29
30
/**
30
31
*
31
- * This example generates the exact same output as {@link App} however the callback has been
32
- * defined as a Lambdas expression.
32
+ * This example generates the exact same output as {@link App} however the
33
+ * callback has been defined as a Lambdas expression.
33
34
*
34
35
*/
35
- public class LambdasApp {
36
+ public final class LambdasApp {
37
+
38
+ private static final Logger LOGGER = getLogger (LambdasApp .class );
36
39
37
- private static final Logger LOGGER = LoggerFactory . getLogger ( LambdasApp . class );
40
+ private LambdasApp () { }
38
41
39
42
/**
40
43
* Program entry point
41
44
*/
42
- public static void main (String [] args ) {
45
+ public static void main (final String [] args ) {
43
46
Task task = new SimpleTask ();
44
47
Callback c = () -> LOGGER .info ("I'm done now." );
45
48
task .executeWith (c );
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .callback ;
25
25
26
26
import org .slf4j .Logger ;
27
- import org .slf4j .LoggerFactory ;
27
+
28
+ import static org .slf4j .LoggerFactory .getLogger ;
28
29
29
30
/**
30
- *
31
+ *
31
32
* Implementation of task that need to be executed
32
- *
33
+ *
33
34
*/
34
- public class SimpleTask extends Task {
35
+ public final class SimpleTask extends Task {
35
36
36
- private static final Logger LOGGER = LoggerFactory . getLogger (SimpleTask .class );
37
+ private static final Logger LOGGER = getLogger (SimpleTask .class );
37
38
38
39
@ Override
39
40
public void execute () {
40
- LOGGER .info ("Perform some important activity and after call the callback method." );
41
+ LOGGER .info ("Perform some important activity and after call the"
42
+ + " callback method." );
41
43
}
42
44
}
Original file line number Diff line number Diff line change 24
24
package com .iluwatar .callback ;
25
25
26
26
/**
27
- *
27
+ *
28
28
* Template-method class for callback hook execution
29
- *
29
+ *
30
30
*/
31
31
public abstract class Task {
32
32
33
33
/**
34
34
* Execute with callback
35
35
*/
36
- public final void executeWith (Callback callback ) {
36
+ final void executeWith (final Callback callback ) {
37
37
execute ();
38
38
if (callback != null ) {
39
39
callback .call ();
Original file line number Diff line number Diff line change
1
+ package com .iluwatar .callback ;
You can’t perform that action at this time.
0 commit comments