Skip to content

Commit

Permalink
Merge branch 'iluwatar:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Songtao-Zhu authored Oct 30, 2022
2 parents 116c803 + f8a3d93 commit 10e711e
Show file tree
Hide file tree
Showing 22 changed files with 958 additions and 127 deletions.
46 changes: 46 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -2033,6 +2033,52 @@
"contributions": [
"translation"
]
},
{
"login": "JanFidor",
"name": "JanFidor",
"avatar_url": "https://avatars.githubusercontent.com/u/66260538?v=4",
"profile": "https://github.com/JanFidor",
"contributions": [
"code",
"doc"
]
},
{
"login": "drakulavich",
"name": "Anton Yakutovich",
"avatar_url": "https://avatars.githubusercontent.com/u/129260?v=4",
"profile": "https://github.com/drakulavich",
"contributions": [
"code"
]
},
{
"login": "steph88ss",
"name": "steph88ss",
"avatar_url": "https://avatars.githubusercontent.com/u/111041594?v=4",
"profile": "https://github.com/steph88ss",
"contributions": [
"doc"
]
},
{
"login": "0xYujan",
"name": "Yujan Ranjitkar",
"avatar_url": "https://avatars.githubusercontent.com/u/63731234?v=4",
"profile": "http://yujanranjitkar.com.np",
"contributions": [
"translation"
]
},
{
"login": "yusha-g",
"name": "yusha-g",
"avatar_url": "https://avatars.githubusercontent.com/u/110189579?v=4",
"profile": "https://github.com/yusha-g",
"contributions": [
"translation"
]
}
],
"contributorsPerLine": 7,
Expand Down
59 changes: 59 additions & 0 deletions .github/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Configuration for probot-stale - https://github.com/probot/stale

# Number of days of inactivity before an Issue or Pull Request becomes stale
daysUntilStale: 30

# Number of days of inactivity before an Issue or Pull Request with the stale label is closed.
# Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale.
daysUntilClose: false

# Only issues or pull requests with all of these labels are check if stale. Defaults to `[]` (disabled)
onlyLabels: []

# Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable
exemptLabels:
- "info: help wanted"

# Set to true to ignore issues in a project (defaults to false)
exemptProjects: false

# Set to true to ignore issues in a milestone (defaults to false)
exemptMilestones: false

# Set to true to ignore issues with an assignee (defaults to false)
exemptAssignees: false

# Label to use when marking as stale
staleLabel: "status: stale"

# Comment to post when marking as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when removing the stale label.
# unmarkComment: >
# Your comment here.

# Comment to post when closing a stale Issue or Pull Request.
# closeComment: >
# Your comment here.

# Limit the number of actions per hour, from 1-30. Default is 30
limitPerRun: 30

# Limit to only `issues` or `pulls`
# only: issues

# Optionally, specify configuration settings that are specific to just 'issues' or 'pulls':
# pulls:
# daysUntilStale: 30
# markComment: >
# This pull request has been automatically marked as stale because it has not had
# recent activity. It will be closed if no further activity occurs. Thank you
# for your contributions.

# issues:
# exemptLabels:
# - confirmed
10 changes: 5 additions & 5 deletions .github/workflows/maven-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,21 @@ jobs:
steps:

- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# Disabling shallow clone for improving relevancy of SonarQube reporting
fetch-depth: 0

- name: Set up JDK 11.0.3
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
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
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
Expand All @@ -84,10 +84,10 @@ jobs:
steps:

- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK 11 (Latest)
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'zulu'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/maven-pr-builder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ jobs:
steps:

- name: Checkout Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up JDK ${{ matrix.java-version }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.java-version }}
distribution: 'zulu'
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](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 -->
[![All Contributors](https://img.shields.io/badge/all_contributors-223-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-228-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<br/>

Read in different language : [**zh**](localization/zh/README.md), [**ko**](localization/ko/README.md), [**fr**](localization/fr/README.md), [**tr**](localization/tr/README.md), [**ar**](localization/ar/README.md), [**es**](localization/es/README.md), [**pt**](localization/pt/README.md), [**id**](localization/id/README.md), [**ru**](localization/ru/README.md), [**de**](localization/de/README.md), [**ja**](localization/ja/README.md), [**vi**](localization/vi/README.md), [**bn**](localization/bn/README.md)
Read in different language : [**zh**](localization/zh/README.md), [**ko**](localization/ko/README.md), [**fr**](localization/fr/README.md), [**tr**](localization/tr/README.md), [**ar**](localization/ar/README.md), [**es**](localization/es/README.md), [**pt**](localization/pt/README.md), [**id**](localization/id/README.md), [**ru**](localization/ru/README.md), [**de**](localization/de/README.md), [**ja**](localization/ja/README.md), [**vi**](localization/vi/README.md), [**bn**](localization/bn/README.md), [**np**](localization/np/README.md)
<br/>

# Introduction
Expand Down Expand Up @@ -361,6 +361,13 @@ This project is licensed under the terms of the MIT license.
<td align="center"><a href="https://github.com/LeseChe"><img src="https://avatars.githubusercontent.com/u/79553089?v=4?s=100" width="100px;" alt="Qixiang Chen"/><br /><sub><b>Qixiang Chen</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=LeseChe" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/shouryamanekar"><img src="https://avatars.githubusercontent.com/u/72398499?v=4?s=100" width="100px;" alt="Shourya Manekar"/><br /><sub><b>Shourya Manekar</b></sub></a><br /><a href="#translation-shouryamanekar" title="Translation">🌍</a></td>
<td align="center"><a href="https://seongkyu-lim.github.io/Blog/"><img src="https://avatars.githubusercontent.com/u/55138532?v=4?s=100" width="100px;" alt="Alan"/><br /><sub><b>Alan</b></sub></a><br /><a href="#translation-seongkyu-lim" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/JanFidor"><img src="https://avatars.githubusercontent.com/u/66260538?v=4?s=100" width="100px;" alt="JanFidor"/><br /><sub><b>JanFidor</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=JanFidor" title="Code">💻</a> <a href="https://github.com/iluwatar/java-design-patterns/commits?author=JanFidor" title="Documentation">📖</a></td>
</tr>
<tr>
<td align="center"><a href="https://github.com/drakulavich"><img src="https://avatars.githubusercontent.com/u/129260?v=4?s=100" width="100px;" alt="Anton Yakutovich"/><br /><sub><b>Anton Yakutovich</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=drakulavich" title="Code">💻</a></td>
<td align="center"><a href="https://github.com/steph88ss"><img src="https://avatars.githubusercontent.com/u/111041594?v=4?s=100" width="100px;" alt="steph88ss"/><br /><sub><b>steph88ss</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=steph88ss" title="Documentation">📖</a></td>
<td align="center"><a href="http://yujanranjitkar.com.np"><img src="https://avatars.githubusercontent.com/u/63731234?v=4?s=100" width="100px;" alt="Yujan Ranjitkar"/><br /><sub><b>Yujan Ranjitkar</b></sub></a><br /><a href="#translation-0xYujan" title="Translation">🌍</a></td>
<td align="center"><a href="https://github.com/yusha-g"><img src="https://avatars.githubusercontent.com/u/110189579?v=4?s=100" width="100px;" alt="yusha-g"/><br /><sub><b>yusha-g</b></sub></a><br /><a href="#translation-yusha-g" title="Translation">🌍</a></td>
</tr>
</tbody>
</table>
Expand Down
12 changes: 9 additions & 3 deletions chain-of-responsibility/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,24 @@ The Orc King gives the orders and forms the chain.

```java
public class OrcKing {
RequestHandler chain;

private List<RequestHandler> handlers;

public OrcKing() {
buildChain();
}

private void buildChain() {
chain = new OrcCommander(new OrcOfficer(new OrcSoldier(null)));
handlers = Arrays.asList(new OrcCommander(), new OrcOfficer(), new OrcSoldier());
}

public void makeRequest(Request req) {
chain.handleRequest(req);
handlers
.stream()
.sorted(Comparator.comparing(RequestHandler::getPriority))
.filter(handler -> handler.canHandleRequest(req))
.findFirst()
.ifPresent(handler -> handler.handle(req));
}
}
```
Expand Down
Binary file modified chain-of-responsibility/etc/chain-of-responsibility.urm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
50 changes: 28 additions & 22 deletions chain-of-responsibility/etc/chain-of-responsibility.urm.puml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@ package com.iluwatar.chain {
+ main(args : String[]) {static}
}
class OrcCommander {
+ OrcCommander(handler : RequestHandler)
+ handleRequest(req : Request)
+ toString() : String
- LOGGER : Logger {static}
+ OrcCommander()
+ canHandleRequest(req : Request) : boolean
+ getPriority() : int
+ handle(req : Request)
+ name() : String
}
class OrcKing {
- chain : RequestHandler
- handlers : List<RequestHandler>
+ OrcKing()
- buildChain()
+ makeRequest(req : Request)
}
class OrcOfficer {
+ OrcOfficer(handler : RequestHandler)
+ handleRequest(req : Request)
+ toString() : String
- LOGGER : Logger {static}
+ OrcOfficer()
+ canHandleRequest(req : Request) : boolean
+ getPriority() : int
+ handle(req : Request)
+ name() : String
}
class OrcSoldier {
+ OrcSoldier(handler : RequestHandler)
+ handleRequest(req : Request)
+ toString() : String
- LOGGER : Logger {static}
+ OrcSoldier()
+ canHandleRequest(req : Request) : boolean
+ getPriority() : int
+ handle(req : Request)
+ name() : String
}
class Request {
- handled : boolean
Expand All @@ -36,13 +45,11 @@ package com.iluwatar.chain {
+ markHandled()
+ toString() : String
}
abstract class RequestHandler {
- LOGGER : Logger {static}
- next : RequestHandler
+ RequestHandler(next : RequestHandler)
+ handleRequest(req : Request)
# printHandling(req : Request)
+ toString() : String {abstract}
interface RequestHandler {
+ canHandleRequest(Request) : boolean {abstract}
+ getPriority() : int {abstract}
+ handle(Request) {abstract}
+ name() : String {abstract}
}
enum RequestType {
+ COLLECT_TAX {static}
Expand All @@ -52,10 +59,9 @@ package com.iluwatar.chain {
+ values() : RequestType[] {static}
}
}
OrcKing --> "-chain" RequestHandler
RequestHandler --> "-next" RequestHandler
OrcKing --> "-handlers" RequestHandler
Request --> "-requestType" RequestType
OrcCommander --|> RequestHandler
OrcOfficer --|> RequestHandler
OrcSoldier --|> RequestHandler
OrcCommander ..|> RequestHandler
OrcOfficer ..|> RequestHandler
OrcSoldier ..|> RequestHandler
@enduml
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,31 @@
*/
package com.iluwatar.chain;

import lombok.extern.slf4j.Slf4j;

/**
* OrcCommander.
*/
public class OrcCommander extends RequestHandler {
@Slf4j
public class OrcCommander implements RequestHandler {
@Override
public boolean canHandleRequest(Request req) {
return req.getRequestType() == RequestType.DEFEND_CASTLE;
}

public OrcCommander(RequestHandler handler) {
super(handler);
@Override
public int getPriority() {
return 2;
}

@Override
public void handleRequest(Request req) {
if (RequestType.DEFEND_CASTLE == req.getRequestType()) {
printHandling(req);
req.markHandled();
} else {
super.handleRequest(req);
}
public void handle(Request req) {
req.markHandled();
LOGGER.info("{} handling request \"{}\"", name(), req);
}

@Override
public String toString() {
public String name() {
return "Orc commander";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,34 @@
*/
package com.iluwatar.chain;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

/**
* OrcKing makes requests that are handled by the chain.
*/
public class OrcKing {

private RequestHandler chain;
private List<RequestHandler> handlers;

public OrcKing() {
buildChain();
}

private void buildChain() {
chain = new OrcCommander(new OrcOfficer(new OrcSoldier(null)));
handlers = Arrays.asList(new OrcCommander(), new OrcOfficer(), new OrcSoldier());
}

/**
* Handle request by the chain.
*/
public void makeRequest(Request req) {
chain.handleRequest(req);
handlers
.stream()
.sorted(Comparator.comparing(RequestHandler::getPriority))
.filter(handler -> handler.canHandleRequest(req))
.findFirst()
.ifPresent(handler -> handler.handle(req));
}

}
Loading

0 comments on commit 10e711e

Please sign in to comment.