Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
0c6237c
Type object pattern #555 (#848)
AnaghaSasikumar Jul 24, 2019
17bfc91
Change Travis CI build env. to Trusty (#911)
ptrax Jul 28, 2019
c6ecf58
508 : sonar qube critical issue fixes (#852)
kanwarpreet25 Jul 28, 2019
f7e22a1
508 : Sonar qube critical Issue Fix (#854)
kanwarpreet25 Jul 28, 2019
a113de6
Add licenses
iluwatar Jul 28, 2019
d9a567c
Commander pattern #505 (#857)
AnaghaSasikumar Jul 29, 2019
2757b21
Best practice when compare enum (#869)
hoangnam2261 Jul 29, 2019
aaabc8f
Fix the dependency conflict issue (#872)
HelloCoCooo Jul 29, 2019
b497d41
Modify Observer pattern UML (#877)
dRadest Jul 29, 2019
3454941
Typo coresponding -> corresponding (#879)
pierDipi Jul 29, 2019
36e80c4
fixed failing tests (#860) (#880)
id4us Jul 29, 2019
517c209
Added one more Credit/Article about the benefits of Repository patter…
tomrlh Jul 29, 2019
6daaeec
Remove the transitive dependency(junit-jupiter-api) (#916)
hoangnam2261 Jul 30, 2019
ccb257d
fixed bug #883 (#885)
ranjeet-floyd Aug 4, 2019
61ef59d
fix code example containing syntax error (#890)
makaravind Aug 11, 2019
085e47b
Update SonarCloud badge
iluwatar Aug 21, 2019
11c0550
Create .sonarcloud.properties
iluwatar Aug 21, 2019
7f6067f
Added priority queue design pattern (#888)
ranjeet-floyd Aug 31, 2019
318f811
Bytecode pattern #553 (#896)
pzawitowski Sep 3, 2019
35dc25d
MInor bug fix Issue #895 -> Code comment change (https://github.com/i…
saksham93 Sep 7, 2019
c653edf
fix must override a superclass method (#919)
anancds Sep 7, 2019
8c865e6
clean code (#910)
ibrahimAlii Sep 7, 2019
f141033
Fix issue #761: ThreadSafeDoubleCheckLocking.java: Instantiating by R…
Azureyjt Sep 7, 2019
88fae07
Fix broken links #915 (#921)
snehalatapandit Sep 7, 2019
9bf7a05
Java Design Patterns v1.21.0
iluwatar Sep 8, 2019
b874adc
Set version for next development iteration
iluwatar Sep 8, 2019
019abc9
Add license headers
iluwatar Sep 10, 2019
5f39f7f
Updating README.md file to update doc as suggested in issue#925 (#926)
hbothra15 Sep 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# The MIT License
# Copyright (c) 2014 Ilkka Seppälä
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

# Path to sources
#sonar.sources=.
#sonar.exclusions=
#sonar.inclusions=

# Path to tests
#sonar.tests=
#sonar.test.exclusions=
#sonar.test.inclusions=

# Source encoding
#sonar.sourceEncoding=UTF-8

# Exclusions for copy-paste detection
#sonar.cpd.exclusions=
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: java
dist: trusty # Xenial build environment won't allow installation of Java 8
jdk:
- oraclejdk8

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master)](https://travis-ci.org/iluwatar/java-design-patterns)
[![License MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/LICENSE.md)
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Quality Gate](https://sonarcloud.io/api/project_badges/measure?project=com.iluwatar%3Ajava-design-patterns&metric=alert_status)](https://sonarcloud.io/dashboard/index/com.iluwatar%3Ajava-design-patterns)
[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=alert_status)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)

# Introduction

Expand Down
9 changes: 2 additions & 7 deletions abstract-document/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
<parent>
<artifactId>java-design-patterns</artifactId>
<groupId>com.iluwatar</groupId>
<version>1.21.0-SNAPSHOT</version>
<version>1.22.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-document</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,16 @@ public Object get(String key) {

@Override
public <T> Stream<T> children(String key, Function<Map<String, Object>, T> constructor) {
Optional<List<Map<String, Object>>> any = Stream.of(get(key)).filter(el -> el != null)
Optional<List<Map<String, Object>>> any = Stream.of(get(key)).filter(Objects::nonNull)
.map(el -> (List<Map<String, Object>>) el).findAny();
return any.isPresent() ? any.get().stream().map(constructor) : Stream.empty();
return any.map(maps -> maps.stream().map(constructor)).orElseGet(Stream::empty);
}

@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getName()).append("[");
properties.entrySet()
.forEach(e -> builder.append("[").append(e.getKey()).append(" : ").append(e.getValue()).append("]"));
properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value).append("]"));
builder.append("]");
return builder.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
*/
package com.iluwatar.abstractdocument;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.HasModel;
import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* The Abstract Document pattern enables handling additional, non-static
* properties. This pattern uses concept of traits to enable type safety and
Expand All @@ -55,20 +53,20 @@ public App() {
LOGGER.info("Constructing parts and car");

Map<String, Object> carProperties = new HashMap<>();
carProperties.put(HasModel.PROPERTY, "300SL");
carProperties.put(HasPrice.PROPERTY, 10000L);
carProperties.put(Property.MODEL.toString(), "300SL");
carProperties.put(Property.PRICE.toString(), 10000L);

Map<String, Object> wheelProperties = new HashMap<>();
wheelProperties.put(HasType.PROPERTY, "wheel");
wheelProperties.put(HasModel.PROPERTY, "15C");
wheelProperties.put(HasPrice.PROPERTY, 100L);
wheelProperties.put(Property.TYPE.toString(), "wheel");
wheelProperties.put(Property.MODEL.toString(), "15C");
wheelProperties.put(Property.PRICE.toString(), 100L);

Map<String, Object> doorProperties = new HashMap<>();
doorProperties.put(HasType.PROPERTY, "door");
doorProperties.put(HasModel.PROPERTY, "Lambo");
doorProperties.put(HasPrice.PROPERTY, 300L);
doorProperties.put(Property.TYPE.toString(), "door");
doorProperties.put(Property.MODEL.toString(), "Lambo");
doorProperties.put(Property.PRICE.toString(), 300L);

carProperties.put(HasParts.PROPERTY, Arrays.asList(wheelProperties, doorProperties));
carProperties.put(Property.PARTS.toString(), Arrays.asList(wheelProperties, doorProperties));

Car car = new Car(carProperties);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
import java.util.Optional;

import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* HasModel trait for static access to 'model' property
*/
public interface HasModel extends Document {

String PROPERTY = "model";

default Optional<String> getModel() {
return Optional.ofNullable((String) get(PROPERTY));
return Optional.ofNullable((String) get(Property.MODEL.toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
import java.util.stream.Stream;

import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* HasParts trait for static access to 'parts' property
*/
public interface HasParts extends Document {

String PROPERTY = "parts";

default Stream<Part> getParts() {
return children(PROPERTY, Part::new);
return children(Property.PARTS.toString(), Part::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
import java.util.Optional;

import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* HasPrice trait for static access to 'price' property
*/
public interface HasPrice extends Document {

String PROPERTY = "price";

default Optional<Number> getPrice() {
return Optional.ofNullable((Number) get(PROPERTY));
return Optional.ofNullable((Number) get(Property.PRICE.toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@
*/
package com.iluwatar.abstractdocument.domain;

import com.iluwatar.abstractdocument.Document;

import java.util.Optional;

import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* HasType trait for static access to 'type' property
*/
public interface HasType extends Document {

String PROPERTY = "type";

default Optional<String> getType() {
return Optional.ofNullable((String) get(PROPERTY));
return Optional.ofNullable((String) get(Property.TYPE.toString()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* The MIT License
* Copyright (c) 2014 Ilkka Seppälä
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.iluwatar.abstractdocument.domain.enums;

/**
*
* Enum To Describe Property type
*
*/
public enum Property {

PARTS, TYPE, PRICE, MODEL
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@
*/
package com.iluwatar.abstractdocument;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.HasModel;
import com.iluwatar.abstractdocument.domain.HasParts;
import com.iluwatar.abstractdocument.domain.HasPrice;
import com.iluwatar.abstractdocument.domain.HasType;
import com.iluwatar.abstractdocument.domain.Part;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;

import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.Part;
import com.iluwatar.abstractdocument.domain.enums.Property;

/**
* Test for Part and Car
Expand All @@ -51,9 +49,9 @@ public class DomainTest {
@Test
public void shouldConstructPart() {
Map<String, Object> partProperties = new HashMap<>();
partProperties.put(HasType.PROPERTY, TEST_PART_TYPE);
partProperties.put(HasModel.PROPERTY, TEST_PART_MODEL);
partProperties.put(HasPrice.PROPERTY, TEST_PART_PRICE);
partProperties.put(Property.TYPE.toString(), TEST_PART_TYPE);
partProperties.put(Property.MODEL.toString(), TEST_PART_MODEL);
partProperties.put(Property.PRICE.toString(), TEST_PART_PRICE);
Part part = new Part(partProperties);

assertEquals(TEST_PART_TYPE, part.getType().get());
Expand All @@ -64,9 +62,9 @@ public void shouldConstructPart() {
@Test
public void shouldConstructCar() {
Map<String, Object> carProperties = new HashMap<>();
carProperties.put(HasModel.PROPERTY, TEST_CAR_MODEL);
carProperties.put(HasPrice.PROPERTY, TEST_CAR_PRICE);
carProperties.put(HasParts.PROPERTY, Arrays.asList(new HashMap<>(), new HashMap<>()));
carProperties.put(Property.MODEL.toString(), TEST_CAR_MODEL);
carProperties.put(Property.PRICE.toString(), TEST_CAR_PRICE);
carProperties.put(Property.PARTS.toString(), Arrays.asList(new HashMap<>(), new HashMap<>()));
Car car = new Car(carProperties);

assertEquals(TEST_CAR_MODEL, car.getModel().get());
Expand Down
7 changes: 1 addition & 6 deletions abstract-factory/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.21.0-SNAPSHOT</version>
<version>1.22.0-SNAPSHOT</version>
</parent>
<artifactId>abstract-factory</artifactId>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
*/
public class ElfKingdomFactory implements KingdomFactory {

@Override
public Castle createCastle() {
return new ElfCastle();
}

@Override
public King createKing() {
return new ElfKing();
}

@Override
public Army createArmy() {
return new ElfArmy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,17 @@
*/
public class OrcKingdomFactory implements KingdomFactory {

@Override
public Castle createCastle() {
return new OrcCastle();
}

@Override
public King createKing() {
return new OrcKing();
}

@Override
public Army createArmy() {
return new OrcArmy();
}
Expand Down
7 changes: 1 addition & 6 deletions acyclic-visitor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<groupId>com.iluwatar</groupId>
<artifactId>java-design-patterns</artifactId>
<version>1.21.0-SNAPSHOT</version>
<version>1.22.0-SNAPSHOT</version>
</parent>

<artifactId>acyclic-visitor</artifactId>
Expand All @@ -56,11 +56,6 @@
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
Expand Down
Loading