Compare commits
506 Commits
Author | SHA1 | Date | |
---|---|---|---|
73f9b8bef1 | |||
19b129c28e | |||
63c707fcb1 | |||
cc4b990ae8 | |||
8747f1fd7a | |||
9e58edf05e | |||
271d7ae9bd | |||
26f4aa8001 | |||
1fdc650545 | |||
3ccc9baa1a | |||
df8a4e3b47 | |||
cc571f4149 | |||
51b444dccf | |||
50467c9e76 | |||
87af122509 | |||
160b737dcc | |||
f04fc3c0dc | |||
3c57bf7078 | |||
33ea7335b1 | |||
6ef840f3cf | |||
1e76d91929 | |||
390795154f | |||
37599eb48f | |||
c954a436ad | |||
2628cc0dfc | |||
0272d71851 | |||
329479dda0 | |||
c4418311c6 | |||
f0f0143d48 | |||
b92eb5229d | |||
9c8ad4485b | |||
4dae1fae57 | |||
5ae2ce6e2e | |||
7c888e8886 | |||
f2c91eb836 | |||
01e489c77b | |||
eae09fc07e | |||
7f06f3b78c | |||
dda09535e6 | |||
4f9ee0189c | |||
de56cbb971 | |||
2f49648047 | |||
31f27a720b | |||
efc17fcc70 | |||
6d1c0b1563 | |||
74c7273381 | |||
8f85353baf | |||
09b4663b9a | |||
1fa8a604eb | |||
50986fa15b | |||
8ecdee44c8 | |||
47ae477a56 | |||
7dc47da131 | |||
fbcfeb072a | |||
ffeee2f1a4 | |||
1b32e23493 | |||
3a4677c56d | |||
c4c37d77e9 | |||
0b17abdf11 | |||
7ac47b291d | |||
564cf1239f | |||
768e647108 | |||
a8c7771784 | |||
1d4a7681e2 | |||
55b0341c8d | |||
3b1a28149b | |||
1eb1961f1b | |||
cc85c73fbc | |||
cdb80b8ddd | |||
a9dfd7e809 | |||
fca7e9c8c7 | |||
91a085d3d1 | |||
ff52848481 | |||
ccc1a6340b | |||
a65a601835 | |||
c8a481bb77 | |||
dd971d8c19 | |||
6bb3438965 | |||
63fb8dc318 | |||
b50189e283 | |||
9f7e3fe552 | |||
d1767bbb51 | |||
5d47488fe9 | |||
d01a3a66b4 | |||
e3827945c8 | |||
fadad43f8b | |||
c7fee7bb07 | |||
954e7300e9 | |||
03e1e92b52 | |||
af8c5ed0dd | |||
349d8edebf | |||
12f13a631e | |||
0b8d78e4bf | |||
58d8fa1758 | |||
f7a53f2d17 | |||
70ddeaa194 | |||
6aeafcf2aa | |||
1cb1bdcb57 | |||
1b6cecda19 | |||
9403d53096 | |||
630532cdda | |||
acaa6cdc62 | |||
4904d7eea0 | |||
c81c3ff1c7 | |||
5fc03ee9f8 | |||
20b4195fb2 | |||
f00ebe1a8d | |||
2217fbc5ff | |||
82f9a6c232 | |||
f671f03d13 | |||
f09a7eb468 | |||
7c5d5f6b0d | |||
8a4844792f | |||
0c60a95d8f | |||
c3656109a7 | |||
a204383f45 | |||
2982db456d | |||
c308ca09e5 | |||
880b234d8f | |||
a5646b63c1 | |||
27c131c2cb | |||
c438ec0557 | |||
dd5997b495 | |||
e6c71b63fc | |||
7e698a90dd | |||
088bb764f3 | |||
47d92bbffb | |||
cfdfedbd2e | |||
72b174619f | |||
9ebbc421dd | |||
fcc1c0a27c | |||
6faec9901a | |||
e36bbbb22b | |||
71f26c3e59 | |||
795b6be17d | |||
90ea4506ca | |||
41b8d80479 | |||
f903d7e9a9 | |||
84c4b034a9 | |||
f5455f9887 | |||
2b1c09aa72 | |||
94ca254626 | |||
60171e3c87 | |||
933de30d42 | |||
364c43a73a | |||
218ba44dbf | |||
05d0f0babf | |||
823c58bef2 | |||
b03e0b8c35 | |||
3d62e02891 | |||
06fa92af2c | |||
6b297b701f | |||
5f39f7fbf7 | |||
019abc9980 | |||
b874adc296 | |||
9bf7a059b8 | |||
88fae070e6 | |||
f1410337b5 | |||
8c865e6b4d | |||
c653edf38f | |||
35dc25d480 | |||
318f811fea | |||
7f6067f19f | |||
11c0550559 | |||
085e47b50d | |||
61ef59de02 | |||
ccb257d525 | |||
6daaeec5c6 | |||
517c20960d | |||
36e80c4e69 | |||
3454941dcd | |||
b497d41f61 | |||
aaabc8f517 | |||
2757b210ea | |||
d9a567cf97 | |||
a113de6a14 | |||
f7e22a1cf6 | |||
c6ecf58687 | |||
17bfc91f45 | |||
0c6237c225 | |||
fedc2d9e47 | |||
b6b4602baf | |||
eafe52e17a | |||
5251ec4a93 | |||
26f1a608ab | |||
7a25c57474 | |||
55c7579983 | |||
10cb191533 | |||
a6749cb63e | |||
7b8c9b07ed | |||
0fa18d91c6 | |||
53b673d5b0 | |||
966c56311c | |||
150f72758e | |||
4446e74338 | |||
70f6e54353 | |||
1f1fcae513 | |||
2aa9e78ddd | |||
25ed7c09c5 | |||
922fd62da6 | |||
9e7a500743 | |||
21a149ee77 | |||
f5eaf06c1c | |||
3c6fb0c53b | |||
829df031c3 | |||
37ae182630 | |||
ab2c12e734 | |||
b3f0cc7e00 | |||
86e9c66ca5 | |||
a6e6c22bf6 | |||
db33cc533b | |||
8433c7b712 | |||
ee74fec53c | |||
7a7e891384 | |||
26d6d96f78 | |||
3cec7a9ec1 | |||
b079aec1fd | |||
8f53df91b9 | |||
709405d964 | |||
f3749a2b9d | |||
1d12d94bac | |||
9e56e5cbc1 | |||
1698b066f3 | |||
4ed039d807 | |||
ec6d2a8ebe | |||
98c3f93e82 | |||
26fbbed62e | |||
0f9089dd62 | |||
038befea26 | |||
9daa3140e4 | |||
8458e426bc | |||
e6f84f2f41 | |||
74f3799eb4 | |||
b23d8430af | |||
cb6b0b3600 | |||
cd44ef3c81 | |||
1c2ddfad54 | |||
f36de036f6 | |||
b64262303a | |||
9d012772fd | |||
e1a2f141c5 | |||
cce104a271 | |||
16df157181 | |||
c34004bea5 | |||
3e0cfa5684 | |||
ce459e8f9f | |||
535431fac1 | |||
facb9e51a6 | |||
9eb8c30bcb | |||
fc87f8b7d3 | |||
b453753790 | |||
d2b900b524 | |||
2c8d1744df | |||
d915b66e70 | |||
328f917749 | |||
ae07423470 | |||
7add7b833c | |||
c7f9266768 | |||
0453bf9063 | |||
f9bdd58bb7 | |||
57f60c5ebf | |||
51659fe9c5 | |||
04d80f05c8 | |||
6636fb151b | |||
6a0fa747ad | |||
8b1ed95d6b | |||
6167d06dce | |||
49feead13f | |||
179a02bcdd | |||
71f61cd40e | |||
d54e29051f | |||
4456a440bc | |||
c48a1e9193 | |||
971a74e13a | |||
868e4561b5 | |||
c4dd94a019 | |||
ff579fabcf | |||
5393c96247 | |||
bae51f5803 | |||
74190e36bb | |||
6b10f4bdd1 | |||
73925cef2e | |||
987994f0fe | |||
95df47e418 | |||
afe85e22e7 | |||
4023944240 | |||
17164c282a | |||
27f58e0925 | |||
36a14778dc | |||
5e1da6361f | |||
97718846d1 | |||
bbdf1cd738 | |||
323395daaf | |||
75734a6b7d | |||
3f92b8f84e | |||
18a75c0620 | |||
9e15abbafc | |||
e9a219f643 | |||
8bf53fe91d | |||
c713dbcbf4 | |||
f3e1cd3a1d | |||
4ab46c7fcb | |||
d7893c1fc2 | |||
eddfe76a84 | |||
a386d4266d | |||
29edeabaae | |||
abcc39871b | |||
4ac6f90c96 | |||
a8d89ca861 | |||
998600f09e | |||
1e04b17a2d | |||
187b16c9e0 | |||
3b45f2cad6 | |||
65e1cae2de | |||
0b7343dd34 | |||
379a825182 | |||
522fbc035f | |||
40e5cc628a | |||
7a13012855 | |||
1c0e0cd88b | |||
3407392664 | |||
474c218f85 | |||
17ea0b17f6 | |||
7d4ccc6490 | |||
8b06ea52ab | |||
86ee59c232 | |||
6879990857 | |||
855cf75dd6 | |||
ecad864703 | |||
c3b102e547 | |||
69be74c016 | |||
3f9a5a254e | |||
05a9c030c0 | |||
c723289bbb | |||
477da92e2f | |||
ac57d67f45 | |||
960d2ea6f7 | |||
87cb33f69b | |||
915a1f3eb0 | |||
c8fd0bc23d | |||
696ed86aff | |||
e0b8f6f850 | |||
143213483c | |||
678fa93838 | |||
b2607010b4 | |||
b2dd36f607 | |||
af6973884f | |||
3894a0bb6c | |||
49f8434911 | |||
55bbb88ac9 | |||
ce88fd723e | |||
e01d640499 | |||
7fef5e4cd5 | |||
3333a2839b | |||
a60fa76fd9 | |||
565f5a4e70 | |||
b73ef6e6c5 | |||
991ba320a6 | |||
d78434fed8 | |||
f9f93695fe | |||
a367832d9e | |||
7a7ba871dc | |||
36f5947cd7 | |||
f62ae456b0 | |||
5cbf651a3e | |||
e7b119c95c | |||
ec28b1250d | |||
2dcf63c646 | |||
0805716515 | |||
9f797b3009 | |||
33a3d6fef4 | |||
dddfb52c70 | |||
9667878b5f | |||
4c4cbd41cf | |||
f7825f6c99 | |||
8960ef6111 | |||
a82000650d | |||
e9021329e1 | |||
e9a541259b | |||
94fdefee3a | |||
b61b64073a | |||
09c0891948 | |||
90570f809b | |||
55be744c4a | |||
c34975bdff | |||
ed37d5cdc7 | |||
f87754917c | |||
e046007db7 | |||
0306161380 | |||
dea2316f1f | |||
cb38501ea2 | |||
7f959ed157 | |||
6694d742a3 | |||
a20e54d0a7 | |||
e8496c5d48 | |||
3defc1b36a | |||
9677cc4eea | |||
fc690869db | |||
37c9b922a7 | |||
0824529471 | |||
235fe6a7ca | |||
5373214b70 | |||
93c54a2ee5 | |||
5a930f6a26 | |||
2a4edad23a | |||
c1ea04e002 | |||
10c0879d3b | |||
620f408688 | |||
2456b9f4b0 | |||
144db43ad4 | |||
f7c396b0fd | |||
6b4ae0d0b1 | |||
04f2be64c6 | |||
6c4de3bcef | |||
a2d155cbb9 | |||
52f09d043c | |||
11de22bf4a | |||
6614d0735e | |||
8312e09f6e | |||
176bb85f40 | |||
7e7a0c83f5 | |||
4dbf646b37 | |||
506d316529 | |||
8a9162f542 | |||
4b1650fbde | |||
d26f2620ec | |||
fb5c2a0324 | |||
7cf897a051 | |||
171c4b30b9 | |||
bf98299db2 | |||
b0f9582824 | |||
fb64d69347 | |||
4450000a83 | |||
14279278cd | |||
071cde8d70 | |||
6339e26838 | |||
5c953d7d00 | |||
51096ec445 | |||
f3f1f54ccc | |||
f58256d70a | |||
933c84ff1c | |||
3634b3338c | |||
d37922bf82 | |||
87ee97a112 | |||
c45e9a1faf | |||
390c33e36e | |||
5f90b2597a | |||
6e0bf59e5a | |||
7185830700 | |||
ec6eea61a5 | |||
89bfaf876e | |||
e289779dd3 | |||
a2a13758e0 | |||
5ed46c2c64 | |||
168c9cf3a9 | |||
0312392b3c | |||
df04e19994 | |||
8c15b89295 | |||
eeaf7e4b7c | |||
dd828bcd6c | |||
0aa84e37f2 | |||
767f41ad90 | |||
9c7ee5ed1d | |||
141d448c17 | |||
41710cbe9e | |||
04dd93f8bc | |||
624a4ef857 | |||
0453ba1315 | |||
60f07d1940 | |||
dfb43299a8 | |||
b2dd175851 | |||
31120a8fa0 | |||
ed1852a789 | |||
56ba78a5e9 | |||
522721559b | |||
f80d903cff | |||
0d4a8db114 | |||
4e236f6da8 | |||
4abef6da33 | |||
b5eca2f856 | |||
b8491436dd | |||
04891e5bf3 | |||
244e9c7caa | |||
01b85b9721 | |||
e6342d5956 | |||
e4b0153ddc | |||
8e73728fde | |||
684cad9beb | |||
a1ee8859d6 | |||
677f020813 | |||
00dcf24e16 | |||
1fb0525c6e | |||
633d3a97a0 | |||
9ee2255c1f | |||
bf700fd995 | |||
1dc143abca | |||
530b9e9662 | |||
2c9098aecc | |||
5fe9d2be6c | |||
68ed2a4726 | |||
acc2fad818 | |||
8a53a2626e | |||
e43b6f13fd | |||
4ecc337c7d | |||
3c6f7aa046 | |||
8953bfc81b |
1
.github/FUNDING.yml
vendored
Normal file
1
.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
github: [iluwatar]
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -16,5 +16,4 @@ datanucleus.log
|
|||||||
/bin/
|
/bin/
|
||||||
/bin/
|
/bin/
|
||||||
*.log
|
*.log
|
||||||
data-mapper/src/main/resources/log4j.xml
|
|
||||||
event-sourcing/Journal.json
|
event-sourcing/Journal.json
|
||||||
|
39
.travis.yml
39
.travis.yml
@ -1,30 +1,29 @@
|
|||||||
language: java
|
language: java
|
||||||
|
dist: bionic
|
||||||
jdk:
|
jdk:
|
||||||
- oraclejdk8
|
- openjdk11
|
||||||
|
sudo: required
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
- GH_REF: github.com/iluwatar/java-design-patterns.git
|
- secure: "DCpazS3nkLnter3sguXEAS2fC/1ZWNfM+XLyif9MfNFxlZdpni2vCD/jA0Rdpga8puQWHNVLyAec+RPFH/2qSmJ1c1UTV5MaLv8tPqwUX0VFA+1I6XoSv6oX4ldHTBWHEWqQHkRFOLoil0h0edc0tTOWQwXF8U+DLAB+HkRb4gw="
|
||||||
- secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg=
|
|
||||||
- secure: "eoWlW9GyTJY04P8K3pxayXwU9/hmptQg/LfirispQkV9YvmziCfSzXnatnBhNfud98sCzY8BScXnb+OWLTnjLKpId4rtEqb0aJ40Jc32cUKzgzFAUn7cNcDAbUIfyPAGVqyQqfj/11wYSADwWMMOPlW97ExUtoyiH2WenXuRHso="
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- export DISPLAY=:99.0
|
|
||||||
- sh -e /etc/init.d/xvfb start
|
|
||||||
|
|
||||||
# default install command is just "mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V"
|
services:
|
||||||
install:
|
- xvfb
|
||||||
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -e
|
|
||||||
|
addons:
|
||||||
|
sonarcloud:
|
||||||
|
organization: "iluwatar"
|
||||||
|
token:
|
||||||
|
secure: "FpHwMYPMkdWU6CeIB7+O3qIeIM4vJMp47UjkKK53f0w0s6tPZofZZkab+gcL2TqKSil7sFVB/AQXU1cUubflRszwcLbNsc8H2yFehD79o0o0Mqd1Dd5ip/q0KQbHkkln+InFlVLfvrLB4Xd4mlQVxbGhqpULBhXjKzFzQlRFcuU="
|
||||||
|
script:
|
||||||
|
# Because of Travis security restrictions, SonarCloud analysis cannot be run on pull requests originated from forks
|
||||||
|
# See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
|
||||||
|
- 'if [ "$TRAVIS_PULL_REQUEST" != "false" ]; then mvn clean verify; fi'
|
||||||
|
- 'if [ "$TRAVIS_PULL_REQUEST" = "false" ]; then mvn clean verify sonar:sonar -Dsonar.projectKey=iluwatar_java-design-patterns -Dsonar.host.url=https://sonarcloud.io; fi'
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
|
- bash update-website.sh
|
||||||
- bash update-ghpages.sh
|
|
||||||
|
|
||||||
# use latest java version available instead of travis default
|
|
||||||
addons:
|
|
||||||
apt:
|
|
||||||
packages:
|
|
||||||
- oracle-java8-installer
|
|
||||||
|
|
||||||
notifications:
|
notifications:
|
||||||
email:
|
email:
|
||||||
@ -35,5 +34,3 @@ notifications:
|
|||||||
on_success: change # options: [always|never|change] default: always
|
on_success: change # options: [always|never|change] default: always
|
||||||
on_failure: always # options: [always|never|change] default: always
|
on_failure: always # options: [always|never|change] default: always
|
||||||
on_start: never # options: [always|never|change] default: always
|
on_start: never # options: [always|never|change] default: always
|
||||||
|
|
||||||
sudo: required
|
|
@ -1,13 +0,0 @@
|
|||||||
# Code Coverage Report generation
|
|
||||||
|
|
||||||
To generate the code coverage report, execute the following command:
|
|
||||||
> mvn clean verify
|
|
||||||
|
|
||||||
This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser.
|
|
||||||
> target/site/jacoco/index.html
|
|
||||||
|
|
||||||
Please note that the above folder is created under each of the modules. For example:
|
|
||||||
* adapter/target/site/jacoco/index.html
|
|
||||||
* busniess-delegate/target/site/jacoco/index.html
|
|
||||||
|
|
||||||
|
|
15
PULL_REQUEST_TEMPLATE.md
Normal file
15
PULL_REQUEST_TEMPLATE.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
|
||||||
|
Pull request title
|
||||||
|
|
||||||
|
- Clearly and concisely describes what it does
|
||||||
|
- Refer to the issue that it solves, if available
|
||||||
|
|
||||||
|
|
||||||
|
Pull request description
|
||||||
|
|
||||||
|
- Describes the main changes that come with the pull request
|
||||||
|
- Any relevant additional information is provided
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
> For detailed contributing instructions see https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute
|
24
README.md
24
README.md
@ -7,24 +7,31 @@
|
|||||||
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
||||||
[](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
|
[](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
|
||||||
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
[](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
||||||
[](https://sonarqube.com/dashboard/index/com.iluwatar%3Ajava-design-patterns)
|
[](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
|
||||||
|
|
||||||
# Introduction
|
# Introduction
|
||||||
|
|
||||||
Design patterns are formalized best practices that the programmer can use to
|
Design patterns are the best formalized practices a programmer can use to
|
||||||
solve common problems when designing an application or system.
|
solve common problems when designing an application or system.
|
||||||
|
|
||||||
Design patterns can speed up the development process by providing tested, proven
|
Design patterns can speed up the development process by providing tested, proven
|
||||||
development paradigms.
|
development paradigms.
|
||||||
|
|
||||||
Reusing design patterns helps to prevent subtle issues that can cause major
|
Reusing design patterns help prevent subtle issues that cause major
|
||||||
problems, and it also improves code readability for coders and architects who
|
problems, and it also improves code readability for coders and architects who
|
||||||
are familiar with the patterns.
|
are familiar with the patterns.
|
||||||
|
|
||||||
# Getting started
|
# Getting started
|
||||||
|
|
||||||
|
This site showcases Java Design Patterns. The solutions have been developed by
|
||||||
|
experienced programmers and architects from the open source community. The
|
||||||
|
patterns can be browsed by their high level descriptions or by looking at their
|
||||||
|
source code. The source code examples are well commented and can be thought as
|
||||||
|
programming tutorials how to implement a specific pattern. We use the most
|
||||||
|
popular battle-proven open source Java technologies.
|
||||||
|
|
||||||
Before you dive into the material, you should be familiar with various
|
Before you dive into the material, you should be familiar with various
|
||||||
Programming/Software Design Principles.
|
software design principles.
|
||||||
|
|
||||||
All designs should be as simple as possible. You should start with KISS, YAGNI,
|
All designs should be as simple as possible. You should start with KISS, YAGNI,
|
||||||
and Do The Simplest Thing That Could Possibly Work principles. Complexity and
|
and Do The Simplest Thing That Could Possibly Work principles. Complexity and
|
||||||
@ -35,12 +42,17 @@ Once you are familiar with these concepts you can start drilling down into
|
|||||||
patterns by any of the following approaches
|
patterns by any of the following approaches
|
||||||
|
|
||||||
- Using difficulty tags, `Difficulty-Beginner`, `Difficulty-Intermediate` & `Difficulty-Expert`.
|
- Using difficulty tags, `Difficulty-Beginner`, `Difficulty-Intermediate` & `Difficulty-Expert`.
|
||||||
- Using pattern categories, `Creational`, `Behavioral` and others.
|
- Using pattern categories, `Creational`, `Behavioral`, and others.
|
||||||
- Search for a specific pattern. Can't find one? Please report a new pattern [here](https://github.com/iluwatar/java-design-patterns/issues).
|
- Search for a specific pattern. Can't find one? Please report a new pattern [here](https://github.com/iluwatar/java-design-patterns/issues).
|
||||||
|
|
||||||
|
Hopefully you find the object oriented solutions presented on this site useful
|
||||||
|
in your architectures and have as much fun learning them as we had developing them.
|
||||||
|
|
||||||
# How to contribute
|
# How to contribute
|
||||||
|
|
||||||
If you are willing to contribute to the project you will find the relevant information in our [developer wiki](https://github.com/iluwatar/java-design-patterns/wiki). We will help you and answer your questions in the [Gitter chatroom](https://gitter.im/iluwatar/java-design-patterns).
|
If you are willing to contribute to the project you will find the relevant information in
|
||||||
|
our [developer wiki](https://github.com/iluwatar/java-design-patterns/wiki). We will help
|
||||||
|
you and answer your questions in the [Gitter chatroom](https://gitter.im/iluwatar/java-design-patterns).
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
@ -1,67 +0,0 @@
|
|||||||
#
|
|
||||||
# The MIT License
|
|
||||||
# Copyright (c) 2014-2016 Ilkka Seppälä
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
# THE SOFTWARE.
|
|
||||||
#
|
|
||||||
|
|
||||||
import requests, glob, re, os
|
|
||||||
|
|
||||||
# taken from here: http://stackoverflow.com/a/13641746
|
|
||||||
def replace(file, pattern, subst):
|
|
||||||
# Read contents from file as a single string
|
|
||||||
file_handle = open(file, 'r')
|
|
||||||
file_string = file_handle.read()
|
|
||||||
file_handle.close()
|
|
||||||
|
|
||||||
# Use RE package to allow for replacement (also allowing for (multiline) REGEX)
|
|
||||||
file_string = (re.sub(pattern, subst, file_string))
|
|
||||||
|
|
||||||
# Write contents to file.
|
|
||||||
# Using mode 'w' truncates the file.
|
|
||||||
file_handle = open(file, 'w')
|
|
||||||
file_handle.write(file_string)
|
|
||||||
file_handle.close()
|
|
||||||
|
|
||||||
# list of all puml files
|
|
||||||
fileList = glob.glob('*/etc/*.puml')
|
|
||||||
for puml in fileList:
|
|
||||||
pathSplit = puml.split("/")
|
|
||||||
# parent folder
|
|
||||||
parent = pathSplit[0]
|
|
||||||
# individual artifact/project name
|
|
||||||
artifact = pathSplit[2].replace(".urm.puml", "")
|
|
||||||
print "parent: " + parent + "; artifact: " + artifact
|
|
||||||
|
|
||||||
# do a POST to the official plantuml hosting site with a little trick "!includeurl" and raw github content
|
|
||||||
data = {
|
|
||||||
'text': "!includeurl https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/" + puml
|
|
||||||
}
|
|
||||||
r = requests.post('http://plantuml.com/plantuml/uml', data=data)
|
|
||||||
pumlId = r.url.replace("http://plantuml.com/plantuml/uml/", "")
|
|
||||||
|
|
||||||
# the only thing needed to get a png/svg/ascii from the server back
|
|
||||||
print "Puml Server ID: " + pumlId
|
|
||||||
|
|
||||||
# add the id so jekyll/liquid can use it
|
|
||||||
if (parent == artifact):
|
|
||||||
replace("./" + parent + "/README.md", "categories:", "pumlid: {}\\ncategories:".format(pumlId))
|
|
||||||
else:
|
|
||||||
print "I dont want to program this, just add the following lines to the README.md file that corresponds to this puml file '" + puml + "'\npumlid: {}".format(pumlId)
|
|
||||||
|
|
@ -3,7 +3,6 @@ layout: pattern
|
|||||||
title: Abstract Document
|
title: Abstract Document
|
||||||
folder: abstract-document
|
folder: abstract-document
|
||||||
permalink: /patterns/abstract-document/
|
permalink: /patterns/abstract-document/
|
||||||
pumlid: PSjB3eCm34NHhPG599vtDyQn85L-ifzX-p3lxEf8Twj3MXGDQvyJMFubChxpKN767gucSq07iinEjSNDOACVNvoAUZr6MWoe3QVE_WRnxZ0Mf38b-hkIGlurX_MyehS7
|
|
||||||
categories: Structural
|
categories: Structural
|
||||||
tags:
|
tags:
|
||||||
- Java
|
- Java
|
||||||
@ -13,8 +12,6 @@ tags:
|
|||||||
## Intent
|
## Intent
|
||||||
Achieve flexibility of untyped languages and keep the type-safety
|
Achieve flexibility of untyped languages and keep the type-safety
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 15 KiB |
@ -1,58 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
|
||||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
|
||||||
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="249" y="405"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<class id="2" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="250" y="237"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="108" y="75"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="-1" width="-1" x="400" y="76"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</class>
|
|
||||||
<generalization id="5">
|
|
||||||
<end type="SOURCE" refId="4"/>
|
|
||||||
<end type="TARGET" refId="2"/>
|
|
||||||
</generalization>
|
|
||||||
<realization id="6">
|
|
||||||
<end type="SOURCE" refId="2"/>
|
|
||||||
<end type="TARGET" refId="1"/>
|
|
||||||
</realization>
|
|
||||||
<generalization id="7">
|
|
||||||
<end type="SOURCE" refId="3"/>
|
|
||||||
<end type="TARGET" refId="2"/>
|
|
||||||
</generalization>
|
|
||||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</classifier-display>
|
|
||||||
<association-display labels="true" multiplicity="true"/>
|
|
||||||
</class-diagram>
|
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 94 KiB |
@ -1,91 +1,137 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
|
<class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
|
||||||
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||||
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
|
<class id="1" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="abstract-document"
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false"
|
||||||
<position height="-1" width="-1" x="341" y="376"/>
|
corner="BOTTOM_RIGHT">
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<position height="-1" width="-1" x="659" y="286"/>
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="2" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="173" x="41" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="3" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="175" x="254" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<interface id="4" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="81" width="173" x="469" y="194"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
|
||||||
sort-features="false" accessors="true" visibility="true">
|
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
|
||||||
</display>
|
|
||||||
</interface>
|
|
||||||
<class id="5" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
|
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
|
|
||||||
<position height="99" width="173" x="254" y="37"/>
|
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<class id="6" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
|
<interface id="2" language="java" name="com.iluwatar.abstractdocument.Document" project="abstract-document"
|
||||||
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/Document.java" binary="false"
|
||||||
<position height="99" width="173" x="41" y="37"/>
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="562" y="27"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Car.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="348" y="737"/>
|
||||||
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
</display>
|
</display>
|
||||||
</class>
|
</class>
|
||||||
<realization id="7">
|
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="abstract-document"
|
||||||
<end type="SOURCE" refId="5"/>
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/Part.java" binary="false"
|
||||||
<end type="TARGET" refId="2"/>
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="760" y="746"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<interface id="5" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="355" y="297"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="6" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="109" y="297"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="7" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="1008" y="283"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="8" language="java" name="com.iluwatar.abstractdocument.domain.HasType" project="abstract-document"
|
||||||
|
file="/abstract-document/src/main/java/com/iluwatar/abstractdocument/domain/HasType.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="1257" y="277"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<realization id="9">
|
||||||
|
<end type="SOURCE" refId="4"/>
|
||||||
|
<end type="TARGET" refId="8"/>
|
||||||
</realization>
|
</realization>
|
||||||
<realization id="8">
|
<realization id="10">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="7"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="11">
|
||||||
<end type="SOURCE" refId="6"/>
|
<end type="SOURCE" refId="6"/>
|
||||||
<end type="TARGET" refId="2"/>
|
<end type="TARGET" refId="2"/>
|
||||||
</realization>
|
|
||||||
<generalization id="9">
|
|
||||||
<end type="SOURCE" refId="2"/>
|
|
||||||
<end type="TARGET" refId="1"/>
|
|
||||||
</generalization>
|
</generalization>
|
||||||
<realization id="10">
|
<realization id="12">
|
||||||
<end type="SOURCE" refId="5"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="3"/>
|
<end type="TARGET" refId="5"/>
|
||||||
</realization>
|
</realization>
|
||||||
<realization id="11">
|
<realization id="13">
|
||||||
<end type="SOURCE" refId="5"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="4"/>
|
<end type="TARGET" refId="7"/>
|
||||||
</realization>
|
</realization>
|
||||||
<generalization id="12">
|
<generalization id="14">
|
||||||
<end type="SOURCE" refId="3"/>
|
<end type="SOURCE" refId="3"/>
|
||||||
<end type="TARGET" refId="1"/>
|
<end type="TARGET" refId="1"/>
|
||||||
</generalization>
|
</generalization>
|
||||||
<generalization id="13">
|
<realization id="15">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="6"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="16">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<generalization id="17">
|
||||||
|
<end type="SOURCE" refId="7"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<realization id="18">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="5"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="19">
|
||||||
<end type="SOURCE" refId="4"/>
|
<end type="SOURCE" refId="4"/>
|
||||||
<end type="TARGET" refId="1"/>
|
<end type="TARGET" refId="1"/>
|
||||||
</generalization>
|
</generalization>
|
||||||
<realization id="14">
|
<generalization id="20">
|
||||||
<end type="SOURCE" refId="6"/>
|
<end type="SOURCE" refId="5"/>
|
||||||
<end type="TARGET" refId="3"/>
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<realization id="21">
|
||||||
|
<end type="SOURCE" refId="1"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
</realization>
|
</realization>
|
||||||
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
sort-features="false" accessors="true" visibility="true">
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.abstractdocument.domain {
|
|
||||||
class Car {
|
|
||||||
+ Car(properties : Map<String, Object>)
|
|
||||||
}
|
|
||||||
interface HasModel {
|
|
||||||
+ PROPERTY : String {static}
|
|
||||||
+ getModel() : Optional<String>
|
|
||||||
}
|
|
||||||
interface HasParts {
|
|
||||||
+ PROPERTY : String {static}
|
|
||||||
+ getParts() : Stream<Part>
|
|
||||||
}
|
|
||||||
interface HasPrice {
|
|
||||||
+ PROPERTY : String {static}
|
|
||||||
+ getPrice() : Optional<Number>
|
|
||||||
}
|
|
||||||
interface HasType {
|
|
||||||
+ PROPERTY : String {static}
|
|
||||||
+ getType() : Optional<String>
|
|
||||||
}
|
|
||||||
class Part {
|
|
||||||
+ Part(properties : Map<String, Object>)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
package com.iluwatar.abstractdocument {
|
|
||||||
abstract class AbstractDocument {
|
|
||||||
- properties : Map<String, Object>
|
|
||||||
# AbstractDocument(properties : Map<String, Object>)
|
|
||||||
+ children(key : String, constructor : Function<Map<String, Object>, T>) : Stream<T>
|
|
||||||
+ get(key : String) : Object
|
|
||||||
+ put(key : String, value : Object)
|
|
||||||
+ toString() : String
|
|
||||||
}
|
|
||||||
class App {
|
|
||||||
- LOGGER : Logger {static}
|
|
||||||
+ App()
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
}
|
|
||||||
interface Document {
|
|
||||||
+ children(String, Function<Map<String, Object>, T>) : Stream<T> {abstract}
|
|
||||||
+ get(String) : Object {abstract}
|
|
||||||
+ put(String, Object) {abstract}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AbstractDocument ..|> Document
|
|
||||||
Car ..|> HasModel
|
|
||||||
Car ..|> HasPrice
|
|
||||||
Car ..|> HasParts
|
|
||||||
Car --|> AbstractDocument
|
|
||||||
HasModel --|> Document
|
|
||||||
HasParts --|> Document
|
|
||||||
HasPrice --|> Document
|
|
||||||
HasType --|> Document
|
|
||||||
Part ..|> HasType
|
|
||||||
Part ..|> HasModel
|
|
||||||
Part ..|> HasPrice
|
|
||||||
Part --|> AbstractDocument
|
|
||||||
@enduml
|
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,14 +29,14 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>abstract-document</artifactId>
|
<artifactId>abstract-document</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,17 +20,18 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract implementation of Document interface
|
* Abstract implementation of Document interface.
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractDocument implements Document {
|
public abstract class AbstractDocument implements Document {
|
||||||
|
|
||||||
@ -54,17 +55,21 @@ public abstract class AbstractDocument implements Document {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
|
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
|
||||||
Optional<List<Map<String, Object>>> any = Stream.of(get(key)).filter(el -> el != null)
|
return Stream.ofNullable(get(key))
|
||||||
.map(el -> (List<Map<String, Object>>) el).findAny();
|
.filter(Objects::nonNull)
|
||||||
return any.isPresent() ? any.get().stream().map(constructor) : Stream.empty();
|
.map(el -> (List<Map<String, Object>>) el)
|
||||||
|
.findAny()
|
||||||
|
.stream()
|
||||||
|
.flatMap(Collection::stream)
|
||||||
|
.map(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
StringBuilder builder = new StringBuilder();
|
var builder = new StringBuilder();
|
||||||
builder.append(getClass().getName()).append("[");
|
builder.append(getClass().getName()).append("[");
|
||||||
properties.entrySet()
|
properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value)
|
||||||
.forEach(e -> builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]"));
|
.append("]"));
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,67 +20,64 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.domain.Car;
|
import com.iluwatar.abstractdocument.domain.Car;
|
||||||
import com.iluwatar.abstractdocument.domain.HasModel;
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import com.iluwatar.abstractdocument.domain.HasParts;
|
import java.util.List;
|
||||||
import com.iluwatar.abstractdocument.domain.HasPrice;
|
import java.util.Map;
|
||||||
import com.iluwatar.abstractdocument.domain.HasType;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Abstract Document pattern enables handling additional, non-static
|
* The Abstract Document pattern enables handling additional, non-static properties. This pattern
|
||||||
* properties. This pattern uses concept of traits to enable type safety and
|
* uses concept of traits to enable type safety and separate properties of different classes into
|
||||||
* separate properties of different classes into set of interfaces.
|
* set of interfaces.
|
||||||
* <p>
|
*
|
||||||
* <p>
|
* <p>In Abstract Document pattern,({@link AbstractDocument}) fully implements {@link Document})
|
||||||
* In Abstract Document pattern,({@link AbstractDocument}) fully implements
|
* interface. Traits are then defined to enable access to properties in usual, static way.
|
||||||
* {@link Document}) interface. Traits are then defined to enable access to
|
|
||||||
* properties in usual, static way.
|
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the App
|
* Executes the App.
|
||||||
*/
|
*/
|
||||||
public App() {
|
public App() {
|
||||||
LOGGER.info("Constructing parts and car");
|
LOGGER.info("Constructing parts and car");
|
||||||
|
|
||||||
Map<String, Object> carProperties = new HashMap<>();
|
var wheelProperties = Map.of(
|
||||||
carProperties.put(HasModel.PROPERTY, "300SL");
|
Property.TYPE.toString(), "wheel",
|
||||||
carProperties.put(HasPrice.PROPERTY, 10000L);
|
Property.MODEL.toString(), "15C",
|
||||||
|
Property.PRICE.toString(), 100L);
|
||||||
|
|
||||||
Map<String, Object> wheelProperties = new HashMap<>();
|
var doorProperties = Map.of(
|
||||||
wheelProperties.put(HasType.PROPERTY, "wheel");
|
Property.TYPE.toString(), "door",
|
||||||
wheelProperties.put(HasModel.PROPERTY, "15C");
|
Property.MODEL.toString(), "Lambo",
|
||||||
wheelProperties.put(HasPrice.PROPERTY, 100L);
|
Property.PRICE.toString(), 300L);
|
||||||
|
|
||||||
Map<String, Object> doorProperties = new HashMap<>();
|
var carProperties = Map.of(
|
||||||
doorProperties.put(HasType.PROPERTY, "door");
|
Property.MODEL.toString(), "300SL",
|
||||||
doorProperties.put(HasModel.PROPERTY, "Lambo");
|
Property.PRICE.toString(), 10000L,
|
||||||
doorProperties.put(HasPrice.PROPERTY, 300L);
|
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
||||||
|
|
||||||
carProperties.put(HasParts.PROPERTY, Arrays.asList(wheelProperties, doorProperties));
|
var car = new Car(carProperties);
|
||||||
|
|
||||||
Car car = new Car(carProperties);
|
|
||||||
|
|
||||||
LOGGER.info("Here is our car:");
|
LOGGER.info("Here is our car:");
|
||||||
LOGGER.info("-> model: {}", car.getModel().get());
|
LOGGER.info("-> model: {}", car.getModel().orElseThrow());
|
||||||
LOGGER.info("-> price: {}", car.getPrice().get());
|
LOGGER.info("-> price: {}", car.getPrice().orElseThrow());
|
||||||
LOGGER.info("-> parts: ");
|
LOGGER.info("-> parts: ");
|
||||||
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
|
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}",
|
||||||
|
p.getType().orElse(null),
|
||||||
|
p.getModel().orElse(null),
|
||||||
|
p.getPrice().orElse(null))
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -27,12 +28,12 @@ import java.util.function.Function;
|
|||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Document interface
|
* Document interface.
|
||||||
*/
|
*/
|
||||||
public interface Document {
|
public interface Document {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Puts the value related to the key
|
* Puts the value related to the key.
|
||||||
*
|
*
|
||||||
* @param key element key
|
* @param key element key
|
||||||
* @param value element value
|
* @param value element value
|
||||||
@ -41,7 +42,7 @@ public interface Document {
|
|||||||
Void put(String key, Object value);
|
Void put(String key, Object value);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the value for the key
|
* Gets the value for the key.
|
||||||
*
|
*
|
||||||
* @param key element key
|
* @param key element key
|
||||||
* @return value or null
|
* @return value or null
|
||||||
@ -49,7 +50,7 @@ public interface Document {
|
|||||||
Object get(String key);
|
Object get(String key);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the stream of child documents
|
* Gets the stream of child documents.
|
||||||
*
|
*
|
||||||
* @param key element key
|
* @param key element key
|
||||||
* @param constructor constructor of child class
|
* @param constructor constructor of child class
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,14 +20,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Car entity
|
* Car entity.
|
||||||
*/
|
*/
|
||||||
public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts {
|
public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts {
|
||||||
|
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,20 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractdocument.Document;
|
||||||
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.Document;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasModel trait for static access to 'model' property
|
* HasModel trait for static access to 'model' property.
|
||||||
*/
|
*/
|
||||||
public interface HasModel extends Document {
|
public interface HasModel extends Document {
|
||||||
|
|
||||||
String PROPERTY = "model";
|
|
||||||
|
|
||||||
default Optional<String> getModel() {
|
default Optional<String> getModel() {
|
||||||
return Optional.ofNullable((String) get(PROPERTY));
|
return Optional.ofNullable((String) get(Property.MODEL.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,21 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractdocument.Document;
|
||||||
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.Document;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasParts trait for static access to 'parts' property
|
* HasParts trait for static access to 'parts' property.
|
||||||
*/
|
*/
|
||||||
public interface HasParts extends Document {
|
public interface HasParts extends Document {
|
||||||
|
|
||||||
String PROPERTY = "parts";
|
|
||||||
|
|
||||||
default Stream<Part> getParts() {
|
default Stream<Part> getParts() {
|
||||||
return children(PROPERTY, Part::new);
|
return children(Property.PARTS.toString(), Part::new);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,21 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractdocument.Document;
|
||||||
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.Document;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasPrice trait for static access to 'price' property
|
* HasPrice trait for static access to 'price' property.
|
||||||
*/
|
*/
|
||||||
public interface HasPrice extends Document {
|
public interface HasPrice extends Document {
|
||||||
|
|
||||||
String PROPERTY = "price";
|
|
||||||
|
|
||||||
default Optional<Number> getPrice() {
|
default Optional<Number> getPrice() {
|
||||||
return Optional.ofNullable((Number) get(PROPERTY));
|
return Optional.ofNullable((Number) get(Property.PRICE.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,21 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.Document;
|
import com.iluwatar.abstractdocument.Document;
|
||||||
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasType trait for static access to 'type' property
|
* HasType trait for static access to 'type' property.
|
||||||
*/
|
*/
|
||||||
public interface HasType extends Document {
|
public interface HasType extends Document {
|
||||||
|
|
||||||
String PROPERTY = "type";
|
|
||||||
|
|
||||||
default Optional<String> getType() {
|
default Optional<String> getType() {
|
||||||
return Optional.ofNullable((String) get(PROPERTY));
|
return Optional.ofNullable((String) get(Property.TYPE.toString()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,14 +20,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument.domain;
|
package com.iluwatar.abstractdocument.domain;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part entity
|
* Part entity.
|
||||||
*/
|
*/
|
||||||
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {
|
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {
|
||||||
|
|
||||||
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.abstractdocument.domain.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enum To Describe Property type.
|
||||||
|
*/
|
||||||
|
public enum Property {
|
||||||
|
|
||||||
|
PARTS, TYPE, PRICE, MODEL
|
||||||
|
}
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,18 +20,17 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Stream;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertEquals;
|
|
||||||
import static junit.framework.TestCase.assertNotNull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AbstractDocument test class
|
* AbstractDocument test class
|
||||||
@ -58,31 +57,28 @@ public class AbstractDocumentTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldRetrieveChildren() {
|
public void shouldRetrieveChildren() {
|
||||||
Map<String, Object> child1 = new HashMap<>();
|
var children = List.of(Map.of(), Map.of());
|
||||||
Map<String, Object> child2 = new HashMap<>();
|
|
||||||
List<Map<String, Object>> children = Arrays.asList(child1, child2);
|
|
||||||
|
|
||||||
document.put(KEY, children);
|
document.put(KEY, children);
|
||||||
|
|
||||||
Stream<DocumentImplementation> childrenStream = document.children(KEY, DocumentImplementation::new);
|
var childrenStream = document.children(KEY, DocumentImplementation::new);
|
||||||
assertNotNull(children);
|
assertNotNull(children);
|
||||||
assertEquals(2, childrenStream.count());
|
assertEquals(2, childrenStream.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldRetrieveEmptyStreamForNonExistingChildren() {
|
public void shouldRetrieveEmptyStreamForNonExistingChildren() {
|
||||||
Stream<DocumentImplementation> children = document.children(KEY, DocumentImplementation::new);
|
var children = document.children(KEY, DocumentImplementation::new);
|
||||||
assertNotNull(children);
|
assertNotNull(children);
|
||||||
assertEquals(0, children.count());
|
assertEquals(0, children.count());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldIncludePropsInToString() {
|
public void shouldIncludePropsInToString() {
|
||||||
Map<String, Object> props = new HashMap<>();
|
var props = Map.of(KEY, (Object) VALUE);
|
||||||
props.put(KEY, VALUE);
|
var document = new DocumentImplementation(props);
|
||||||
DocumentImplementation document = new DocumentImplementation(props);
|
assertTrue(document.toString().contains(KEY));
|
||||||
assertNotNull(document.toString().contains(KEY));
|
assertTrue(document.toString().contains(VALUE));
|
||||||
assertNotNull(document.toString().contains(VALUE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,9 +20,10 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple App test
|
* Simple App test
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,17 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractdocument;
|
package com.iluwatar.abstractdocument;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
import com.iluwatar.abstractdocument.domain.Car;
|
import com.iluwatar.abstractdocument.domain.Car;
|
||||||
import com.iluwatar.abstractdocument.domain.HasModel;
|
|
||||||
import com.iluwatar.abstractdocument.domain.HasParts;
|
|
||||||
import com.iluwatar.abstractdocument.domain.HasPrice;
|
|
||||||
import com.iluwatar.abstractdocument.domain.HasType;
|
|
||||||
import com.iluwatar.abstractdocument.domain.Part;
|
import com.iluwatar.abstractdocument.domain.Part;
|
||||||
import org.junit.Test;
|
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
import static junit.framework.TestCase.assertEquals;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for Part and Car
|
* Test for Part and Car
|
||||||
@ -50,27 +46,27 @@ public class DomainTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConstructPart() {
|
public void shouldConstructPart() {
|
||||||
Map<String, Object> partProperties = new HashMap<>();
|
var partProperties = Map.of(
|
||||||
partProperties.put(HasType.PROPERTY, TEST_PART_TYPE);
|
Property.TYPE.toString(), TEST_PART_TYPE,
|
||||||
partProperties.put(HasModel.PROPERTY, TEST_PART_MODEL);
|
Property.MODEL.toString(), TEST_PART_MODEL,
|
||||||
partProperties.put(HasPrice.PROPERTY, TEST_PART_PRICE);
|
Property.PRICE.toString(), (Object) TEST_PART_PRICE
|
||||||
Part part = new Part(partProperties);
|
);
|
||||||
|
var part = new Part(partProperties);
|
||||||
assertEquals(TEST_PART_TYPE, part.getType().get());
|
assertEquals(TEST_PART_TYPE, part.getType().orElseThrow());
|
||||||
assertEquals(TEST_PART_MODEL, part.getModel().get());
|
assertEquals(TEST_PART_MODEL, part.getModel().orElseThrow());
|
||||||
assertEquals(TEST_PART_PRICE, part.getPrice().get());
|
assertEquals(TEST_PART_PRICE, part.getPrice().orElseThrow());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldConstructCar() {
|
public void shouldConstructCar() {
|
||||||
Map<String, Object> carProperties = new HashMap<>();
|
var carProperties = Map.of(
|
||||||
carProperties.put(HasModel.PROPERTY, TEST_CAR_MODEL);
|
Property.MODEL.toString(), TEST_CAR_MODEL,
|
||||||
carProperties.put(HasPrice.PROPERTY, TEST_CAR_PRICE);
|
Property.PRICE.toString(), TEST_CAR_PRICE,
|
||||||
carProperties.put(HasParts.PROPERTY, Arrays.asList(new HashMap<>(), new HashMap<>()));
|
Property.PARTS.toString(), List.of(Map.of(), Map.of())
|
||||||
Car car = new Car(carProperties);
|
);
|
||||||
|
var car = new Car(carProperties);
|
||||||
assertEquals(TEST_CAR_MODEL, car.getModel().get());
|
assertEquals(TEST_CAR_MODEL, car.getModel().orElseThrow());
|
||||||
assertEquals(TEST_CAR_PRICE, car.getPrice().get());
|
assertEquals(TEST_CAR_PRICE, car.getPrice().orElseThrow());
|
||||||
assertEquals(2, car.getParts().count());
|
assertEquals(2, car.getParts().count());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ layout: pattern
|
|||||||
title: Abstract Factory
|
title: Abstract Factory
|
||||||
folder: abstract-factory
|
folder: abstract-factory
|
||||||
permalink: /patterns/abstract-factory/
|
permalink: /patterns/abstract-factory/
|
||||||
pumlid: PSZB3OD034NHLa81Czwd6sCC39gVxEUWT1_ssLmTtQLqgR5fM7sTmFGtaV6TZu8prd0r6HtQaMKqAZLk1XjT_E6qgPUZfyc0MdTgx0-8LuUn8ErFXdr98NypXxKyezKV
|
|
||||||
categories: Creational
|
categories: Creational
|
||||||
tags:
|
tags:
|
||||||
- Java
|
- Java
|
||||||
@ -35,7 +34,7 @@ Wikipedia says
|
|||||||
|
|
||||||
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the kingdom
|
Translating the kingdom example above. First of all we have some interfaces and implementation for the objects in the kingdom
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface Castle {
|
public interface Castle {
|
||||||
String getDescription();
|
String getDescription();
|
||||||
}
|
}
|
||||||
@ -75,7 +74,7 @@ public class ElfArmy implements Army {
|
|||||||
|
|
||||||
Then we have the abstraction and implementations for the kingdom factory
|
Then we have the abstraction and implementations for the kingdom factory
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface KingdomFactory {
|
public interface KingdomFactory {
|
||||||
Castle createCastle();
|
Castle createCastle();
|
||||||
King createKing();
|
King createKing();
|
||||||
@ -109,17 +108,56 @@ public class OrcKingdomFactory implements KingdomFactory {
|
|||||||
|
|
||||||
Now we have our abstract factory that lets us make family of related objects i.e. Elven kingdom factory creates Elven castle, king and army etc.
|
Now we have our abstract factory that lets us make family of related objects i.e. Elven kingdom factory creates Elven castle, king and army etc.
|
||||||
|
|
||||||
```
|
```java
|
||||||
KingdomFactory factory = new ElfKingdomFactory();
|
var factory = new ElfKingdomFactory();
|
||||||
Castle castle = factory.createCastle();
|
var castle = factory.createCastle();
|
||||||
King king = factory.createKing();
|
var king = factory.createKing();
|
||||||
Army army = factory.createArmy();
|
var army = factory.createArmy();
|
||||||
|
|
||||||
castle.getDescription(); // Output: This is the Elven castle!
|
castle.getDescription(); // Output: This is the Elven castle!
|
||||||
king.getDescription(); // Output: This is the Elven king!
|
king.getDescription(); // Output: This is the Elven king!
|
||||||
army.getDescription(); // Output: This is the Elven Army!
|
army.getDescription(); // Output: This is the Elven Army!
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Now, we can design a factory for our different kingdom factories. In this example, we created FactoryMaker, responsible for returning an instance of either ElfKingdomFactory or OrcKingdomFactory.
|
||||||
|
The client can use FactoryMaker to create the desired concrete factory which, in turn, will produce different concrete objects (Army, King, Castle).
|
||||||
|
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public static class FactoryMaker {
|
||||||
|
|
||||||
|
public enum KingdomType {
|
||||||
|
ELF, ORC
|
||||||
|
}
|
||||||
|
|
||||||
|
public static KingdomFactory makeFactory(KingdomType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ELF:
|
||||||
|
return new ElfKingdomFactory();
|
||||||
|
case ORC:
|
||||||
|
return new OrcKingdomFactory();
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("KingdomType not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
var app = new App();
|
||||||
|
|
||||||
|
LOGGER.info("Elf Kingdom");
|
||||||
|
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
|
||||||
|
LOGGER.info(app.getArmy().getDescription());
|
||||||
|
LOGGER.info(app.getCastle().getDescription());
|
||||||
|
LOGGER.info(app.getKing().getDescription());
|
||||||
|
|
||||||
|
LOGGER.info("Orc Kingdom");
|
||||||
|
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
|
||||||
|
-- similar use of the orc factory
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Applicability
|
## Applicability
|
||||||
Use the Abstract Factory pattern when
|
Use the Abstract Factory pattern when
|
||||||
|
|
||||||
@ -131,15 +169,25 @@ Use the Abstract Factory pattern when
|
|||||||
* you need a run-time value to construct a particular dependency
|
* you need a run-time value to construct a particular dependency
|
||||||
* you want to decide which product to call from a family at runtime.
|
* you want to decide which product to call from a family at runtime.
|
||||||
* you need to supply one or more parameters only known at run-time before you can resolve a dependency.
|
* you need to supply one or more parameters only known at run-time before you can resolve a dependency.
|
||||||
|
* when you need consistency among products
|
||||||
|
* you don’t want to change existing code when adding new products or families of products to the program.
|
||||||
|
|
||||||
## Use Cases:
|
## Use Cases:
|
||||||
|
|
||||||
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime.
|
* Selecting to call the appropriate implementation of FileSystemAcmeService or DatabaseAcmeService or NetworkAcmeService at runtime.
|
||||||
* Unit test case writing becomes much easier
|
* Unit test case writing becomes much easier
|
||||||
|
* UI tools for different OS
|
||||||
|
|
||||||
## Consequences:
|
## Consequences:
|
||||||
|
|
||||||
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
|
* Dependency injection in java hides the service class dependencies that can lead to runtime errors that would have been caught at compile time.
|
||||||
|
* While the pattern is great when creating predefined objects, adding the new ones might be challenging.
|
||||||
|
* The code may become more complicated than it should be, since a lot of new interfaces and classes are introduced along with the pattern.
|
||||||
|
|
||||||
|
|
||||||
|
## Tutorial
|
||||||
|
* [Abstract Factory Pattern Tutorial](https://www.journaldev.com/1418/abstract-factory-design-pattern-in-java)
|
||||||
|
|
||||||
|
|
||||||
## Real world examples
|
## Real world examples
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,13 +29,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>abstract-factory</artifactId>
|
<artifactId>abstract-factory</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,25 +20,26 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
|
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that
|
||||||
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
|
* have a common theme without specifying their concrete classes. In normal usage, the client
|
||||||
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of
|
* software creates a concrete implementation of the abstract factory and then uses the generic
|
||||||
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part
|
* interface of the factory to create the concrete objects that are part of the theme. The client
|
||||||
* of the theme. The client does not know (or care) which concrete objects it gets from each of these internal
|
* does not know (or care) which concrete objects it gets from each of these internal factories,
|
||||||
* factories, since it uses only the generic interfaces of their products. This pattern separates the details of
|
* since it uses only the generic interfaces of their products. This pattern separates the details
|
||||||
* implementation of a set of objects from their general usage and relies on object composition, as object creation is
|
* of implementation of a set of objects from their general usage and relies on object composition,
|
||||||
* implemented in methods exposed in the factory interface.
|
* as object creation is implemented in methods exposed in the factory interface.
|
||||||
* <p>
|
*
|
||||||
* The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and its implementations (
|
* <p>The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory})
|
||||||
* {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both concrete implementations to create a
|
* and its implementations ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
|
||||||
* king, a castle and an army.
|
* both concrete implementations to create a king, a castle and an army.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
@ -49,7 +50,7 @@ public class App {
|
|||||||
private Army army;
|
private Army army;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates kingdom
|
* Creates kingdom.
|
||||||
*/
|
*/
|
||||||
public void createKingdom(final KingdomFactory factory) {
|
public void createKingdom(final KingdomFactory factory) {
|
||||||
setKing(factory.createKing());
|
setKing(factory.createKing());
|
||||||
@ -68,7 +69,7 @@ public class App {
|
|||||||
private void setKing(final King king) {
|
private void setKing(final King king) {
|
||||||
this.king = king;
|
this.king = king;
|
||||||
}
|
}
|
||||||
|
|
||||||
Castle getCastle(final KingdomFactory factory) {
|
Castle getCastle(final KingdomFactory factory) {
|
||||||
return factory.createCastle();
|
return factory.createCastle();
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ public class App {
|
|||||||
private void setCastle(final Castle castle) {
|
private void setCastle(final Castle castle) {
|
||||||
this.castle = castle;
|
this.castle = castle;
|
||||||
}
|
}
|
||||||
|
|
||||||
Army getArmy(final KingdomFactory factory) {
|
Army getArmy(final KingdomFactory factory) {
|
||||||
return factory.createArmy();
|
return factory.createArmy();
|
||||||
}
|
}
|
||||||
@ -92,29 +93,53 @@ public class App {
|
|||||||
private void setArmy(final Army army) {
|
private void setArmy(final Army army) {
|
||||||
this.army = army;
|
this.army = army;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* The factory of kingdom factories.
|
||||||
*
|
*/
|
||||||
* @param args
|
public static class FactoryMaker {
|
||||||
* command line args
|
|
||||||
|
/**
|
||||||
|
* Enumeration for the different types of Kingdoms.
|
||||||
|
*/
|
||||||
|
public enum KingdomType {
|
||||||
|
ELF, ORC
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The factory method to create KingdomFactory concrete objects.
|
||||||
|
*/
|
||||||
|
public static KingdomFactory makeFactory(KingdomType type) {
|
||||||
|
switch (type) {
|
||||||
|
case ELF:
|
||||||
|
return new ElfKingdomFactory();
|
||||||
|
case ORC:
|
||||||
|
return new OrcKingdomFactory();
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException("KingdomType not supported.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Program entry point.
|
||||||
|
*
|
||||||
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
App app = new App();
|
var app = new App();
|
||||||
|
|
||||||
LOGGER.info("Elf Kingdom");
|
LOGGER.info("Elf Kingdom");
|
||||||
app.createKingdom(new ElfKingdomFactory());
|
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ELF));
|
||||||
LOGGER.info(app.getArmy().getDescription());
|
LOGGER.info(app.getArmy().getDescription());
|
||||||
LOGGER.info(app.getCastle().getDescription());
|
LOGGER.info(app.getCastle().getDescription());
|
||||||
LOGGER.info(app.getKing().getDescription());
|
LOGGER.info(app.getKing().getDescription());
|
||||||
|
|
||||||
LOGGER.info("Orc Kingdom");
|
LOGGER.info("Orc Kingdom");
|
||||||
app.createKingdom(new OrcKingdomFactory());
|
app.createKingdom(FactoryMaker.makeFactory(KingdomType.ORC));
|
||||||
LOGGER.info(app.getArmy().getDescription());
|
LOGGER.info(app.getArmy().getDescription());
|
||||||
LOGGER.info(app.getCastle().getDescription());
|
LOGGER.info(app.getCastle().getDescription());
|
||||||
LOGGER.info(app.getKing().getDescription());
|
LOGGER.info(app.getKing().getDescription());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Army interface.
|
||||||
* Army interface
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Army {
|
public interface Army {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Castle interface.
|
||||||
* Castle interface
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface Castle {
|
public interface Castle {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* ElfArmy.
|
||||||
* ElfArmy
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ElfArmy implements Army {
|
public class ElfArmy implements Army {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* ElfCastle.
|
||||||
* ElfCastle
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ElfCastle implements Castle {
|
public class ElfCastle implements Castle {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* ElfKing.
|
||||||
* ElfKing
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ElfKing implements King {
|
public class ElfKing implements King {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,23 +20,25 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* ElfKingdomFactory concrete factory.
|
* ElfKingdomFactory concrete factory.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ElfKingdomFactory implements KingdomFactory {
|
public class ElfKingdomFactory implements KingdomFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Castle createCastle() {
|
public Castle createCastle() {
|
||||||
return new ElfCastle();
|
return new ElfCastle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public King createKing() {
|
public King createKing() {
|
||||||
return new ElfKing();
|
return new ElfKing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Army createArmy() {
|
public Army createArmy() {
|
||||||
return new ElfArmy();
|
return new ElfArmy();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* King interface.
|
||||||
* King interface
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface King {
|
public interface King {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* KingdomFactory factory interface.
|
* KingdomFactory factory interface.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface KingdomFactory {
|
public interface KingdomFactory {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* OrcArmy.
|
||||||
* OrcArmy
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class OrcArmy implements Army {
|
public class OrcArmy implements Army {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* OrcCastle.
|
||||||
* OrcCastle
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class OrcCastle implements Castle {
|
public class OrcCastle implements Castle {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* OrcKing.
|
||||||
* OrcKing
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class OrcKing implements King {
|
public class OrcKing implements King {
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,23 +20,25 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* OrcKingdomFactory concrete factory.
|
* OrcKingdomFactory concrete factory.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class OrcKingdomFactory implements KingdomFactory {
|
public class OrcKingdomFactory implements KingdomFactory {
|
||||||
|
|
||||||
|
@Override
|
||||||
public Castle createCastle() {
|
public Castle createCastle() {
|
||||||
return new OrcCastle();
|
return new OrcCastle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public King createKing() {
|
public King createKing() {
|
||||||
return new OrcKing();
|
return new OrcKing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Army createArmy() {
|
public Army createArmy() {
|
||||||
return new OrcArmy();
|
return new OrcArmy();
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,16 +20,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
import org.junit.Before;
|
import com.iluwatar.abstractfactory.App.FactoryMaker;
|
||||||
import org.junit.Test;
|
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for abstract factory
|
* Test for abstract factory.
|
||||||
*/
|
*/
|
||||||
public class AbstractFactoryTest {
|
public class AbstractFactoryTest {
|
||||||
|
|
||||||
@ -37,38 +40,38 @@ public class AbstractFactoryTest {
|
|||||||
private KingdomFactory elfFactory;
|
private KingdomFactory elfFactory;
|
||||||
private KingdomFactory orcFactory;
|
private KingdomFactory orcFactory;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
elfFactory = new ElfKingdomFactory();
|
elfFactory = FactoryMaker.makeFactory(KingdomType.ELF);
|
||||||
orcFactory = new OrcKingdomFactory();
|
orcFactory = FactoryMaker.makeFactory(KingdomType.ORC);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void king() {
|
public void king() {
|
||||||
final King elfKing = app.getKing(elfFactory);
|
final var elfKing = app.getKing(elfFactory);
|
||||||
assertTrue(elfKing instanceof ElfKing);
|
assertTrue(elfKing instanceof ElfKing);
|
||||||
assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription());
|
assertEquals(ElfKing.DESCRIPTION, elfKing.getDescription());
|
||||||
final King orcKing = app.getKing(orcFactory);
|
final var orcKing = app.getKing(orcFactory);
|
||||||
assertTrue(orcKing instanceof OrcKing);
|
assertTrue(orcKing instanceof OrcKing);
|
||||||
assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription());
|
assertEquals(OrcKing.DESCRIPTION, orcKing.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void castle() {
|
public void castle() {
|
||||||
final Castle elfCastle = app.getCastle(elfFactory);
|
final var elfCastle = app.getCastle(elfFactory);
|
||||||
assertTrue(elfCastle instanceof ElfCastle);
|
assertTrue(elfCastle instanceof ElfCastle);
|
||||||
assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription());
|
assertEquals(ElfCastle.DESCRIPTION, elfCastle.getDescription());
|
||||||
final Castle orcCastle = app.getCastle(orcFactory);
|
final var orcCastle = app.getCastle(orcFactory);
|
||||||
assertTrue(orcCastle instanceof OrcCastle);
|
assertTrue(orcCastle instanceof OrcCastle);
|
||||||
assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription());
|
assertEquals(OrcCastle.DESCRIPTION, orcCastle.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void army() {
|
public void army() {
|
||||||
final Army elfArmy = app.getArmy(elfFactory);
|
final var elfArmy = app.getArmy(elfFactory);
|
||||||
assertTrue(elfArmy instanceof ElfArmy);
|
assertTrue(elfArmy instanceof ElfArmy);
|
||||||
assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription());
|
assertEquals(ElfArmy.DESCRIPTION, elfArmy.getDescription());
|
||||||
final Army orcArmy = app.getArmy(orcFactory);
|
final var orcArmy = app.getArmy(orcFactory);
|
||||||
assertTrue(orcArmy instanceof OrcArmy);
|
assertTrue(orcArmy instanceof OrcArmy);
|
||||||
assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription());
|
assertEquals(OrcArmy.DESCRIPTION, orcArmy.getDescription());
|
||||||
}
|
}
|
||||||
@ -76,9 +79,9 @@ public class AbstractFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void createElfKingdom() {
|
public void createElfKingdom() {
|
||||||
app.createKingdom(elfFactory);
|
app.createKingdom(elfFactory);
|
||||||
final King king = app.getKing();
|
final var king = app.getKing();
|
||||||
final Castle castle = app.getCastle();
|
final var castle = app.getCastle();
|
||||||
final Army army = app.getArmy();
|
final var army = app.getArmy();
|
||||||
assertTrue(king instanceof ElfKing);
|
assertTrue(king instanceof ElfKing);
|
||||||
assertEquals(ElfKing.DESCRIPTION, king.getDescription());
|
assertEquals(ElfKing.DESCRIPTION, king.getDescription());
|
||||||
assertTrue(castle instanceof ElfCastle);
|
assertTrue(castle instanceof ElfCastle);
|
||||||
@ -90,9 +93,9 @@ public class AbstractFactoryTest {
|
|||||||
@Test
|
@Test
|
||||||
public void createOrcKingdom() {
|
public void createOrcKingdom() {
|
||||||
app.createKingdom(orcFactory);
|
app.createKingdom(orcFactory);
|
||||||
final King king = app.getKing();
|
final var king = app.getKing();
|
||||||
final Castle castle = app.getCastle();
|
final var castle = app.getCastle();
|
||||||
final Army army = app.getArmy();
|
final var army = app.getArmy();
|
||||||
assertTrue(king instanceof OrcKing);
|
assertTrue(king instanceof OrcKing);
|
||||||
assertEquals(OrcKing.DESCRIPTION, king.getDescription());
|
assertEquals(OrcKing.DESCRIPTION, king.getDescription());
|
||||||
assertTrue(castle instanceof OrcCastle);
|
assertTrue(castle instanceof OrcCastle);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,19 +20,17 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.abstractfactory;
|
package com.iluwatar.abstractfactory;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that Abstract Factory example runs without errors.
|
* Tests that Abstract Factory example runs without errors.
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() {
|
||||||
String[] args = {};
|
App.main(new String[]{});
|
||||||
App.main(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
39
acyclic-visitor/README.md
Normal file
39
acyclic-visitor/README.md
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
---
|
||||||
|
layout: pattern
|
||||||
|
title: Acyclic Visitor
|
||||||
|
folder: acyclic-visitor
|
||||||
|
permalink: /patterns/acyclic-visitor/
|
||||||
|
categories: Behavioral
|
||||||
|
tags:
|
||||||
|
- Java
|
||||||
|
- Difficulty-Intermediate
|
||||||
|
---
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Intent
|
||||||
|
Allow new functions to be added to existing class hierarchies without affecting those hierarchies, and without creating the troublesome dependency cycles that are inherent to the GOF VISITOR Pattern.
|
||||||
|
|
||||||
|
## Applicability
|
||||||
|
This pattern can be used:
|
||||||
|
* When you need to add a new function to an existing hierarchy without the need to alter or affect that hierarchy.
|
||||||
|
* When there are functions that operate upon a hierarchy, but which do not belong in the hierarchy itself. e.g. the ConfigureForDOS / ConfigureForUnix / ConfigureForX issue.
|
||||||
|
* When you need to perform very different operations on an object depending upon its type.
|
||||||
|
* When the visited class hierarchy will be frequently extended with new derivatives of the Element class.
|
||||||
|
* When the recompilation, relinking, retesting or redistribution of the derivatives of Element is very expensive.
|
||||||
|
|
||||||
|
## Consequences
|
||||||
|
The good:
|
||||||
|
* No dependency cycles between class hierarchies.
|
||||||
|
* No need to recompile all the visitors if a new one is added.
|
||||||
|
* Does not cause compilation failure in existing visitors if class hierarchy has a new member.
|
||||||
|
|
||||||
|
The bad:
|
||||||
|
* Violates the principle of least surprise or Liskov's Substitution principle by showing that it can accept all visitors but actually only being interested in particular visitors.
|
||||||
|
* Parallel hierarchy of visitors has to be created for all members in visitable class hierarchy.
|
||||||
|
|
||||||
|
## Related patterns
|
||||||
|
* [Visitor Pattern](../visitor/)
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
* [Acyclic Visitor](http://condor.depaul.edu/dmumaugh/OOT/Design-Principles/acv.pdf)
|
115
acyclic-visitor/etc/Acyclic Visitor.ucls
Normal file
115
acyclic-visitor/etc/Acyclic Visitor.ucls
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<class-diagram version="1.2.2" icons="true" always-add-relationships="false" generalizations="true" realizations="true"
|
||||||
|
associations="true" dependencies="false" nesting-relationships="true" router="FAN">
|
||||||
|
<interface id="1" language="java" name="com.iluwatar.acyclicvisitor.ModemVisitor" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ModemVisitor.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="860" y="67"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<class id="2" language="java" name="com.iluwatar.acyclicvisitor.Modem" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Modem.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="327" y="77"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<class id="3" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForUnixVisitor" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForUnixVisitor.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="124" width="196" x="647" y="225"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<class id="4" language="java" name="com.iluwatar.acyclicvisitor.Zoom" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Zoom.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="203" y="305"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<interface id="5" language="java" name="com.iluwatar.acyclicvisitor.HayesVisitor" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/HayesVisitor.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="1019" y="468"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<interface id="6" language="java" name="com.iluwatar.acyclicvisitor.ZoomVisitor" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ZoomVisitor.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="758" y="467"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</interface>
|
||||||
|
<class id="7" language="java" name="com.iluwatar.acyclicvisitor.Hayes" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/Hayes.java" binary="false" corner="BOTTOM_RIGHT">
|
||||||
|
<position height="-1" width="-1" x="479" y="307"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<class id="8" language="java" name="com.iluwatar.acyclicvisitor.ConfigureForDosVisitor" project="acyclic-visitor"
|
||||||
|
file="/acyclic-visitor/src/main/java/com/iluwatar/acyclicvisitor/ConfigureForDosVisitor.java" binary="false"
|
||||||
|
corner="BOTTOM_RIGHT">
|
||||||
|
<position height="142" width="192" x="883" y="225"/>
|
||||||
|
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</display>
|
||||||
|
</class>
|
||||||
|
<generalization id="9">
|
||||||
|
<end type="SOURCE" refId="7"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<realization id="10">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="6"/>
|
||||||
|
</realization>
|
||||||
|
<realization id="11">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="5"/>
|
||||||
|
</realization>
|
||||||
|
<realization id="12">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="6"/>
|
||||||
|
</realization>
|
||||||
|
<realization id="13">
|
||||||
|
<end type="SOURCE" refId="3"/>
|
||||||
|
<end type="TARGET" refId="1"/>
|
||||||
|
</realization>
|
||||||
|
<realization id="14">
|
||||||
|
<end type="SOURCE" refId="8"/>
|
||||||
|
<end type="TARGET" refId="1"/>
|
||||||
|
</realization>
|
||||||
|
<generalization id="15">
|
||||||
|
<end type="SOURCE" refId="4"/>
|
||||||
|
<end type="TARGET" refId="2"/>
|
||||||
|
</generalization>
|
||||||
|
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
|
||||||
|
sort-features="false" accessors="true" visibility="true">
|
||||||
|
<attributes public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
<operations public="true" package="true" protected="true" private="true" static="true"/>
|
||||||
|
</classifier-display>
|
||||||
|
<association-display labels="true" multiplicity="true"/>
|
||||||
|
</class-diagram>
|
BIN
acyclic-visitor/etc/acyclic-visitor.png
Normal file
BIN
acyclic-visitor/etc/acyclic-visitor.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 26 KiB |
71
acyclic-visitor/pom.xml
Normal file
71
acyclic-visitor/pom.xml
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<!--
|
||||||
|
|
||||||
|
The MIT License
|
||||||
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>com.iluwatar</groupId>
|
||||||
|
<artifactId>java-design-patterns</artifactId>
|
||||||
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>acyclic-visitor</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.assertj</groupId>
|
||||||
|
<artifactId>assertj-core</artifactId>
|
||||||
|
<version>3.9.1</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<!-- https://mvnrepository.com/artifact/uk.org.lidalia/slf4j-test -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>uk.org.lidalia</groupId>
|
||||||
|
<artifactId>slf4j-test</artifactId>
|
||||||
|
<version>1.0.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-all</artifactId>
|
||||||
|
<version>1.9.5</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All ModemVisitor interface extends all visitor interfaces. This interface provides ease of use
|
||||||
|
* when a visitor needs to visit all modem types.
|
||||||
|
*/
|
||||||
|
public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Acyclic Visitor pattern allows new functions to be added to existing class hierarchies
|
||||||
|
* without affecting those hierarchies, and without creating the dependency cycles that are inherent
|
||||||
|
* to the GoF Visitor pattern, by making the Visitor base class degenerate
|
||||||
|
*
|
||||||
|
* <p>In this example the visitor base class is {@link ModemVisitor}. The base class of the visited
|
||||||
|
* hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom} each one having
|
||||||
|
* its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor} respectively. {@link
|
||||||
|
* ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor} implement each derivative's visit
|
||||||
|
* method only if it is required
|
||||||
|
*/
|
||||||
|
public class App {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Program's entry point.
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
var conUnix = new ConfigureForUnixVisitor();
|
||||||
|
var conDos = new ConfigureForDosVisitor();
|
||||||
|
|
||||||
|
var zoom = new Zoom();
|
||||||
|
var hayes = new Hayes();
|
||||||
|
|
||||||
|
hayes.accept(conDos); // Hayes modem with Dos configurator
|
||||||
|
zoom.accept(conDos); // Zoom modem with Dos configurator
|
||||||
|
hayes.accept(conUnix); // Hayes modem with Unix configurator
|
||||||
|
zoom.accept(conUnix); // Zoom modem with Unix configurator
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos
|
||||||
|
* manufacturer.
|
||||||
|
*/
|
||||||
|
public class ConfigureForDosVisitor implements AllModemVisitor {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Hayes hayes) {
|
||||||
|
LOGGER.info(hayes + " used with Dos configurator.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Zoom zoom) {
|
||||||
|
LOGGER.info(zoom + " used with Dos configurator.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigureForUnixVisitor class implements zoom's visit method for Unix manufacturer, unlike
|
||||||
|
* traditional visitor pattern, this class may selectively implement visit for other modems.
|
||||||
|
*/
|
||||||
|
public class ConfigureForUnixVisitor implements ZoomVisitor {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(Zoom zoom) {
|
||||||
|
LOGGER.info(zoom + " used with Unix configurator.");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hayes class implements its accept method.
|
||||||
|
*/
|
||||||
|
public class Hayes extends Modem {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts all visitors but honors only HayesVisitor.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void accept(ModemVisitor modemVisitor) {
|
||||||
|
if (modemVisitor instanceof HayesVisitor) {
|
||||||
|
((HayesVisitor) modemVisitor).visit(this);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Only HayesVisitor is allowed to visit Hayes modem");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hayes' modem's toString method.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Hayes modem";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* HayesVisitor interface.
|
||||||
|
*/
|
||||||
|
public interface HayesVisitor extends ModemVisitor {
|
||||||
|
void visit(Hayes hayes);
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Modem abstract class.
|
||||||
|
*/
|
||||||
|
public abstract class Modem {
|
||||||
|
public abstract void accept(ModemVisitor modemVisitor);
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ModemVisitor interface does not contain any visit methods so that it does not depend on the
|
||||||
|
* visited hierarchy. Each derivative's visit method is declared in its own visitor interface
|
||||||
|
*/
|
||||||
|
public interface ModemVisitor {
|
||||||
|
// Visitor is a degenerate base class for all visitors.
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zoom class implements its accept method.
|
||||||
|
*/
|
||||||
|
public class Zoom extends Modem {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Accepts all visitors but honors only ZoomVisitor.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void accept(ModemVisitor modemVisitor) {
|
||||||
|
if (modemVisitor instanceof ZoomVisitor) {
|
||||||
|
((ZoomVisitor) modemVisitor).visit(this);
|
||||||
|
} else {
|
||||||
|
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zoom modem's toString method.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Zoom modem";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ZoomVisitor interface.
|
||||||
|
*/
|
||||||
|
public interface ZoomVisitor extends ModemVisitor {
|
||||||
|
void visit(Zoom zoom);
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests that the Acyclic Visitor example runs without errors.
|
||||||
|
*/
|
||||||
|
public class AppTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
App.main(new String[]{});
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.groups.Tuple.tuple;
|
||||||
|
import static uk.org.lidalia.slf4jext.Level.INFO;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import uk.org.lidalia.slf4jtest.TestLogger;
|
||||||
|
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigureForDosVisitor test class
|
||||||
|
*/
|
||||||
|
public class ConfigureForDosVisitorTest {
|
||||||
|
|
||||||
|
private TestLogger logger = TestLoggerFactory.getTestLogger(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitForZoom() {
|
||||||
|
var conDos = new ConfigureForDosVisitor();
|
||||||
|
var zoom = new Zoom();
|
||||||
|
|
||||||
|
conDos.visit(zoom);
|
||||||
|
|
||||||
|
assertThat(logger.getLoggingEvents())
|
||||||
|
.extracting("level", "message")
|
||||||
|
.contains(tuple(INFO, zoom + " used with Dos configurator."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitForHayes() {
|
||||||
|
var conDos = new ConfigureForDosVisitor();
|
||||||
|
var hayes = new Hayes();
|
||||||
|
|
||||||
|
conDos.visit(hayes);
|
||||||
|
|
||||||
|
assertThat(logger.getLoggingEvents())
|
||||||
|
.extracting("level", "message")
|
||||||
|
.contains(tuple(INFO, hayes + " used with Dos configurator."));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void clearLoggers() {
|
||||||
|
TestLoggerFactory.clear();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.groups.Tuple.tuple;
|
||||||
|
import static uk.org.lidalia.slf4jext.Level.INFO;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import uk.org.lidalia.slf4jtest.TestLogger;
|
||||||
|
import uk.org.lidalia.slf4jtest.TestLoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ConfigureForUnixVisitor test class
|
||||||
|
*/
|
||||||
|
public class ConfigureForUnixVisitorTest {
|
||||||
|
|
||||||
|
private static final TestLogger LOGGER = TestLoggerFactory.getTestLogger(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void clearLoggers() {
|
||||||
|
TestLoggerFactory.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testVisitForZoom() {
|
||||||
|
var conUnix = new ConfigureForUnixVisitor();
|
||||||
|
var zoom = new Zoom();
|
||||||
|
|
||||||
|
conUnix.visit(zoom);
|
||||||
|
|
||||||
|
assertThat(LOGGER.getLoggingEvents())
|
||||||
|
.extracting("level", "message")
|
||||||
|
.contains(tuple(INFO, zoom + " used with Unix configurator."));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hayes test class
|
||||||
|
*/
|
||||||
|
public class HayesTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptForDos() {
|
||||||
|
var hayes = new Hayes();
|
||||||
|
var mockVisitor = mock(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
hayes.accept(mockVisitor);
|
||||||
|
verify((HayesVisitor)mockVisitor).visit(eq(hayes));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptForUnix() {
|
||||||
|
var hayes = new Hayes();
|
||||||
|
var mockVisitor = mock(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
|
hayes.accept(mockVisitor);
|
||||||
|
|
||||||
|
verifyZeroInteractions(mockVisitor);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.acyclicvisitor;
|
||||||
|
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zoom test class
|
||||||
|
*/
|
||||||
|
public class ZoomTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptForDos() {
|
||||||
|
var zoom = new Zoom();
|
||||||
|
var mockVisitor = mock(ConfigureForDosVisitor.class);
|
||||||
|
|
||||||
|
zoom.accept(mockVisitor);
|
||||||
|
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAcceptForUnix() {
|
||||||
|
var zoom = new Zoom();
|
||||||
|
var mockVisitor = mock(ConfigureForUnixVisitor.class);
|
||||||
|
|
||||||
|
zoom.accept(mockVisitor);
|
||||||
|
verify((ZoomVisitor)mockVisitor).visit(eq(zoom));
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@ layout: pattern
|
|||||||
title: Adapter
|
title: Adapter
|
||||||
folder: adapter
|
folder: adapter
|
||||||
permalink: /patterns/adapter/
|
permalink: /patterns/adapter/
|
||||||
pumlid: DSR14S8m30J0Lg20M7-wEMnDOiPMFDA9j0yyUEtUkzMHJTF7xI1NF4GSLzaxZtncgDVJgCPIpobzv0N2vOKtjgRHTziMI7KBcOXl10thfxB-Nz9dMJd71m00
|
|
||||||
categories: Structural
|
categories: Structural
|
||||||
tags:
|
tags:
|
||||||
- Java
|
- Java
|
||||||
@ -41,7 +40,7 @@ Consider a captain that can only use rowing boats and cannot sail at all.
|
|||||||
|
|
||||||
First we have interfaces `RowingBoat` and `FishingBoat`
|
First we have interfaces `RowingBoat` and `FishingBoat`
|
||||||
|
|
||||||
```
|
```java
|
||||||
public interface RowingBoat {
|
public interface RowingBoat {
|
||||||
void row();
|
void row();
|
||||||
}
|
}
|
||||||
@ -56,16 +55,15 @@ public class FishingBoat {
|
|||||||
|
|
||||||
And captain expects an implementation of `RowingBoat` interface to be able to move
|
And captain expects an implementation of `RowingBoat` interface to be able to move
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class Captain implements RowingBoat {
|
public class Captain {
|
||||||
|
|
||||||
private RowingBoat rowingBoat;
|
private RowingBoat rowingBoat;
|
||||||
|
// default constructor and setter for rowingBoat
|
||||||
public Captain(RowingBoat rowingBoat) {
|
public Captain(RowingBoat rowingBoat) {
|
||||||
this.rowingBoat = rowingBoat;
|
this.rowingBoat = rowingBoat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void row() {
|
public void row() {
|
||||||
rowingBoat.row();
|
rowingBoat.row();
|
||||||
}
|
}
|
||||||
@ -74,7 +72,7 @@ public class Captain implements RowingBoat {
|
|||||||
|
|
||||||
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
|
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
|
||||||
|
|
||||||
```
|
```java
|
||||||
public class FishingBoatAdapter implements RowingBoat {
|
public class FishingBoatAdapter implements RowingBoat {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoatAdapter.class);
|
||||||
@ -94,8 +92,8 @@ public class FishingBoatAdapter implements RowingBoat {
|
|||||||
|
|
||||||
And now the `Captain` can use the `FishingBoat` to escape the pirates.
|
And now the `Captain` can use the `FishingBoat` to escape the pirates.
|
||||||
|
|
||||||
```
|
```java
|
||||||
Captain captain = new Captain(new FishingBoatAdapter());
|
var captain = new Captain(new FishingBoatAdapter());
|
||||||
captain.row();
|
captain.row();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,13 +29,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>adapter</artifactId>
|
<artifactId>adapter</artifactId>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -28,33 +29,33 @@ package com.iluwatar.adapter;
|
|||||||
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
|
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
|
||||||
* the interface of one class into an interface expected by the clients.
|
* the interface of one class into an interface expected by the clients.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>There are two variations of the Adapter pattern: The class adapter implements the adaptee's
|
||||||
* There are two variations of the Adapter pattern: The class adapter implements the adaptee's
|
|
||||||
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
|
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
|
||||||
* object. This example uses the object adapter approach.
|
* object. This example uses the object adapter approach.
|
||||||
*
|
*
|
||||||
* <p>
|
* <p>The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class ({@link
|
||||||
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class (
|
* FishingBoat}) into a suitable one expected by the client ({@link RowingBoat}).
|
||||||
* {@link FishingBoat}) into a suitable one expected by the client ( {@link RowingBoat} ).
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* The story of this implementation is this. <br>
|
|
||||||
* Pirates are coming! we need a {@link RowingBoat} to flee! We have a {@link FishingBoat} and our
|
|
||||||
* captain. We have no time to make up a new ship! we need to reuse this {@link FishingBoat}. The
|
|
||||||
* captain needs a rowing boat which he can operate. The spec is in {@link RowingBoat}. We will
|
|
||||||
* use the Adapter pattern to reuse {@link FishingBoat}.
|
|
||||||
*
|
*
|
||||||
|
* <p>The story of this implementation is this. <br> Pirates are coming! we need a {@link
|
||||||
|
* RowingBoat} to flee! We have a {@link FishingBoat} and our captain. We have no time to make up a
|
||||||
|
* new ship! we need to reuse this {@link FishingBoat}. The captain needs a rowing boat which he can
|
||||||
|
* operate. The spec is in {@link RowingBoat}. We will use the Adapter pattern to reuse {@link
|
||||||
|
* FishingBoat}.
|
||||||
*/
|
*/
|
||||||
public class App {
|
public final class App {
|
||||||
|
|
||||||
|
private App() {
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point.
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(final String[] args) {
|
||||||
// The captain can only operate rowing boats but with adapter he is able to use fishing boats as well
|
// The captain can only operate rowing boats but with adapter he is able to
|
||||||
Captain captain = new Captain(new FishingBoatAdapter());
|
// use fishing boats as well
|
||||||
|
var captain = new Captain(new FishingBoatAdapter());
|
||||||
captain.row();
|
captain.row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,28 +20,28 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Captain uses {@link RowingBoat} to sail. <br>
|
* The Captain uses {@link RowingBoat} to sail. <br> This is the client in the pattern.
|
||||||
* This is the client in the pattern.
|
|
||||||
*/
|
*/
|
||||||
public class Captain implements RowingBoat {
|
public final class Captain {
|
||||||
|
|
||||||
private RowingBoat rowingBoat;
|
private RowingBoat rowingBoat;
|
||||||
|
|
||||||
public Captain() {}
|
public Captain() {
|
||||||
|
|
||||||
public Captain(RowingBoat rowingBoat) {
|
|
||||||
this.rowingBoat = rowingBoat;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRowingBoat(RowingBoat rowingBoat) {
|
public Captain(final RowingBoat boat) {
|
||||||
this.rowingBoat = rowingBoat;
|
this.rowingBoat = boat;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void setRowingBoat(final RowingBoat boat) {
|
||||||
public void row() {
|
this.rowingBoat = boat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void row() {
|
||||||
rowingBoat.row();
|
rowingBoat.row();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,22 +20,22 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
|
import static org.slf4j.LoggerFactory.getLogger;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Device class (adaptee in the pattern). We want to reuse this class. Fishing boat moves by
|
||||||
* Device class (adaptee in the pattern). We want to reuse this class.
|
* sailing.
|
||||||
* Fishing boat moves by sailing.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class FishingBoat {
|
final class FishingBoat {
|
||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
|
private static final Logger LOGGER = getLogger(FishingBoat.class);
|
||||||
|
|
||||||
public void sail() {
|
void sail() {
|
||||||
LOGGER.info("The fishing boat is sailing");
|
LOGGER.info("The fishing boat is sailing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,13 +20,12 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
|
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
|
||||||
* interface expected by the client ({@link Captain}).
|
* interface expected by the client ({@link Captain}).
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class FishingBoatAdapter implements RowingBoat {
|
public class FishingBoatAdapter implements RowingBoat {
|
||||||
|
|
||||||
@ -36,8 +35,7 @@ public class FishingBoatAdapter implements RowingBoat {
|
|||||||
boat = new FishingBoat();
|
boat = new FishingBoat();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public final void row() {
|
||||||
public void row() {
|
|
||||||
boat.sail();
|
boat.sail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,12 +20,11 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The interface expected by the client.<br>
|
* The interface expected by the client.<br> A rowing boat is rowed to move.
|
||||||
* A rowing boat is rowed to move.
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface RowingBoat {
|
public interface RowingBoat {
|
||||||
|
|
||||||
|
24
adapter/src/main/java/com/iluwatar/adapter/package-info.java
Normal file
24
adapter/src/main/java/com/iluwatar/adapter/package-info.java
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* The MIT License
|
||||||
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.iluwatar.adapter;
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,20 +20,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class
|
* Test class
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class AdapterPatternTest {
|
public class AdapterPatternTest {
|
||||||
|
|
||||||
@ -46,33 +45,33 @@ public class AdapterPatternTest {
|
|||||||
/**
|
/**
|
||||||
* This method runs before the test execution and sets the bean objects in the beans Map.
|
* This method runs before the test execution and sets the bean objects in the beans Map.
|
||||||
*/
|
*/
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
beans = new HashMap<>();
|
beans = new HashMap<>();
|
||||||
|
|
||||||
FishingBoatAdapter fishingBoatAdapter = spy(new FishingBoatAdapter());
|
var fishingBoatAdapter = spy(new FishingBoatAdapter());
|
||||||
beans.put(FISHING_BEAN, fishingBoatAdapter);
|
beans.put(FISHING_BEAN, fishingBoatAdapter);
|
||||||
|
|
||||||
Captain captain = new Captain();
|
var captain = new Captain();
|
||||||
captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
|
captain.setRowingBoat((FishingBoatAdapter) beans.get(FISHING_BEAN));
|
||||||
beans.put(ROWING_BEAN, captain);
|
beans.put(ROWING_BEAN, captain);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test asserts that when we use the row() method on a captain bean(client), it is
|
* This test asserts that when we use the row() method on a captain bean(client), it is internally
|
||||||
* internally calling sail method on the fishing boat object. The Adapter ({@link FishingBoatAdapter}
|
* calling sail method on the fishing boat object. The Adapter ({@link FishingBoatAdapter} )
|
||||||
* ) converts the interface of the target class ( {@link FishingBoat}) into a suitable one
|
* converts the interface of the target class ( {@link FishingBoat}) into a suitable one expected
|
||||||
* expected by the client ({@link Captain} ).
|
* by the client ({@link Captain} ).
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testAdapter() {
|
public void testAdapter() {
|
||||||
RowingBoat captain = (RowingBoat) beans.get(ROWING_BEAN);
|
var captain = (Captain) beans.get(ROWING_BEAN);
|
||||||
|
|
||||||
// when captain moves
|
// when captain moves
|
||||||
captain.row();
|
captain.row();
|
||||||
|
|
||||||
// the captain internally calls the battleship object to move
|
// the captain internally calls the battleship object to move
|
||||||
RowingBoat adapter = (RowingBoat) beans.get(FISHING_BEAN);
|
var adapter = (RowingBoat) beans.get(FISHING_BEAN);
|
||||||
verify(adapter).row();
|
verify(adapter).row();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,19 +20,17 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.adapter;
|
package com.iluwatar.adapter;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that Adapter example runs without errors.
|
* Tests that Adapter example runs without errors.
|
||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() {
|
||||||
String[] args = {};
|
App.main(new String[]{});
|
||||||
App.main(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ layout: pattern
|
|||||||
title: Aggregator Microservices
|
title: Aggregator Microservices
|
||||||
folder: aggregator-microservices
|
folder: aggregator-microservices
|
||||||
permalink: /patterns/aggregator-microservices/
|
permalink: /patterns/aggregator-microservices/
|
||||||
pumlid: JOov3SCm301NIGQGs7iRXYPa1g8ayB7NjuiKwGvtmBrbKC-Tq_hhY5Y-0HXUjKaS-Kbdepc2HrIQ2jBpma23BvvOTdPfeooCO1iEYlu0O6l63MDQKI6Rp-CKOWSE-ey_NzEqhjH-0m00
|
|
||||||
categories: Architectural
|
categories: Architectural
|
||||||
tags:
|
tags:
|
||||||
- Java
|
- Java
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,21 +29,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>aggregator-service</artifactId>
|
<artifactId>aggregator-service</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@ -54,8 +44,8 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -63,10 +53,6 @@
|
|||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
|
||||||
<artifactId>httpclient</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@ -74,7 +60,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -85,4 +70,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,16 +20,19 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import static java.util.Objects.requireNonNullElse;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The aggregator aggregates calls on various micro-services, collects
|
* The aggregator aggregates calls on various micro-services, collects data and further publishes
|
||||||
* data and further publishes them under a REST endpoint.
|
* them under a REST endpoint.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class Aggregator {
|
public class Aggregator {
|
||||||
@ -47,11 +50,19 @@ public class Aggregator {
|
|||||||
*
|
*
|
||||||
* @return a Product.
|
* @return a Product.
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/product")
|
@RequestMapping(path = "/product", method = RequestMethod.GET)
|
||||||
public Product getProduct() {
|
public Product getProduct() {
|
||||||
Product product = new Product();
|
|
||||||
product.setTitle(informationClient.getProductTitle());
|
var product = new Product();
|
||||||
product.setProductInventories(inventoryClient.getProductInventories());
|
var productTitle = informationClient.getProductTitle();
|
||||||
|
var productInventory = inventoryClient.getProductInventories();
|
||||||
|
|
||||||
|
//Fallback to error message
|
||||||
|
product.setTitle(requireNonNullElse(productTitle, "Error: Fetching Product Title Failed"));
|
||||||
|
|
||||||
|
//Fallback to default error inventory
|
||||||
|
product.setProductInventories(requireNonNullElse(productInventory, -1));
|
||||||
|
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,19 +20,20 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spring Boot EntryPoint Class
|
* Spring Boot EntryPoint Class.
|
||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Program entry point
|
* Program entry point.
|
||||||
*
|
*
|
||||||
* @param args command line args
|
* @param args command line args
|
||||||
*/
|
*/
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,19 +20,18 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import java.io.IOException;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import java.net.URI;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import java.net.http.HttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import java.net.http.HttpRequest;
|
||||||
import org.apache.http.util.EntityUtils;
|
import java.net.http.HttpResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An adapter to communicate with information micro-service.
|
* An adapter to communicate with information micro-service.
|
||||||
*/
|
*/
|
||||||
@ -43,15 +42,19 @@ public class ProductInformationClientImpl implements ProductInformationClient {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getProductTitle() {
|
public String getProductTitle() {
|
||||||
String response = null;
|
var request = HttpRequest.newBuilder()
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
.GET()
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:51515/information");
|
.uri(URI.create("http://localhost:51515/information"))
|
||||||
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
|
.build();
|
||||||
response = EntityUtils.toString(httpResponse.getEntity());
|
var client = HttpClient.newHttpClient();
|
||||||
}
|
try {
|
||||||
} catch (IOException e) {
|
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
LOGGER.error("Exception caught.", e);
|
return httpResponse.body();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
LOGGER.error("IOException Occurred", ioe);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
LOGGER.error("InterruptedException Occurred", ie);
|
||||||
}
|
}
|
||||||
return response;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -27,5 +28,5 @@ package com.iluwatar.aggregator.microservices;
|
|||||||
*/
|
*/
|
||||||
public interface ProductInventoryClient {
|
public interface ProductInventoryClient {
|
||||||
|
|
||||||
int getProductInventories();
|
Integer getProductInventories();
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,19 +20,18 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import java.io.IOException;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import java.net.URI;
|
||||||
import org.apache.http.impl.client.CloseableHttpClient;
|
import java.net.http.HttpClient;
|
||||||
import org.apache.http.impl.client.HttpClients;
|
import java.net.http.HttpRequest;
|
||||||
import org.apache.http.util.EntityUtils;
|
import java.net.http.HttpResponse;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An adapter to communicate with inventory micro-service.
|
* An adapter to communicate with inventory micro-service.
|
||||||
*/
|
*/
|
||||||
@ -42,16 +41,26 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
|||||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getProductInventories() {
|
public Integer getProductInventories() {
|
||||||
String response = "0";
|
var response = "";
|
||||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
|
||||||
HttpGet httpGet = new HttpGet("http://localhost:51516/inventories");
|
var request = HttpRequest.newBuilder()
|
||||||
try (CloseableHttpResponse httpResponse = httpClient.execute(httpGet)) {
|
.GET()
|
||||||
response = EntityUtils.toString(httpResponse.getEntity());
|
.uri(URI.create("http://localhost:51516/inventories"))
|
||||||
}
|
.build();
|
||||||
} catch (IOException e) {
|
var client = HttpClient.newHttpClient();
|
||||||
LOGGER.error("Exception caught.", e);
|
try {
|
||||||
|
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||||
|
response = httpResponse.body();
|
||||||
|
} catch (IOException ioe) {
|
||||||
|
LOGGER.error("IOException Occurred", ioe);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
LOGGER.error("InterruptedException Occurred", ie);
|
||||||
|
}
|
||||||
|
if ("".equalsIgnoreCase(response)) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return Integer.parseInt(response);
|
||||||
}
|
}
|
||||||
return Integer.parseInt(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# The MIT License
|
# The MIT License
|
||||||
# Copyright (c) 2014-2016 Ilkka Seppälä
|
# Copyright © 2014-2019 Ilkka Seppälä
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,5 +20,4 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
server.port=50004
|
server.port=50004
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,13 +20,14 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.aggregator.microservices;
|
package com.iluwatar.aggregator.microservices;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.InjectMocks;
|
import org.mockito.InjectMocks;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
@ -45,7 +46,7 @@ public class AggregatorTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private ProductInventoryClient inventoryClient;
|
private ProductInventoryClient inventoryClient;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
}
|
}
|
||||||
@ -55,13 +56,13 @@ public class AggregatorTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetProduct() {
|
public void testGetProduct() {
|
||||||
String title = "The Product Title.";
|
var title = "The Product Title.";
|
||||||
int inventories = 5;
|
var inventories = 5;
|
||||||
|
|
||||||
when(informationClient.getProductTitle()).thenReturn(title);
|
when(informationClient.getProductTitle()).thenReturn(title);
|
||||||
when(inventoryClient.getProductInventories()).thenReturn(inventories);
|
when(inventoryClient.getProductInventories()).thenReturn(inventories);
|
||||||
|
|
||||||
Product testProduct = aggregator.getProduct();
|
var testProduct = aggregator.getProduct();
|
||||||
|
|
||||||
assertEquals(title, testProduct.getTitle());
|
assertEquals(title, testProduct.getTitle());
|
||||||
assertEquals(inventories, testProduct.getProductInventories());
|
assertEquals(inventories, testProduct.getProductInventories());
|
||||||
|
@ -1,43 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.aggregator.microservices {
|
|
||||||
class Aggregator {
|
|
||||||
- informationClient : ProductInformationClient
|
|
||||||
- inventoryClient : ProductInventoryClient
|
|
||||||
+ Aggregator()
|
|
||||||
+ getProduct() : Product
|
|
||||||
}
|
|
||||||
class App {
|
|
||||||
+ App()
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
}
|
|
||||||
class Product {
|
|
||||||
- productInventories : int
|
|
||||||
- title : String
|
|
||||||
+ Product()
|
|
||||||
+ getProductInventories() : int
|
|
||||||
+ getTitle() : String
|
|
||||||
+ setProductInventories(productInventories : int)
|
|
||||||
+ setTitle(title : String)
|
|
||||||
}
|
|
||||||
interface ProductInformationClient {
|
|
||||||
+ getProductTitle() : String {abstract}
|
|
||||||
}
|
|
||||||
class ProductInformationClientImpl {
|
|
||||||
- LOGGER : Logger {static}
|
|
||||||
+ ProductInformationClientImpl()
|
|
||||||
+ getProductTitle() : String
|
|
||||||
}
|
|
||||||
interface ProductInventoryClient {
|
|
||||||
+ getProductInventories() : int {abstract}
|
|
||||||
}
|
|
||||||
class ProductInventoryClientImpl {
|
|
||||||
- LOGGER : Logger {static}
|
|
||||||
+ ProductInventoryClientImpl()
|
|
||||||
+ getProductInventories() : int
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Aggregator --> "-informationClient" ProductInformationClient
|
|
||||||
Aggregator --> "-inventoryClient" ProductInventoryClient
|
|
||||||
ProductInformationClientImpl ..|> ProductInformationClient
|
|
||||||
ProductInventoryClientImpl ..|> ProductInventoryClient
|
|
||||||
@enduml
|
|
@ -1,12 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.information.microservice {
|
|
||||||
class InformationApplication {
|
|
||||||
+ InformationApplication()
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
}
|
|
||||||
class InformationController {
|
|
||||||
+ InformationController()
|
|
||||||
+ getProductTitle() : String
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@enduml
|
|
@ -1,12 +0,0 @@
|
|||||||
@startuml
|
|
||||||
package com.iluwatar.inventory.microservice {
|
|
||||||
class InventoryApplication {
|
|
||||||
+ InventoryApplication()
|
|
||||||
+ main(args : String[]) {static}
|
|
||||||
}
|
|
||||||
class InventoryController {
|
|
||||||
+ InventoryController()
|
|
||||||
+ getProductInventories() : int
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@enduml
|
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,21 +29,13 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>information-microservice</artifactId>
|
<artifactId>information-microservice</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@ -54,8 +46,8 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -65,7 +57,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.information.microservice;
|
package com.iluwatar.information.microservice;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.information.microservice;
|
package com.iluwatar.information.microservice;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -27,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller providing endpoints to retrieve information about products
|
* Controller providing endpoints to retrieve information about products.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class InformationController {
|
public class InformationController {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# The MIT License
|
# The MIT License
|
||||||
# Copyright (c) 2014-2016 Ilkka Seppälä
|
# Copyright © 2014-2019 Ilkka Seppälä
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,5 +20,4 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
server.port=51515
|
server.port=51515
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,10 +20,12 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.information.microservice;
|
package com.iluwatar.information.microservice;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for Information Rest Controller
|
* Test for Information Rest Controller
|
||||||
@ -32,11 +34,9 @@ public class InformationControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetProductTitle() {
|
public void shouldGetProductTitle() {
|
||||||
InformationController infoController = new InformationController();
|
var infoController = new InformationController();
|
||||||
|
var title = infoController.getProductTitle();
|
||||||
String title = infoController.getProductTitle();
|
assertEquals("The Product Title.", title);
|
||||||
|
|
||||||
Assert.assertEquals("The Product Title.", title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,21 +29,12 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>inventory-microservice</artifactId>
|
<artifactId>inventory-microservice</artifactId>
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<dependencyManagement>
|
<packaging>jar</packaging>
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
@ -54,8 +45,8 @@
|
|||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@ -65,7 +56,6 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<version>${spring-boot.version}</version>
|
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<goals>
|
<goals>
|
||||||
@ -76,4 +66,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.inventory.microservice;
|
package com.iluwatar.inventory.microservice;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,6 +20,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.inventory.microservice;
|
package com.iluwatar.inventory.microservice;
|
||||||
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@ -27,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller providing endpoints to retrieve product inventories
|
* Controller providing endpoints to retrieve product inventories.
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
public class InventoryController {
|
public class InventoryController {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#
|
#
|
||||||
# The MIT License
|
# The MIT License
|
||||||
# Copyright (c) 2014-2016 Ilkka Seppälä
|
# Copyright © 2014-2019 Ilkka Seppälä
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -20,5 +20,4 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
# THE SOFTWARE.
|
# THE SOFTWARE.
|
||||||
#
|
#
|
||||||
|
|
||||||
server.port=51516
|
server.port=51516
|
@ -1,17 +1,17 @@
|
|||||||
/**
|
/*
|
||||||
* The MIT License
|
* The MIT License
|
||||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
* Copyright © 2014-2019 Ilkka Seppälä
|
||||||
* <p/>
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
* in the Software without restriction, including without limitation the rights
|
* in the Software without restriction, including without limitation the rights
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
* furnished to do so, subject to the following conditions:
|
* furnished to do so, subject to the following conditions:
|
||||||
* <p/>
|
*
|
||||||
* The above copyright notice and this permission notice shall be included in
|
* The above copyright notice and this permission notice shall be included in
|
||||||
* all copies or substantial portions of the Software.
|
* all copies or substantial portions of the Software.
|
||||||
* <p/>
|
*
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
@ -20,21 +20,21 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.iluwatar.inventory.microservice;
|
package com.iluwatar.inventory.microservice;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.junit.Test;
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Inventory Rest Controller
|
* Test Inventory Rest Controller
|
||||||
*/
|
*/
|
||||||
public class InventoryControllerTest {
|
public class InventoryControllerTest {
|
||||||
@Test
|
@Test
|
||||||
public void testGetProductInventories() throws Exception {
|
public void testGetProductInventories() {
|
||||||
InventoryController inventoryController = new InventoryController();
|
var inventoryController = new InventoryController();
|
||||||
|
var numberOfInventories = inventoryController.getProductInventories();
|
||||||
int numberOfInventories = inventoryController.getProductInventories();
|
assertEquals(5, numberOfInventories);
|
||||||
|
|
||||||
Assert.assertEquals(5, numberOfInventories);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<!--
|
<!--
|
||||||
|
|
||||||
The MIT License
|
The MIT License
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@ -29,32 +29,11 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>java-design-patterns</artifactId>
|
<artifactId>java-design-patterns</artifactId>
|
||||||
<groupId>com.iluwatar</groupId>
|
<groupId>com.iluwatar</groupId>
|
||||||
<version>1.17.0</version>
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<artifactId>aggregator-microservices</artifactId>
|
<artifactId>aggregator-microservices</artifactId>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>com.github.markusmo3.urm</groupId>
|
|
||||||
<artifactId>urm-maven-plugin</artifactId>
|
|
||||||
<version>${urm.version}</version>
|
|
||||||
<configuration combine.self="override">
|
|
||||||
<outputDirectory>${project.basedir}/../etc</outputDirectory>
|
|
||||||
<packages>
|
|
||||||
<param>com.iluwatar</param>
|
|
||||||
</packages>
|
|
||||||
<skipForProjects>
|
|
||||||
<!-- skip for parent project -->
|
|
||||||
<param>aggregator-microservices</param>
|
|
||||||
</skipForProjects>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>information-microservice</module>
|
<module>information-microservice</module>
|
||||||
<module>aggregator-service</module>
|
<module>aggregator-service</module>
|
||||||
|
176
ambassador/README.md
Normal file
176
ambassador/README.md
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
---
|
||||||
|
layout: pattern
|
||||||
|
title: Ambassador
|
||||||
|
folder: ambassador
|
||||||
|
permalink: /patterns/ambassador/
|
||||||
|
categories: Structural
|
||||||
|
tags:
|
||||||
|
- Java
|
||||||
|
- Difficulty-Intermediate
|
||||||
|
---
|
||||||
|
|
||||||
|
## Intent
|
||||||
|
Provide a helper service instance on a client and offload common functionality away from a shared resource.
|
||||||
|
|
||||||
|
## Explanation
|
||||||
|
Real world example
|
||||||
|
|
||||||
|
> A remote service has many clients accessing a function it provides. The service is a legacy application and is impossible to update. Large numbers of requests from users are causing connectivity issues. New rules for request frequency should be implemented along with latency checks and client-side logging.
|
||||||
|
|
||||||
|
In plain words
|
||||||
|
|
||||||
|
> Using the ambassador pattern, we can implement less-frequent polling from clients along with latency checks and logging.
|
||||||
|
|
||||||
|
Microsoft documentation states
|
||||||
|
|
||||||
|
> An ambassador service can be thought of as an out-of-process proxy that is co-located with the client.
|
||||||
|
This pattern can be useful for offloading common client connectivity tasks such as monitoring, logging, routing, security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities. It can also enable a specialized team to implement those features.
|
||||||
|
|
||||||
|
**Programmatic Example**
|
||||||
|
|
||||||
|
With the above example in mind we will imitate the functionality in a simple manner. We have an interface implemented by the remote service as well as the ambassador service:
|
||||||
|
|
||||||
|
```java
|
||||||
|
interface RemoteServiceInterface {
|
||||||
|
|
||||||
|
long doRemoteFunction(int value) throws Exception;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A remote services represented as a singleton.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class RemoteService implements RemoteServiceInterface {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(RemoteService.class);
|
||||||
|
private static RemoteService service = null;
|
||||||
|
|
||||||
|
static synchronized RemoteService getRemoteService() {
|
||||||
|
if (service == null) {
|
||||||
|
service = new RemoteService();
|
||||||
|
}
|
||||||
|
return service;
|
||||||
|
}
|
||||||
|
|
||||||
|
private RemoteService() {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long doRemoteFunction(int value) {
|
||||||
|
long waitTime = (long) Math.floor(Math.random() * 1000);
|
||||||
|
|
||||||
|
try {
|
||||||
|
sleep(waitTime);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.error("Thread sleep interrupted", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return waitTime >= 200 ? value * 10 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A service ambassador adding additional features such as logging, latency checks
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class ServiceAmbassador implements RemoteServiceInterface {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceAmbassador.class);
|
||||||
|
private static final int RETRIES = 3;
|
||||||
|
private static final int DELAY_MS = 3000;
|
||||||
|
|
||||||
|
ServiceAmbassador() {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long doRemoteFunction(int value) {
|
||||||
|
return safeCall(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long checkLatency(int value) {
|
||||||
|
var startTime = System.currentTimeMillis();
|
||||||
|
var result = RemoteService.getRemoteService().doRemoteFunction(value);
|
||||||
|
var timeTaken = System.currentTimeMillis() - startTime;
|
||||||
|
|
||||||
|
LOGGER.info("Time taken (ms): " + timeTaken);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private long safeCall(int value) {
|
||||||
|
var retries = 0;
|
||||||
|
var result = (long) FAILURE;
|
||||||
|
|
||||||
|
for (int i = 0; i < RETRIES; i++) {
|
||||||
|
if (retries >= RETRIES) {
|
||||||
|
return FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((result = checkLatency(value)) == FAILURE) {
|
||||||
|
LOGGER.info("Failed to reach remote: (" + (i + 1) + ")");
|
||||||
|
retries++;
|
||||||
|
try {
|
||||||
|
sleep(DELAY_MS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
LOGGER.error("Thread sleep state interrupted", e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
A client has a local service ambassador used to interact with the remote service:
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class Client {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Client.class);
|
||||||
|
private final ServiceAmbassador serviceAmbassador = new ServiceAmbassador();
|
||||||
|
|
||||||
|
long useService(int value) {
|
||||||
|
var result = serviceAmbassador.doRemoteFunction(value);
|
||||||
|
LOGGER.info("Service result: " + result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
And here are two clients using the service.
|
||||||
|
|
||||||
|
```java
|
||||||
|
public class App {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
var host1 = new Client();
|
||||||
|
var host2 = new Client();
|
||||||
|
host1.useService(12);
|
||||||
|
host2.useService(73);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Applicability
|
||||||
|
Ambassador is applicable when working with a legacy remote service that cannot
|
||||||
|
be modified or would be extremely difficult to modify. Connectivity features can
|
||||||
|
be implemented on the client avoiding the need for changes on the remote service.
|
||||||
|
|
||||||
|
* Ambassador provides a local interface for a remote service.
|
||||||
|
* Ambassador provides logging, circuit breaking, retries and security on the client.
|
||||||
|
|
||||||
|
## Typical Use Case
|
||||||
|
|
||||||
|
* Control access to another object
|
||||||
|
* Implement logging
|
||||||
|
* Implement circuit breaking
|
||||||
|
* Offload remote service tasks
|
||||||
|
* Facilitate network connection
|
||||||
|
|
||||||
|
## Real world examples
|
||||||
|
|
||||||
|
* [Kubernetes-native API gateway for microservices](https://github.com/datawire/ambassador)
|
||||||
|
|
||||||
|
## Credits
|
||||||
|
|
||||||
|
* [Ambassador pattern](https://docs.microsoft.com/en-us/azure/architecture/patterns/ambassador)
|
||||||
|
* [Designing Distributed Systems: Patterns and Paradigms for Scalable, Reliable Services](https://books.google.co.uk/books?id=6BJNDwAAQBAJ&pg=PT35&lpg=PT35&dq=ambassador+pattern+in+real+world&source=bl&ots=d2e7GhYdHi&sig=Lfl_MDnCgn6lUcjzOg4GXrN13bQ&hl=en&sa=X&ved=0ahUKEwjk9L_18rrbAhVpKcAKHX_KA7EQ6AEIWTAI#v=onepage&q=ambassador%20pattern%20in%20real%20world&f=false)
|
43
ambassador/pom.xml
Normal file
43
ambassador/pom.xml
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
The MIT License
|
||||||
|
Copyright © 2014-2019 Ilkka Seppälä
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<parent>
|
||||||
|
<artifactId>java-design-patterns</artifactId>
|
||||||
|
<groupId>com.iluwatar</groupId>
|
||||||
|
<version>1.22.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>ambassador</artifactId>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter-engine</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user