From 271d7ae9bdfc835c5b5f62c21f1d8c630cab7647 Mon Sep 17 00:00:00 2001 From: Anurag Agarwal Date: Sat, 16 Nov 2019 18:26:26 +0530 Subject: [PATCH] Resolves checkstyle errors for remaining p (#1091) * Reduces checkstyle errors in page-object * Reduces checkstyle errors in partial-response * Reduces checkstyle errors in pipeline * Reduces checkstyle errors in poison-pill * Reduces checkstyle errors in priority-queue * Reduces checkstyle errors in private-class-data * Reduces checkstyle errors in property * Reduces checkstyle errors in prototype * Reduces checkstyle errors in proxy --- .../java/com/iluwatar/pageobject/App.java | 51 +++++++++---------- .../java/com/iluwatar/pageobject/App.java | 47 ++++++++--------- .../iluwatar/pageobject/AlbumListPage.java | 8 ++- .../com/iluwatar/pageobject/AlbumPage.java | 29 +++++------ .../com/iluwatar/pageobject/LoginPage.java | 18 +++---- .../java/com/iluwatar/pageobject/Page.java | 9 ++-- .../com/iluwatar/partialresponse/App.java | 26 +++++----- .../partialresponse/FieldJsonMapper.java | 4 +- .../com/iluwatar/partialresponse/Video.java | 27 +++++----- .../partialresponse/VideoResource.java | 8 ++- .../main/java/com/iluwatar/pipeline/App.java | 19 ++++--- .../pipeline/ConvertToCharArrayHandler.java | 9 ++-- .../java/com/iluwatar/pipeline/Handler.java | 4 +- .../java/com/iluwatar/pipeline/Pipeline.java | 5 +- .../pipeline/RemoveAlphabetsHandler.java | 12 +++-- .../pipeline/RemoveDigitsHandler.java | 8 +-- .../java/com/iluwatar/poison/pill/App.java | 9 ++-- .../com/iluwatar/poison/pill/Consumer.java | 6 +-- .../com/iluwatar/poison/pill/Message.java | 2 +- .../iluwatar/poison/pill/MessageQueue.java | 2 +- .../iluwatar/poison/pill/MqPublishPoint.java | 2 +- .../poison/pill/MqSubscribePoint.java | 2 +- .../com/iluwatar/poison/pill/Producer.java | 11 ++-- .../iluwatar/poison/pill/SimpleMessage.java | 2 +- .../poison/pill/SimpleMessageQueue.java | 2 +- .../iluwatar/priority/queue/Application.java | 11 ++-- .../com/iluwatar/priority/queue/Message.java | 2 +- .../priority/queue/PriorityMessageQueue.java | 12 ++--- .../iluwatar/priority/queue/QueueManager.java | 6 +-- .../com/iluwatar/priority/queue/Worker.java | 6 +-- .../com/iluwatar/privateclassdata/App.java | 20 ++++---- .../privateclassdata/ImmutableStew.java | 11 ++-- .../com/iluwatar/privateclassdata/Stew.java | 10 ++-- .../iluwatar/privateclassdata/StewData.java | 6 +-- .../main/java/com/iluwatar/property/App.java | 22 ++++---- .../java/com/iluwatar/property/Character.java | 34 +++++++------ .../java/com/iluwatar/property/Prototype.java | 2 +- .../java/com/iluwatar/property/Stats.java | 2 +- .../main/java/com/iluwatar/prototype/App.java | 36 ++++++------- .../java/com/iluwatar/prototype/Beast.java | 4 +- .../java/com/iluwatar/prototype/ElfBeast.java | 6 +-- .../java/com/iluwatar/prototype/ElfMage.java | 8 ++- .../com/iluwatar/prototype/ElfWarlord.java | 6 +-- .../com/iluwatar/prototype/HeroFactory.java | 2 - .../iluwatar/prototype/HeroFactoryImpl.java | 10 ++-- .../java/com/iluwatar/prototype/Mage.java | 4 +- .../java/com/iluwatar/prototype/OrcBeast.java | 10 ++-- .../java/com/iluwatar/prototype/OrcMage.java | 6 +-- .../com/iluwatar/prototype/OrcWarlord.java | 6 +-- .../com/iluwatar/prototype/Prototype.java | 4 +- .../java/com/iluwatar/prototype/Warlord.java | 4 +- .../src/main/java/com/iluwatar/proxy/App.java | 12 ++--- .../java/com/iluwatar/proxy/IvoryTower.java | 2 - .../main/java/com/iluwatar/proxy/Wizard.java | 4 +- .../java/com/iluwatar/proxy/WizardTower.java | 2 +- .../com/iluwatar/proxy/WizardTowerProxy.java | 2 - 56 files changed, 281 insertions(+), 313 deletions(-) diff --git a/page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java b/page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java index aae08c15f..e3a86599c 100644 --- a/page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java +++ b/page-object/sample-application/src/main/java/com/iluwatar/pageobject/App.java @@ -26,63 +26,60 @@ package com.iluwatar.pageobject; import java.awt.Desktop; import java.io.File; import java.io.IOException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Page Object pattern wraps an UI component with an application specific API allowing you to - * manipulate the UI elements without having to dig around with the underlying UI technology used. This is - * especially useful for testing as it means your tests will be less brittle. Your tests can concentrate on - * the actual test cases where as the manipulation of the UI can be left to the internals of the page object - * itself. + * manipulate the UI elements without having to dig around with the underlying UI technology used. + * This is especially useful for testing as it means your tests will be less brittle. Your tests can + * concentrate on the actual test cases where as the manipulation of the UI can be left to the + * internals of the page object itself. * - *

- * Due to this reason, it has become very popular within the test automation community. - * In particular, it is very common in that the page object is used to represent the html pages of a - * web application that is under test. This web application is referred to as AUT (Application Under Test). - * A web browser automation tool/framework like Selenium for instance, is then used to drive the automating - * of the browser navigation and user actions journeys through this web application. Your test class would - * therefore only be responsible for particular test cases and page object would be used by the test class - * for UI manipulation required for the tests. + *

Due to this reason, it has become very popular within the test automation community. In + * particular, it is very common in that the page object is used to represent the html pages of a + * web application that is under test. This web application is referred to as AUT (Application Under + * Test). A web browser automation tool/framework like Selenium for instance, is then used to drive + * the automating of the browser navigation and user actions journeys through this web application. + * Your test class would therefore only be responsible for particular test cases and page object + * would be used by the test class for UI manipulation required for the tests. * - *

- * In this implementation rather than using Selenium, the HtmlUnit library is used as a replacement to - * represent the specific html elements and to drive the browser. The purpose of this example is just to - * provide a simple version that showcase the intentions of this pattern and how this pattern is used - * in order to understand it. + *

In this implementation rather than using Selenium, the HtmlUnit library is used as a + * replacement to represent the specific html elements and to drive the browser. The purpose of this + * example is just to provide a simple version that showcase the intentions of this pattern and how + * this pattern is used in order to understand it. */ public final class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); + private App() { } /** * Application entry point * - *

- * The application under development is a web application. Normally you would probably have a - * backend that is probably implemented in an object-oriented language (e.g. Java) that serves - * the frontend which comprises of a series of HTML, CSS, JS etc... + *

The application under development is a web application. Normally you would probably have a + * backend that is probably implemented in an object-oriented language (e.g. Java) that serves the + * frontend which comprises of a series of HTML, CSS, JS etc... * - *

- * For illustrations purposes only, a very simple static html app is used here. This main method - * just fires up this simple web app in a default browser. + *

For illustrations purposes only, a very simple static html app is used here. This main + * method just fires up this simple web app in a default browser. * * @param args arguments */ public static void main(String[] args) { try { - File applicationFile = new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); + File applicationFile = + new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); // should work for unix like OS (mac, unix etc...) if (Desktop.isDesktopSupported()) { Desktop.getDesktop().open(applicationFile); } else { - // java Desktop not supported - above unlikely to work for Windows so try following instead... + // java Desktop not supported - above unlikely to work for Windows so try instead... Runtime.getRuntime().exec("cmd.exe start " + applicationFile); } diff --git a/page-object/src/main/java/com/iluwatar/pageobject/App.java b/page-object/src/main/java/com/iluwatar/pageobject/App.java index c76867e89..9c4c21607 100644 --- a/page-object/src/main/java/com/iluwatar/pageobject/App.java +++ b/page-object/src/main/java/com/iluwatar/pageobject/App.java @@ -29,25 +29,23 @@ import java.io.IOException; /** * Page Object pattern wraps an UI component with an application specific API allowing you to - * manipulate the UI elements without having to dig around with the underlying UI technology used. This is - * especially useful for testing as it means your tests will be less brittle. Your tests can concentrate on - * the actual test cases where as the manipulation of the UI can be left to the internals of the page object - * itself. + * manipulate the UI elements without having to dig around with the underlying UI technology used. + * This is especially useful for testing as it means your tests will be less brittle. Your tests can + * concentrate on the actual test cases where as the manipulation of the UI can be left to the + * internals of the page object itself. * - *

- * Due to this reason, it has become very popular within the test automation community. - * In particular, it is very common in that the page object is used to represent the html pages of a - * web application that is under test. This web application is referred to as AUT (Application Under Test). - * A web browser automation tool/framework like Selenium for instance, is then used to drive the automating - * of the browser navigation and user actions journeys through this web application. Your test class would - * therefore only be responsible for particular test cases and page object would be used by the test class - * for UI manipulation required for the tests. + *

Due to this reason, it has become very popular within the test automation community. In + * particular, it is very common in that the page object is used to represent the html pages of a + * web application that is under test. This web application is referred to as AUT (Application Under + * Test). A web browser automation tool/framework like Selenium for instance, is then used to drive + * the automating of the browser navigation and user actions journeys through this web application. + * Your test class would therefore only be responsible for particular test cases and page object + * would be used by the test class for UI manipulation required for the tests. * - *

- * In this implementation rather than using Selenium, the HtmlUnit library is used as a replacement to - * represent the specific html elements and to drive the browser. The purpose of this example is just to - * provide a simple version that showcase the intentions of this pattern and how this pattern is used - * in order to understand it. + *

In this implementation rather than using Selenium, the HtmlUnit library is used as a + * replacement to represent the specific html elements and to drive the browser. The purpose of this + * example is just to provide a simple version that showcase the intentions of this pattern and how + * this pattern is used in order to understand it. */ public final class App { @@ -57,21 +55,20 @@ public final class App { /** * Application entry point * - *

- * The application under development is a web application. Normally you would probably have a - * backend that is probably implemented in an object-oriented language (e.g. Java) that serves - * the frontend which comprises of a series of HTML, CSS, JS etc... + *

The application under development is a web application. Normally you would probably have a + * backend that is probably implemented in an object-oriented language (e.g. Java) that serves the + * frontend which comprises of a series of HTML, CSS, JS etc... * - *

- * For illustrations purposes only, a very simple static html app is used here. This main method - * just fires up this simple web app in a default browser. + *

For illustrations purposes only, a very simple static html app is used here. This main + * method just fires up this simple web app in a default browser. * * @param args arguments */ public static void main(String[] args) { try { - File applicationFile = new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); + File applicationFile = + new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath()); // should work for unix like OS (mac, unix etc...) if (Desktop.isDesktopSupported()) { diff --git a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumListPage.java b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumListPage.java index feab7838c..2851d24d5 100644 --- a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumListPage.java +++ b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumListPage.java @@ -26,10 +26,8 @@ package com.iluwatar.pageobject; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlPage; - import java.io.IOException; import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +44,7 @@ public class AlbumListPage extends Page { /** - * Constructor + * Constructor. */ public AlbumListPage(WebClient webClient) { super(webClient); @@ -54,7 +52,7 @@ public class AlbumListPage extends Page { /** - * Navigates to the Album List Page + * Navigates to the Album List Page. * * @return {@link AlbumListPage} */ @@ -76,7 +74,7 @@ public class AlbumListPage extends Page { } /** - * Selects an album by the given album title + * Selects an album by the given album title. * * @param albumTitle the title of the album to click * @return the album page diff --git a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumPage.java b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumPage.java index cf8c50dd7..953a47ba2 100644 --- a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumPage.java +++ b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/AlbumPage.java @@ -23,11 +23,6 @@ package com.iluwatar.pageobject; -import java.io.IOException; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlNumberInput; import com.gargoylesoftware.htmlunit.html.HtmlOption; @@ -35,6 +30,9 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlSelect; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; +import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Page Object encapsulating the Album Page (album-page.html) @@ -49,7 +47,7 @@ public class AlbumPage extends Page { /** - * Constructor + * Constructor. */ public AlbumPage(WebClient webClient) { super(webClient); @@ -57,7 +55,7 @@ public class AlbumPage extends Page { /** - * Navigates to the album page + * Navigates to the album page. * * @return {@link AlbumPage} */ @@ -81,7 +79,7 @@ public class AlbumPage extends Page { /** - * Sets the album title input text field + * Sets the album title input text field. * * @param albumTitle the new album title value to set * @return {@link AlbumPage} @@ -94,7 +92,7 @@ public class AlbumPage extends Page { /** - * Sets the artist input text field + * Sets the artist input text field. * * @param artist the new artist value to set * @return {@link AlbumPage} @@ -107,7 +105,7 @@ public class AlbumPage extends Page { /** - * Selects the select's option value based on the year value given + * Selects the select's option value based on the year value given. * * @param year the new year value to set * @return {@link AlbumPage} @@ -121,7 +119,7 @@ public class AlbumPage extends Page { /** - * Sets the album rating input text field + * Sets the album rating input text field. * * @param albumRating the new album rating value to set * @return {@link AlbumPage} @@ -133,20 +131,21 @@ public class AlbumPage extends Page { } /** - * Sets the number of songs number input field + * Sets the number of songs number input field. * * @param numberOfSongs the new number of songs value to be set * @return {@link AlbumPage} */ public AlbumPage changeNumberOfSongs(int numberOfSongs) { - HtmlNumberInput numberOfSongsNumberField = (HtmlNumberInput) page.getElementById("numberOfSongs"); + HtmlNumberInput numberOfSongsNumberField = + (HtmlNumberInput) page.getElementById("numberOfSongs"); numberOfSongsNumberField.setText(Integer.toString(numberOfSongs)); return this; } /** - * Cancel changes made by clicking the cancel button + * Cancel changes made by clicking the cancel button. * * @return {@link AlbumListPage} */ @@ -162,7 +161,7 @@ public class AlbumPage extends Page { /** - * Saves changes made by clicking the save button + * Saves changes made by clicking the save button. * * @return {@link AlbumPage} */ diff --git a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/LoginPage.java b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/LoginPage.java index b139253a7..78d3fa329 100644 --- a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/LoginPage.java +++ b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/LoginPage.java @@ -29,7 +29,6 @@ import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import com.gargoylesoftware.htmlunit.html.HtmlTextInput; import java.io.IOException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,7 +44,7 @@ public class LoginPage extends Page { private HtmlPage page; /** - * Constructor + * Constructor. * * @param webClient {@link WebClient} */ @@ -54,7 +53,7 @@ public class LoginPage extends Page { } /** - * Navigates to the Login page + * Navigates to the Login page. * * @return {@link LoginPage} */ @@ -77,7 +76,7 @@ public class LoginPage extends Page { /** - * Enters the username into the username input text field + * Enters the username into the username input text field. * * @param username the username to enter * @return {@link LoginPage} @@ -90,23 +89,24 @@ public class LoginPage extends Page { /** - * Enters the password into the password input password field + * Enters the password into the password input password field. * * @param password the password to enter * @return {@link LoginPage} */ public LoginPage enterPassword(String password) { - HtmlPasswordInput passwordInputPasswordField = (HtmlPasswordInput) page.getElementById("password"); + HtmlPasswordInput passwordInputPasswordField = + (HtmlPasswordInput) page.getElementById("password"); passwordInputPasswordField.setText(password); return this; } /** - * Clicking on the login button to 'login' + * Clicking on the login button to 'login'. * - * @return {@link AlbumListPage} - * - this is the page that user gets navigated to once successfully logged in + * @return {@link AlbumListPage} - this is the page that user gets navigated to once successfully + * logged in */ public AlbumListPage login() { HtmlSubmitInput loginButton = (HtmlSubmitInput) page.getElementById("loginButton"); diff --git a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/Page.java b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/Page.java index 78bc4618c..ddf7ec63e 100644 --- a/page-object/test-automation/src/main/java/com/iluwatar/pageobject/Page.java +++ b/page-object/test-automation/src/main/java/com/iluwatar/pageobject/Page.java @@ -26,20 +26,19 @@ package com.iluwatar.pageobject; import com.gargoylesoftware.htmlunit.WebClient; /** - * Encapsulation for a generic 'Page' + * Encapsulation for a generic 'Page'. */ public abstract class Page { /** - * Application Under Test path - * This directory location is where html web pages are located + * Application Under Test path This directory location is where html web pages are located. */ public static final String AUT_PATH = "../sample-application/src/main/resources/sample-ui/"; protected final WebClient webClient; /** - * Constructor + * Constructor. * * @param webClient {@link WebClient} */ @@ -48,7 +47,7 @@ public abstract class Page { } /** - * Checks that the current page is actually the page this page object represents + * Checks that the current page is actually the page this page object represents. * * @return true if so, otherwise false */ diff --git a/partial-response/src/main/java/com/iluwatar/partialresponse/App.java b/partial-response/src/main/java/com/iluwatar/partialresponse/App.java index 314846a3d..5a3e7d950 100644 --- a/partial-response/src/main/java/com/iluwatar/partialresponse/App.java +++ b/partial-response/src/main/java/com/iluwatar/partialresponse/App.java @@ -23,18 +23,16 @@ package com.iluwatar.partialresponse; +import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Map; - /** - * The Partial response pattern is a design pattern in which client specifies fields to fetch to serve. - * Here {@link App} is playing as client for {@link VideoResource} server. - * Client ask for specific fields information in video to server. - *

- *

- * {@link VideoResource} act as server to serve video information. + * The Partial response pattern is a design pattern in which client specifies fields to fetch to + * serve. Here {@link App} is playing as client for {@link VideoResource} server. Client ask for + * specific fields information in video to server. + * + *

{@link VideoResource} act as server to serve video information. */ public class App { @@ -47,12 +45,12 @@ public class App { */ public static void main(String[] args) throws Exception { Map videos = Map.of( - 1, new Video(1, "Avatar", 178, "epic science fiction film", - "James Cameron", "English"), - 2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", - "Hideaki Anno", "Japanese"), - 3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", - "Christopher Nolan", "English")); + 1, new Video(1, "Avatar", 178, "epic science fiction film", + "James Cameron", "English"), + 2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", + "Hideaki Anno", "Japanese"), + 3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", + "Christopher Nolan", "English")); VideoResource videoResource = new VideoResource(new FieldJsonMapper(), videos); diff --git a/partial-response/src/main/java/com/iluwatar/partialresponse/FieldJsonMapper.java b/partial-response/src/main/java/com/iluwatar/partialresponse/FieldJsonMapper.java index da1d22620..f735b4d2b 100644 --- a/partial-response/src/main/java/com/iluwatar/partialresponse/FieldJsonMapper.java +++ b/partial-response/src/main/java/com/iluwatar/partialresponse/FieldJsonMapper.java @@ -26,11 +26,13 @@ package com.iluwatar.partialresponse; import java.lang.reflect.Field; /** - * Map a video to json + * Map a video to json. */ public class FieldJsonMapper { /** + * Gets json of required fields from video. + * * @param video object containing video information * @param fields fields information to get * @return json of required fields from video diff --git a/partial-response/src/main/java/com/iluwatar/partialresponse/Video.java b/partial-response/src/main/java/com/iluwatar/partialresponse/Video.java index fcfda7497..9e3ad5ea3 100644 --- a/partial-response/src/main/java/com/iluwatar/partialresponse/Video.java +++ b/partial-response/src/main/java/com/iluwatar/partialresponse/Video.java @@ -24,8 +24,7 @@ package com.iluwatar.partialresponse; /** - * {@link Video} is a entity to serve from server.It contains all video related information.. - *

+ * {@link Video} is a entity to serve from server.It contains all video related information. */ public class Video { private final Integer id; @@ -36,23 +35,27 @@ public class Video { private final String language; /** - * @param id video unique id - * @param title video title - * @param length video length in minutes - * @param description video description by publisher - * @param director video director name - * @param language video language {private, public} + * Constructor. + * + * @param id video unique id + * @param title video title + * @param len video length in minutes + * @param desc video description by publisher + * @param director video director name + * @param lang video language {private, public} */ - public Video(Integer id, String title, Integer length, String description, String director, String language) { + public Video(Integer id, String title, Integer len, String desc, String director, String lang) { this.id = id; this.title = title; - this.length = length; - this.description = description; + this.length = len; + this.description = desc; this.director = director; - this.language = language; + this.language = lang; } /** + * ToString. + * * @return json representaion of video */ @Override diff --git a/partial-response/src/main/java/com/iluwatar/partialresponse/VideoResource.java b/partial-response/src/main/java/com/iluwatar/partialresponse/VideoResource.java index d0d77af05..a61a3c429 100644 --- a/partial-response/src/main/java/com/iluwatar/partialresponse/VideoResource.java +++ b/partial-response/src/main/java/com/iluwatar/partialresponse/VideoResource.java @@ -26,14 +26,16 @@ package com.iluwatar.partialresponse; import java.util.Map; /** - * The resource class which serves video information. - * This class act as server in the demo. Which has all video details. + * The resource class which serves video information. This class act as server in the demo. Which + * has all video details. */ public class VideoResource { private FieldJsonMapper fieldJsonMapper; private Map videos; /** + * Constructor. + * * @param fieldJsonMapper map object to json. * @param videos initialize resource with existing videos. Act as database. */ @@ -43,6 +45,8 @@ public class VideoResource { } /** + * Get Details. + * * @param id video id * @param fields fields to get information about * @return full response if no fields specified else partial response for given field. diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/App.java b/pipeline/src/main/java/com/iluwatar/pipeline/App.java index 3298a6eb6..1b1e443e6 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/App.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/App.java @@ -24,21 +24,20 @@ package com.iluwatar.pipeline; /** - * The Pipeline pattern uses ordered stages to process a sequence of input values. - * Each implemented task is represented by a stage of the pipeline. You can think of - * pipelines as similar to assembly lines in a factory, where each item in the assembly - * line is constructed in stages. The partially assembled item is passed from one assembly - * stage to another. The outputs of the assembly line occur in the same order as that of the - * inputs. + * The Pipeline pattern uses ordered stages to process a sequence of input values. Each implemented + * task is represented by a stage of the pipeline. You can think of pipelines as similar to assembly + * lines in a factory, where each item in the assembly line is constructed in stages. The partially + * assembled item is passed from one assembly stage to another. The outputs of the assembly line + * occur in the same order as that of the inputs. * - * Classes used in this example are suffixed with "Handlers", and synonymously refers to the + *

Classes used in this example are suffixed with "Handlers", and synonymously refers to the * "stage". */ public class App { /** - * Specify the initial input type for the first stage handler and the expected output type - * of the last stage handler as type parameters for Pipeline. Use the fluent builder by - * calling addHandler to add more stage handlers on the pipeline. + * Specify the initial input type for the first stage handler and the expected output type of the + * last stage handler as type parameters for Pipeline. Use the fluent builder by calling + * addHandler to add more stage handlers on the pipeline. */ public static void main(String[] args) { /* diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/ConvertToCharArrayHandler.java b/pipeline/src/main/java/com/iluwatar/pipeline/ConvertToCharArrayHandler.java index 104d81f40..365fc1cdc 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/ConvertToCharArrayHandler.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/ConvertToCharArrayHandler.java @@ -23,11 +23,10 @@ package com.iluwatar.pipeline; +import java.util.Arrays; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.Arrays; - /** * Stage handler that converts an input String to its char[] array counterpart. */ @@ -38,8 +37,10 @@ class ConvertToCharArrayHandler implements Handler { @Override public char[] process(String input) { char[] characters = input.toCharArray(); - LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", - ConvertToCharArrayHandler.class, input, String.class, Arrays.toString(characters), Character[].class)); + LOGGER + .info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", + ConvertToCharArrayHandler.class, input, String.class, Arrays + .toString(characters), Character[].class)); return characters; } diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/Handler.java b/pipeline/src/main/java/com/iluwatar/pipeline/Handler.java index 253bc22f5..5591632e0 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/Handler.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/Handler.java @@ -24,7 +24,9 @@ package com.iluwatar.pipeline; /** - * Forms a contract to all stage handlers to accept a certain type of input and return a processed output. + * Forms a contract to all stage handlers to accept a certain type of input and return a processed + * output. + * * @param the input type of the handler * @param the processed output type of the handler */ diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/Pipeline.java b/pipeline/src/main/java/com/iluwatar/pipeline/Pipeline.java index af5c69b1d..81b63e6cf 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/Pipeline.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/Pipeline.java @@ -24,8 +24,9 @@ package com.iluwatar.pipeline; /** - * Main Pipeline class that initially sets the current handler. Processed output - * of the initial handler is then passed as the input to the next stage handlers. + * Main Pipeline class that initially sets the current handler. Processed output of the initial + * handler is then passed as the input to the next stage handlers. + * * @param the type of the input for the first stage handler * @param the final stage handler's output type */ diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/RemoveAlphabetsHandler.java b/pipeline/src/main/java/com/iluwatar/pipeline/RemoveAlphabetsHandler.java index 930332671..b2ed938cf 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/RemoveAlphabetsHandler.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/RemoveAlphabetsHandler.java @@ -27,7 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Stage handler that returns a new instance of String without the alphabet characters of the input string. + * Stage handler that returns a new instance of String without the alphabet characters of the input + * string. */ class RemoveAlphabetsHandler implements Handler { @@ -47,8 +48,13 @@ class RemoveAlphabetsHandler implements Handler { } String inputWithoutAlphabetsStr = inputWithoutAlphabets.toString(); - LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", - RemoveAlphabetsHandler.class, input, String.class, inputWithoutAlphabetsStr, String.class)); + LOGGER.info( + String.format( + "Current handler: %s, input is %s of type %s, output is %s, of type %s", + RemoveAlphabetsHandler.class, input, + String.class, inputWithoutAlphabetsStr, String.class + ) + ); return inputWithoutAlphabetsStr; } diff --git a/pipeline/src/main/java/com/iluwatar/pipeline/RemoveDigitsHandler.java b/pipeline/src/main/java/com/iluwatar/pipeline/RemoveDigitsHandler.java index 6fd591006..450bef717 100644 --- a/pipeline/src/main/java/com/iluwatar/pipeline/RemoveDigitsHandler.java +++ b/pipeline/src/main/java/com/iluwatar/pipeline/RemoveDigitsHandler.java @@ -27,7 +27,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Stage handler that returns a new instance of String without the digit characters of the input string. + * Stage handler that returns a new instance of String without the digit characters of the input + * string. */ class RemoveDigitsHandler implements Handler { @@ -47,8 +48,9 @@ class RemoveDigitsHandler implements Handler { } String inputWithoutDigitsStr = inputWithoutDigits.toString(); - LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", - RemoveDigitsHandler.class, input, String.class, inputWithoutDigitsStr, String.class)); + LOGGER + .info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", + RemoveDigitsHandler.class, input, String.class, inputWithoutDigitsStr, String.class)); return inputWithoutDigitsStr; } diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java index 6d6a41eb9..7fdf71a09 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/App.java @@ -30,16 +30,15 @@ package com.iluwatar.poison.pill; * Pill will stop reading messages from the queue. You must also ensure that the Poison Pill will be * the last message that will be read from the queue (if you have prioritized queue then this can be * tricky). - *

- * In simple cases the Poison Pill can be just a null-reference, but holding a unique separate + * + *

In simple cases the Poison Pill can be just a null-reference, but holding a unique separate * shared object-marker (with name "Poison" or "Poison Pill") is more clear and self describing. - * */ public class App { /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/Consumer.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/Consumer.java index 12cc246d8..25d2338e1 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/Consumer.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/Consumer.java @@ -28,10 +28,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Class responsible for receiving and handling submitted to the queue messages + * Class responsible for receiving and handling submitted to the queue messages. */ public class Consumer { - + private static final Logger LOGGER = LoggerFactory.getLogger(Consumer.class); private final MqSubscribePoint queue; @@ -43,7 +43,7 @@ public class Consumer { } /** - * Consume message + * Consume message. */ public void consume() { while (true) { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java index 9b35bf53a..b0298e407 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/Message.java @@ -65,7 +65,7 @@ public interface Message { }; /** - * Enumeration of Type of Headers + * Enumeration of Type of Headers. */ enum Headers { DATE, SENDER diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/MessageQueue.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/MessageQueue.java index ce8005fce..2928e172d 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/MessageQueue.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/MessageQueue.java @@ -24,7 +24,7 @@ package com.iluwatar.poison.pill; /** - * Represents abstraction of channel (or pipe) that bounds {@link Producer} and {@link Consumer} + * Represents abstraction of channel (or pipe) that bounds {@link Producer} and {@link Consumer}. */ public interface MessageQueue extends MqPublishPoint, MqSubscribePoint { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/MqPublishPoint.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/MqPublishPoint.java index b0e086637..f61a57987 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/MqPublishPoint.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/MqPublishPoint.java @@ -24,7 +24,7 @@ package com.iluwatar.poison.pill; /** - * Endpoint to publish {@link Message} to queue + * Endpoint to publish {@link Message} to queue. */ public interface MqPublishPoint { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/MqSubscribePoint.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/MqSubscribePoint.java index bb01e6395..b7133de8c 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/MqSubscribePoint.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/MqSubscribePoint.java @@ -24,7 +24,7 @@ package com.iluwatar.poison.pill; /** - * Endpoint to retrieve {@link Message} from queue + * Endpoint to retrieve {@link Message} from queue. */ public interface MqSubscribePoint { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/Producer.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/Producer.java index 0b746b31f..679500e43 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/Producer.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/Producer.java @@ -23,15 +23,14 @@ package com.iluwatar.poison.pill; -import java.util.Date; - import com.iluwatar.poison.pill.Message.Headers; +import java.util.Date; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * Class responsible for producing unit of work that can be expressed as message and submitted to - * queue + * queue. */ public class Producer { @@ -42,7 +41,7 @@ public class Producer { private boolean isStopped; /** - * Constructor + * Constructor. */ public Producer(String name, MqPublishPoint queue) { this.name = name; @@ -51,7 +50,7 @@ public class Producer { } /** - * Send message to queue + * Send message to queue. */ public void send(String body) { if (isStopped) { @@ -72,7 +71,7 @@ public class Producer { } /** - * Stop system by sending poison pill + * Stop system by sending poison pill. */ public void stop() { isStopped = true; diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessage.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessage.java index efc45fc83..8a7af515f 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessage.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessage.java @@ -28,7 +28,7 @@ import java.util.HashMap; import java.util.Map; /** - * {@link Message} basic implementation + * {@link Message} basic implementation. */ public class SimpleMessage implements Message { diff --git a/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessageQueue.java b/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessageQueue.java index 7f1b662cd..f6a50d4ff 100644 --- a/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessageQueue.java +++ b/poison-pill/src/main/java/com/iluwatar/poison/pill/SimpleMessageQueue.java @@ -27,7 +27,7 @@ import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; /** - * Bounded blocking queue wrapper + * Bounded blocking queue wrapper. */ public class SimpleMessageQueue implements MessageQueue { diff --git a/priority-queue/src/main/java/com/iluwatar/priority/queue/Application.java b/priority-queue/src/main/java/com/iluwatar/priority/queue/Application.java index 1e6e44a68..e803489b2 100644 --- a/priority-queue/src/main/java/com/iluwatar/priority/queue/Application.java +++ b/priority-queue/src/main/java/com/iluwatar/priority/queue/Application.java @@ -25,16 +25,15 @@ package com.iluwatar.priority.queue; /** * Prioritize requests sent to services so that requests with a higher priority are received and - * processed more quickly than those of a lower priority. - * This pattern is useful in applications that offer different service level guarantees - * to individual clients. - * Example :Send multiple message with different priority to worker queue. - * Worker execute higher priority message first + * processed more quickly than those of a lower priority. This pattern is useful in applications + * that offer different service level guarantees to individual clients. Example :Send multiple + * message with different priority to worker queue. Worker execute higher priority message first + * * @see "https://docs.microsoft.com/en-us/previous-versions/msp-n-p/dn589794(v=pandp.10)" */ public class Application { /** - * main entry + * main entry. */ public static void main(String[] args) throws Exception { diff --git a/priority-queue/src/main/java/com/iluwatar/priority/queue/Message.java b/priority-queue/src/main/java/com/iluwatar/priority/queue/Message.java index b874bd677..a9a3dcfa6 100644 --- a/priority-queue/src/main/java/com/iluwatar/priority/queue/Message.java +++ b/priority-queue/src/main/java/com/iluwatar/priority/queue/Message.java @@ -24,7 +24,7 @@ package com.iluwatar.priority.queue; /** - * Message bean + * Message bean. */ public class Message implements Comparable { private final String message; diff --git a/priority-queue/src/main/java/com/iluwatar/priority/queue/PriorityMessageQueue.java b/priority-queue/src/main/java/com/iluwatar/priority/queue/PriorityMessageQueue.java index ff73a496f..66f4d4f59 100644 --- a/priority-queue/src/main/java/com/iluwatar/priority/queue/PriorityMessageQueue.java +++ b/priority-queue/src/main/java/com/iluwatar/priority/queue/PriorityMessageQueue.java @@ -23,11 +23,11 @@ package com.iluwatar.priority.queue; +import static java.util.Arrays.copyOf; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static java.util.Arrays.copyOf; - /** * Keep high Priority message on top using maxHeap. * @@ -50,14 +50,14 @@ public class PriorityMessageQueue { } /** - * Remove top message from queue + * Remove top message from queue. */ public T remove() { if (isEmpty()) { return null; } - T root = queue[0]; + final T root = queue[0]; queue[0] = queue[size - 1]; size--; maxHeapifyDown(); @@ -65,7 +65,7 @@ public class PriorityMessageQueue { } /** - * Add message to queue + * Add message to queue. */ public void add(T t) { ensureCapacity(); @@ -75,7 +75,7 @@ public class PriorityMessageQueue { } /** - * Check queue size + * Check queue size. */ public boolean isEmpty() { return size == 0; diff --git a/priority-queue/src/main/java/com/iluwatar/priority/queue/QueueManager.java b/priority-queue/src/main/java/com/iluwatar/priority/queue/QueueManager.java index ade211766..7eca0aca6 100644 --- a/priority-queue/src/main/java/com/iluwatar/priority/queue/QueueManager.java +++ b/priority-queue/src/main/java/com/iluwatar/priority/queue/QueueManager.java @@ -24,7 +24,7 @@ package com.iluwatar.priority.queue; /** - * Manage priority queue + * Manage priority queue. */ public class QueueManager { /* @@ -37,7 +37,7 @@ public class QueueManager { } /** - * Publish message to queue + * Publish message to queue. */ public void publishMessage(Message message) { messagePriorityMessageQueue.add(message); @@ -45,7 +45,7 @@ public class QueueManager { /** - * recive message from queue + * recive message from queue. */ public Message receiveMessage() { if (messagePriorityMessageQueue.isEmpty()) { diff --git a/priority-queue/src/main/java/com/iluwatar/priority/queue/Worker.java b/priority-queue/src/main/java/com/iluwatar/priority/queue/Worker.java index bbeb64b73..18ed16199 100644 --- a/priority-queue/src/main/java/com/iluwatar/priority/queue/Worker.java +++ b/priority-queue/src/main/java/com/iluwatar/priority/queue/Worker.java @@ -27,7 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * Message Worker + * Message Worker. */ public class Worker { @@ -40,7 +40,7 @@ public class Worker { } /** - * Keep checking queue for message + * Keep checking queue for message. */ @SuppressWarnings("squid:S2189") public void run() throws Exception { @@ -56,7 +56,7 @@ public class Worker { } /** - * Process message + * Process message. */ private void processMessage(Message message) { LOGGER.info(message.toString()); diff --git a/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java b/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java index c5b75eee4..367baaf8b 100644 --- a/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java +++ b/private-class-data/src/main/java/com/iluwatar/privateclassdata/App.java @@ -24,26 +24,24 @@ package com.iluwatar.privateclassdata; /** - * * The Private Class Data design pattern seeks to reduce exposure of attributes by limiting their * visibility. It reduces the number of class attributes by encapsulating them in single data * object. It allows the class designer to remove write privilege of attributes that are intended to * be set only during construction, even from methods of the target class. - *

- * In the example we have normal {@link Stew} class with some ingredients given in constructor. Then - * we have methods to enumerate the ingredients and to taste the stew. The method for tasting the - * stew alters the private members of the {@link Stew} class. - * - * The problem is solved with the Private Class Data pattern. We introduce {@link ImmutableStew} - * class that contains {@link StewData}. The private data members of {@link Stew} are now in - * {@link StewData} and cannot be altered by {@link ImmutableStew} methods. * + *

In the example we have normal {@link Stew} class with some ingredients given in constructor. + * Then we have methods to enumerate the ingredients and to taste the stew. The method for tasting + * the stew alters the private members of the {@link Stew} class. + * + *

The problem is solved with the Private Class Data pattern. We introduce {@link ImmutableStew} + * class that contains {@link StewData}. The private data members of {@link Stew} are now in {@link + * StewData} and cannot be altered by {@link ImmutableStew} methods. */ public class App { /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) { diff --git a/private-class-data/src/main/java/com/iluwatar/privateclassdata/ImmutableStew.java b/private-class-data/src/main/java/com/iluwatar/privateclassdata/ImmutableStew.java index 627d74462..695424695 100644 --- a/private-class-data/src/main/java/com/iluwatar/privateclassdata/ImmutableStew.java +++ b/private-class-data/src/main/java/com/iluwatar/privateclassdata/ImmutableStew.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * Immutable stew class, protected with Private Class Data pattern - * + * Immutable stew class, protected with Private Class Data pattern. */ public class ImmutableStew { @@ -42,10 +40,11 @@ public class ImmutableStew { } /** - * Mix the stew + * Mix the stew. */ public void mix() { - LOGGER.info("Mixing the immutable stew we find: {} potatoes, {} carrots, {} meat and {} peppers", - data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers()); + LOGGER + .info("Mixing the immutable stew we find: {} potatoes, {} carrots, {} meat and {} peppers", + data.getNumPotatoes(), data.getNumCarrots(), data.getNumMeat(), data.getNumPeppers()); } } diff --git a/private-class-data/src/main/java/com/iluwatar/privateclassdata/Stew.java b/private-class-data/src/main/java/com/iluwatar/privateclassdata/Stew.java index 6618ee5da..65ba6c08e 100644 --- a/private-class-data/src/main/java/com/iluwatar/privateclassdata/Stew.java +++ b/private-class-data/src/main/java/com/iluwatar/privateclassdata/Stew.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * - * Mutable stew class - * + * Mutable stew class. */ public class Stew { @@ -41,7 +39,7 @@ public class Stew { private int numPeppers; /** - * Constructor + * Constructor. */ public Stew(int numPotatoes, int numCarrots, int numMeat, int numPeppers) { this.numPotatoes = numPotatoes; @@ -51,7 +49,7 @@ public class Stew { } /** - * Mix the stew + * Mix the stew. */ public void mix() { LOGGER.info("Mixing the stew we find: {} potatoes, {} carrots, {} meat and {} peppers", @@ -59,7 +57,7 @@ public class Stew { } /** - * Taste the stew + * Taste the stew. */ public void taste() { LOGGER.info("Tasting the stew"); diff --git a/private-class-data/src/main/java/com/iluwatar/privateclassdata/StewData.java b/private-class-data/src/main/java/com/iluwatar/privateclassdata/StewData.java index c170a531e..bcdaba3e9 100644 --- a/private-class-data/src/main/java/com/iluwatar/privateclassdata/StewData.java +++ b/private-class-data/src/main/java/com/iluwatar/privateclassdata/StewData.java @@ -24,9 +24,7 @@ package com.iluwatar.privateclassdata; /** - * - * Stew ingredients - * + * Stew ingredients. */ public class StewData { @@ -36,7 +34,7 @@ public class StewData { private int numPeppers; /** - * Constructor + * Constructor. */ public StewData(int numPotatoes, int numCarrots, int numMeat, int numPeppers) { this.numPotatoes = numPotatoes; diff --git a/property/src/main/java/com/iluwatar/property/App.java b/property/src/main/java/com/iluwatar/property/App.java index a7045e6df..d37dd5fd7 100644 --- a/property/src/main/java/com/iluwatar/property/App.java +++ b/property/src/main/java/com/iluwatar/property/App.java @@ -28,25 +28,23 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * The Property pattern is also known as Prototype inheritance. - *

- * In prototype inheritance instead of classes, as opposite to Java class inheritance, objects are - * used to create another objects and object hierarchies. Hierarchies are created using prototype - * chain through delegation: every object has link to parent object. Any base (parent) object can be - * amended at runtime (by adding or removal of some property), and all child objects will be - * affected as result. - *

- * In this example we demonstrate {@link Character} instantiation using the Property pattern. - * + * + *

In prototype inheritance instead of classes, as opposite to Java class inheritance, objects + * are used to create another objects and object hierarchies. Hierarchies are created using + * prototype chain through delegation: every object has link to parent object. Any base (parent) + * object can be amended at runtime (by adding or removal of some property), and all child objects + * will be affected as result. + * + *

In this example we demonstrate {@link Character} instantiation using the Property pattern. */ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) { diff --git a/property/src/main/java/com/iluwatar/property/Character.java b/property/src/main/java/com/iluwatar/property/Character.java index ef19f0107..bbe701459 100644 --- a/property/src/main/java/com/iluwatar/property/Character.java +++ b/property/src/main/java/com/iluwatar/property/Character.java @@ -32,7 +32,7 @@ import java.util.Map; public class Character implements Prototype { /** - * Enumeration of Character types + * Enumeration of Character types. */ public enum Type { WARRIOR, MAGE, ROGUE @@ -45,26 +45,28 @@ public class Character implements Prototype { private Type type; /** - * Constructor + * Constructor. */ public Character() { this.prototype = new Prototype() { // Null-value object - @Override - public Integer get(Stats stat) { - return null; - } + @Override + public Integer get(Stats stat) { + return null; + } - @Override - public boolean has(Stats stat) { - return false; - } + @Override + public boolean has(Stats stat) { + return false; + } - @Override - public void set(Stats stat, Integer val) {} + @Override + public void set(Stats stat, Integer val) { + } - @Override - public void remove(Stats stat) {} - }; + @Override + public void remove(Stats stat) { + } + }; } public Character(Type type, Prototype prototype) { @@ -73,7 +75,7 @@ public class Character implements Prototype { } /** - * Constructor + * Constructor. */ public Character(String name, Character prototype) { this.name = name; diff --git a/property/src/main/java/com/iluwatar/property/Prototype.java b/property/src/main/java/com/iluwatar/property/Prototype.java index 9570f6653..423863522 100644 --- a/property/src/main/java/com/iluwatar/property/Prototype.java +++ b/property/src/main/java/com/iluwatar/property/Prototype.java @@ -24,7 +24,7 @@ package com.iluwatar.property; /** - * Interface for prototype inheritance + * Interface for prototype inheritance. */ public interface Prototype { diff --git a/property/src/main/java/com/iluwatar/property/Stats.java b/property/src/main/java/com/iluwatar/property/Stats.java index 4015e5693..2941299d5 100644 --- a/property/src/main/java/com/iluwatar/property/Stats.java +++ b/property/src/main/java/com/iluwatar/property/Stats.java @@ -24,7 +24,7 @@ package com.iluwatar.property; /** - * All possible attributes that Character can have + * All possible attributes that Character can have. */ public enum Stats { diff --git a/prototype/src/main/java/com/iluwatar/prototype/App.java b/prototype/src/main/java/com/iluwatar/prototype/App.java index 457f4f2a0..9b1d4eb32 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/App.java +++ b/prototype/src/main/java/com/iluwatar/prototype/App.java @@ -27,41 +27,43 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * The Prototype pattern is a creational design pattern in software development. It is used when the * type of objects to create is determined by a prototypical instance, which is cloned to produce * new objects. This pattern is used to: - avoid subclasses of an object creator in the client * application, like the abstract factory pattern does. - avoid the inherent cost of creating a new * object in the standard way (e.g., using the 'new' keyword) - *

- * In this example we have a factory class ({@link HeroFactoryImpl}) producing objects by cloning - * the existing ones. The factory's prototype objects are given as constructor parameters. - * + * + *

In this example we have a factory class ({@link HeroFactoryImpl}) producing objects by + * cloning the existing ones. The factory's prototype objects are given as constructor parameters. */ public class App { private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** - * Program entry point - * + * Program entry point. + * * @param args command line args */ public static void main(String[] args) { - HeroFactory factory; - Mage mage; - Warlord warlord; - Beast beast; - - factory = new HeroFactoryImpl(new ElfMage("cooking"), new ElfWarlord("cleaning"), new ElfBeast("protecting")); - mage = factory.createMage(); - warlord = factory.createWarlord(); - beast = factory.createBeast(); + HeroFactory factory = new HeroFactoryImpl( + new ElfMage("cooking"), + new ElfWarlord("cleaning"), + new ElfBeast("protecting") + ); + Mage mage = factory.createMage(); + Warlord warlord = factory.createWarlord(); + Beast beast = factory.createBeast(); LOGGER.info(mage.toString()); LOGGER.info(warlord.toString()); LOGGER.info(beast.toString()); - factory = new HeroFactoryImpl(new OrcMage("axe"), new OrcWarlord("sword"), new OrcBeast("laser")); + factory = + new HeroFactoryImpl( + new OrcMage("axe"), + new OrcWarlord("sword"), + new OrcBeast("laser") + ); mage = factory.createMage(); warlord = factory.createWarlord(); beast = factory.createBeast(); diff --git a/prototype/src/main/java/com/iluwatar/prototype/Beast.java b/prototype/src/main/java/com/iluwatar/prototype/Beast.java index 3b82cdd9d..e3b25b850 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Beast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Beast.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * Beast - * + * Beast. */ public abstract class Beast extends Prototype { diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java index 9ef44b164..50761964a 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfBeast.java @@ -24,12 +24,10 @@ package com.iluwatar.prototype; /** - * - * ElfBeast - * + * ElfBeast. */ public class ElfBeast extends Beast { - + private String helpType; public ElfBeast(String helpType) { diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java index 14b6e6261..014c39bac 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfMage.java @@ -24,15 +24,13 @@ package com.iluwatar.prototype; /** - * - * ElfMage - * + * ElfMage. */ public class ElfMage extends Mage { - + private String helpType; - + public ElfMage(String helpType) { this.helpType = helpType; } diff --git a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java index 6c5a4a4ff..43cdac7e5 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/ElfWarlord.java @@ -24,14 +24,12 @@ package com.iluwatar.prototype; /** - * - * ElfWarlord - * + * ElfWarlord. */ public class ElfWarlord extends Warlord { private String helpType; - + public ElfWarlord(String helpType) { this.helpType = helpType; } diff --git a/prototype/src/main/java/com/iluwatar/prototype/HeroFactory.java b/prototype/src/main/java/com/iluwatar/prototype/HeroFactory.java index 791671289..264416797 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/HeroFactory.java +++ b/prototype/src/main/java/com/iluwatar/prototype/HeroFactory.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * * Interface for the factory class. - * */ public interface HeroFactory { diff --git a/prototype/src/main/java/com/iluwatar/prototype/HeroFactoryImpl.java b/prototype/src/main/java/com/iluwatar/prototype/HeroFactoryImpl.java index 5803ee8ef..b9348a3b2 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/HeroFactoryImpl.java +++ b/prototype/src/main/java/com/iluwatar/prototype/HeroFactoryImpl.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * * Concrete factory class. - * */ public class HeroFactoryImpl implements HeroFactory { @@ -35,7 +33,7 @@ public class HeroFactoryImpl implements HeroFactory { private Beast beast; /** - * Constructor + * Constructor. */ public HeroFactoryImpl(Mage mage, Warlord warlord, Beast beast) { this.mage = mage; @@ -44,7 +42,7 @@ public class HeroFactoryImpl implements HeroFactory { } /** - * Create mage + * Create mage. */ public Mage createMage() { try { @@ -55,7 +53,7 @@ public class HeroFactoryImpl implements HeroFactory { } /** - * Create warlord + * Create warlord. */ public Warlord createWarlord() { try { @@ -66,7 +64,7 @@ public class HeroFactoryImpl implements HeroFactory { } /** - * Create beast + * Create beast. */ public Beast createBeast() { try { diff --git a/prototype/src/main/java/com/iluwatar/prototype/Mage.java b/prototype/src/main/java/com/iluwatar/prototype/Mage.java index 9da5e45ba..27c3bae7a 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Mage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Mage.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * Mage - * + * Mage. */ public abstract class Mage extends Prototype { diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java index 2b5fb5159..c800b3ac5 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcBeast.java @@ -24,18 +24,16 @@ package com.iluwatar.prototype; /** - * - * OrcBeast - * + * OrcBeast. */ public class OrcBeast extends Beast { - + private String weapon; public OrcBeast(String weapon) { this.weapon = weapon; } - + public OrcBeast(OrcBeast orcBeast) { this.weapon = orcBeast.weapon; } @@ -49,6 +47,6 @@ public class OrcBeast extends Beast { public String toString() { return "Orcish wolf attacks with " + weapon; } - + } diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java index de15b5e10..c71b59d06 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcMage.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * OrcMage - * + * OrcMage. */ public class OrcMage extends Mage { @@ -35,7 +33,7 @@ public class OrcMage extends Mage { public OrcMage(String weapon) { this.weapon = weapon; } - + public OrcMage(OrcMage orcMage) { this.weapon = orcMage.weapon; } diff --git a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java index 0b117357f..096fd49dc 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/OrcWarlord.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * OrcWarlord - * + * OrcWarlord. */ public class OrcWarlord extends Warlord { @@ -35,7 +33,7 @@ public class OrcWarlord extends Warlord { public OrcWarlord(String weapon) { this.weapon = weapon; } - + public OrcWarlord(OrcWarlord orcWarlord) { this.weapon = orcWarlord.weapon; } diff --git a/prototype/src/main/java/com/iluwatar/prototype/Prototype.java b/prototype/src/main/java/com/iluwatar/prototype/Prototype.java index bae58b026..c74c82f4a 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Prototype.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Prototype.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * Prototype - * + * Prototype. */ public abstract class Prototype implements Cloneable { diff --git a/prototype/src/main/java/com/iluwatar/prototype/Warlord.java b/prototype/src/main/java/com/iluwatar/prototype/Warlord.java index 7ce8922e9..c270ab80b 100644 --- a/prototype/src/main/java/com/iluwatar/prototype/Warlord.java +++ b/prototype/src/main/java/com/iluwatar/prototype/Warlord.java @@ -24,9 +24,7 @@ package com.iluwatar.prototype; /** - * - * Warlord - * + * Warlord. */ public abstract class Warlord extends Prototype { diff --git a/proxy/src/main/java/com/iluwatar/proxy/App.java b/proxy/src/main/java/com/iluwatar/proxy/App.java index 4c9d0efaa..ff02a6074 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/App.java +++ b/proxy/src/main/java/com/iluwatar/proxy/App.java @@ -24,25 +24,23 @@ package com.iluwatar.proxy; /** - * * A proxy, in its most general form, is a class functioning as an interface to something else. The * proxy could interface to anything: a network connection, a large object in memory, a file, or * some other resource that is expensive or impossible to duplicate. In short, a proxy is a wrapper * or agent object that is being called by the client to access the real serving object behind the * scenes. - *

- * The Proxy design pattern allows you to provide an interface to other objects by creating a + * + *

The Proxy design pattern allows you to provide an interface to other objects by creating a * wrapper class as the proxy. The wrapper class, which is the proxy, can add additional * functionality to the object of interest without changing the object's code. - *

- * In this example the proxy ({@link WizardTowerProxy}) controls access to the actual object ( + * + *

In this example the proxy ({@link WizardTowerProxy}) controls access to the actual object ( * {@link IvoryTower}). - * */ public class App { /** - * Program entry point + * Program entry point. */ public static void main(String[] args) { diff --git a/proxy/src/main/java/com/iluwatar/proxy/IvoryTower.java b/proxy/src/main/java/com/iluwatar/proxy/IvoryTower.java index 3adb96d86..658b19949 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/IvoryTower.java +++ b/proxy/src/main/java/com/iluwatar/proxy/IvoryTower.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * The object to be proxyed. - * */ public class IvoryTower implements WizardTower { diff --git a/proxy/src/main/java/com/iluwatar/proxy/Wizard.java b/proxy/src/main/java/com/iluwatar/proxy/Wizard.java index 031ab8dfd..fc77d80df 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/Wizard.java +++ b/proxy/src/main/java/com/iluwatar/proxy/Wizard.java @@ -24,9 +24,7 @@ package com.iluwatar.proxy; /** - * - * Wizard - * + * Wizard. */ public class Wizard { diff --git a/proxy/src/main/java/com/iluwatar/proxy/WizardTower.java b/proxy/src/main/java/com/iluwatar/proxy/WizardTower.java index ac83aa6ea..c08b49e7d 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/WizardTower.java +++ b/proxy/src/main/java/com/iluwatar/proxy/WizardTower.java @@ -24,7 +24,7 @@ package com.iluwatar.proxy; /** - * WizardTower interface + * WizardTower interface. */ public interface WizardTower { diff --git a/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java b/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java index 7e6b2acf0..e295850de 100644 --- a/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java +++ b/proxy/src/main/java/com/iluwatar/proxy/WizardTowerProxy.java @@ -27,9 +27,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * * The proxy controlling access to the {@link IvoryTower}. - * */ public class WizardTowerProxy implements WizardTower {