📍Use lombok, reformat, and optimize the code (#1560)
* Use lombok, reformat, and optimize the code * Fix merge conflicts and some sonar issues Co-authored-by: va1m <va1m@email.com>
This commit is contained in:
@ -23,11 +23,9 @@
|
||||
|
||||
package com.iluwatar.balking;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* In Balking Design Pattern if an object’s method is invoked when it is in an inappropriate state,
|
||||
@ -40,11 +38,9 @@ import org.slf4j.LoggerFactory;
|
||||
* been already washing and any other thread execute wash() it can't do that once again and returns
|
||||
* doing nothing.
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Entry Point.
|
||||
*
|
||||
@ -61,6 +57,7 @@ public class App {
|
||||
executorService.awaitTermination(10, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("ERROR: Waiting on executor service shutdown!");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,15 +24,14 @@
|
||||
package com.iluwatar.balking;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* Washing machine class.
|
||||
*/
|
||||
@Slf4j
|
||||
public class WashingMachine {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(WashingMachine.class);
|
||||
private final DelayProvider delayProvider;
|
||||
private WashingMachineState washingMachineState;
|
||||
|
||||
@ -44,7 +43,8 @@ public class WashingMachine {
|
||||
try {
|
||||
Thread.sleep(timeUnit.toMillis(interval));
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
LOGGER.error("", ie);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
task.run();
|
||||
});
|
||||
@ -71,7 +71,7 @@ public class WashingMachine {
|
||||
var 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!");
|
||||
LOGGER.error("Cannot wash if the machine has been already washing!");
|
||||
return;
|
||||
}
|
||||
this.washingMachineState = WashingMachineState.WASHING;
|
||||
|
@ -28,5 +28,6 @@ package com.iluwatar.balking;
|
||||
* as well as during washing.
|
||||
*/
|
||||
public enum WashingMachineState {
|
||||
ENABLED, WASHING
|
||||
ENABLED,
|
||||
WASHING
|
||||
}
|
||||
|
Reference in New Issue
Block a user