From 22ddd571467f811e120d37a43dae0edbc9071779 Mon Sep 17 00:00:00 2001
From: Harshal <37841724+harshalkh@users.noreply.github.com>
Date: Sun, 31 Oct 2021 12:38:49 +0530
Subject: [PATCH 1/3] sonar fix: Update App.java (#1898)
---
.../main/java/com/iluwatar/strategy/App.java | 22 +++++++++++--------
1 file changed, 13 insertions(+), 9 deletions(-)
diff --git a/strategy/src/main/java/com/iluwatar/strategy/App.java b/strategy/src/main/java/com/iluwatar/strategy/App.java
index 383712c39..d54c06008 100644
--- a/strategy/src/main/java/com/iluwatar/strategy/App.java
+++ b/strategy/src/main/java/com/iluwatar/strategy/App.java
@@ -41,6 +41,10 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class App {
+ private static final String RED_DRAGON_EMERGES = "Red dragon emerges.";
+ private static final String GREEN_DRAGON_SPOTTED = "Green dragon spotted ahead!";
+ private static final String BLACK_DRAGON_LANDS = "Black dragon lands before you.";
+
/**
* Program entry point.
*
@@ -48,38 +52,38 @@ public class App {
*/
public static void main(String[] args) {
// GoF Strategy pattern
- LOGGER.info("Green dragon spotted ahead!");
+ LOGGER.info(GREEN_DRAGON_SPOTTED);
var dragonSlayer = new DragonSlayer(new MeleeStrategy());
dragonSlayer.goToBattle();
- LOGGER.info("Red dragon emerges.");
+ LOGGER.info(RED_DRAGON_EMERGES);
dragonSlayer.changeStrategy(new ProjectileStrategy());
dragonSlayer.goToBattle();
- LOGGER.info("Black dragon lands before you.");
+ LOGGER.info(BLACK_DRAGON_LANDS);
dragonSlayer.changeStrategy(new SpellStrategy());
dragonSlayer.goToBattle();
// Java 8 functional implementation Strategy pattern
- LOGGER.info("Green dragon spotted ahead!");
+ LOGGER.info(GREEN_DRAGON_SPOTTED);
dragonSlayer = new DragonSlayer(
() -> LOGGER.info("With your Excalibur you severe the dragon's head!"));
dragonSlayer.goToBattle();
- LOGGER.info("Red dragon emerges.");
+ LOGGER.info(RED_DRAGON_EMERGES);
dragonSlayer.changeStrategy(() -> LOGGER.info(
"You shoot the dragon with the magical crossbow and it falls dead on the ground!"));
dragonSlayer.goToBattle();
- LOGGER.info("Black dragon lands before you.");
+ LOGGER.info(BLACK_DRAGON_LANDS);
dragonSlayer.changeStrategy(() -> LOGGER.info(
"You cast the spell of disintegration and the dragon vaporizes in a pile of dust!"));
dragonSlayer.goToBattle();
// Java 8 lambda implementation with enum Strategy pattern
- LOGGER.info("Green dragon spotted ahead!");
+ LOGGER.info(GREEN_DRAGON_SPOTTED);
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.MeleeStrategy);
dragonSlayer.goToBattle();
- LOGGER.info("Red dragon emerges.");
+ LOGGER.info(RED_DRAGON_EMERGES);
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.ProjectileStrategy);
dragonSlayer.goToBattle();
- LOGGER.info("Black dragon lands before you.");
+ LOGGER.info(BLACK_DRAGON_LANDS);
dragonSlayer.changeStrategy(LambdaStrategy.Strategy.SpellStrategy);
dragonSlayer.goToBattle();
}
From 36c6ce1df7f0008c71d82a6eb784df788505a9b3 Mon Sep 17 00:00:00 2001
From: Harshal <37841724+harshalkh@users.noreply.github.com>
Date: Sun, 31 Oct 2021 12:40:58 +0530
Subject: [PATCH 2/3] sonar fix: Update App.java (#1896)
* Update App.java
Sonar issue fix
* Update App.java
---
.../src/main/java/com/iluwatar/factory/method/App.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/factory-method/src/main/java/com/iluwatar/factory/method/App.java b/factory-method/src/main/java/com/iluwatar/factory/method/App.java
index b76a918d1..d903ee7c7 100644
--- a/factory-method/src/main/java/com/iluwatar/factory/method/App.java
+++ b/factory-method/src/main/java/com/iluwatar/factory/method/App.java
@@ -41,6 +41,8 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class App {
+ private static final String MANUFACTURED = "{} manufactured {}";
+
/**
* Program entry point.
* @param args command line args
@@ -49,14 +51,14 @@ public class App {
Blacksmith blacksmith = new OrcBlacksmith();
Weapon weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
- LOGGER.info("{} manufactured {}", blacksmith, weapon);
+ LOGGER.info(MANUFACTURED, blacksmith, weapon);
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
- LOGGER.info("{} manufactured {}", blacksmith, weapon);
+ LOGGER.info(MANUFACTURED, blacksmith, weapon);
blacksmith = new ElfBlacksmith();
weapon = blacksmith.manufactureWeapon(WeaponType.SPEAR);
- LOGGER.info("{} manufactured {}", blacksmith, weapon);
+ LOGGER.info(MANUFACTURED, blacksmith, weapon);
weapon = blacksmith.manufactureWeapon(WeaponType.AXE);
- LOGGER.info("{} manufactured {}", blacksmith, weapon);
+ LOGGER.info(MANUFACTURED, blacksmith, weapon);
}
}
From 0a7b524bd10b0eb67ac6045d12415759b1dc7fd0 Mon Sep 17 00:00:00 2001
From: "allcontributors[bot]"
<46447321+allcontributors[bot]@users.noreply.github.com>
Date: Sun, 31 Oct 2021 09:12:05 +0200
Subject: [PATCH 3/3] docs: add harshalkh as a contributor for code (#1900)
* docs: update README.md [skip ci]
* docs: update .all-contributorsrc [skip ci]
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
---
.all-contributorsrc | 9 +++++++++
README.md | 3 ++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/.all-contributorsrc b/.all-contributorsrc
index d19c152f9..13876cc83 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -1712,6 +1712,15 @@
"contributions": [
"doc"
]
+ },
+ {
+ "login": "harshalkh",
+ "name": "Harshal",
+ "avatar_url": "https://avatars.githubusercontent.com/u/37841724?v=4",
+ "profile": "https://github.com/harshalkh",
+ "contributions": [
+ "code"
+ ]
}
],
"contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 52303f5d4..2a7e43185 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
-[](#contributors-)
+[](#contributors-)
@@ -316,6 +316,7 @@ This project is licensed under the terms of the MIT license.