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:
parent
390795154f
commit
1e76d91929
@ -31,7 +31,7 @@ import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Abstract implementation of Document interface
|
||||
* Abstract implementation of Document interface.
|
||||
*/
|
||||
public abstract class AbstractDocument implements Document {
|
||||
|
||||
@ -64,7 +64,8 @@ public abstract class AbstractDocument implements Document {
|
||||
public String toString() {
|
||||
var builder = new StringBuilder();
|
||||
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("]");
|
||||
return builder.toString();
|
||||
}
|
||||
|
@ -25,46 +25,43 @@ package com.iluwatar.abstractdocument;
|
||||
|
||||
import com.iluwatar.abstractdocument.domain.Car;
|
||||
import com.iluwatar.abstractdocument.domain.enums.Property;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The Abstract Document pattern enables handling additional, non-static
|
||||
* properties. This pattern uses concept of traits to enable type safety and
|
||||
* separate properties of different classes into set of interfaces.
|
||||
* <p>
|
||||
* <p>
|
||||
* In Abstract Document pattern,({@link AbstractDocument}) fully implements
|
||||
* {@link Document}) interface. Traits are then defined to enable access to
|
||||
* properties in usual, static way.
|
||||
* The Abstract Document pattern enables handling additional, non-static properties. This pattern
|
||||
* uses concept of traits to enable type safety and separate properties of different classes into
|
||||
* set of interfaces.
|
||||
*
|
||||
* <p>In Abstract Document pattern,({@link AbstractDocument}) fully implements {@link Document})
|
||||
* interface. Traits are then defined to enable access to properties in usual, static way.
|
||||
*/
|
||||
public class App {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
|
||||
|
||||
/**
|
||||
* Executes the App
|
||||
* Executes the App.
|
||||
*/
|
||||
public App() {
|
||||
LOGGER.info("Constructing parts and car");
|
||||
|
||||
var wheelProperties = Map.of(
|
||||
Property.TYPE.toString(), "wheel",
|
||||
Property.MODEL.toString(), "15C",
|
||||
Property.PRICE.toString(), 100L);
|
||||
Property.TYPE.toString(), "wheel",
|
||||
Property.MODEL.toString(), "15C",
|
||||
Property.PRICE.toString(), 100L);
|
||||
|
||||
var doorProperties = Map.of(
|
||||
Property.TYPE.toString(), "door",
|
||||
Property.MODEL.toString(), "Lambo",
|
||||
Property.PRICE.toString(), 300L);
|
||||
Property.TYPE.toString(), "door",
|
||||
Property.MODEL.toString(), "Lambo",
|
||||
Property.PRICE.toString(), 300L);
|
||||
|
||||
var carProperties = Map.of(
|
||||
Property.MODEL.toString(), "300SL",
|
||||
Property.PRICE.toString(), 10000L,
|
||||
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
||||
Property.MODEL.toString(), "300SL",
|
||||
Property.PRICE.toString(), 10000L,
|
||||
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
||||
|
||||
var car = new Car(carProperties);
|
||||
|
||||
@ -72,11 +69,12 @@ public class App {
|
||||
LOGGER.info("-> model: {}", car.getModel().get());
|
||||
LOGGER.info("-> price: {}", car.getPrice().get());
|
||||
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
|
||||
*/
|
||||
|
@ -28,12 +28,12 @@ import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Document interface
|
||||
* Document interface.
|
||||
*/
|
||||
public interface Document {
|
||||
|
||||
/**
|
||||
* Puts the value related to the key
|
||||
* Puts the value related to the key.
|
||||
*
|
||||
* @param key element key
|
||||
* @param value element value
|
||||
@ -42,7 +42,7 @@ public interface Document {
|
||||
Void put(String key, Object value);
|
||||
|
||||
/**
|
||||
* Gets the value for the key
|
||||
* Gets the value for the key.
|
||||
*
|
||||
* @param key element key
|
||||
* @return value or null
|
||||
@ -50,7 +50,7 @@ public interface Document {
|
||||
Object get(String key);
|
||||
|
||||
/**
|
||||
* Gets the stream of child documents
|
||||
* Gets the stream of child documents.
|
||||
*
|
||||
* @param key element key
|
||||
* @param constructor constructor of child class
|
||||
|
@ -23,12 +23,11 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||
import java.util.Map;
|
||||
|
||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||
|
||||
/**
|
||||
* Car entity
|
||||
* Car entity.
|
||||
*/
|
||||
public class Car extends AbstractDocument implements HasModel, HasPrice, HasParts {
|
||||
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.iluwatar.abstractdocument.Document;
|
||||
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 {
|
||||
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import com.iluwatar.abstractdocument.Document;
|
||||
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 {
|
||||
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.iluwatar.abstractdocument.Document;
|
||||
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 {
|
||||
|
||||
|
@ -23,13 +23,12 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.iluwatar.abstractdocument.Document;
|
||||
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 {
|
||||
|
||||
|
@ -23,12 +23,11 @@
|
||||
|
||||
package com.iluwatar.abstractdocument.domain;
|
||||
|
||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||
import java.util.Map;
|
||||
|
||||
import com.iluwatar.abstractdocument.AbstractDocument;
|
||||
|
||||
/**
|
||||
* Part entity
|
||||
* Part entity.
|
||||
*/
|
||||
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractdocument.domain.enums;
|
||||
|
||||
/**
|
||||
*
|
||||
* Enum To Describe Property type
|
||||
*
|
||||
* Enum To Describe Property type.
|
||||
*/
|
||||
public enum Property {
|
||||
|
||||
|
@ -23,25 +23,23 @@
|
||||
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
import com.iluwatar.abstractfactory.App.FactoryMaker.KingdomType;
|
||||
import org.slf4j.Logger;
|
||||
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 have a common theme
|
||||
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of
|
||||
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part
|
||||
* of the theme. The client does not know (or care) which concrete objects it gets from each of these internal
|
||||
* factories, since it uses only the generic interfaces of their products. This pattern separates the details of
|
||||
* implementation of a set of objects from their general usage and relies on object composition, 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 (
|
||||
* {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both concrete implementations to create a
|
||||
* king, a castle and an army.
|
||||
*
|
||||
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that
|
||||
* have a common theme without specifying their concrete classes. In normal usage, the client
|
||||
* software creates a concrete implementation of the abstract factory and then uses the generic
|
||||
* interface of the factory to create the concrete objects that are part of the theme. The client
|
||||
* does not know (or care) which concrete objects it gets from each of these internal factories,
|
||||
* since it uses only the generic interfaces of their products. This pattern separates the details
|
||||
* of implementation of a set of objects from their general usage and relies on object composition,
|
||||
* 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 ( {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses
|
||||
* both concrete implementations to create a king, a castle and an army.
|
||||
*/
|
||||
public class App {
|
||||
|
||||
@ -52,14 +50,14 @@ public class App {
|
||||
private Army army;
|
||||
|
||||
/**
|
||||
* Creates kingdom
|
||||
* Creates kingdom.
|
||||
*/
|
||||
public void createKingdom(final KingdomFactory factory) {
|
||||
setKing(factory.createKing());
|
||||
setCastle(factory.createCastle());
|
||||
setArmy(factory.createArmy());
|
||||
}
|
||||
|
||||
|
||||
King getKing(final KingdomFactory factory) {
|
||||
return factory.createKing();
|
||||
}
|
||||
@ -71,7 +69,7 @@ public class App {
|
||||
private void setKing(final King king) {
|
||||
this.king = king;
|
||||
}
|
||||
|
||||
|
||||
Castle getCastle(final KingdomFactory factory) {
|
||||
return factory.createCastle();
|
||||
}
|
||||
@ -83,7 +81,7 @@ public class App {
|
||||
private void setCastle(final Castle castle) {
|
||||
this.castle = castle;
|
||||
}
|
||||
|
||||
|
||||
Army getArmy(final KingdomFactory factory) {
|
||||
return factory.createArmy();
|
||||
}
|
||||
@ -125,9 +123,8 @@ public class App {
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args
|
||||
* command line args
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Army interface
|
||||
*
|
||||
* Army interface.
|
||||
*/
|
||||
public interface Army {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* Castle interface
|
||||
*
|
||||
* Castle interface.
|
||||
*/
|
||||
public interface Castle {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfArmy
|
||||
*
|
||||
* ElfArmy.
|
||||
*/
|
||||
public class ElfArmy implements Army {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfCastle
|
||||
*
|
||||
* ElfCastle.
|
||||
*/
|
||||
public class ElfCastle implements Castle {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfKing
|
||||
*
|
||||
* ElfKing.
|
||||
*/
|
||||
public class ElfKing implements King {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* ElfKingdomFactory concrete factory.
|
||||
*
|
||||
*/
|
||||
public class ElfKingdomFactory implements KingdomFactory {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* King interface
|
||||
*
|
||||
* King interface.
|
||||
*/
|
||||
public interface King {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* KingdomFactory factory interface.
|
||||
*
|
||||
*/
|
||||
public interface KingdomFactory {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcArmy
|
||||
*
|
||||
* OrcArmy.
|
||||
*/
|
||||
public class OrcArmy implements Army {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcCastle
|
||||
*
|
||||
* OrcCastle.
|
||||
*/
|
||||
public class OrcCastle implements Castle {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcKing
|
||||
*
|
||||
* OrcKing.
|
||||
*/
|
||||
public class OrcKing implements King {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.abstractfactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* OrcKingdomFactory concrete factory.
|
||||
*
|
||||
*/
|
||||
public class OrcKingdomFactory implements KingdomFactory {
|
||||
|
||||
|
@ -24,9 +24,9 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* All ModemVisitor interface extends all visitor interfaces. This interface
|
||||
* provides ease of use when a visitor needs to visit all modem types.
|
||||
* All ModemVisitor interface extends all visitor interfaces. This interface provides ease of use
|
||||
* when a visitor needs to visit all modem types.
|
||||
*/
|
||||
public interface AllModemVisitor extends ZoomVisitor, HayesVisitor{
|
||||
public interface AllModemVisitor extends ZoomVisitor, HayesVisitor {
|
||||
|
||||
}
|
||||
|
@ -24,30 +24,28 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* The Acyclic Visitor pattern allows new functions to be added to existing class
|
||||
* hierarchies without affecting those hierarchies, and without creating the dependency
|
||||
* cycles that are inherent to the GoF Visitor pattern, by making the Visitor base class
|
||||
* degenerate
|
||||
* <p>
|
||||
* In this example the visitor base class is {@link ModemVisitor}. The base class of the
|
||||
* visited hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom}
|
||||
* each one having its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor}
|
||||
* respectively. {@link ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor}
|
||||
* implement each derivative's visit method only if it is required
|
||||
* The Acyclic Visitor pattern allows new functions to be added to existing class hierarchies
|
||||
* without affecting those hierarchies, and without creating the dependency cycles that are inherent
|
||||
* to the GoF Visitor pattern, by making the Visitor base class degenerate
|
||||
*
|
||||
* <p>In this example the visitor base class is {@link ModemVisitor}. The base class of the visited
|
||||
* hierarchy is {@link Modem} and has two children {@link Hayes} and {@link Zoom} each one having
|
||||
* its own visitor interface {@link HayesVisitor} and {@link ZoomVisitor} respectively. {@link
|
||||
* ConfigureForUnixVisitor} and {@link ConfigureForDosVisitor} implement each derivative's visit
|
||||
* method only if it is required
|
||||
*/
|
||||
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 conDos = new ConfigureForDosVisitor();
|
||||
|
||||
|
||||
var zoom = new Zoom();
|
||||
var hayes = new Hayes();
|
||||
|
||||
|
||||
hayes.accept(conDos); // Hayes modem with Dos configurator
|
||||
zoom.accept(conDos); // Zoom modem with Dos configurator
|
||||
hayes.accept(conUnix); // Hayes modem with Unix configurator
|
||||
|
@ -27,8 +27,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method
|
||||
* for Dos manufacturer
|
||||
* ConfigureForDosVisitor class implements both zoom's and hayes' visit method for Dos
|
||||
* manufacturer.
|
||||
*/
|
||||
public class ConfigureForDosVisitor implements AllModemVisitor {
|
||||
|
||||
|
@ -27,9 +27,8 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* ConfigureForUnixVisitor class implements zoom's visit method for Unix
|
||||
* manufacturer, unlike traditional visitor pattern, this class may selectively implement
|
||||
* visit for other modems.
|
||||
* ConfigureForUnixVisitor class implements zoom's visit method for Unix manufacturer, unlike
|
||||
* traditional visitor pattern, this class may selectively implement visit for other modems.
|
||||
*/
|
||||
public class ConfigureForUnixVisitor implements ZoomVisitor {
|
||||
|
||||
|
@ -27,14 +27,14 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Hayes class implements its accept method
|
||||
* Hayes class implements its accept method.
|
||||
*/
|
||||
public class Hayes extends Modem {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
|
||||
|
||||
/**
|
||||
* Accepts all visitors but honors only HayesVisitor
|
||||
* Accepts all visitors but honors only HayesVisitor.
|
||||
*/
|
||||
@Override
|
||||
public void accept(ModemVisitor modemVisitor) {
|
||||
@ -45,10 +45,9 @@ public class Hayes extends Modem {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Hayes' modem's toString
|
||||
* method
|
||||
* Hayes' modem's toString method.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* HayesVisitor interface
|
||||
* HayesVisitor interface.
|
||||
*/
|
||||
public interface HayesVisitor extends ModemVisitor {
|
||||
void visit(Hayes hayes);
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* Modem abstract class
|
||||
* Modem abstract class.
|
||||
*/
|
||||
public abstract class Modem {
|
||||
public abstract void accept(ModemVisitor modemVisitor);
|
||||
|
@ -24,9 +24,8 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* ModemVisitor interface does not contain any visit methods so that it does not
|
||||
* depend on the visited hierarchy. Each derivative's visit method is declared in
|
||||
* its own visitor interface
|
||||
* ModemVisitor interface does not contain any visit methods so that it does not depend on the
|
||||
* visited hierarchy. Each derivative's visit method is declared in its own visitor interface
|
||||
*/
|
||||
public interface ModemVisitor {
|
||||
// Visitor is a degenerate base class for all visitors.
|
||||
|
@ -27,27 +27,26 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Zoom class implements its accept method
|
||||
* Zoom class implements its accept method.
|
||||
*/
|
||||
public class Zoom extends Modem {
|
||||
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ConfigureForDosVisitor.class);
|
||||
|
||||
/**
|
||||
* Accepts all visitors but honors only ZoomVisitor
|
||||
* Accepts all visitors but honors only ZoomVisitor.
|
||||
*/
|
||||
@Override
|
||||
public void accept(ModemVisitor modemVisitor) {
|
||||
if (modemVisitor instanceof ZoomVisitor) {
|
||||
if (modemVisitor instanceof ZoomVisitor) {
|
||||
((ZoomVisitor) modemVisitor).visit(this);
|
||||
} else {
|
||||
LOGGER.info("Only ZoomVisitor is allowed to visit Zoom modem");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Zoom modem's toString
|
||||
* method
|
||||
* Zoom modem's toString method.
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
|
@ -24,7 +24,7 @@
|
||||
package com.iluwatar.acyclicvisitor;
|
||||
|
||||
/**
|
||||
* ZoomVisitor interface
|
||||
* ZoomVisitor interface.
|
||||
*/
|
||||
public interface ZoomVisitor extends ModemVisitor {
|
||||
void visit(Zoom zoom);
|
||||
|
@ -24,35 +24,28 @@
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
/**
|
||||
* An adapter helps two incompatible interfaces to work together. This is the
|
||||
* real world definition for an adapter. Interfaces may be incompatible but
|
||||
* the inner functionality should suit the need. The Adapter design pattern
|
||||
* allows otherwise incompatible classes to work together by converting the
|
||||
* interface of one class into an interface expected by the clients.
|
||||
* An adapter helps two incompatible interfaces to work together. This is the real world definition
|
||||
* for an adapter. Interfaces may be incompatible but the inner functionality should suit the need.
|
||||
* The Adapter design pattern allows otherwise incompatible classes to work together by converting
|
||||
* the interface of one class into an interface expected by the clients.
|
||||
*
|
||||
* <p>
|
||||
* There are two variations of the Adapter pattern: The class adapter
|
||||
* implements the adaptee's interface whereas the object adapter uses
|
||||
* composition to contain the adaptee in the adapter object. This example uses
|
||||
* the object adapter approach.
|
||||
* <p>There are two variations of the Adapter pattern: The class adapter implements the adaptee's
|
||||
* interface whereas the object adapter uses composition to contain the adaptee in the adapter
|
||||
* object. This example uses the object adapter approach.
|
||||
*
|
||||
* <p>
|
||||
* The Adapter ({@link FishingBoatAdapter}) converts the interface of the
|
||||
* 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 Adapter ({@link FishingBoatAdapter}) converts the interface of the 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}.
|
||||
*/
|
||||
public final class App {
|
||||
|
||||
private App() { }
|
||||
private App() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
|
@ -24,14 +24,14 @@
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
/**
|
||||
* The Captain uses {@link RowingBoat} to sail. <br>
|
||||
* This is the client in the pattern.
|
||||
* The Captain uses {@link RowingBoat} to sail. <br> This is the client in the pattern.
|
||||
*/
|
||||
public final class Captain {
|
||||
|
||||
private RowingBoat rowingBoat;
|
||||
|
||||
public Captain() { }
|
||||
public Captain() {
|
||||
}
|
||||
|
||||
public Captain(final RowingBoat boat) {
|
||||
this.rowingBoat = boat;
|
||||
|
@ -23,15 +23,13 @@
|
||||
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
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 sailing.
|
||||
*
|
||||
* Device class (adaptee in the pattern). We want to reuse this class. Fishing boat moves by
|
||||
* sailing.
|
||||
*/
|
||||
final class FishingBoat {
|
||||
|
||||
|
@ -24,10 +24,8 @@
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Adapter class. Adapts the interface of the device ({@link FishingBoat})
|
||||
* into {@link RowingBoat} interface expected by the client ({@link Captain}).
|
||||
*
|
||||
* Adapter class. Adapts the interface of the device ({@link FishingBoat}) into {@link RowingBoat}
|
||||
* interface expected by the client ({@link Captain}).
|
||||
*/
|
||||
public class FishingBoatAdapter implements RowingBoat {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.adapter;
|
||||
|
||||
/**
|
||||
* The interface expected by the client.<br>
|
||||
* A rowing boat is rowed to move.
|
||||
*
|
||||
* The interface expected by the client.<br> A rowing boat is rowed to move.
|
||||
*/
|
||||
public interface RowingBoat {
|
||||
|
||||
|
@ -24,14 +24,13 @@
|
||||
package com.iluwatar.aggregator.microservices;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* The aggregator aggregates calls on various micro-services, collects
|
||||
* data and further publishes them under a REST endpoint.
|
||||
* The aggregator aggregates calls on various micro-services, collects data and further publishes
|
||||
* them under a REST endpoint.
|
||||
*/
|
||||
@RestController
|
||||
public class Aggregator {
|
||||
|
@ -27,13 +27,13 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
/**
|
||||
* Spring Boot EntryPoint Class
|
||||
* Spring Boot EntryPoint Class.
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class App {
|
||||
|
||||
/**
|
||||
* Program entry point
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args
|
||||
*/
|
||||
|
@ -28,7 +28,6 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -44,7 +43,9 @@ public class ProductInformationClientImpl implements ProductInformationClient {
|
||||
@Override
|
||||
public String getProductTitle() {
|
||||
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();
|
||||
try {
|
||||
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
|
@ -28,7 +28,6 @@ import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
@ -45,7 +44,9 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
public Integer getProductInventories() {
|
||||
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();
|
||||
try {
|
||||
var httpResponse = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
@ -55,10 +56,10 @@ public class ProductInventoryClientImpl implements ProductInventoryClient {
|
||||
} catch (InterruptedException ie) {
|
||||
LOGGER.error("InterruptedException Occurred", ie);
|
||||
}
|
||||
if("".equalsIgnoreCase(response)) {
|
||||
return null;
|
||||
if ("".equalsIgnoreCase(response)) {
|
||||
return null;
|
||||
} else {
|
||||
return Integer.parseInt(response);
|
||||
return Integer.parseInt(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,4 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
server.port=50004
|
@ -23,15 +23,15 @@
|
||||
|
||||
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.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Test Aggregation of domain objects
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve information about products
|
||||
* Controller providing endpoints to retrieve information about products.
|
||||
*/
|
||||
@RestController
|
||||
public class InformationController {
|
||||
|
@ -20,5 +20,4 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
server.port=51515
|
@ -23,10 +23,10 @@
|
||||
|
||||
package com.iluwatar.information.microservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test for Information Rest Controller
|
||||
*/
|
||||
|
@ -28,7 +28,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* Controller providing endpoints to retrieve product inventories
|
||||
* Controller providing endpoints to retrieve product inventories.
|
||||
*/
|
||||
@RestController
|
||||
public class InventoryController {
|
||||
|
@ -20,5 +20,4 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
# THE SOFTWARE.
|
||||
#
|
||||
|
||||
server.port=51516
|
@ -23,10 +23,10 @@
|
||||
|
||||
package com.iluwatar.inventory.microservice;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test Inventory Rest Controller
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user