diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD new file mode 100644 index 000000000..39087fbf1 --- /dev/null +++ b/CONTRIBUTING.MD @@ -0,0 +1,4 @@ +This is great you have something to contribute! + +Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki) +with conventions and rules we used for this project. diff --git a/README.md b/README.md index 64ac04329..f1ce0bfc7 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ that smart and dearly wants an empty line before a heading to be able to display it as such, e.g. website) --> -# Design pattern samples in Java +# Design patterns implemented in Java [![Build status](https://travis-ci.org/iluwatar/java-design-patterns.svg?branch=master)](https://travis-ci.org/iluwatar/java-design-patterns) [![Coverage Status](https://coveralls.io/repos/iluwatar/java-design-patterns/badge.svg?branch=master)](https://coveralls.io/r/iluwatar/java-design-patterns?branch=master) diff --git a/abstract-factory/index.md b/abstract-factory/index.md index f824f7e0e..f31ed2d01 100644 --- a/abstract-factory/index.md +++ b/abstract-factory/index.md @@ -7,6 +7,7 @@ categories: Creational tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Also known as:** Kit diff --git a/adapter/index.md b/adapter/index.md index 7c7dc15e5..f77018e45 100644 --- a/adapter/index.md +++ b/adapter/index.md @@ -7,6 +7,7 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Beginner --- **Also known as:** Wrapper diff --git a/async-method-invocation/index.md b/async-method-invocation/index.md index dfcee0208..b9fadb886 100644 --- a/async-method-invocation/index.md +++ b/async-method-invocation/index.md @@ -4,7 +4,10 @@ title: Async Method Invocation folder: async-method-invocation permalink: /patterns/async-method-invocation/ categories: Concurrency -tags: Java +tags: + - Java + - Difficulty-Intermediate + - Functional --- **Intent:** Asynchronous method invocation is pattern where the calling thread diff --git a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java index 9c43fa1b1..c9d222e55 100644 --- a/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java +++ b/async-method-invocation/src/test/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutorTest.java @@ -89,9 +89,9 @@ public class ThreadAsyncExecutorTest { final Object result = new Object(); final Callable task = mock(Callable.class); when(task.call()).thenAnswer(i -> { - Thread.sleep(1500); - return result; - }); + Thread.sleep(1500); + return result; + }); final AsyncResult asyncResult = executor.startProcess(task); assertNotNull(asyncResult); @@ -128,9 +128,9 @@ public class ThreadAsyncExecutorTest { final Object result = new Object(); final Callable task = mock(Callable.class); when(task.call()).thenAnswer(i -> { - Thread.sleep(1500); - return result; - }); + Thread.sleep(1500); + return result; + }); final AsyncCallback callback = mock(AsyncCallback.class); final AsyncResult asyncResult = executor.startProcess(task, callback); @@ -177,9 +177,9 @@ public class ThreadAsyncExecutorTest { final Object result = new Object(); final Callable task = mock(Callable.class); when(task.call()).thenAnswer(i -> { - Thread.sleep(1500); - return result; - }); + Thread.sleep(1500); + return result; + }); final AsyncResult asyncResult = executor.startProcess(task); assertNotNull(asyncResult); diff --git a/bridge/index.md b/bridge/index.md index 4a1d0bcbb..008325ce5 100644 --- a/bridge/index.md +++ b/bridge/index.md @@ -7,6 +7,7 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Also known as:** Handle/Body diff --git a/builder/index.md b/builder/index.md index f350638d2..8f299d116 100644 --- a/builder/index.md +++ b/builder/index.md @@ -7,6 +7,7 @@ categories: Creational tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Intent:** Separate the construction of a complex object from its diff --git a/business-delegate/index.md b/business-delegate/index.md index a55febaf9..0b28a5a2f 100644 --- a/business-delegate/index.md +++ b/business-delegate/index.md @@ -4,7 +4,9 @@ title: Business Delegate folder: business-delegate permalink: /patterns/business-delegate/ categories: Business Tier -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** The Business Delegate pattern adds an abstraction layer between diff --git a/caching/index.md b/caching/index.md index f79f13e42..d15fbb7d9 100644 --- a/caching/index.md +++ b/caching/index.md @@ -6,6 +6,8 @@ permalink: /patterns/caching/ categories: Other tags: - Java + - Difficulty-Intermediate + - Performance --- **Intent:** To avoid expensive re-acquisition of resources by not releasing diff --git a/callback/index.md b/callback/index.md index b724f1edc..a70da1ff4 100644 --- a/callback/index.md +++ b/callback/index.md @@ -4,7 +4,11 @@ title: Callback folder: callback permalink: /patterns/callback/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Beginner + - Functional + - Idiom --- **Intent:** Callback is a piece of executable code that is passed as an diff --git a/chain/index.md b/chain/index.md index 9be376324..5432b51b6 100644 --- a/chain/index.md +++ b/chain/index.md @@ -7,6 +7,7 @@ categories: Behavioral tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Intent:** Avoid coupling the sender of a request to its receiver by giving diff --git a/checkstyle-suppressions.xml b/checkstyle-suppressions.xml new file mode 100644 index 000000000..a3a2c23a8 --- /dev/null +++ b/checkstyle-suppressions.xml @@ -0,0 +1,9 @@ + + + + + + + + diff --git a/checkstyle.xml b/checkstyle.xml index 6d969afde..cbf92f7b0 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -158,7 +158,7 @@ - + @@ -168,4 +168,9 @@ + + + + + diff --git a/command/index.md b/command/index.md index 3fa774d8f..4052a8ae7 100644 --- a/command/index.md +++ b/command/index.md @@ -7,6 +7,7 @@ categories: Behavioral tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Also known as:** Action, Transaction diff --git a/composite/index.md b/composite/index.md index 4a31a1b33..bf5a920ac 100644 --- a/composite/index.md +++ b/composite/index.md @@ -7,6 +7,7 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Intent:** Compose objects into tree structures to represent part-whole diff --git a/dao/index.md b/dao/index.md index cf9f43a68..91f6dc776 100644 --- a/dao/index.md +++ b/dao/index.md @@ -3,7 +3,7 @@ layout: pattern title: Data Access Object folder: dao permalink: /patterns/dao/ -categories: Architectural +categories: Persistence Tier tags: - Java - Difficulty-Beginner diff --git a/decorator/index.md b/decorator/index.md index 61eeeac60..ca6c7bb50 100644 --- a/decorator/index.md +++ b/decorator/index.md @@ -7,6 +7,7 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Beginner --- **Also known as:** Wrapper diff --git a/dependency-injection/index.md b/dependency-injection/index.md index f6ead97a7..4caa30c94 100644 --- a/dependency-injection/index.md +++ b/dependency-injection/index.md @@ -4,7 +4,9 @@ title: Dependency Injection folder: dependency-injection permalink: /patterns/dependency-injection/ categories: Behavioral -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Dependency Injection is a software design pattern in which one or diff --git a/double-checked-locking/index.md b/double-checked-locking/index.md index b1b0108ec..05ec2006f 100644 --- a/double-checked-locking/index.md +++ b/double-checked-locking/index.md @@ -4,7 +4,10 @@ title: Double Checked Locking folder: double-checked-locking permalink: /patterns/double-checked-locking/ categories: Concurrency -tags: Java +tags: + - Java + - Difficulty-Beginner + - Idiom --- **Intent:** Reduce the overhead of acquiring a lock by first testing the diff --git a/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/InventoryTest.java b/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/InventoryTest.java index b5cd6b312..a09f19e57 100644 --- a/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/InventoryTest.java +++ b/double-checked-locking/src/test/java/com/iluwatar/doublechecked/locking/InventoryTest.java @@ -14,7 +14,10 @@ import java.util.concurrent.TimeUnit; import static junit.framework.Assert.assertTrue; import static junit.framework.TestCase.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/10/15 - 9:34 PM @@ -74,8 +77,8 @@ public class InventoryTest { final ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT); for (int i = 0; i < THREAD_COUNT; i++) { executorService.execute(() -> { - while (inventory.addItem(new Item())) {}; - }); + while (inventory.addItem(new Item())) {}; + }); } // Wait until all threads have finished diff --git a/double-dispatch/index.md b/double-dispatch/index.md index 6847b7a41..a660e0f88 100644 --- a/double-dispatch/index.md +++ b/double-dispatch/index.md @@ -4,7 +4,10 @@ title: Double Dispatch folder: double-dispatch permalink: /patterns/double-dispatch/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Intermediate + - Idiom --- **Intent:** Double Dispatch pattern is a way to create maintainable dynamic diff --git a/double-dispatch/src/test/java/com/iluwatar/doubledispatch/CollisionTest.java b/double-dispatch/src/test/java/com/iluwatar/doubledispatch/CollisionTest.java index 7e77a6651..6792a5d37 100644 --- a/double-dispatch/src/test/java/com/iluwatar/doubledispatch/CollisionTest.java +++ b/double-dispatch/src/test/java/com/iluwatar/doubledispatch/CollisionTest.java @@ -7,7 +7,10 @@ import java.io.PrintStream; import java.util.Objects; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/10/15 - 8:37 PM diff --git a/event-aggregator/index.md b/event-aggregator/index.md index 1c89c7188..05e94e0de 100644 --- a/event-aggregator/index.md +++ b/event-aggregator/index.md @@ -4,7 +4,9 @@ title: Event Aggregator folder: event-aggregator permalink: /patterns/event-aggregator/ categories: Structural -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** A system with lots of objects can lead to complexities when a diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/EventEmitterTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/EventEmitterTest.java index 99e0ac65e..37bd36da4 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/EventEmitterTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/EventEmitterTest.java @@ -7,7 +7,11 @@ import java.util.function.Function; import java.util.function.Supplier; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 10:58 PM diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java index d57f26969..c1d054936 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingJoffreyTest.java @@ -6,7 +6,11 @@ import org.junit.Test; import java.io.PrintStream; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 3:04 PM diff --git a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingsHandTest.java b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingsHandTest.java index 5c61bb540..e62bb3f52 100644 --- a/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingsHandTest.java +++ b/event-aggregator/src/test/java/com/iluwatar/event/aggregator/KingsHandTest.java @@ -3,7 +3,11 @@ package com.iluwatar.event.aggregator; import org.junit.Test; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 10:57 AM diff --git a/execute-around/index.md b/execute-around/index.md index 56ece4ac4..8e62d5a8c 100644 --- a/execute-around/index.md +++ b/execute-around/index.md @@ -4,7 +4,10 @@ title: Execute Around folder: execute-around permalink: /patterns/execute-around/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Beginner + - Idiom --- **Intent:** Execute Around idiom frees the user from certain actions that diff --git a/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java b/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java index c461a910c..1f4380fe4 100644 --- a/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java +++ b/execute-around/src/test/java/com/iluwatar/execute/around/SimpleFileWriterTest.java @@ -67,8 +67,8 @@ public class SimpleFileWriterTest { public void testIoException() throws Exception { final File temporaryFile = this.testFolder.newFile(); new SimpleFileWriter(temporaryFile.getPath(), writer -> { - throw new IOException(""); - }); + throw new IOException(""); + }); } } diff --git a/facade/index.md b/facade/index.md index 59ff888b2..9ad9cb985 100644 --- a/facade/index.md +++ b/facade/index.md @@ -7,6 +7,7 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Beginner --- **Intent:** Provide a unified interface to a set of interfaces in a subsystem. diff --git a/facade/src/test/java/com/iluwatar/facade/DwarvenGoldmineFacadeTest.java b/facade/src/test/java/com/iluwatar/facade/DwarvenGoldmineFacadeTest.java index 20a5f6e0a..9a9bc5d66 100644 --- a/facade/src/test/java/com/iluwatar/facade/DwarvenGoldmineFacadeTest.java +++ b/facade/src/test/java/com/iluwatar/facade/DwarvenGoldmineFacadeTest.java @@ -7,7 +7,9 @@ import org.junit.Test; import java.io.PrintStream; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.internal.verification.VerificationModeFactory.times; /** diff --git a/fluentinterface/index.md b/fluentinterface/index.md index 27a4d1a26..0cabed598 100644 --- a/fluentinterface/index.md +++ b/fluentinterface/index.md @@ -7,6 +7,7 @@ categories: Other tags: - Java - Difficulty-Intermediate + - Functional --- **Intent:** A fluent interface provides an easy-readable, flowing interface, that often mimics a domain specific language. Using this pattern results in code that can be read nearly as human language. diff --git a/flux/index.md b/flux/index.md index 227237168..c1ef0b4f9 100644 --- a/flux/index.md +++ b/flux/index.md @@ -4,7 +4,9 @@ title: Flux folder: flux permalink: /patterns/flux/ categories: Presentation Tier -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Flux eschews MVC in favor of a unidirectional data flow. When a diff --git a/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java b/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java index d679e7b87..7c66e7a81 100644 --- a/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java +++ b/flux/src/test/java/com/iluwatar/flux/dispatcher/DispatcherTest.java @@ -1,6 +1,11 @@ package com.iluwatar.flux.dispatcher; -import com.iluwatar.flux.action.*; +import com.iluwatar.flux.action.Action; +import com.iluwatar.flux.action.ActionType; +import com.iluwatar.flux.action.Content; +import com.iluwatar.flux.action.ContentAction; +import com.iluwatar.flux.action.MenuAction; +import com.iluwatar.flux.action.MenuItem; import com.iluwatar.flux.store.Store; import org.junit.Before; import org.junit.Test; @@ -11,8 +16,13 @@ import java.lang.reflect.Field; import java.util.List; import java.util.stream.Collectors; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 8:22 PM diff --git a/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java b/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java index 345e6a607..00a7a924d 100644 --- a/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java +++ b/flux/src/test/java/com/iluwatar/flux/store/ContentStoreTest.java @@ -9,7 +9,11 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 10:18 PM diff --git a/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java b/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java index 7d4bdf463..6fdc4e5d3 100644 --- a/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java +++ b/flux/src/test/java/com/iluwatar/flux/store/MenuStoreTest.java @@ -9,7 +9,11 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 10:18 PM diff --git a/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java b/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java index bc65a21bf..cf452233b 100644 --- a/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java +++ b/flux/src/test/java/com/iluwatar/flux/view/ContentViewTest.java @@ -4,7 +4,11 @@ import com.iluwatar.flux.action.Content; import com.iluwatar.flux.store.ContentStore; import org.junit.Test; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.mockito.Mockito.verifyNoMoreInteractions; /** * Date: 12/12/15 - 10:31 PM diff --git a/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java b/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java index 28d631f64..08a601c71 100644 --- a/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java +++ b/flux/src/test/java/com/iluwatar/flux/view/MenuViewTest.java @@ -8,7 +8,11 @@ import com.iluwatar.flux.store.Store; import org.junit.Test; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; /** * Date: 12/12/15 - 10:31 PM diff --git a/flyweight/index.md b/flyweight/index.md index e2273c197..41a45f555 100644 --- a/flyweight/index.md +++ b/flyweight/index.md @@ -7,6 +7,8 @@ categories: Structural tags: - Java - Gang Of Four + - Difficulty-Intermediate + - Performance --- **Intent:** Use sharing to support large numbers of fine-grained objects diff --git a/front-controller/index.md b/front-controller/index.md index ba593a157..603bfef2b 100644 --- a/front-controller/index.md +++ b/front-controller/index.md @@ -4,7 +4,9 @@ title: Front Controller folder: front-controller permalink: /patterns/front-controller/ categories: Presentation Tier -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Introduce a common handler for all requests for a web site. This diff --git a/half-sync-half-async/index.md b/half-sync-half-async/index.md index dc1930e3b..5eb93c058 100644 --- a/half-sync-half-async/index.md +++ b/half-sync-half-async/index.md @@ -4,7 +4,9 @@ title: Half-Sync/Half-Async folder: half-sync-half-async permalink: /patterns/half-sync-half-async/ categories: Concurrency -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** The Half-Sync/Half-Async pattern decouples synchronous I/O from diff --git a/intercepting-filter/index.md b/intercepting-filter/index.md index 41825745b..3aa70ba02 100644 --- a/intercepting-filter/index.md +++ b/intercepting-filter/index.md @@ -4,7 +4,9 @@ title: Intercepting Filter folder: intercepting-filter permalink: /patterns/intercepting-filter/ categories: Behavioral -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Provide pluggable filters to conduct necessary pre-processing and diff --git a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java index 68b4410a7..022bd7586 100644 --- a/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java +++ b/intercepting-filter/src/test/java/com/iluwatar/intercepting/filter/FilterManagerTest.java @@ -4,7 +4,11 @@ import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyZeroInteractions; +import static org.mockito.Mockito.when; /** * Date: 12/13/15 - 3:01 PM diff --git a/interpreter/index.md b/interpreter/index.md index 57b117e06..dd6a7eda2 100644 --- a/interpreter/index.md +++ b/interpreter/index.md @@ -7,6 +7,7 @@ categories: Behavioral tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Intent:** Given a language, define a representation for its grammar along diff --git a/layers/index.md b/layers/index.md index 37089a19c..5f746d4d2 100644 --- a/layers/index.md +++ b/layers/index.md @@ -4,7 +4,10 @@ title: Layers folder: layers permalink: /patterns/layers/ categories: Architectural -tags: Java +tags: + - Java + - Difficulty-Intermediate + - Spring --- **Intent:** Layers is an architectural style where software responsibilities are diff --git a/layers/src/test/java/com/iluwatar/layers/CakeTest.java b/layers/src/test/java/com/iluwatar/layers/CakeTest.java index 30d1df0fc..8c2bd4c15 100644 --- a/layers/src/test/java/com/iluwatar/layers/CakeTest.java +++ b/layers/src/test/java/com/iluwatar/layers/CakeTest.java @@ -88,8 +88,8 @@ public class CakeTest { cake.setTopping(topping); cake.addLayer(layer); - final String expected = "id=1234 topping=id=2345 name=topping calories=20 " + - "layers=[id=3456 name=layer calories=100]"; + final String expected = "id=1234 topping=id=2345 name=topping calories=20 " + + "layers=[id=3456 name=layer calories=100]"; assertEquals(expected, cake.toString()); } diff --git a/lazy-loading/index.md b/lazy-loading/index.md index 700892af0..6f2501b7e 100644 --- a/lazy-loading/index.md +++ b/lazy-loading/index.md @@ -4,7 +4,11 @@ title: Lazy Loading folder: lazy-loading permalink: /patterns/lazy-loading/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Beginner + - Idiom + - Performance --- **Intent:** Lazy loading is a design pattern commonly used to defer diff --git a/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java b/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java index 165e8f490..31b7222e9 100644 --- a/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java +++ b/mediator/src/test/java/com/iluwatar/mediator/PartyMemberTest.java @@ -12,7 +12,10 @@ import java.util.Collection; import java.util.function.Supplier; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.verifyZeroInteractions; /** * Date: 12/19/15 - 10:13 PM diff --git a/memento/index.md b/memento/index.md index f299506e0..7322aef50 100644 --- a/memento/index.md +++ b/memento/index.md @@ -7,6 +7,7 @@ categories: Behavioral tags: - Java - Gang Of Four + - Difficulty-Intermediate --- **Also known as:** Token diff --git a/message-channel/index.md b/message-channel/index.md index 06cf93488..3b742a983 100644 --- a/message-channel/index.md +++ b/message-channel/index.md @@ -7,6 +7,7 @@ categories: Integration tags: - Java - EIP + - Camel --- **Intent:** When two applications communicate using a messaging system they do it by using logical addresses diff --git a/model-view-controller/index.md b/model-view-controller/index.md index 1ba1089c0..3d1d3e929 100644 --- a/model-view-controller/index.md +++ b/model-view-controller/index.md @@ -4,7 +4,9 @@ title: Model-View-Controller folder: model-view-controller permalink: /patterns/model-view-controller/ categories: Presentation Tier -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Separate the user interface into three interconnected components: diff --git a/model-view-presenter/index.md b/model-view-presenter/index.md index b51268013..a65a9a651 100644 --- a/model-view-presenter/index.md +++ b/model-view-presenter/index.md @@ -4,7 +4,9 @@ title: Model-View-Presenter folder: model-view-presenter permalink: /patterns/model-view-presenter/ categories: Presentation Tier -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Apply a "Separation of Concerns" principle in a way that allows diff --git a/monostate/index.md b/monostate/index.md index 2b88f131e..4176af3ce 100644 --- a/monostate/index.md +++ b/monostate/index.md @@ -4,7 +4,9 @@ title: MonoState folder: monostate permalink: /patterns/monostate/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Enforces a behaviour like sharing the same state amongst all instances. diff --git a/multiton/index.md b/multiton/index.md index 617bedb6a..6491de442 100644 --- a/multiton/index.md +++ b/multiton/index.md @@ -4,7 +4,9 @@ title: Multiton folder: multiton permalink: /patterns/multiton/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Ensure a class only has limited number of instances, and provide a diff --git a/naked-objects/index.md b/naked-objects/index.md index 805cea810..e3dd09a81 100644 --- a/naked-objects/index.md +++ b/naked-objects/index.md @@ -4,7 +4,9 @@ title: Naked Objects folder: naked-objects permalink: /patterns/naked-objects/ categories: Architectural -tags: Java +tags: + - Java + - Difficulty-Expert --- **Intent:** The Naked Objects architectural pattern is well suited for rapid diff --git a/null-object/index.md b/null-object/index.md index 5127e8565..6b659b5cc 100644 --- a/null-object/index.md +++ b/null-object/index.md @@ -4,7 +4,9 @@ title: Null Object folder: null-object permalink: /patterns/null-object/ categories: Behavioral -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** In most object-oriented languages, such as Java or C#, references diff --git a/object-pool/index.md b/object-pool/index.md index 276d9a1f6..0d37041c3 100644 --- a/object-pool/index.md +++ b/object-pool/index.md @@ -4,7 +4,10 @@ title: Object Pool folder: object-pool permalink: /patterns/object-pool/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Beginner + - Performance --- **Intent:** When objects are expensive to create and they are needed only for diff --git a/poison-pill/index.md b/poison-pill/index.md index cd60e1a68..90dff3c36 100644 --- a/poison-pill/index.md +++ b/poison-pill/index.md @@ -4,7 +4,9 @@ title: Poison Pill folder: poison-pill permalink: /patterns/poison-pill/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Poison Pill is known predefined data item that allows to provide diff --git a/pom.xml b/pom.xml index de278177e..00bfa1a83 100644 --- a/pom.xml +++ b/pom.xml @@ -258,6 +258,7 @@ UTF-8 true true + true diff --git a/private-class-data/index.md b/private-class-data/index.md index 83c95d308..4c09df0d0 100644 --- a/private-class-data/index.md +++ b/private-class-data/index.md @@ -4,7 +4,10 @@ title: Private Class Data folder: private-class-data permalink: /patterns/private-class-data/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Beginner + - Idiom --- **Intent:** Private Class Data design pattern seeks to reduce exposure of diff --git a/producer-consumer/index.md b/producer-consumer/index.md index 58dc45e0d..124c98a2a 100644 --- a/producer-consumer/index.md +++ b/producer-consumer/index.md @@ -3,15 +3,16 @@ layout: pattern title: Producer Consumer folder: producer-consumer permalink: /patterns/producer-consumer/ -categories: Other -tags: Java +categories: Concurrency +tags: + - Java + - Difficulty-Intermediate + - I/O --- -**Intent:** Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces +**Intent:** Producer Consumer Design pattern is a classic concurrency pattern which reduces coupling between Producer and Consumer by separating Identification of work with Execution of - Work.. - - + Work. ![alt text](./etc/producer-consumer.png "Producer Consumer") @@ -19,4 +20,3 @@ tags: Java * decouple system by separate work in two process produce and consume. * addresses the issue of different timing require to produce work or consuming work - diff --git a/property/index.md b/property/index.md index 1c5b28db6..9949239c1 100644 --- a/property/index.md +++ b/property/index.md @@ -4,7 +4,9 @@ title: Property folder: property permalink: /patterns/property/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Create hierarchy of objects and new objects using already existing diff --git a/prototype/index.md b/prototype/index.md index 9d108ff06..457c2f46a 100644 --- a/prototype/index.md +++ b/prototype/index.md @@ -7,6 +7,7 @@ categories: Creational tags: - Java - Gang Of Four + - Difficulty-Beginner --- **Intent:** Specify the kinds of objects to create using a prototypical diff --git a/proxy/index.md b/proxy/index.md index baa759600..2f16527a8 100644 --- a/proxy/index.md +++ b/proxy/index.md @@ -7,7 +7,7 @@ categories: Structural tags: - Java - Gang Of Four - - Difficulty-Intermediate + - Difficulty-Beginner --- **Also known as:** Surrogate diff --git a/publish-subscribe/index.md b/publish-subscribe/index.md index b91f22e3b..cd1ad3971 100644 --- a/publish-subscribe/index.md +++ b/publish-subscribe/index.md @@ -7,6 +7,7 @@ categories: Integration tags: - Java - EIP + - Camel --- **Intent:** Broadcast messages from sender to all the interested receivers. diff --git a/reactor/index.md b/reactor/index.md index 6e20598d2..9071413d8 100644 --- a/reactor/index.md +++ b/reactor/index.md @@ -3,10 +3,11 @@ layout: pattern title: Reactor folder: reactor permalink: /patterns/reactor/ -categories: Architectural +categories: Concurrency tags: - Java - Difficulty-Expert + - I/O --- **Intent:** The Reactor design pattern handles service requests that are delivered concurrently to an application by one or more clients. The application can register specific handlers for processing which are called by reactor on specific events. Dispatching of event handlers is performed by an initiation dispatcher, which manages the registered event handlers. Demultiplexing of service requests is performed by a synchronous event demultiplexer. diff --git a/repository/index.md b/repository/index.md index 8ecd16528..697c708f9 100644 --- a/repository/index.md +++ b/repository/index.md @@ -3,8 +3,11 @@ layout: pattern title: Repository folder: repository permalink: /patterns/repository/ -categories: Architectural -tags: Java +categories: Persistence Tier +tags: + - Java + - Difficulty-Intermediate + - Spring --- **Intent:** Repository layer is added between the domain and data mapping diff --git a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java index 682d2021f..6f8746aa6 100644 --- a/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java +++ b/repository/src/test/java/com/iluwatar/repository/AnnotationBasedRepositoryTest.java @@ -90,8 +90,8 @@ public class AnnotationBasedRepositoryTest { assertEquals(3, persons.size()); assertTrue(persons.stream().allMatch((item) -> { - return item.getAge() > 20 && item.getAge() < 40; - })); + return item.getAge() > 20 && item.getAge() < 40; + })); } @Test diff --git a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java index 9eb6b4723..3d6708815 100644 --- a/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java +++ b/repository/src/test/java/com/iluwatar/repository/RepositoryTest.java @@ -88,8 +88,8 @@ public class RepositoryTest { assertEquals(3, persons.size()); assertTrue(persons.stream().allMatch((item) -> { - return item.getAge() > 20 && item.getAge() < 40; - })); + return item.getAge() > 20 && item.getAge() < 40; + })); } @Test diff --git a/resource-acquisition-is-initialization/index.md b/resource-acquisition-is-initialization/index.md index c3aa6c045..e808783fb 100644 --- a/resource-acquisition-is-initialization/index.md +++ b/resource-acquisition-is-initialization/index.md @@ -4,7 +4,10 @@ title: Resource Acquisition Is Initialization folder: resource-acquisition-is-initialization permalink: /patterns/resource-acquisition-is-initialization/ categories: Other -tags: Java +tags: + - Java + - Difficulty-Beginner + - Idiom --- **Intent:** Resource Acquisition Is Initialization pattern can be used to implement exception safe resource management. diff --git a/servant/index.md b/servant/index.md index 38a8e2c60..9cf20a53e 100644 --- a/servant/index.md +++ b/servant/index.md @@ -4,7 +4,9 @@ title: Servant folder: servant permalink: /patterns/servant/ categories: Structural -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Servant is used for providing some behavior to a group of classes. diff --git a/service-layer/index.md b/service-layer/index.md index ea3f3d0ba..68f4f6130 100644 --- a/service-layer/index.md +++ b/service-layer/index.md @@ -4,7 +4,9 @@ title: Service Layer folder: service-layer permalink: /patterns/service-layer/ categories: Architectural -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Service Layer is an abstraction over domain logic. Typically diff --git a/service-locator/index.md b/service-locator/index.md index 03c432749..7357a0ac0 100644 --- a/service-locator/index.md +++ b/service-locator/index.md @@ -4,7 +4,10 @@ title: Service Locator folder: service-locator permalink: /patterns/service-locator/ categories: Structural -tags: Java +tags: + - Java + - Difficulty-Beginner + - Performance --- **Intent:** Encapsulate the processes involved in obtaining a service with a diff --git a/specification/index.md b/specification/index.md index 6b76d5102..f95c7921a 100644 --- a/specification/index.md +++ b/specification/index.md @@ -4,7 +4,9 @@ title: Specification folder: specification permalink: /patterns/specification/ categories: Behavioral -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Specification pattern separates the statement of how to match a diff --git a/step-builder/index.md b/step-builder/index.md index 766479358..7ca93c276 100644 --- a/step-builder/index.md +++ b/step-builder/index.md @@ -4,7 +4,9 @@ title: Step Builder folder: step-builder permalink: /patterns/step-builder/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** An extension of the Builder pattern that fully guides the user through the creation of the object with no chances of confusion. diff --git a/thread-pool/index.md b/thread-pool/index.md index d9f00f428..d4b61607d 100644 --- a/thread-pool/index.md +++ b/thread-pool/index.md @@ -4,7 +4,10 @@ title: Thread Pool folder: thread-pool permalink: /patterns/thread-pool/ categories: Concurrency -tags: Java +tags: + - Java + - Difficulty-Intermediate + - Performance --- **Intent:** It is often the case that tasks to be executed are short-lived and diff --git a/tolerant-reader/index.md b/tolerant-reader/index.md index b2bfd376a..895886f77 100644 --- a/tolerant-reader/index.md +++ b/tolerant-reader/index.md @@ -4,7 +4,9 @@ title: Tolerant Reader folder: tolerant-reader permalink: /patterns/tolerant-reader/ categories: Integration -tags: Java +tags: + - Java + - Difficulty-Beginner --- **Intent:** Tolerant Reader is an integration pattern that helps creating diff --git a/twin/index.md b/twin/index.md index 475437754..e0e449047 100644 --- a/twin/index.md +++ b/twin/index.md @@ -4,14 +4,14 @@ title: Twin folder: twin permalink: /patterns/twin/ categories: Creational -tags: Java +tags: + - Java + - Difficulty-Intermediate --- **Intent:** Twin pattern is a design pattern which provides a standard solution to simulate multiple inheritance in java - - ![alt text](./etc/twin.png "Twin") **Applicability:** Use the Twin idiom when @@ -21,4 +21,4 @@ inheritance in java **Credits:** -* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf) \ No newline at end of file +* [Twin – A Design Pattern for Modeling Multiple Inheritance](http://www.ssw.uni-linz.ac.at/Research/Papers/Moe99/Paper.pdf) diff --git a/visitor/index.md b/visitor/index.md index 5f32edbbd..760f2c705 100644 --- a/visitor/index.md +++ b/visitor/index.md @@ -6,7 +6,7 @@ permalink: /patterns/visitor/ categories: Behavioral tags: - Java - - Difficulty-Expert + - Difficulty-Intermediate - Gang Of Four ---