Skip to content

Commit 547d798

Browse files
Merge pull request iluwatar#1 from iluwatar/master
merging changes into fork from origin
2 parents db6ec3c + 3001fa4 commit 547d798

File tree

1,283 files changed

+67513
-9846
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,283 files changed

+67513
-9846
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ target
1111
.idea
1212
*.iml
1313
*.swp
14+
datanucleus.log
15+
/bin/
16+
/bin/
17+
/bin/
1418

19+
data-mapper/src/main/resources/log4j.xml

.travis.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
language: java
2-
32
jdk:
4-
- oraclejdk8
3+
- oraclejdk8
54

6-
# whitelist
7-
branches:
8-
only:
9-
- master
5+
env:
6+
global:
7+
- GH_REF: github.com/iluwatar/java-design-patterns.git
8+
- secure: LxTDuNS/rBWIvKkaEqr79ImZAe48mCdoYCF41coxNXgNoippo4GIBArknqtv+XvdkiuRZ1yGyj6pn8GU33c/yn+krddTUkVCwTbVatbalW5jhQjDbHYym/JcxaK9ZS/3JTeGcWrBgiPqHEEDhCf26vPZsXoMSeVCEORVKTp1BSg=
9+
10+
before_install:
11+
- export DISPLAY=:99.0
12+
- sh -e /etc/init.d/xvfb start
1013

1114
after_success:
12-
- mvn clean test jacoco:report coveralls:report
15+
- mvn clean test jacoco:report coveralls:report
16+
- bash update-ghpages.sh
17+
18+
sudo: false # route the build to the container-based infrastructure for a faster build

CODE_COVERAGE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Code Coverage Report generation
2+
3+
To generate the code coverage report, execute the following command:
4+
> mvn clean verify
5+
6+
This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser.
7+
> target/site/jacoco/index.html
8+
9+
Please note that the above folder is created under each of the modules. For example:
10+
* adapter/target/site/jacoco/index.html
11+
* busniess-delegate/target/site/jacoco/index.html
12+
13+

CONTRIBUTING.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
This is great you have something to contribute!
2+
3+
Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki)
4+
with conventions and rules we used for this project.

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2014 Ilkka Seppälä
3+
Copyright (c) 2014-2016 Ilkka Seppälä
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 29 additions & 721 deletions
Large diffs are not rendered by default.

abstract-document/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
layout: pattern
3+
title: Abstract Document
4+
folder: abstract-document
5+
permalink: /patterns/abstract-document/
6+
categories: Structural
7+
tags:
8+
- Java
9+
- Difficulty-Intermediate
10+
---
11+
12+
## Intent
13+
Achieve flexibility of untyped languages and keep the type-safety
14+
15+
![alt text](./etc/abstract-document-base.png "Abstract Document Base")
16+
17+
![alt text](./etc/abstract-document.png "Abstract Document Traits and Domain")
18+
19+
20+
## Applicability
21+
Use the Abstract Document Pattern when
22+
23+
* there is a need to add new properties on the fly
24+
* you want a flexible way to organize domain in tree like structure
25+
* you want more loosely coupled system
26+
27+
28+
## Credits
29+
30+
* [Wikipedia: Abstract Document Pattern](https://en.wikipedia.org/wiki/Abstract_Document_Pattern)
31+
* [Martin Fowler: Dealing with properties](http://martinfowler.com/apsupp/properties.pdf)
14.6 KB
Loading
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
3+
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
4+
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
5+
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
6+
<position height="-1" width="-1" x="249" y="405"/>
7+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
8+
sort-features="false" accessors="true" visibility="true">
9+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
10+
<operations public="true" package="true" protected="true" private="true" static="true"/>
11+
</display>
12+
</interface>
13+
<class id="2" language="java" name="com.iluwatar.abstractdocument.AbstractDocument" project="design-patterns"
14+
file="/design-patterns/src/com/iluwatar/abstractdocument/AbstractDocument.java" binary="false" corner="BOTTOM_RIGHT">
15+
<position height="-1" width="-1" x="250" y="237"/>
16+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
17+
sort-features="false" accessors="true" visibility="true">
18+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
19+
<operations public="true" package="true" protected="true" private="true" static="true"/>
20+
</display>
21+
</class>
22+
<class id="3" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
23+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
24+
<position height="-1" width="-1" x="108" y="75"/>
25+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
26+
sort-features="false" accessors="true" visibility="true">
27+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
28+
<operations public="true" package="true" protected="true" private="true" static="true"/>
29+
</display>
30+
</class>
31+
<class id="4" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
32+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
33+
<position height="-1" width="-1" x="400" y="76"/>
34+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
35+
sort-features="false" accessors="true" visibility="true">
36+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
37+
<operations public="true" package="true" protected="true" private="true" static="true"/>
38+
</display>
39+
</class>
40+
<generalization id="5">
41+
<end type="SOURCE" refId="4"/>
42+
<end type="TARGET" refId="2"/>
43+
</generalization>
44+
<realization id="6">
45+
<end type="SOURCE" refId="2"/>
46+
<end type="TARGET" refId="1"/>
47+
</realization>
48+
<generalization id="7">
49+
<end type="SOURCE" refId="3"/>
50+
<end type="TARGET" refId="2"/>
51+
</generalization>
52+
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
53+
sort-features="false" accessors="true" visibility="true">
54+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
55+
<operations public="true" package="true" protected="true" private="true" static="true"/>
56+
</classifier-display>
57+
<association-display labels="true" multiplicity="true"/>
58+
</class-diagram>
16.3 KB
Loading
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<class-diagram version="1.1.9" icons="true" automaticImage="PNG" always-add-relationships="false" generalizations="true"
3+
realizations="true" associations="true" dependencies="false" nesting-relationships="true" router="FAN">
4+
<interface id="1" language="java" name="com.iluwatar.abstractdocument.Document" project="design-patterns"
5+
file="/design-patterns/src/com/iluwatar/abstractdocument/Document.java" binary="false" corner="BOTTOM_RIGHT">
6+
<position height="-1" width="-1" x="341" y="376"/>
7+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
8+
sort-features="false" accessors="true" visibility="true">
9+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
10+
<operations public="true" package="true" protected="true" private="true" static="true"/>
11+
</display>
12+
</interface>
13+
<interface id="2" language="java" name="com.iluwatar.abstractdocument.domain.HasModel" project="design-patterns"
14+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasModel.java" binary="false" corner="BOTTOM_RIGHT">
15+
<position height="81" width="173" x="41" y="194"/>
16+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
17+
sort-features="false" accessors="true" visibility="true">
18+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
19+
<operations public="true" package="true" protected="true" private="true" static="true"/>
20+
</display>
21+
</interface>
22+
<interface id="3" language="java" name="com.iluwatar.abstractdocument.domain.HasPrice" project="design-patterns"
23+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasPrice.java" binary="false" corner="BOTTOM_RIGHT">
24+
<position height="81" width="175" x="254" y="194"/>
25+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
26+
sort-features="false" accessors="true" visibility="true">
27+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
28+
<operations public="true" package="true" protected="true" private="true" static="true"/>
29+
</display>
30+
</interface>
31+
<interface id="4" language="java" name="com.iluwatar.abstractdocument.domain.HasParts" project="design-patterns"
32+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/HasParts.java" binary="false" corner="BOTTOM_RIGHT">
33+
<position height="81" width="173" x="469" y="194"/>
34+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
35+
sort-features="false" accessors="true" visibility="true">
36+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
37+
<operations public="true" package="true" protected="true" private="true" static="true"/>
38+
</display>
39+
</interface>
40+
<class id="5" language="java" name="com.iluwatar.abstractdocument.domain.Car" project="design-patterns"
41+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Car.java" binary="false" corner="BOTTOM_RIGHT">
42+
<position height="99" width="173" x="254" y="37"/>
43+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
44+
sort-features="false" accessors="true" visibility="true">
45+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
46+
<operations public="true" package="true" protected="true" private="true" static="true"/>
47+
</display>
48+
</class>
49+
<class id="6" language="java" name="com.iluwatar.abstractdocument.domain.Part" project="design-patterns"
50+
file="/design-patterns/src/com/iluwatar/abstractdocument/domain/Part.java" binary="false" corner="BOTTOM_RIGHT">
51+
<position height="99" width="173" x="41" y="37"/>
52+
<display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
53+
sort-features="false" accessors="true" visibility="true">
54+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
55+
<operations public="true" package="true" protected="true" private="true" static="true"/>
56+
</display>
57+
</class>
58+
<realization id="7">
59+
<end type="SOURCE" refId="5"/>
60+
<end type="TARGET" refId="2"/>
61+
</realization>
62+
<realization id="8">
63+
<end type="SOURCE" refId="6"/>
64+
<end type="TARGET" refId="2"/>
65+
</realization>
66+
<generalization id="9">
67+
<end type="SOURCE" refId="2"/>
68+
<end type="TARGET" refId="1"/>
69+
</generalization>
70+
<realization id="10">
71+
<end type="SOURCE" refId="5"/>
72+
<end type="TARGET" refId="3"/>
73+
</realization>
74+
<realization id="11">
75+
<end type="SOURCE" refId="5"/>
76+
<end type="TARGET" refId="4"/>
77+
</realization>
78+
<generalization id="12">
79+
<end type="SOURCE" refId="3"/>
80+
<end type="TARGET" refId="1"/>
81+
</generalization>
82+
<generalization id="13">
83+
<end type="SOURCE" refId="4"/>
84+
<end type="TARGET" refId="1"/>
85+
</generalization>
86+
<realization id="14">
87+
<end type="SOURCE" refId="6"/>
88+
<end type="TARGET" refId="3"/>
89+
</realization>
90+
<classifier-display autosize="true" stereotype="true" package="true" initial-value="false" signature="true"
91+
sort-features="false" accessors="true" visibility="true">
92+
<attributes public="true" package="true" protected="true" private="true" static="true"/>
93+
<operations public="true" package="true" protected="true" private="true" static="true"/>
94+
</classifier-display>
95+
<association-display labels="true" multiplicity="true"/>
96+
</class-diagram>

abstract-document/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
The MIT License
5+
Copyright (c) 2014 Ilkka Seppälä
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
25+
-->
26+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
27+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
28+
<modelVersion>4.0.0</modelVersion>
29+
<parent>
30+
<artifactId>java-design-patterns</artifactId>
31+
<groupId>com.iluwatar</groupId>
32+
<version>1.13.0-SNAPSHOT</version>
33+
</parent>
34+
<artifactId>abstract-document</artifactId>
35+
<dependencies>
36+
<dependency>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
<scope>test</scope>
40+
</dependency>
41+
</dependencies>
42+
</project>
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* The MIT License
3+
* Copyright (c) 2014 Ilkka Seppälä
4+
* <p>
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
* <p>
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
* <p>
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
* THE SOFTWARE.
22+
*/
23+
package com.iluwatar.abstractdocument;
24+
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.Objects;
28+
import java.util.Optional;
29+
import java.util.function.Function;
30+
import java.util.stream.Stream;
31+
32+
/**
33+
* Abstract implementation of Document interface
34+
*/
35+
public abstract class AbstractDocument implements Document {
36+
37+
private final Map<String, Object> properties;
38+
39+
protected AbstractDocument(Map<String, Object> properties) {
40+
Objects.requireNonNull(properties, "properties map is required");
41+
this.properties = properties;
42+
}
43+
44+
@Override
45+
public Void put(String key, Object value) {
46+
properties.put(key, value);
47+
return null;
48+
}
49+
50+
@Override
51+
public Object get(String key) {
52+
return properties.get(key);
53+
}
54+
55+
@Override
56+
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
57+
Optional<List<Map<String, Object>>> any = Stream.of(get(key)).filter(el -> el != null)
58+
.map(el -> (List<Map<String, Object>>) el).findAny();
59+
return any.isPresent() ? any.get().stream().map(constructor) : Stream.empty();
60+
}
61+
62+
@Override
63+
public String toString() {
64+
StringBuilder builder = new StringBuilder();
65+
builder.append(getClass().getName()).append("[");
66+
properties.entrySet()
67+
.forEach(e -> builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]"));
68+
builder.append("]");
69+
return builder.toString();
70+
}
71+
72+
}

0 commit comments

Comments
 (0)