Resolves checkstyle errors for execute-around extension-objects (#1071)

* Reduces checkstyle errors in execute-around

* Reduces checkstyle errors in extension-objects
This commit is contained in:
Anurag Agarwal 2019-11-10 23:08:51 +05:30 committed by Ilkka Seppälä
parent 5ae2ce6e2e
commit 4dae1fae57
15 changed files with 27 additions and 29 deletions

View File

@ -29,16 +29,15 @@ import java.io.IOException;
* The Execute Around idiom specifies some code to be executed before and after a method. Typically * The Execute Around idiom specifies some code to be executed before and after a method. Typically
* the idiom is used when the API has methods to be executed in pairs, such as resource * the idiom is used when the API has methods to be executed in pairs, such as resource
* allocation/deallocation or lock acquisition/release. * allocation/deallocation or lock acquisition/release.
* <p>
* In this example, we have {@link SimpleFileWriter} class that opens and closes the file for the
* user. The user specifies only what to do with the file by providing the {@link FileWriterAction}
* implementation.
* *
* <p>In this example, we have {@link SimpleFileWriter} class that opens and closes the file for
* the user. The user specifies only what to do with the file by providing the {@link
* FileWriterAction} implementation.
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
*/ */
public static void main(String[] args) throws IOException { public static void main(String[] args) throws IOException {

View File

@ -27,9 +27,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
/** /**
*
* Interface for specifying what to do with the file resource. * Interface for specifying what to do with the file resource.
*
*/ */
@FunctionalInterface @FunctionalInterface
public interface FileWriterAction { public interface FileWriterAction {

View File

@ -27,15 +27,13 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
/** /**
*
* SimpleFileWriter handles opening and closing file for the user. The user only has to specify what * SimpleFileWriter handles opening and closing file for the user. The user only has to specify what
* to do with the file resource through {@link FileWriterAction} parameter. * to do with the file resource through {@link FileWriterAction} parameter.
*
*/ */
public class SimpleFileWriter { public class SimpleFileWriter {
/** /**
* Constructor * Constructor.
*/ */
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException { public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
try (FileWriter writer = new FileWriter(filename)) { try (FileWriter writer = new FileWriter(filename)) {

View File

@ -24,21 +24,21 @@
import abstractextensions.CommanderExtension; import abstractextensions.CommanderExtension;
import abstractextensions.SergeantExtension; import abstractextensions.SergeantExtension;
import abstractextensions.SoldierExtension; import abstractextensions.SoldierExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import units.CommanderUnit; import units.CommanderUnit;
import units.SergeantUnit; import units.SergeantUnit;
import units.SoldierUnit; import units.SoldierUnit;
import units.Unit; import units.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Anticipate that an objects interface needs to be extended in the future. * Anticipate that an objects interface needs to be extended in the future. Additional interfaces
* Additional interfaces are defined by extension objects. * are defined by extension objects.
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */
@ -59,9 +59,12 @@ public class App {
private static void checkExtensionsForUnit(Unit unit) { private static void checkExtensionsForUnit(Unit unit) {
final Logger logger = LoggerFactory.getLogger(App.class); final Logger logger = LoggerFactory.getLogger(App.class);
SoldierExtension soldierExtension = (SoldierExtension) unit.getUnitExtension("SoldierExtension"); SoldierExtension soldierExtension =
SergeantExtension sergeantExtension = (SergeantExtension) unit.getUnitExtension("SergeantExtension"); (SoldierExtension) unit.getUnitExtension("SoldierExtension");
CommanderExtension commanderExtension = (CommanderExtension) unit.getUnitExtension("CommanderExtension"); SergeantExtension sergeantExtension =
(SergeantExtension) unit.getUnitExtension("SergeantExtension");
CommanderExtension commanderExtension =
(CommanderExtension) unit.getUnitExtension("CommanderExtension");
//if unit have extension call the method //if unit have extension call the method
if (soldierExtension != null) { if (soldierExtension != null) {

View File

@ -24,7 +24,7 @@
package abstractextensions; package abstractextensions;
/** /**
* Interface with their method * Interface with their method.
*/ */
public interface CommanderExtension extends UnitExtension { public interface CommanderExtension extends UnitExtension {

View File

@ -24,7 +24,7 @@
package abstractextensions; package abstractextensions;
/** /**
* Interface with their method * Interface with their method.
*/ */
public interface SergeantExtension extends UnitExtension { public interface SergeantExtension extends UnitExtension {

View File

@ -24,7 +24,7 @@
package abstractextensions; package abstractextensions;
/** /**
* Interface with their method * Interface with their method.
*/ */
public interface SoldierExtension extends UnitExtension { public interface SoldierExtension extends UnitExtension {
void soldierReady(); void soldierReady();

View File

@ -24,7 +24,7 @@
package abstractextensions; package abstractextensions;
/** /**
* Other Extensions will extend this interface * Other Extensions will extend this interface.
*/ */
public interface UnitExtension { public interface UnitExtension {
} }

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import units.CommanderUnit; import units.CommanderUnit;
/** /**
* Class defining Commander * Class defining Commander.
*/ */
public class Commander implements CommanderExtension { public class Commander implements CommanderExtension {

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import units.SergeantUnit; import units.SergeantUnit;
/** /**
* Class defining Sergeant * Class defining Sergeant.
*/ */
public class Sergeant implements SergeantExtension { public class Sergeant implements SergeantExtension {

View File

@ -29,7 +29,7 @@ import org.slf4j.LoggerFactory;
import units.SoldierUnit; import units.SoldierUnit;
/** /**
* Class defining Soldier * Class defining Soldier.
*/ */
public class Soldier implements SoldierExtension { public class Soldier implements SoldierExtension {
private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class); private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class);

View File

@ -27,7 +27,7 @@ import abstractextensions.UnitExtension;
import concreteextensions.Commander; import concreteextensions.Commander;
/** /**
* Class defining CommanderUnit * Class defining CommanderUnit.
*/ */
public class CommanderUnit extends Unit { public class CommanderUnit extends Unit {

View File

@ -27,7 +27,7 @@ import abstractextensions.UnitExtension;
import concreteextensions.Sergeant; import concreteextensions.Sergeant;
/** /**
* Class defining SergeantUnit * Class defining SergeantUnit.
*/ */
public class SergeantUnit extends Unit { public class SergeantUnit extends Unit {

View File

@ -27,7 +27,7 @@ import abstractextensions.UnitExtension;
import concreteextensions.Soldier; import concreteextensions.Soldier;
/** /**
* Class defining SoldierUnit * Class defining SoldierUnit.
*/ */
public class SoldierUnit extends Unit { public class SoldierUnit extends Unit {

View File

@ -26,7 +26,7 @@ package units;
import abstractextensions.UnitExtension; import abstractextensions.UnitExtension;
/** /**
* Class defining Unit, other units will extend this class * Class defining Unit, other units will extend this class.
*/ */
public class Unit { public class Unit {