Compare commits
5 Commits
l10n_maste
...
all-contri
Author | SHA1 | Date | |
---|---|---|---|
a29d9194ef | |||
2679820677 | |||
22ddd57146 | |||
72bb189dc0 | |||
bee1283371 |
@ -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,
|
||||
|
49
.github/workflows/maven-ci.yml
vendored
49
.github/workflows/maven-ci.yml
vendored
@ -24,6 +24,9 @@
|
||||
# This workflow will build a Java project with Maven
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
|
||||
|
||||
# We are using two jobs here for testing our code on the latest JDK 11 build as well as a more satble build version of 11.0.3
|
||||
# You can see the full discussion here https://github.com/iluwatar/java-design-patterns/pull/1868#issue-1029459688
|
||||
|
||||
name: Java CI
|
||||
|
||||
on:
|
||||
@ -33,12 +36,11 @@ on:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
# This Workflow Job will build this project and run Sonar analysis using JDK 11.0.3
|
||||
build-and-analyze:
|
||||
|
||||
name: Build and Run Sonar analysis on JDK 11.0.3
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [ 11.0.3, 11 ]
|
||||
steps:
|
||||
|
||||
- name: Checkout Code
|
||||
@ -47,12 +49,14 @@ jobs:
|
||||
# Disabling shallow clone for improving relevancy of SonarQube reporting
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up JDK ${{ matrix.java-version }}
|
||||
- name: Set up JDK 11.0.3
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: ${{ matrix.java-version }}
|
||||
java-version: 11.0.3
|
||||
distribution: 'zulu'
|
||||
cache: 'maven'
|
||||
|
||||
# Cache Sonar packages which as used to run anaylysis and collect metrics
|
||||
- name: Cache SonarCloud packages
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
@ -60,14 +64,6 @@ jobs:
|
||||
key: ${{ runner.os }}-sonar
|
||||
restore-keys: ${{ runner.os }}-sonar
|
||||
|
||||
- name: Cache Maven dependencies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
|
||||
# Some tests need screen access
|
||||
- name: Install xvfb
|
||||
run: sudo apt-get install -y xvfb
|
||||
@ -78,3 +74,28 @@ jobs:
|
||||
# These two env variables are needed for sonar analysis
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
||||
|
||||
|
||||
# This Workflow Job is going to build the project on the latest stable JDK 11
|
||||
build:
|
||||
|
||||
name: Build and Test on JDK 11
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Set up JDK 11 (Latest)
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
java-version: 11
|
||||
distribution: 'zulu'
|
||||
cache: 'maven'
|
||||
|
||||
# Some tests need screen access
|
||||
- name: Install xvfb
|
||||
run: sudo apt-get install -y xvfb
|
||||
|
||||
- name: Build with Maven
|
||||
run: xvfb-run ./mvnw clean verify
|
||||
|
11
.github/workflows/maven-pr-builder.yml
vendored
11
.github/workflows/maven-pr-builder.yml
vendored
@ -34,11 +34,13 @@ on:
|
||||
jobs:
|
||||
build:
|
||||
|
||||
name: Build JDP
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [ 11.0.3, 11 ]
|
||||
steps:
|
||||
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
@ -47,14 +49,7 @@ jobs:
|
||||
with:
|
||||
java-version: ${{ matrix.java-version }}
|
||||
distribution: 'zulu'
|
||||
|
||||
- name: Cache Maven Dependecies
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.m2/repository
|
||||
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-maven-
|
||||
cache: 'maven'
|
||||
|
||||
# Some tests need screen access
|
||||
- name: Install xvfb
|
||||
|
@ -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)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
||||
[](#contributors-)
|
||||
[](#contributors-)
|
||||
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
||||
|
||||
<br/>
|
||||
@ -316,6 +316,7 @@ This project is licensed under the terms of the MIT license.
|
||||
<td align="center"><a href="https://github.com/blueberry404"><img src="https://avatars.githubusercontent.com/u/39243539?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Anum Amin</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=blueberry404" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://uh-zz.github.io/blog/"><img src="https://avatars.githubusercontent.com/u/47747828?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Reo Uehara</b></sub></a><br /><a href="#translation-uh-zz" title="Translation">🌍</a></td>
|
||||
<td align="center"><a href="https://github.com/Fiordy"><img src="https://avatars.githubusercontent.com/u/53420573?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Fiordy</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Fiordy" title="Documentation">📖</a></td>
|
||||
<td align="center"><a href="https://github.com/harshalkh"><img src="https://avatars.githubusercontent.com/u/37841724?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Harshal</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=harshalkh" title="Code">💻</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
|
@ -39,7 +39,13 @@ In plain words
|
||||
Let's first look at the person entity that we need to persist.
|
||||
|
||||
```java
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@Setter
|
||||
@Getter
|
||||
@Entity
|
||||
@NoArgsConstructor
|
||||
public class Person {
|
||||
|
||||
@Id
|
||||
@ -49,17 +55,15 @@ public class Person {
|
||||
private String surname;
|
||||
private int age;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
public Person(String name, String surname, int age) {
|
||||
this.name = name;
|
||||
this.surname = surname;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
// getters and setters ->
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user