Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@
* 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
* 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 {

/**
* Program entry point
* Program entry point.
*/
public static void main(String[] args) throws IOException {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@
import java.io.IOException;

/**
*
* Interface for specifying what to do with the file resource.
*
*/
@FunctionalInterface
public interface FileWriterAction {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,13 @@
import java.io.IOException;

/**
*
* 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.
*
*/
public class SimpleFileWriter {

/**
* Constructor
* Constructor.
*/
public SimpleFileWriter(String filename, FileWriterAction action) throws IOException {
try (FileWriter writer = new FileWriter(filename)) {
Expand Down
19 changes: 11 additions & 8 deletions extension-objects/src/main/java/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
import abstractextensions.CommanderExtension;
import abstractextensions.SergeantExtension;
import abstractextensions.SoldierExtension;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import units.CommanderUnit;
import units.SergeantUnit;
import units.SoldierUnit;
import units.Unit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Anticipate that an object’s interface needs to be extended in the future.
* Additional interfaces are defined by extension objects.
* Anticipate that an object’s interface needs to be extended in the future. Additional interfaces
* are defined by extension objects.
*/
public class App {

/**
* Program entry point
* Program entry point.
*
* @param args command line args
*/
Expand All @@ -59,9 +59,12 @@ public static void main(String[] args) {
private static void checkExtensionsForUnit(Unit unit) {
final Logger logger = LoggerFactory.getLogger(App.class);

SoldierExtension soldierExtension = (SoldierExtension) unit.getUnitExtension("SoldierExtension");
SergeantExtension sergeantExtension = (SergeantExtension) unit.getUnitExtension("SergeantExtension");
CommanderExtension commanderExtension = (CommanderExtension) unit.getUnitExtension("CommanderExtension");
SoldierExtension soldierExtension =
(SoldierExtension) unit.getUnitExtension("SoldierExtension");
SergeantExtension sergeantExtension =
(SergeantExtension) unit.getUnitExtension("SergeantExtension");
CommanderExtension commanderExtension =
(CommanderExtension) unit.getUnitExtension("CommanderExtension");

//if unit have extension call the method
if (soldierExtension != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package abstractextensions;

/**
* Interface with their method
* Interface with their method.
*/
public interface CommanderExtension extends UnitExtension {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package abstractextensions;

/**
* Interface with their method
* Interface with their method.
*/
public interface SergeantExtension extends UnitExtension {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package abstractextensions;

/**
* Interface with their method
* Interface with their method.
*/
public interface SoldierExtension extends UnitExtension {
void soldierReady();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
package abstractextensions;

/**
* Other Extensions will extend this interface
* Other Extensions will extend this interface.
*/
public interface UnitExtension {
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import units.CommanderUnit;

/**
* Class defining Commander
* Class defining Commander.
*/
public class Commander implements CommanderExtension {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import units.SergeantUnit;

/**
* Class defining Sergeant
* Class defining Sergeant.
*/
public class Sergeant implements SergeantExtension {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import units.SoldierUnit;

/**
* Class defining Soldier
* Class defining Soldier.
*/
public class Soldier implements SoldierExtension {
private static final Logger LOGGER = LoggerFactory.getLogger(Soldier.class);
Expand Down
2 changes: 1 addition & 1 deletion extension-objects/src/main/java/units/CommanderUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import concreteextensions.Commander;

/**
* Class defining CommanderUnit
* Class defining CommanderUnit.
*/
public class CommanderUnit extends Unit {

Expand Down
2 changes: 1 addition & 1 deletion extension-objects/src/main/java/units/SergeantUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import concreteextensions.Sergeant;

/**
* Class defining SergeantUnit
* Class defining SergeantUnit.
*/
public class SergeantUnit extends Unit {

Expand Down
2 changes: 1 addition & 1 deletion extension-objects/src/main/java/units/SoldierUnit.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import concreteextensions.Soldier;

/**
* Class defining SoldierUnit
* Class defining SoldierUnit.
*/
public class SoldierUnit extends Unit {

Expand Down
2 changes: 1 addition & 1 deletion extension-objects/src/main/java/units/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import abstractextensions.UnitExtension;

/**
* Class defining Unit, other units will extend this class
* Class defining Unit, other units will extend this class.
*/
public class Unit {

Expand Down