Resolves checkstyle errors for ambassador, async-method-invocation, balking, bridge, builder (#1058)

* Decreases checkstyle errors for ambassador pattern

* Reduces checkstyle errors in async-method-invocation

* Reduces checkstyle errors in balking

* Reduces checkstyle errors in bridge

* Reduces checkstyle errors in builder
This commit is contained in:
Anurag Agarwal
2019-11-10 00:33:22 +05:30
committed by Ilkka Seppälä
parent 1fa8a604eb
commit 6d1c0b1563
29 changed files with 179 additions and 225 deletions

View File

@ -23,23 +23,22 @@
package com.iluwatar.balking;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* In Balking Design Pattern if an objects method is invoked when it is in an inappropriate state,
* then the method will return without doing anything. Objects that use this pattern are generally only in a
* state that is prone to balking temporarily but for an unknown amount of time
* then the method will return without doing anything. Objects that use this pattern are generally
* only in a state that is prone to balking temporarily but for an unknown amount of time
*
* In this example implementation WashingMachine is an object that has two states
* in which it can be: ENABLED and WASHING. If the machine is ENABLED
* the state is changed into WASHING that any other thread can't invoke this action on this and then do the job.
* On the other hand if it have been already washing and any other thread execute wash()
* it can't do that once again and returns doing nothing.
* <p>In this example implementation WashingMachine is an object that has two states in which it
* can be: ENABLED and WASHING. If the machine is ENABLED the state is changed into WASHING that any
* other thread can't invoke this action on this and then do the job. On the other hand if it have
* been already washing and any other thread execute wash() it can't do that once again and returns
* doing nothing.
*/
public class App {
@ -47,6 +46,8 @@ public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Entry Point.
*
* @param args the command line arguments - not used
*/
public static void main(String... args) {

View File

@ -23,13 +23,12 @@
package com.iluwatar.balking;
import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
/**
* Washing machine class
* Washing machine class.
*/
public class WashingMachine {
@ -38,7 +37,7 @@ public class WashingMachine {
private WashingMachineState washingMachineState;
/**
* Creates a new instance of WashingMachine
* Creates a new instance of WashingMachine.
*/
public WashingMachine() {
this((interval, timeUnit, task) -> {
@ -52,8 +51,8 @@ public class WashingMachine {
}
/**
* Creates a new instance of WashingMachine using provided delayProvider. This constructor is used only for
* unit testing purposes.
* Creates a new instance of WashingMachine using provided delayProvider. This constructor is used
* only for unit testing purposes.
*/
public WashingMachine(DelayProvider delayProvider) {
this.delayProvider = delayProvider;
@ -65,17 +64,17 @@ public class WashingMachine {
}
/**
* Method responsible for washing
* if the object is in appropriate state
* Method responsible for washing if the object is in appropriate state.
*/
public void wash() {
synchronized (this) {
LOGGER.info("{}: Actual machine state: {}", Thread.currentThread().getName(), getWashingMachineState());
if (washingMachineState == WashingMachineState.WASHING) {
WashingMachineState machineState = getWashingMachineState();
LOGGER.info("{}: Actual machine state: {}", Thread.currentThread().getName(), machineState);
if (this.washingMachineState == WashingMachineState.WASHING) {
LOGGER.error("ERROR: Cannot wash if the machine has been already washing!");
return;
}
washingMachineState = WashingMachineState.WASHING;
this.washingMachineState = WashingMachineState.WASHING;
}
LOGGER.info("{}: Doing the washing", Thread.currentThread().getName());
@ -83,8 +82,7 @@ public class WashingMachine {
}
/**
* Method responsible of ending the washing
* by changing machine state
* Method responsible of ending the washing by changing machine state.
*/
public synchronized void endOfWashing() {
washingMachineState = WashingMachineState.ENABLED;

View File

@ -24,10 +24,9 @@
package com.iluwatar.balking;
/**
* WashingMachineState enum describes in which state machine is,
* it can be enabled and ready to work as well as during washing
* WashingMachineState enum describes in which state machine is, it can be enabled and ready to work
* as well as during washing.
*/
public enum WashingMachineState {
ENABLED, WASHING
}

View File

@ -23,11 +23,10 @@
package com.iluwatar.balking;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.TimeUnit;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/**
* Tests for {@link WashingMachine}