Compare commits
179 Commits
Author | SHA1 | Date | |
---|---|---|---|
8fea969912 | |||
139876f96a | |||
f3c4640d12 | |||
c1c4411957 | |||
3f272bf291 | |||
2921448f8b | |||
952c207a62 | |||
6ba4d7be98 | |||
854101bb49 | |||
a5ab5c7d8e | |||
286d6c3a4c | |||
c2a7b902a9 | |||
09585c3874 | |||
f84c4c1611 | |||
2c2d874ac8 | |||
72a0765ec6 | |||
cca4d5a670 | |||
bb4a1bdc05 | |||
1aed5905d7 | |||
175e9f58c1 | |||
77a534385c | |||
2ed7acbc31 | |||
3a243eee6e | |||
8632bafcd7 | |||
449aed1a53 | |||
a20abae21c | |||
7423f47daa | |||
f09578c091 | |||
29715028d1 | |||
e5034c6ae9 | |||
a09866d35b | |||
1824b4138b | |||
764ff4bf53 | |||
e8b634c33e | |||
8871f788d2 | |||
e9c54011e9 | |||
fd7107694a | |||
cca4760f69 | |||
a1ff55b462 | |||
ddac9dc6cb | |||
2bbf84233e | |||
82f8460243 | |||
59ea20745f | |||
3d3dd58501 | |||
3324e1bc43 | |||
6202f3ab44 | |||
453862cfc2 | |||
a8e2c157de | |||
080965fb17 | |||
7200329a6b | |||
f170aaa42b | |||
c598748549 | |||
ed11c4c4f9 | |||
283f198ba8 | |||
15913d6382 | |||
65e047974c | |||
c529e35791 | |||
3342851005 | |||
c167f87ce5 | |||
e8fc3427c6 | |||
26b79a5382 | |||
9ec0935a1c | |||
c6d0d28557 | |||
e26215578c | |||
d6fc28e120 | |||
115a85301c | |||
29c5b80f19 | |||
0c8bb1c22e | |||
0c48695fa5 | |||
8d34ccf827 | |||
512a5c0560 | |||
9cf1918425 | |||
5e57cd03d1 | |||
6292690250 | |||
ad93184a79 | |||
20b1c2bd49 | |||
95f2c19780 | |||
120033b58b | |||
e210e4ed62 | |||
fb98da86c4 | |||
c8b3c773c7 | |||
61b1356976 | |||
487f9ddc80 | |||
9b7ce556e3 | |||
e17cf27e5a | |||
937a1e269d | |||
803a97237c | |||
e64f7faa3f | |||
15d660b117 | |||
544f7fb6d1 | |||
c4eb198a8d | |||
7067d1ae56 | |||
d80edd1ed3 | |||
aeefc11f25 | |||
c94c8a3e74 | |||
5d8806858b | |||
efc2c887e9 | |||
1d6d0c54a7 | |||
1387e2bc96 | |||
faa29f8025 | |||
89e7f51e99 | |||
cc02ff472b | |||
7d995056ff | |||
8574e06966 | |||
82d3d7bf1f | |||
1a75ab8df1 | |||
92f8501f7d | |||
b9ac0dc6a3 | |||
5e7887d9be | |||
e8f7187e4b | |||
d6b5456f98 | |||
52a81eb368 | |||
12b70cb39c | |||
68ec24c62e | |||
3091ff21b0 | |||
95b651f177 | |||
f67d2fd9a9 | |||
4ff8fa3721 | |||
9180bb0fef | |||
1abf5b11c3 | |||
22d973c460 | |||
c850295aab | |||
4c24d99414 | |||
e1ae1067db | |||
6f3e2985a4 | |||
b37190a214 | |||
0a427710bb | |||
e138163c4f | |||
124fd33da0 | |||
9433c78d29 | |||
932700d9b1 | |||
27d6d500bc | |||
ea7752c5e1 | |||
7ba6cb43fd | |||
1ace4c05d6 | |||
7015e95ac3 | |||
2a77ac29e9 | |||
6aed26e61e | |||
74ac79b01e | |||
750fa4f954 | |||
20295316c2 | |||
56b0884258 | |||
0438811489 | |||
1c02785927 | |||
19cb715d20 | |||
ffdaf2ec47 | |||
a37a29e12b | |||
b66e8ecef9 | |||
99677867c6 | |||
0f7b44c3b1 | |||
70318123fe | |||
986c529eb6 | |||
64bdab46b9 | |||
37b930c3b7 | |||
85060784a7 | |||
f114b5b957 | |||
863ea75381 | |||
3a9d1684fd | |||
eea8785a22 | |||
8f1758c28f | |||
622376e0fa | |||
5eacf522a2 | |||
12544caa75 | |||
9512f3ec70 | |||
4ca205c03c | |||
b31edda3cf | |||
e3355d76d1 | |||
865f788612 | |||
6ed842e58b | |||
69cab15d75 | |||
371b262a51 | |||
dbd605e378 | |||
f2159515bc | |||
9a90f2de1f | |||
fce30db803 | |||
233f1e69f9 | |||
f11597136f | |||
e1836fee2f | |||
2d99061902 |
30
.gitignore
vendored
30
.gitignore
vendored
@ -1,19 +1,19 @@
|
||||
target
|
||||
.metadata
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
*.class
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
.idea
|
||||
*.iml
|
||||
*.swp
|
||||
target
|
||||
.metadata
|
||||
.settings
|
||||
.classpath
|
||||
.project
|
||||
*.class
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
.idea
|
||||
*.iml
|
||||
*.swp
|
||||
datanucleus.log
|
||||
/bin/
|
||||
/bin/
|
||||
/bin/
|
||||
|
||||
data-mapper/src/main/resources/log4j.xml
|
||||
*.log
|
||||
data-mapper/src/main/resources/log4j.xml
|
||||
|
@ -6,6 +6,7 @@ env:
|
||||
global:
|
||||
- GH_REF: github.com/iluwatar/java-design-patterns.git
|
||||
- secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg=
|
||||
- secure: "eoWlW9GyTJY04P8K3pxayXwU9/hmptQg/LfirispQkV9YvmziCfSzXnatnBhNfud98sCzY8BScXnb+OWLTnjLKpId4rtEqb0aJ40Jc32cUKzgzFAUn7cNcDAbUIfyPAGVqyQqfj/11wYSADwWMMOPlW97ExUtoyiH2WenXuRHso="
|
||||
|
||||
before_install:
|
||||
- export DISPLAY=:99.0
|
||||
@ -16,7 +17,7 @@ install:
|
||||
- mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V -e
|
||||
|
||||
after_success:
|
||||
- mvn clean test jacoco:report coveralls:report
|
||||
- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent package sonar:sonar -Dsonar.host.url=https://sonarqube.com -Dsonar.login=$SONAR_TOKEN
|
||||
- bash update-ghpages.sh
|
||||
|
||||
# use latest java version available instead of travis default
|
||||
|
@ -5,9 +5,9 @@
|
||||
# Design patterns implemented in Java
|
||||
|
||||
[](https://travis-ci.org/iluwatar/java-design-patterns)
|
||||
[](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master)
|
||||
[](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://sonarqube.com/dashboard/index/com.iluwatar%3Ajava-design-patterns)
|
||||
|
||||
# Introduction
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,33 +1,29 @@
|
||||
@startuml
|
||||
package com.iluwatar.abstractdocument.domain {
|
||||
class Part {
|
||||
+ Part(properties : Map<String, Object>)
|
||||
}
|
||||
interface HasPrice {
|
||||
+ PROPERTY : String {static}
|
||||
+ getPrice() : Optional<Number>
|
||||
}
|
||||
interface HasParts {
|
||||
+ PROPERTY : String {static}
|
||||
+ getParts() : Stream<Part>
|
||||
}
|
||||
class Car {
|
||||
+ Car(properties : Map<String, Object>)
|
||||
}
|
||||
interface HasType {
|
||||
+ PROPERTY : String {static}
|
||||
+ getType() : Optional<String>
|
||||
}
|
||||
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 {
|
||||
class App {
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
abstract class AbstractDocument {
|
||||
- properties : Map<String, Object>
|
||||
# AbstractDocument(properties : Map<String, Object>)
|
||||
@ -36,24 +32,28 @@ package com.iluwatar.abstractdocument {
|
||||
+ 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 --+ Map
|
||||
Part ..|> HasType
|
||||
Part ..|> HasModel
|
||||
Part ..|> HasPrice
|
||||
Part --|> AbstractDocument
|
||||
AbstractDocument ..|> Document
|
||||
HasPrice --|> Document
|
||||
HasParts --|> Document
|
||||
Car ..|> HasModel
|
||||
Car ..|> HasPrice
|
||||
Car ..|> HasParts
|
||||
Car --|> AbstractDocument
|
||||
HasType --|> Document
|
||||
HasModel --|> Document
|
||||
HasParts --|> Document
|
||||
HasPrice --|> Document
|
||||
HasType --|> Document
|
||||
Part ..|> HasType
|
||||
Part ..|> HasModel
|
||||
Part ..|> HasPrice
|
||||
Part --|> AbstractDocument
|
||||
@enduml
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<artifactId>abstract-document</artifactId>
|
||||
<dependencies>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -27,6 +27,8 @@ 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -44,11 +46,13 @@ import java.util.Map;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Executes the App
|
||||
*/
|
||||
public App() {
|
||||
System.out.println("Constructing parts and car");
|
||||
LOGGER.info("Constructing parts and car");
|
||||
|
||||
Map<String, Object> carProperties = new HashMap<>();
|
||||
carProperties.put(HasModel.PROPERTY, "300SL");
|
||||
@ -68,12 +72,11 @@ public class App {
|
||||
|
||||
Car car = new Car(carProperties);
|
||||
|
||||
System.out.println("Here is our car:");
|
||||
System.out.println("-> model: " + car.getModel().get());
|
||||
System.out.println("-> price: " + car.getPrice().get());
|
||||
System.out.println("-> parts: ");
|
||||
car.getParts().forEach(p -> System.out
|
||||
.println("\t" + p.getType().get() + "/" + p.getModel().get() + "/" + p.getPrice().get()));
|
||||
LOGGER.info("Here is our car:");
|
||||
LOGGER.info("-> model: {}", car.getModel().get());
|
||||
LOGGER.info("-> price: {}", car.getPrice().get());
|
||||
LOGGER.info("-> parts: ");
|
||||
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,7 @@
|
||||
@startuml
|
||||
package com.iluwatar.abstractfactory {
|
||||
class App {
|
||||
- LOGGER : Logger {static}
|
||||
- army : Army
|
||||
- castle : Castle
|
||||
- king : King
|
||||
@ -17,58 +18,58 @@ package com.iluwatar.abstractfactory {
|
||||
- setCastle(castle : Castle)
|
||||
- setKing(king : King)
|
||||
}
|
||||
class OrcKingdomFactory {
|
||||
+ OrcKingdomFactory()
|
||||
+ createArmy() : Army
|
||||
+ createCastle() : Castle
|
||||
+ createKing() : King
|
||||
interface Army {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
interface Castle {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
class ElfArmy {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ ElfArmy()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class ElfCastle {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ ElfCastle()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class ElfKing {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ ElfKing()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class ElfKingdomFactory {
|
||||
+ ElfKingdomFactory()
|
||||
+ createArmy() : Army
|
||||
+ createCastle() : Castle
|
||||
+ createKing() : King
|
||||
}
|
||||
interface King {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
interface KingdomFactory {
|
||||
+ createArmy() : Army {abstract}
|
||||
+ createCastle() : Castle {abstract}
|
||||
+ createKing() : King {abstract}
|
||||
}
|
||||
class OrcArmy {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ OrcArmy()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class OrcCastle {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ OrcCastle()
|
||||
+ getDescription() : String
|
||||
}
|
||||
interface KingdomFactory {
|
||||
+ createArmy() : Army {abstract}
|
||||
+ createCastle() : Castle {abstract}
|
||||
+ createKing() : King {abstract}
|
||||
}
|
||||
class ElfKing {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ ElfKing()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class ElfArmy {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ ElfArmy()
|
||||
+ getDescription() : String
|
||||
}
|
||||
interface Castle {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
interface Army {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
class OrcKing {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ OrcKing()
|
||||
+ getDescription() : String
|
||||
}
|
||||
class OrcArmy {
|
||||
~ DESCRIPTION : String {static}
|
||||
+ OrcArmy()
|
||||
+ getDescription() : String
|
||||
}
|
||||
interface King {
|
||||
+ getDescription() : String {abstract}
|
||||
}
|
||||
class ElfKingdomFactory {
|
||||
+ ElfKingdomFactory()
|
||||
class OrcKingdomFactory {
|
||||
+ OrcKingdomFactory()
|
||||
+ createArmy() : Army
|
||||
+ createCastle() : Castle
|
||||
+ createKing() : King
|
||||
@ -77,12 +78,12 @@ package com.iluwatar.abstractfactory {
|
||||
App --> "-castle" Castle
|
||||
App --> "-king" King
|
||||
App --> "-army" Army
|
||||
OrcKingdomFactory ..|> KingdomFactory
|
||||
ElfCastle ..|> Castle
|
||||
OrcCastle ..|> Castle
|
||||
ElfKing ..|> King
|
||||
ElfArmy ..|> Army
|
||||
OrcKing ..|> King
|
||||
OrcArmy ..|> Army
|
||||
ElfCastle ..|> Castle
|
||||
ElfKing ..|> King
|
||||
ElfKingdomFactory ..|> KingdomFactory
|
||||
OrcArmy ..|> Army
|
||||
OrcCastle ..|> Castle
|
||||
OrcKing ..|> King
|
||||
OrcKingdomFactory ..|> KingdomFactory
|
||||
@enduml
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<artifactId>abstract-factory</artifactId>
|
||||
<dependencies>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
|
||||
@ -39,6 +42,8 @@ package com.iluwatar.abstractfactory;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
private King king;
|
||||
private Castle castle;
|
||||
private Army army;
|
||||
@ -98,17 +103,17 @@ public class App {
|
||||
|
||||
App app = new App();
|
||||
|
||||
System.out.println("Elf Kingdom");
|
||||
LOGGER.info("Elf Kingdom");
|
||||
app.createKingdom(new ElfKingdomFactory());
|
||||
System.out.println(app.getArmy().getDescription());
|
||||
System.out.println(app.getCastle().getDescription());
|
||||
System.out.println(app.getKing().getDescription());
|
||||
LOGGER.info(app.getArmy().getDescription());
|
||||
LOGGER.info(app.getCastle().getDescription());
|
||||
LOGGER.info(app.getKing().getDescription());
|
||||
|
||||
System.out.println("\nOrc Kingdom");
|
||||
LOGGER.info("Orc Kingdom");
|
||||
app.createKingdom(new OrcKingdomFactory());
|
||||
System.out.println(app.getArmy().getDescription());
|
||||
System.out.println(app.getCastle().getDescription());
|
||||
System.out.println(app.getKing().getDescription());
|
||||
LOGGER.info(app.getArmy().getDescription());
|
||||
LOGGER.info(app.getCastle().getDescription());
|
||||
LOGGER.info(app.getKing().getDescription());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -28,6 +28,9 @@ import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for abstract factory
|
||||
*/
|
||||
public class AbstractFactoryTest {
|
||||
|
||||
private App app = new App();
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,18 +1,19 @@
|
||||
@startuml
|
||||
package com.iluwatar.adapter {
|
||||
interface BattleShip {
|
||||
+ fire() {abstract}
|
||||
+ move() {abstract}
|
||||
class App {
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
class BattleFishingBoat {
|
||||
- LOGGER : Logger {static}
|
||||
- boat : FishingBoat
|
||||
+ BattleFishingBoat()
|
||||
+ fire()
|
||||
+ move()
|
||||
}
|
||||
class App {
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
interface BattleShip {
|
||||
+ fire() {abstract}
|
||||
+ move() {abstract}
|
||||
}
|
||||
class Captain {
|
||||
- battleship : BattleShip
|
||||
@ -23,6 +24,7 @@ package com.iluwatar.adapter {
|
||||
+ setBattleship(battleship : BattleShip)
|
||||
}
|
||||
class FishingBoat {
|
||||
- LOGGER : Logger {static}
|
||||
+ FishingBoat()
|
||||
+ fish()
|
||||
+ sail()
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<artifactId>adapter</artifactId>
|
||||
<dependencies>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link BattleShip}
|
||||
@ -33,6 +36,8 @@ package com.iluwatar.adapter;
|
||||
*/
|
||||
public class BattleFishingBoat implements BattleShip {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(BattleFishingBoat.class);
|
||||
|
||||
private FishingBoat boat;
|
||||
|
||||
public BattleFishingBoat() {
|
||||
@ -41,7 +46,7 @@ public class BattleFishingBoat implements BattleShip {
|
||||
|
||||
@Override
|
||||
public void fire() {
|
||||
System.out.println("fire!");
|
||||
LOGGER.info("fire!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Device class (adaptee in the pattern). We want to reuse this class
|
||||
@ -29,12 +32,14 @@ package com.iluwatar.adapter;
|
||||
*/
|
||||
public class FishingBoat {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(FishingBoat.class);
|
||||
|
||||
public void sail() {
|
||||
System.out.println("The Boat is moving to that place");
|
||||
LOGGER.info("The Boat is moving to that place");
|
||||
}
|
||||
|
||||
public void fish() {
|
||||
System.out.println("fishing ...");
|
||||
LOGGER.info("fishing ...");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>aggregator-microservices</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -25,6 +25,9 @@ package com.iluwatar.aggregator.microservices;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Spring Boot EntryPoint Class
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -27,6 +27,8 @@ import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -37,6 +39,8 @@ import java.io.IOException;
|
||||
@Component
|
||||
public class ProductInformationClientImpl implements ProductInformationClient {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInformationClientImpl.class);
|
||||
|
||||
@Override
|
||||
public String getProductTitle() {
|
||||
String response = null;
|
||||
@ -46,7 +50,7 @@ public class ProductInformationClientImpl implements ProductInformationClient {
|
||||
response = EntityUtils.toString(httpResponse.getEntity());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Exception caught.", e);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -27,6 +27,8 @@ import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -37,6 +39,8 @@ import java.io.IOException;
|
||||
@Component
|
||||
public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ProductInventoryClientImpl.class);
|
||||
|
||||
@Override
|
||||
public int getProductInventories() {
|
||||
String response = "0";
|
||||
@ -46,7 +50,7 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
response = EntityUtils.toString(httpResponse.getEntity());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.error("Exception caught.", e);
|
||||
}
|
||||
return Integer.parseInt(response);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -22,15 +22,18 @@
|
||||
*/
|
||||
package com.iluwatar.aggregator.microservices;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test Aggregation of domain objects
|
||||
*/
|
||||
public class AggregatorTest {
|
||||
|
||||
@InjectMocks
|
||||
@ -64,4 +67,4 @@ public class AggregatorTest {
|
||||
assertEquals(inventories, testProduct.getProductInventories());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,15 @@
|
||||
@startuml
|
||||
package com.iluwatar.aggregator.microservices {
|
||||
class ProductInventoryClientImpl {
|
||||
+ ProductInventoryClientImpl()
|
||||
+ getProductInventories() : int
|
||||
class Aggregator {
|
||||
- informationClient : ProductInformationClient
|
||||
- inventoryClient : ProductInventoryClient
|
||||
+ Aggregator()
|
||||
+ getProduct() : Product
|
||||
}
|
||||
class App {
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
interface ProductInventoryClient {
|
||||
+ getProductInventories() : int {abstract}
|
||||
}
|
||||
class Product {
|
||||
- productInventories : int
|
||||
- title : String
|
||||
@ -20,22 +19,25 @@ package com.iluwatar.aggregator.microservices {
|
||||
+ setProductInventories(productInventories : int)
|
||||
+ setTitle(title : String)
|
||||
}
|
||||
class Aggregator {
|
||||
- informationClient : ProductInformationClient
|
||||
- inventoryClient : ProductInventoryClient
|
||||
+ Aggregator()
|
||||
+ getProduct() : Product
|
||||
}
|
||||
class ProductInformationClientImpl {
|
||||
+ ProductInformationClientImpl()
|
||||
+ getProductTitle() : 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 --> "-inventoryClient" ProductInventoryClient
|
||||
Aggregator --> "-informationClient" ProductInformationClient
|
||||
ProductInventoryClientImpl ..|> ProductInventoryClient
|
||||
Aggregator --> "-inventoryClient" ProductInventoryClient
|
||||
ProductInformationClientImpl ..|> ProductInformationClient
|
||||
ProductInventoryClientImpl ..|> ProductInventoryClient
|
||||
@enduml
|
@ -1,12 +1,12 @@
|
||||
@startuml
|
||||
package com.iluwatar.inventory.microservice {
|
||||
class InventoryController {
|
||||
+ InventoryController()
|
||||
+ getProductInventories() : int
|
||||
}
|
||||
class InventoryApplication {
|
||||
+ InventoryApplication()
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
class InventoryController {
|
||||
+ InventoryController()
|
||||
+ getProductInventories() : int
|
||||
}
|
||||
}
|
||||
@enduml
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>aggregator-microservices</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -26,6 +26,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve information about products
|
||||
*/
|
||||
@RestController
|
||||
public class InformationController {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -25,6 +25,9 @@ package com.iluwatar.information.microservice;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for Information Rest Controller
|
||||
*/
|
||||
public class InformationControllerTest {
|
||||
|
||||
@Test
|
||||
@ -36,4 +39,4 @@ public class InformationControllerTest {
|
||||
Assert.assertEquals("The Product Title.", title);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>aggregator-microservices</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -26,6 +26,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve product inventories
|
||||
*/
|
||||
@RestController
|
||||
public class InventoryController {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* Copyright (c) 2014-2016 Ilkka Seppälä
|
||||
* <p/>
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@ -25,8 +25,10 @@ package com.iluwatar.inventory.microservice;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test Inventory Rest Controller
|
||||
*/
|
||||
public class InventoryControllerTest {
|
||||
|
||||
@Test
|
||||
public void testGetProductInventories() throws Exception {
|
||||
InventoryController inventoryController = new InventoryController();
|
||||
@ -35,4 +37,4 @@ public class InventoryControllerTest {
|
||||
|
||||
Assert.assertEquals(5, numberOfInventories);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>aggregator-microservices</artifactId>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>api-gateway</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>api-gateway-service</artifactId>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -35,7 +35,7 @@ import java.io.IOException;
|
||||
* An adapter to communicate with the Image microservice
|
||||
*/
|
||||
@Component
|
||||
public class ImageClientImpl implements ImageClient{
|
||||
public class ImageClientImpl implements ImageClient {
|
||||
/**
|
||||
* Makes a simple HTTP Get request to the Image microservice
|
||||
* @return The path to the image
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -35,7 +35,7 @@ import java.io.IOException;
|
||||
* An adapter to communicate with the Price microservice
|
||||
*/
|
||||
@Component
|
||||
public class PriceClientImpl implements PriceClient{
|
||||
public class PriceClientImpl implements PriceClient {
|
||||
/**
|
||||
* Makes a simple HTTP Get request to the Price microservice
|
||||
* @return The price of the product
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -22,15 +22,18 @@
|
||||
*/
|
||||
package com.iluwatar.api.gateway;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test API Gateway Pattern
|
||||
*/
|
||||
public class ApiGatewayTest {
|
||||
|
||||
@InjectMocks
|
||||
|
@ -1,12 +1,27 @@
|
||||
@startuml
|
||||
package com.iluwatar.api.gateway {
|
||||
class ApiGateway {
|
||||
- imageClient : ImageClient
|
||||
- priceClient : PriceClient
|
||||
+ ApiGateway()
|
||||
+ getProductDesktop() : DesktopProduct
|
||||
+ getProductMobile() : MobileProduct
|
||||
}
|
||||
class App {
|
||||
+ App()
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
class PriceClientImpl {
|
||||
+ PriceClientImpl()
|
||||
class DesktopProduct {
|
||||
- imagePath : String
|
||||
- price : String
|
||||
+ DesktopProduct()
|
||||
+ getImagePath() : String
|
||||
+ getPrice() : String
|
||||
+ setImagePath(imagePath : String)
|
||||
+ setPrice(price : String)
|
||||
}
|
||||
interface ImageClient {
|
||||
+ getImagePath() : String {abstract}
|
||||
}
|
||||
class ImageClientImpl {
|
||||
+ ImageClientImpl()
|
||||
@ -18,31 +33,16 @@ package com.iluwatar.api.gateway {
|
||||
+ getPrice() : String
|
||||
+ setPrice(price : String)
|
||||
}
|
||||
interface ImageClient {
|
||||
+ getImagePath() : String {abstract}
|
||||
}
|
||||
class ApiGateway {
|
||||
- imageClient : ImageClient
|
||||
- priceClient : PriceClient
|
||||
+ ApiGateway()
|
||||
+ getProductDesktop() : DesktopProduct
|
||||
+ getProductMobile() : MobileProduct
|
||||
}
|
||||
class DesktopProduct {
|
||||
- imagePath : String
|
||||
- price : String
|
||||
+ DesktopProduct()
|
||||
+ getImagePath() : String
|
||||
+ getPrice() : String
|
||||
+ setImagePath(imagePath : String)
|
||||
+ setPrice(price : String)
|
||||
}
|
||||
interface PriceClient {
|
||||
+ getPrice() : String {abstract}
|
||||
}
|
||||
class PriceClientImpl {
|
||||
+ PriceClientImpl()
|
||||
+ getPrice() : String
|
||||
}
|
||||
}
|
||||
ApiGateway --> "-imageClient" ImageClient
|
||||
ApiGateway --> "-priceClient" PriceClient
|
||||
PriceClientImpl ..|> PriceClient
|
||||
ImageClientImpl ..|> ImageClient
|
||||
PriceClientImpl ..|> PriceClient
|
||||
@enduml
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>api-gateway</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -25,6 +25,9 @@ package com.iluwatar.image.microservice;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for Image Rest Controller
|
||||
*/
|
||||
public class ImageControllerTest {
|
||||
@Test
|
||||
public void testGetImagePath() {
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>api-gateway</artifactId>
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<artifactId>api-gateway</artifactId>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#
|
||||
# The MIT License
|
||||
# Copyright (c) 2014 Ilkka Seppälä
|
||||
# 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -25,6 +25,10 @@ package com.iluwatar.price.microservice;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Test for Price Rest Controller
|
||||
*/
|
||||
public class PriceControllerTest {
|
||||
@Test
|
||||
public void testgetPrice() {
|
||||
|
@ -1,22 +1,26 @@
|
||||
@startuml
|
||||
package com.iluwatar.async.method.invocation {
|
||||
class App {
|
||||
- LOGGER : Logger {static}
|
||||
+ App()
|
||||
- callback(name : String) : AsyncCallback<T> {static}
|
||||
- lazyval(value : T, delayMillis : long) : Callable<T> {static}
|
||||
- log(msg : String) {static}
|
||||
+ main(args : String[]) {static}
|
||||
}
|
||||
interface AsyncResult<T> {
|
||||
+ await() {abstract}
|
||||
+ getValue() : T {abstract}
|
||||
+ isCompleted() : boolean {abstract}
|
||||
interface AsyncCallback<T> {
|
||||
+ onComplete(T, Optional<Exception>) {abstract}
|
||||
}
|
||||
interface AsyncExecutor {
|
||||
+ endProcess(AsyncResult<T>) : T {abstract}
|
||||
+ startProcess(Callable<T>) : AsyncResult<T> {abstract}
|
||||
+ startProcess(Callable<T>, AsyncCallback<T>) : AsyncResult<T> {abstract}
|
||||
}
|
||||
interface AsyncResult<T> {
|
||||
+ await() {abstract}
|
||||
+ getValue() : T {abstract}
|
||||
+ isCompleted() : boolean {abstract}
|
||||
}
|
||||
class ThreadAsyncExecutor {
|
||||
- idx : AtomicInteger
|
||||
+ ThreadAsyncExecutor()
|
||||
@ -24,9 +28,6 @@ package com.iluwatar.async.method.invocation {
|
||||
+ startProcess(task : Callable<T>) : AsyncResult<T>
|
||||
+ startProcess(task : Callable<T>, callback : AsyncCallback<T>) : AsyncResult<T>
|
||||
}
|
||||
interface AsyncCallback<T> {
|
||||
+ onComplete(T, Optional<Exception>) {abstract}
|
||||
}
|
||||
-class CompletableResult<T> {
|
||||
~ COMPLETED : int {static}
|
||||
~ FAILED : int {static}
|
||||
|
@ -2,7 +2,7 @@
|
||||
<!--
|
||||
|
||||
The MIT License
|
||||
Copyright (c) 2014 Ilkka Seppälä
|
||||
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
|
||||
@ -29,7 +29,7 @@
|
||||
<parent>
|
||||
<groupId>com.iluwatar</groupId>
|
||||
<artifactId>java-design-patterns</artifactId>
|
||||
<version>1.13.0</version>
|
||||
<version>1.15.0</version>
|
||||
</parent>
|
||||
<artifactId>async-method-invocation</artifactId>
|
||||
<dependencies>
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -22,6 +22,9 @@
|
||||
*/
|
||||
package com.iluwatar.async.method.invocation;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
@ -54,6 +57,8 @@ import java.util.concurrent.Callable;
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
*/
|
||||
@ -120,6 +125,6 @@ public class App {
|
||||
}
|
||||
|
||||
private static void log(String msg) {
|
||||
System.out.println(String.format("[%1$-10s] - %2$s", Thread.currentThread().getName(), msg));
|
||||
LOGGER.info(msg);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -25,8 +25,8 @@ package com.iluwatar.async.method.invocation;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
*
|
||||
* AsyncResult interface
|
||||
* @param <T> parameter returned when getValue is invoked
|
||||
*/
|
||||
public interface AsyncResult<T> {
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -57,12 +57,10 @@ public class ThreadAsyncExecutor implements AsyncExecutor {
|
||||
|
||||
@Override
|
||||
public <T> T endProcess(AsyncResult<T> asyncResult) throws ExecutionException, InterruptedException {
|
||||
if (asyncResult.isCompleted()) {
|
||||
return asyncResult.getValue();
|
||||
} else {
|
||||
if (!asyncResult.isCompleted()) {
|
||||
asyncResult.await();
|
||||
return asyncResult.getValue();
|
||||
}
|
||||
return asyncResult.getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
|
@ -1,6 +1,6 @@
|
||||
/**
|
||||
* The MIT License
|
||||
* Copyright (c) 2014 Ilkka Seppälä
|
||||
* 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
|
||||
@ -31,7 +31,6 @@ import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
|
||||
|
27
balking/README.md
Normal file
27
balking/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
---
|
||||
layout: pattern
|
||||
title: Balking
|
||||
folder: balking
|
||||
permalink: /patterns/balking/
|
||||
categories: Concurrency
|
||||
tags:
|
||||
- Java
|
||||
- Difficulty-Beginner
|
||||
---
|
||||
|
||||
## Intent
|
||||
Balking Pattern is used to prevent an object from executing certain code if it is an
|
||||
incomplete or inappropriate state
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
Use the Balking pattern when
|
||||
|
||||
*you want to invoke an action on an object only when it is in a particular state
|
||||
*objects are generally only in a state that is prone to balking temporarily
|
||||
but for an unknown amount of time
|
||||
|
||||
## Related patterns
|
||||
* Guarded Suspendion Pattern
|
||||
* Double Checked Locking Pattern
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user