File tree Expand file tree Collapse file tree 6 files changed +36
-26
lines changed
callback/src/main/java/com/iluwatar/callback Expand file tree Collapse file tree 6 files changed +36
-26
lines changed Original file line number Diff line number Diff line change 2424package com .iluwatar .callback ;
2525
2626import org .slf4j .Logger ;
27- import org .slf4j .LoggerFactory ;
27+
28+ import static org .slf4j .LoggerFactory .getLogger ;
2829
2930/**
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+ *
3536 */
36- public class App {
37+ public final class App {
3738
38- private static final Logger LOGGER = LoggerFactory .getLogger (App .class );
39+ private static final Logger LOGGER = getLogger (App .class );
40+
41+ private App () {
42+ }
3943
4044 /**
4145 * Program entry point
4246 */
43- public static void main (String [] args ) {
47+ public static void main (final String [] args ) {
4448 Task task = new SimpleTask ();
4549 Callback callback = () -> LOGGER .info ("I'm done now." );
4650 task .executeWith (callback );
Original file line number Diff line number Diff line change 2424package com .iluwatar .callback ;
2525
2626/**
27- *
27+ *
2828 * Callback interface
29- *
29+ *
3030 */
3131public interface Callback {
3232
Original file line number Diff line number Diff line change 2424package com .iluwatar .callback ;
2525
2626import org .slf4j .Logger ;
27- import org .slf4j .LoggerFactory ;
27+
28+ import static org .slf4j .LoggerFactory .getLogger ;
2829
2930/**
3031 *
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.
3334 *
3435 */
35- public class LambdasApp {
36+ public final class LambdasApp {
37+
38+ private static final Logger LOGGER = getLogger (LambdasApp .class );
3639
37- private static final Logger LOGGER = LoggerFactory . getLogger ( LambdasApp . class );
40+ private LambdasApp () { }
3841
3942 /**
4043 * Program entry point
4144 */
42- public static void main (String [] args ) {
45+ public static void main (final String [] args ) {
4346 Task task = new SimpleTask ();
4447 Callback c = () -> LOGGER .info ("I'm done now." );
4548 task .executeWith (c );
Original file line number Diff line number Diff line change 2424package com .iluwatar .callback ;
2525
2626import org .slf4j .Logger ;
27- import org .slf4j .LoggerFactory ;
27+
28+ import static org .slf4j .LoggerFactory .getLogger ;
2829
2930/**
30- *
31+ *
3132 * Implementation of task that need to be executed
32- *
33+ *
3334 */
34- public class SimpleTask extends Task {
35+ public final class SimpleTask extends Task {
3536
36- private static final Logger LOGGER = LoggerFactory . getLogger (SimpleTask .class );
37+ private static final Logger LOGGER = getLogger (SimpleTask .class );
3738
3839 @ Override
3940 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." );
4143 }
4244}
Original file line number Diff line number Diff line change 2424package com .iluwatar .callback ;
2525
2626/**
27- *
27+ *
2828 * Template-method class for callback hook execution
29- *
29+ *
3030 */
3131public abstract class Task {
3232
3333 /**
3434 * Execute with callback
3535 */
36- public final void executeWith (Callback callback ) {
36+ final void executeWith (final Callback callback ) {
3737 execute ();
3838 if (callback != null ) {
3939 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