Skip to content

Commit 0bc722f

Browse files
committed
Fix CheckStyle iluwatar#324
1 parent fcadb22 commit 0bc722f

File tree

8 files changed

+93
-91
lines changed

8 files changed

+93
-91
lines changed

delegation/src/main/java/com/iluwatar/delegation/simple/AbstractPrinterController.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
/**
44
* Extra layer of abstraction for the controller to allow the controller in this example {@link PrinterController} to
5-
* be as clean as possible. This just provides the default constructor and a simple getter method. The generic of T allows
6-
* any implementation of {@link Printer}
5+
* be as clean as possible. This just provides the default constructor and a simple getter method. The generic of
6+
* T allows any implementation of {@link Printer}
77
*
88
* @param <T> Printer
99
* @see Printer
@@ -12,23 +12,23 @@
1212
public abstract class AbstractPrinterController<T extends Printer> implements Printer {
1313

1414

15-
private T printer;
15+
private T printer;
1616

17-
/**
18-
* @param printer instance of T {@link Printer} this instance is the delegate
19-
*/
20-
public AbstractPrinterController(T printer) {
21-
this.printer = printer;
22-
}
17+
/**
18+
* @param printer instance of T {@link Printer} this instance is the delegate
19+
*/
20+
public AbstractPrinterController(T printer) {
21+
this.printer = printer;
22+
}
2323

24-
/**
25-
* Helper method to return the current instance of T {@link Printer} in order for
26-
* the controller to call operations on the {@link Printer}
27-
*
28-
* @return instance of Printer
29-
* @see Printer
30-
*/
31-
protected T getPrinter() {
32-
return printer;
33-
}
24+
/**
25+
* Helper method to return the current instance of T {@link Printer} in order for
26+
* the controller to call operations on the {@link Printer}
27+
*
28+
* @return instance of Printer
29+
* @see Printer
30+
*/
31+
protected T getPrinter() {
32+
return printer;
33+
}
3434
}

delegation/src/main/java/com/iluwatar/delegation/simple/App.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
import com.iluwatar.delegation.simple.printers.CanonPrinter;
44
import com.iluwatar.delegation.simple.printers.EpsonPrinter;
5-
import com.iluwatar.delegation.simple.printers.HPPrinter;
5+
import com.iluwatar.delegation.simple.printers.HpPrinter;
66

77
/**
8-
* In this example the delegates are {@link EpsonPrinter}, {@link HPPrinter} and {@link CanonPrinter} they all implement
9-
* {@link Printer}. The {@link AbstractPrinterController} and through inheritance {@link PrinterController} also implement
10-
* {@link Printer}. However neither provide the functionality of {@link Printer} by printing to the screen, they actually
11-
* call upon the instance of {@link Printer} that they were instantiated with. Therefore delegating the behaviour to
12-
* another class.
8+
* In this example the delegates are {@link EpsonPrinter}, {@link HpPrinter} and {@link CanonPrinter} they all implement
9+
* {@link Printer}. The {@link AbstractPrinterController} and through inheritance {@link PrinterController} also
10+
* implement {@link Printer}. However neither provide the functionality of {@link Printer} by printing to the screen,
11+
* they actually call upon the instance of {@link Printer} that they were instantiated with. Therefore delegating the
12+
* behaviour to another class.
1313
*/
1414
public class App {
1515

16-
public static final String MESSAGE_TO_PRINT = "hello world";
16+
public static final String MESSAGE_TO_PRINT = "hello world";
1717

18-
/**
19-
* Program entry point
20-
*
21-
* @param args command line args
22-
*/
23-
public static void main(String[] args) {
24-
AbstractPrinterController hpPrinterController = new PrinterController(new HPPrinter());
25-
AbstractPrinterController canonPrinterController = new PrinterController(new CanonPrinter());
26-
AbstractPrinterController epsonPrinterController = new PrinterController(new EpsonPrinter());
18+
/**
19+
* Program entry point
20+
*
21+
* @param args command line args
22+
*/
23+
public static void main(String[] args) {
24+
AbstractPrinterController hpPrinterController = new PrinterController(new HpPrinter());
25+
AbstractPrinterController canonPrinterController = new PrinterController(new CanonPrinter());
26+
AbstractPrinterController epsonPrinterController = new PrinterController(new EpsonPrinter());
2727

28-
hpPrinterController.print(MESSAGE_TO_PRINT);
29-
canonPrinterController.print(MESSAGE_TO_PRINT);
30-
epsonPrinterController.print(MESSAGE_TO_PRINT);
31-
}
28+
hpPrinterController.print(MESSAGE_TO_PRINT);
29+
canonPrinterController.print(MESSAGE_TO_PRINT);
30+
epsonPrinterController.print(MESSAGE_TO_PRINT);
31+
}
3232

3333
}
Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package com.iluwatar.delegation.simple;
22

3+
import com.iluwatar.delegation.simple.printers.HpPrinter;
4+
35
/**
4-
* Interface that both the Controller and the Delegate will implement.
6+
* Interface that both the Controller and the Delegate will implement.
57
*
6-
* @see com.iluwatar.delegation.simple.printers.CanonPrinter
7-
* @see com.iluwatar.delegation.simple.printers.EpsonPrinter
8-
* @see com.iluwatar.delegation.simple.printers.HPPrinter
9-
* @see AbstractPrinterController
8+
* @see com.iluwatar.delegation.simple.printers.CanonPrinter
9+
* @see com.iluwatar.delegation.simple.printers.EpsonPrinter
10+
* @see HpPrinter
11+
* @see AbstractPrinterController
1012
*/
1113
public interface Printer {
1214

13-
/**
14-
* Method that takes a String to print to the screen. This will be implemented on both the
15-
* controller and the delegate allowing the controller to call the same method on the delegate class.
16-
*
17-
* @param message to be printed to the screen
18-
*/
19-
void print(final String message);
15+
/**
16+
* Method that takes a String to print to the screen. This will be implemented on both the
17+
* controller and the delegate allowing the controller to call the same method on the delegate class.
18+
*
19+
* @param message to be printed to the screen
20+
*/
21+
void print(final String message);
2022
}

delegation/src/main/java/com/iluwatar/delegation/simple/PrinterController.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22

33
public class PrinterController extends AbstractPrinterController {
44

5-
public PrinterController(Printer printer) {
6-
super(printer);
7-
}
5+
public PrinterController(Printer printer) {
6+
super(printer);
7+
}
88

9-
/**
10-
* This method is implemented from {@link Printer} however instead on providing an
11-
* implementation, it instead calls upon the class passed through the constructor. This is the delegate,
12-
* hence the pattern. Therefore meaning that the caller does not care of the implementing class only the owning
13-
* controller.
14-
*
15-
* @param message to be printed to the screen
16-
*/
17-
@Override
18-
public void print(String message) {
19-
getPrinter().print(message);
20-
}
9+
/**
10+
* This method is implemented from {@link Printer} however instead on providing an
11+
* implementation, it instead calls upon the class passed through the constructor. This is the delegate,
12+
* hence the pattern. Therefore meaning that the caller does not care of the implementing class only the owning
13+
* controller.
14+
*
15+
* @param message to be printed to the screen
16+
*/
17+
@Override
18+
public void print(String message) {
19+
getPrinter().print(message);
20+
}
2121
}

delegation/src/main/java/com/iluwatar/delegation/simple/printers/CanonPrinter.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
*/
1111
public class CanonPrinter implements Printer {
1212

13-
/**
14-
* {@inheritDoc}
15-
*/
16-
@Override
17-
public void print(String message) {
18-
System.out.println("Canon Printer : " + message);
19-
}
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
@Override
17+
public void print(String message) {
18+
System.out.println("Canon Printer : " + message);
19+
}
2020

2121
}

delegation/src/main/java/com/iluwatar/delegation/simple/printers/EpsonPrinter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
*
99
* @see Printer
1010
*/
11-
public class EpsonPrinter implements Printer{
11+
public class EpsonPrinter implements Printer {
1212

13-
/**
14-
* {@inheritDoc}
15-
*/
16-
@Override
17-
public void print(String message) {
18-
System.out.println("Epson Printer : " + message);
19-
}
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
@Override
17+
public void print(String message) {
18+
System.out.println("Epson Printer : " + message);
19+
}
2020

2121
}

delegation/src/main/java/com/iluwatar/delegation/simple/printers/HPPrinter.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
*
99
* @see Printer
1010
*/
11-
public class HPPrinter implements Printer {
11+
public class HpPrinter implements Printer {
1212

13-
/**
14-
* {@inheritDoc}
15-
*/
16-
@Override
17-
public void print(String message) {
18-
System.out.println("HP Printer : " + message);
19-
}
13+
/**
14+
* {@inheritDoc}
15+
*/
16+
@Override
17+
public void print(String message) {
18+
System.out.println("HP Printer : " + message);
19+
}
2020

2121
}

delegation/src/test/java/com/iluwatar/delegation/simple/DelegateTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.iluwatar.delegation.simple.printers.CanonPrinter;
44
import com.iluwatar.delegation.simple.printers.EpsonPrinter;
5-
import com.iluwatar.delegation.simple.printers.HPPrinter;
5+
import com.iluwatar.delegation.simple.printers.HpPrinter;
66
import org.junit.Rule;
77
import org.junit.Test;
88
import org.junit.contrib.java.lang.system.SystemOutRule;
@@ -26,7 +26,7 @@ public void testCanonPrinter() throws Exception {
2626

2727
@Test
2828
public void testHPPrinter() throws Exception {
29-
AbstractPrinterController abstractController = new PrinterController(new HPPrinter());
29+
AbstractPrinterController abstractController = new PrinterController(new HpPrinter());
3030
abstractController.print(MESSAGE);
3131

3232
assertEquals("HP Printer : Test Message Printed\n", systemOutRule.getLog());

0 commit comments

Comments
 (0)