Resolves checkstyle errors for abstract-document abstract-factory acyclic-visitor adapter aggregator-microservices (#1080)

* Reduces checkstyle errors in abstract-document

* Reduces checkstyle errors in abstract-factory

* Reduces checkstyle errors in acyclic-visitor

* Reduces checkstyle errors in adapter

* Reduces checkstyle errors in aggregator-microservices
This commit is contained in:
Anurag Agarwal 2019-11-12 02:00:08 +05:30 committed by Ilkka Seppälä
parent 390795154f
commit 1e76d91929
50 changed files with 154 additions and 211 deletions

View File

@ -31,7 +31,7 @@ import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* Abstract implementation of Document interface * Abstract implementation of Document interface.
*/ */
public abstract class AbstractDocument implements Document { public abstract class AbstractDocument implements Document {
@ -64,7 +64,8 @@ public abstract class AbstractDocument implements Document {
public String toString() { public String toString() {
var builder = new StringBuilder(); var builder = new StringBuilder();
builder.append(getClass().getName()).append("["); builder.append(getClass().getName()).append("[");
properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value).append("]")); properties.forEach((key, value) -> builder.append("[").append(key).append(" : ").append(value)
.append("]"));
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }

View File

@ -25,46 +25,43 @@ package com.iluwatar.abstractdocument;
import com.iluwatar.abstractdocument.domain.Car; import com.iluwatar.abstractdocument.domain.Car;
import com.iluwatar.abstractdocument.domain.enums.Property; import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.List;
import java.util.Map;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.List;
import java.util.Map;
/** /**
* The Abstract Document pattern enables handling additional, non-static * The Abstract Document pattern enables handling additional, non-static properties. This pattern
* properties. This pattern uses concept of traits to enable type safety and * uses concept of traits to enable type safety and separate properties of different classes into
* separate properties of different classes into set of interfaces. * set of interfaces.
* <p> *
* <p> * <p>In Abstract Document pattern,({@link AbstractDocument}) fully implements {@link Document})
* In Abstract Document pattern,({@link AbstractDocument}) fully implements * interface. Traits are then defined to enable access to properties in usual, static way.
* {@link Document}) interface. Traits are then defined to enable access to
* properties in usual, static way.
*/ */
public class App { public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/** /**
* Executes the App * Executes the App.
*/ */
public App() { public App() {
LOGGER.info("Constructing parts and car"); LOGGER.info("Constructing parts and car");
var wheelProperties = Map.of( var wheelProperties = Map.of(
Property.TYPE.toString(), "wheel", Property.TYPE.toString(), "wheel",
Property.MODEL.toString(), "15C", Property.MODEL.toString(), "15C",
Property.PRICE.toString(), 100L); Property.PRICE.toString(), 100L);
var doorProperties = Map.of( var doorProperties = Map.of(
Property.TYPE.toString(), "door", Property.TYPE.toString(), "door",
Property.MODEL.toString(), "Lambo", Property.MODEL.toString(), "Lambo",
Property.PRICE.toString(), 300L); Property.PRICE.toString(), 300L);
var carProperties = Map.of( var carProperties = Map.of(
Property.MODEL.toString(), "300SL", Property.MODEL.toString(), "300SL",
Property.PRICE.toString(), 10000L, Property.PRICE.toString(), 10000L,
Property.PARTS.toString(), List.of(wheelProperties, doorProperties)); Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
var car = new Car(carProperties); var car = new Car(carProperties);
@ -72,11 +69,12 @@ public class App {
LOGGER.info("-> model: {}", car.getModel().get()); LOGGER.info("-> model: {}", car.getModel().get());
LOGGER.info("-> price: {}", car.getPrice().get()); LOGGER.info("-> price: {}", car.getPrice().get());
LOGGER.info("-> parts: "); LOGGER.info("-> parts: ");
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get())); car.getParts().forEach(p -> LOGGER
.info("\t{}/{}/{}", p.getType().get(), p.getModel().get(), p.getPrice().get()));
} }
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */

View File

@ -28,12 +28,12 @@ import java.util.function.Function;
import java.util.stream.Stream; import java.util.stream.Stream;
/** /**
* Document interface * Document interface.
*/ */
public interface Document { public interface Document {
/** /**
* Puts the value related to the key * Puts the value related to the key.
* *
* @param key element key * @param key element key
* @param value element value * @param value element value
@ -42,7 +42,7 @@ public interface Document {
Void put(String key, Object value); Void put(String key, Object value);
/** /**
* Gets the value for the key * Gets the value for the key.
* *
* @param key element key * @param key element key
* @return value or null * @return value or null
@ -50,7 +50,7 @@ public interface Document {
Object get(String key); Object get(String key);
/** /**
* Gets the stream of child documents * Gets the stream of child documents.
* *
* @param key element key * @param key element key
* @param constructor constructor of child class * @param constructor constructor of child class

View File

@ -23,12 +23,11 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import com.iluwatar.abstractdocument.AbstractDocument;
import java.util.Map; import java.util.Map;
import com.iluwatar.abstractdocument.AbstractDocument;
/** /**
* Car entity * Car entity.
*/ */
public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts { public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts {

View File

@ -23,13 +23,12 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import java.util.Optional;
import com.iluwatar.abstractdocument.Document; import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property; import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.Optional;
/** /**
* HasModel trait for static access to 'model' property * HasModel trait for static access to 'model' property.
*/ */
public interface HasModel extends Document { public interface HasModel extends Document {

View File

@ -23,13 +23,12 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import java.util.stream.Stream;
import com.iluwatar.abstractdocument.Document; import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property; import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.stream.Stream;
/** /**
* HasParts trait for static access to 'parts' property * HasParts trait for static access to 'parts' property.
*/ */
public interface HasParts extends Document { public interface HasParts extends Document {

View File

@ -23,13 +23,12 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import java.util.Optional;
import com.iluwatar.abstractdocument.Document; import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property; import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.Optional;
/** /**
* HasPrice trait for static access to 'price' property * HasPrice trait for static access to 'price' property.
*/ */
public interface HasPrice extends Document { public interface HasPrice extends Document {

View File

@ -23,13 +23,12 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import java.util.Optional;
import com.iluwatar.abstractdocument.Document; import com.iluwatar.abstractdocument.Document;
import com.iluwatar.abstractdocument.domain.enums.Property; import com.iluwatar.abstractdocument.domain.enums.Property;
import java.util.Optional;
/** /**
* HasType trait for static access to 'type' property * HasType trait for static access to 'type' property.
*/ */
public interface HasType extends Document { public interface HasType extends Document {

View File

@ -23,12 +23,11 @@
package com.iluwatar.abstractdocument.domain; package com.iluwatar.abstractdocument.domain;
import com.iluwatar.abstractdocument.AbstractDocument;
import java.util.Map; import java.util.Map;
import com.iluwatar.abstractdocument.AbstractDocument;
/** /**
* Part entity * Part entity.
*/ */
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice { public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractdocument.domain.enums; package com.iluwatar.abstractdocument.domain.enums;
/** /**
* * Enum To Describe Property type.
* Enum To Describe Property type
*
*/ */
public enum Property { public enum Property {

View File

@ -23,25 +23,23 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
/** /**
* * The Abstract Factory pattern provides a way to encapsulate a group of individual factories that
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme * have a common theme without specifying their concrete classes. In normal usage, the client
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of * software creates a concrete implementation of the abstract factory and then uses the generic
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part * interface of the factory to create the concrete objects that are part of the theme. The client
* of the theme. The client does not know (or care) which concrete objects it gets from each of these internal * does not know (or care) which concrete objects it gets from each of these internal factories,
* factories, since it uses only the generic interfaces of their products. This pattern separates the details of * since it uses only the generic interfaces of their products. This pattern separates the details
* implementation of a set of objects from their general usage and relies on object composition, as object creation is * of implementation of a set of objects from their general usage and relies on object composition,
* implemented in methods exposed in the factory interface. * as object creation is implemented in methods exposed in the factory interface.
* <p> *
* The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and its implementations ( * <p>The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory})
* {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both concrete implementations to create a * and its implementations ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
* king, a castle and an army. * both concrete implementations to create a king, a castle and an army.
*
*/ */
public class App { public class App {
@ -52,14 +50,14 @@ public class App {
private Army army; private Army army;
/** /**
* Creates kingdom * Creates kingdom.
*/ */
public void createKingdom(final KingdomFactory factory) { public void createKingdom(final KingdomFactory factory) {
setKing(factory.createKing()); setKing(factory.createKing());
setCastle(factory.createCastle()); setCastle(factory.createCastle());
setArmy(factory.createArmy()); setArmy(factory.createArmy());
} }
King getKing(final KingdomFactory factory) { King getKing(final KingdomFactory factory) {
return factory.createKing(); return factory.createKing();
} }
@ -71,7 +69,7 @@ public class App {
private void setKing(final King king) { private void setKing(final King king) {
this.king = king; this.king = king;
} }
Castle getCastle(final KingdomFactory factory) { Castle getCastle(final KingdomFactory factory) {
return factory.createCastle(); return factory.createCastle();
} }
@ -83,7 +81,7 @@ public class App {
private void setCastle(final Castle castle) { private void setCastle(final Castle castle) {
this.castle = castle; this.castle = castle;
} }
Army getArmy(final KingdomFactory factory) { Army getArmy(final KingdomFactory factory) {
return factory.createArmy(); return factory.createArmy();
} }
@ -125,9 +123,8 @@ public class App {
/** /**
* Program entry point. * Program entry point.
* *
* @param args * @param args command line args
* command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * Army interface.
* Army interface
*
*/ */
public interface Army { public interface Army {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * Castle interface.
* Castle interface
*
*/ */
public interface Castle { public interface Castle {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * ElfArmy.
* ElfArmy
*
*/ */
public class ElfArmy implements Army { public class ElfArmy implements Army {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * ElfCastle.
* ElfCastle
*
*/ */
public class ElfCastle implements Castle { public class ElfCastle implements Castle {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * ElfKing.
* ElfKing
*
*/ */
public class ElfKing implements King { public class ElfKing implements King {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
*
* ElfKingdomFactory concrete factory. * ElfKingdomFactory concrete factory.
*
*/ */
public class ElfKingdomFactory implements KingdomFactory { public class ElfKingdomFactory implements KingdomFactory {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * King interface.
* King interface
*
*/ */
public interface King { public interface King {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
*
* KingdomFactory factory interface. * KingdomFactory factory interface.
*
*/ */
public interface KingdomFactory { public interface KingdomFactory {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * OrcArmy.
* OrcArmy
*
*/ */
public class OrcArmy implements Army { public class OrcArmy implements Army {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * OrcCastle.
* OrcCastle
*
*/ */
public class OrcCastle implements Castle { public class OrcCastle implements Castle {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
* * OrcKing.
* OrcKing
*
*/ */
public class OrcKing implements King { public class OrcKing implements King {

View File

@ -24,9 +24,7 @@
package com.iluwatar.abstractfactory; package com.iluwatar.abstractfactory;
/** /**
*
* OrcKingdomFactory concrete factory. * OrcKingdomFactory concrete factory.
*
*/ */
public class OrcKingdomFactory implements KingdomFactory { public class OrcKingdomFactory implements KingdomFactory {

View File

@ -24,9 +24,9 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* All ModemVisitor interface extends all visitor interfaces. This interface * All ModemVisitor interface extends all visitor interfaces. This interface provides ease of use
* provides ease of use when a visitor needs to visit all modem types. * when a visitor needs to visit all modem types.
*/ */
public interface AllModemVisitor extends ZoomVisitor, HayesVisitor{ public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {
} }

View File

@ -24,30 +24,28 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* The Acyclic Visitor pattern allows new functions to be added to existing class * The Acyclic Visitor pattern allows new functions to be added to existing class hierarchies
* hierarchies without affecting those hierarchies, and without creating the dependency * without affecting those hierarchies, and without creating the dependency cycles that are inherent
* cycles that are inherent to the GoF Visitor pattern, by making the Visitor base class * to the GoF Visitor pattern, by making the Visitor base class degenerate
* degenerate *
* <p> * <p>In this example the visitor base class is {@link ModemVisitor}. The base class of the visited
* In this example the visitor base class is {@link ModemVisitor}. The base class of the * hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom} each one having
* visited hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom} * its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor} respectively. {@link
* each one having its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor} * ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor} implement each derivative's visit
* respectively. {@link ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor} * method only if it is required
* implement each derivative's visit method only if it is required
*/ */
public class App { public class App {
/** /**
* Program's entry point * Program's entry point.
*/ */
public static void main(String[] args) {
public static void main(String[] args) {
var conUnix = new ConfigureForUnixVisitor(); var conUnix = new ConfigureForUnixVisitor();
var conDos = new ConfigureForDosVisitor(); var conDos = new ConfigureForDosVisitor();
var zoom = new Zoom(); var zoom = new Zoom();
var hayes = new Hayes(); var hayes = new Hayes();
hayes.accept(conDos); // Hayes modem with Dos configurator hayes.accept(conDos); // Hayes modem with Dos configurator
zoom.accept(conDos); // Zoom modem with Dos configurator zoom.accept(conDos); // Zoom modem with Dos configurator
hayes.accept(conUnix); // Hayes modem with Unix configurator hayes.accept(conUnix); // Hayes modem with Unix configurator

View File

@ -27,8 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method * ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos
* for Dos manufacturer * manufacturer.
*/ */
public class ConfigureForDosVisitor implements AllModemVisitor { public class ConfigureForDosVisitor implements AllModemVisitor {

View File

@ -27,9 +27,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* ConfigureForUnixVisitor class implements zoom's visit method for Unix * ConfigureForUnixVisitor class implements zoom's visit method for Unix manufacturer, unlike
* manufacturer, unlike traditional visitor pattern, this class may selectively implement * traditional visitor pattern, this class may selectively implement visit for other modems.
* visit for other modems.
*/ */
public class ConfigureForUnixVisitor implements ZoomVisitor { public class ConfigureForUnixVisitor implements ZoomVisitor {

View File

@ -27,14 +27,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Hayes class implements its accept method * Hayes class implements its accept method.
*/ */
public class Hayes extends Modem { public class Hayes extends Modem {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class); private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
/** /**
* Accepts all visitors but honors only HayesVisitor * Accepts all visitors but honors only HayesVisitor.
*/ */
@Override @Override
public void accept(ModemVisitor modemVisitor) { public void accept(ModemVisitor modemVisitor) {
@ -45,10 +45,9 @@ public class Hayes extends Modem {
} }
} }
/** /**
* Hayes' modem's toString * Hayes' modem's toString method.
* method
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -24,7 +24,7 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* HayesVisitor interface * HayesVisitor interface.
*/ */
public interface HayesVisitor extends ModemVisitor { public interface HayesVisitor extends ModemVisitor {
void visit(Hayes hayes); void visit(Hayes hayes);

View File

@ -24,7 +24,7 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* Modem abstract class * Modem abstract class.
*/ */
public abstract class Modem { public abstract class Modem {
public abstract void accept(ModemVisitor modemVisitor); public abstract void accept(ModemVisitor modemVisitor);

View File

@ -24,9 +24,8 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* ModemVisitor interface does not contain any visit methods so that it does not * ModemVisitor interface does not contain any visit methods so that it does not depend on the
* depend on the visited hierarchy. Each derivative's visit method is declared in * visited hierarchy. Each derivative's visit method is declared in its own visitor interface
* its own visitor interface
*/ */
public interface ModemVisitor { public interface ModemVisitor {
// Visitor is a degenerate base class for all visitors. // Visitor is a degenerate base class for all visitors.

View File

@ -27,27 +27,26 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
/** /**
* Zoom class implements its accept method * Zoom class implements its accept method.
*/ */
public class Zoom extends Modem { public class Zoom extends Modem {
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class); private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
/** /**
* Accepts all visitors but honors only ZoomVisitor * Accepts all visitors but honors only ZoomVisitor.
*/ */
@Override @Override
public void accept(ModemVisitor modemVisitor) { public void accept(ModemVisitor modemVisitor) {
if (modemVisitor instanceof ZoomVisitor) { if (modemVisitor instanceof ZoomVisitor) {
((ZoomVisitor) modemVisitor).visit(this); ((ZoomVisitor) modemVisitor).visit(this);
} else { } else {
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem"); LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
} }
} }
/** /**
* Zoom modem's toString * Zoom modem's toString method.
* method
*/ */
@Override @Override
public String toString() { public String toString() {

View File

@ -24,7 +24,7 @@
package com.iluwatar.acyclicvisitor; package com.iluwatar.acyclicvisitor;
/** /**
* ZoomVisitor interface * ZoomVisitor interface.
*/ */
public interface ZoomVisitor extends ModemVisitor { public interface ZoomVisitor extends ModemVisitor {
void visit(Zoom zoom); void visit(Zoom zoom);

View File

@ -24,35 +24,28 @@
package com.iluwatar.adapter; package com.iluwatar.adapter;
/** /**
* An adapter helps two incompatible interfaces to work together. This is the * An adapter helps two incompatible interfaces to work together. This is the real world definition
* real world definition for an adapter. Interfaces may be incompatible but * for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
* the inner functionality should suit the need. The Adapter design pattern * The Adapter design pattern allows otherwise incompatible classes to work together by converting
* allows otherwise incompatible classes to work together by converting the * the interface of one class into an interface expected by the clients.
* interface of one class into an interface expected by the clients.
* *
* <p> * <p>There are two variations of the Adapter pattern: The class adapter implements the adaptee's
* There are two variations of the Adapter pattern: The class adapter * interface whereas the object adapter uses composition to contain the adaptee in the adapter
* implements the adaptee's interface whereas the object adapter uses * object. This example uses the object adapter approach.
* composition to contain the adaptee in the adapter object. This example uses
* the object adapter approach.
* *
* <p> * <p>The Adapter ({@link FishingBoatAdapter}) converts the interface of the adaptee class ({@link
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the * FishingBoat}) into a suitable one expected by the client ({@link RowingBoat}).
* adaptee class ({@link FishingBoat}) into a suitable one expected by the
* client ({@link RowingBoat}).
*
* <p>
* The story of this implementation is this. <br>
* Pirates are coming! we need a {@link RowingBoat} to flee! We have a
* {@link FishingBoat} and our captain. We have no time to make up a new ship!
* we need to reuse this {@link FishingBoat}. The captain needs a rowing boat
* which he can operate. The spec is in {@link RowingBoat}. We will use the
* Adapter pattern to reuse {@link FishingBoat}.
* *
* <p>The story of this implementation is this. <br> Pirates are coming! we need a {@link
* RowingBoat} to flee! We have a {@link FishingBoat} and our captain. We have no time to make up a
* new ship! we need to reuse this {@link FishingBoat}. The captain needs a rowing boat which he can
* operate. The spec is in {@link RowingBoat}. We will use the Adapter pattern to reuse {@link
* FishingBoat}.
*/ */
public final class App { public final class App {
private App() { } private App() {
}
/** /**
* Program entry point. * Program entry point.

View File

@ -24,14 +24,14 @@
package com.iluwatar.adapter; package com.iluwatar.adapter;
/** /**
* The Captain uses {@link RowingBoat} to sail. <br> * The Captain uses {@link RowingBoat} to sail. <br> This is the client in the pattern.
* This is the client in the pattern.
*/ */
public final class Captain { public final class Captain {
private RowingBoat rowingBoat; private RowingBoat rowingBoat;
public Captain() { } public Captain() {
}
public Captain(final RowingBoat boat) { public Captain(final RowingBoat boat) {
this.rowingBoat = boat; this.rowingBoat = boat;

View File

@ -23,15 +23,13 @@
package com.iluwatar.adapter; package com.iluwatar.adapter;
import org.slf4j.Logger;
import static org.slf4j.LoggerFactory.getLogger; import static org.slf4j.LoggerFactory.getLogger;
import org.slf4j.Logger;
/** /**
* * Device class (adaptee in the pattern). We want to reuse this class. Fishing boat moves by
* Device class (adaptee in the pattern). We want to reuse this class. * sailing.
* Fishing boat moves by sailing.
*
*/ */
final class FishingBoat { final class FishingBoat {

View File

@ -24,10 +24,8 @@
package com.iluwatar.adapter; package com.iluwatar.adapter;
/** /**
* * Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) * interface expected by the client ({@link Captain}).
* into {@link RowingBoat} interface expected by the client ({@link Captain}).
*
*/ */
public class FishingBoatAdapter implements RowingBoat { public class FishingBoatAdapter implements RowingBoat {

View File

@ -24,9 +24,7 @@
package com.iluwatar.adapter; package com.iluwatar.adapter;
/** /**
* The interface expected by the client.<br> * The interface expected by the client.<br> A rowing boat is rowed to move.
* A rowing boat is rowed to move.
*
*/ */
public interface RowingBoat { public interface RowingBoat {

View File

@ -24,14 +24,13 @@
package com.iluwatar.aggregator.microservices; package com.iluwatar.aggregator.microservices;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* The aggregator aggregates calls on various micro-services, collects * The aggregator aggregates calls on various micro-services, collects data and further publishes
* data and further publishes them under a REST endpoint. * them under a REST endpoint.
*/ */
@RestController @RestController
public class Aggregator { public class Aggregator {

View File

@ -27,13 +27,13 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
/** /**
* Spring Boot EntryPoint Class * Spring Boot EntryPoint Class.
*/ */
@SpringBootApplication @SpringBootApplication
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */

View File

@ -28,7 +28,6 @@ import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -44,7 +43,9 @@ public class ProductInformationClientImpl implements ProductInformationClient {
@Override @Override
public String getProductTitle() { public String getProductTitle() {
String response = null; String response = null;
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51515/information")).build(); var request =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51515/information"))
.build();
var client = HttpClient.newHttpClient(); var client = HttpClient.newHttpClient();
try { try {
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());

View File

@ -28,7 +28,6 @@ import java.net.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -45,7 +44,9 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
public Integer getProductInventories() { public Integer getProductInventories() {
var response = ""; var response = "";
var request = HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories")).build(); var request =
HttpRequest.newBuilder().GET().uri(URI.create("http://localhost:51516/inventories"))
.build();
var client = HttpClient.newHttpClient(); var client = HttpClient.newHttpClient();
try { try {
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString()); var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
@ -55,10 +56,10 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
} catch (InterruptedException ie) { } catch (InterruptedException ie) {
LOGGER.error("InterruptedException Occurred", ie); LOGGER.error("InterruptedException Occurred", ie);
} }
if("".equalsIgnoreCase(response)) { if ("".equalsIgnoreCase(response)) {
return null; return null;
} else { } else {
return Integer.parseInt(response); return Integer.parseInt(response);
} }
} }
} }

View File

@ -20,5 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
# #
server.port=50004 server.port=50004

View File

@ -23,15 +23,15 @@
package com.iluwatar.aggregator.microservices; package com.iluwatar.aggregator.microservices;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
/** /**
* Test Aggregation of domain objects * Test Aggregation of domain objects
*/ */

View File

@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* Controller providing endpoints to retrieve information about products * Controller providing endpoints to retrieve information about products.
*/ */
@RestController @RestController
public class InformationController { public class InformationController {

View File

@ -20,5 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
# #
server.port=51515 server.port=51515

View File

@ -23,10 +23,10 @@
package com.iluwatar.information.microservice; package com.iluwatar.information.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/** /**
* Test for Information Rest Controller * Test for Information Rest Controller
*/ */

View File

@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
* Controller providing endpoints to retrieve product inventories * Controller providing endpoints to retrieve product inventories.
*/ */
@RestController @RestController
public class InventoryController { public class InventoryController {

View File

@ -20,5 +20,4 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE. # THE SOFTWARE.
# #
server.port=51516 server.port=51516

View File

@ -23,10 +23,10 @@
package com.iluwatar.inventory.microservice; package com.iluwatar.inventory.microservice;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/** /**
* Test Inventory Rest Controller * Test Inventory Rest Controller
*/ */