Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-architectural</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-architectural</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -21,8 +21,8 @@
|
||||
<version>${assertj-core.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax</groupId>
|
||||
<artifactId>javaee-api</artifactId>
|
||||
<version>${javaee.version}</version>
|
||||
@@ -39,16 +39,15 @@
|
||||
<type>jar</type>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
<assertj-core.version>3.9.1</assertj-core.version>
|
||||
|
||||
<javaee.version>8.0</javaee.version>
|
||||
<hibernate-core.version>5.2.16.Final</hibernate-core.version>
|
||||
<mysql-connector.version>6.0.6</mysql-connector.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-behavioral-2</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-behavioral-2</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -22,12 +22,12 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
<assertj.version>3.12.2</assertj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-behavioral</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-behavioral</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -31,7 +31,7 @@
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
@@ -39,13 +39,13 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
<intellij.annotations.version>16.0.2</intellij.annotations.version>
|
||||
<assertj-core.version>3.9.1</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>design-patterns-cloud</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>design-patterns-cloud</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-creational</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-creational</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -26,7 +26,7 @@
|
||||
<artifactId>jsr305</artifactId>
|
||||
<version>${javax.annotations.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
@@ -34,14 +34,15 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
<freebuilder.version>2.4.1</freebuilder.version>
|
||||
<javax.annotations.version>3.0.2</javax.annotations.version>
|
||||
<assertj-core.version>3.9.1</assertj-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.prototype;
|
||||
|
||||
public class PineTree extends Tree {
|
||||
|
||||
private String type;
|
||||
|
||||
public PineTree(double mass, double height) {
|
||||
super(mass, height);
|
||||
this.type = "Pine";
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree copy() {
|
||||
PineTree pineTreeClone = new PineTree(this.getMass(), this.getHeight());
|
||||
pineTreeClone.setPosition(this.getPosition());
|
||||
return pineTreeClone;
|
||||
}
|
||||
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.prototype;
|
||||
|
||||
public class PlasticTree extends Tree {
|
||||
|
||||
private String name;
|
||||
|
||||
public PlasticTree(double mass, double height) {
|
||||
super(mass, height);
|
||||
this.name = "PlasticTree";
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree copy() {
|
||||
PlasticTree plasticTreeClone = new PlasticTree(this.getMass(), this.getHeight());
|
||||
plasticTreeClone.setPosition(this.getPosition());
|
||||
return plasticTreeClone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.prototype;
|
||||
|
||||
public class Tree implements Cloneable {
|
||||
public abstract class Tree {
|
||||
|
||||
private double mass;
|
||||
private double height;
|
||||
@@ -35,20 +35,10 @@ public class Tree implements Cloneable {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tree clone() {
|
||||
Tree tree = null;
|
||||
try {
|
||||
tree = (Tree) super.clone();
|
||||
} catch (CloneNotSupportedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tree;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tree [mass=" + mass + ", height=" + height + ", position=" + position + "]";
|
||||
}
|
||||
|
||||
public abstract Tree copy();
|
||||
}
|
||||
|
||||
+51
-7
@@ -2,23 +2,67 @@ package com.baeldung.prototype;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class TreePrototypeUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenATreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
public void givenAPlasticTreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
double mass = 10.0;
|
||||
double height = 3.7;
|
||||
Position position = new Position(3, 7);
|
||||
Position otherPosition = new Position(4, 8);
|
||||
|
||||
Tree tree = new Tree(mass, height);
|
||||
tree.setPosition(position);
|
||||
Tree anotherTree = tree.clone();
|
||||
anotherTree.setPosition(otherPosition);
|
||||
PlasticTree plasticTree = new PlasticTree(mass, height);
|
||||
plasticTree.setPosition(position);
|
||||
PlasticTree anotherPlasticTree = (PlasticTree) plasticTree.copy();
|
||||
anotherPlasticTree.setPosition(otherPosition);
|
||||
|
||||
assertEquals(position, tree.getPosition());
|
||||
assertEquals(otherPosition, anotherTree.getPosition());
|
||||
assertEquals(position, plasticTree.getPosition());
|
||||
assertEquals(otherPosition, anotherPlasticTree.getPosition());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenAPineTreePrototypeWhenClonedThenCreateA_Clone() {
|
||||
double mass = 10.0;
|
||||
double height = 3.7;
|
||||
Position position = new Position(3, 7);
|
||||
Position otherPosition = new Position(4, 8);
|
||||
|
||||
PineTree pineTree = new PineTree(mass, height);
|
||||
pineTree.setPosition(position);
|
||||
PineTree anotherPineTree = (PineTree) pineTree.copy();
|
||||
anotherPineTree.setPosition(otherPosition);
|
||||
|
||||
assertEquals(position, pineTree.getPosition());
|
||||
assertEquals(otherPosition, anotherPineTree.getPosition());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenA_ListOfTreesWhenClonedThenCreateListOfClones() {
|
||||
double mass = 10.0;
|
||||
double height = 3.7;
|
||||
Position position = new Position(3, 7);
|
||||
Position otherPosition = new Position(4, 8);
|
||||
|
||||
PlasticTree plasticTree = new PlasticTree(mass, height);
|
||||
plasticTree.setPosition(position);
|
||||
PineTree pineTree = new PineTree(mass, height);
|
||||
pineTree.setPosition(otherPosition);
|
||||
|
||||
List<Tree> trees = Arrays.asList(plasticTree, pineTree);
|
||||
|
||||
List<Tree> treeClones = trees.stream().map(Tree::copy).collect(toList());
|
||||
|
||||
Tree plasticTreeClone = treeClones.get(0);
|
||||
|
||||
assertEquals(mass, plasticTreeClone.getMass());
|
||||
assertEquals(height, plasticTreeClone.getHeight());
|
||||
assertEquals(position, plasticTreeClone.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-functional</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-functional</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -14,12 +14,10 @@
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<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>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -5,3 +5,4 @@
|
||||
- [The Decorator Pattern in Java](https://www.baeldung.com/java-decorator-pattern)
|
||||
- [The Adapter Pattern in Java](https://www.baeldung.com/java-adapter-pattern)
|
||||
- [The Proxy Pattern in Java](https://www.baeldung.com/java-proxy-pattern)
|
||||
- [The Bridge Pattern in Java](https://www.baeldung.com/java-bridge-pattern)
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>design-patterns-structural</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>design-patterns-structural</name>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
@@ -21,10 +21,11 @@
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<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>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.dip</groupId>
|
||||
<artifactId>dip</artifactId>
|
||||
<name>dip</name>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>dip</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
@@ -29,7 +29,7 @@
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<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">
|
||||
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>
|
||||
<artifactId>front-controller</artifactId>
|
||||
<name>front-controller</name>
|
||||
<name>front-controller</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<artifactId>patterns</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>patterns</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
@@ -37,4 +37,5 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
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>
|
||||
<artifactId>intercepting-filter</artifactId>
|
||||
<name>intercepting-filter</name>
|
||||
<name>intercepting-filter</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
|
||||
+1
-1
@@ -3,8 +3,8 @@
|
||||
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>
|
||||
<artifactId>patterns</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>patterns</name>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
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>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>solid</artifactId>
|
||||
<name>solid</name>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>solid</name>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
|
||||
Reference in New Issue
Block a user