Skip to content

Commit fca7e9c

Browse files
akrystianiluwatar
authored andcommitted
iluwatar#1021 - decrease number of checkstyle errors in callback pattern (iluwatar#1053)
1 parent 91a085d commit fca7e9c

File tree

6 files changed

+36
-26
lines changed

6 files changed

+36
-26
lines changed

callback/src/main/java/com/iluwatar/callback/App.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,27 @@
2424
package com.iluwatar.callback;
2525

2626
import 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);

callback/src/main/java/com/iluwatar/callback/Callback.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
package com.iluwatar.callback;
2525

2626
/**
27-
*
27+
*
2828
* Callback interface
29-
*
29+
*
3030
*/
3131
public interface Callback {
3232

callback/src/main/java/com/iluwatar/callback/LambdasApp.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,25 @@
2424
package com.iluwatar.callback;
2525

2626
import 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);

callback/src/main/java/com/iluwatar/callback/SimpleTask.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,21 @@
2424
package com.iluwatar.callback;
2525

2626
import 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
}

callback/src/main/java/com/iluwatar/callback/Task.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
package com.iluwatar.callback;
2525

2626
/**
27-
*
27+
*
2828
* Template-method class for callback hook execution
29-
*
29+
*
3030
*/
3131
public 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();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package com.iluwatar.callback;

0 commit comments

Comments
 (0)