📍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:
va1m
2021-03-13 13:19:21 +01:00
committed by GitHub
parent 0e26a6adb5
commit 5cf2fe009b
681 changed files with 2472 additions and 4966 deletions

View File

@ -44,30 +44,27 @@ public interface DragonSlayingStrategy {
void execute();
}
@Slf4j
public class MeleeStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(MeleeStrategy.class);
@Override
public void execute() {
LOGGER.info("With your Excalibur you sever the dragon's head!");
}
}
@Slf4j
public class ProjectileStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectileStrategy.class);
@Override
public void execute() {
LOGGER.info("You shoot the dragon with the magical crossbow and it falls dead on the ground!");
}
}
@Slf4j
public class SpellStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(SpellStrategy.class);
@Override
public void execute() {
LOGGER.info("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");

View File

@ -23,11 +23,10 @@
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
*
*
* <p>The Strategy pattern (also known as the policy pattern) is a software design pattern that
* enables an algorithm's behavior to be selected at runtime.</p>
*
@ -37,12 +36,11 @@ import org.slf4j.LoggerFactory;
*
* <p>In this example ({@link DragonSlayingStrategy}) encapsulates an algorithm. The containing
* object ({@link DragonSlayer}) can alter its behavior by changing its strategy.</p>
*
*
*/
@Slf4j
public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/**
* Program entry point.
*

View File

@ -23,13 +23,11 @@
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LambdaStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(LambdaStrategy.class);
public enum Strategy implements DragonSlayingStrategy {
MeleeStrategy(() -> LOGGER.info(
"With your Excalibur you severe the dragon's head!")),

View File

@ -23,16 +23,14 @@
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Melee strategy.
*/
@Slf4j
public class MeleeStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(MeleeStrategy.class);
@Override
public void execute() {
LOGGER.info("With your Excalibur you sever the dragon's head!");

View File

@ -23,16 +23,14 @@
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Projectile strategy.
*/
@Slf4j
public class ProjectileStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(ProjectileStrategy.class);
@Override
public void execute() {
LOGGER.info("You shoot the dragon with the magical crossbow and it falls dead on the ground!");

View File

@ -23,16 +23,14 @@
package com.iluwatar.strategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;
/**
* Spell strategy.
*/
@Slf4j
public class SpellStrategy implements DragonSlayingStrategy {
private static final Logger LOGGER = LoggerFactory.getLogger(SpellStrategy.class);
@Override
public void execute() {
LOGGER.info("You cast the spell of disintegration and the dragon vaporizes in a pile of dust!");

View File

@ -40,7 +40,7 @@ public class DragonSlayerTest {
* Verify if the dragon slayer uses the strategy during battle.
*/
@Test
public void testGoToBattle() {
void testGoToBattle() {
final var strategy = mock(DragonSlayingStrategy.class);
final var dragonSlayer = new DragonSlayer(strategy);
@ -53,7 +53,7 @@ public class DragonSlayerTest {
* Verify if the dragon slayer uses the new strategy during battle after a change of strategy.
*/
@Test
public void testChangeStrategy() {
void testChangeStrategy() {
final var initialStrategy = mock(DragonSlayingStrategy.class);
final var dragonSlayer = new DragonSlayer(initialStrategy);