Resolves checkstyle errors for ambassador, async-method-invocation, balking, bridge, builder (#1058)
* Decreases checkstyle errors for ambassador pattern * Reduces checkstyle errors in async-method-invocation * Reduces checkstyle errors in balking * Reduces checkstyle errors in bridge * Reduces checkstyle errors in builder
This commit is contained in:
committed by
Ilkka Seppälä
parent
1fa8a604eb
commit
6d1c0b1563
@ -28,36 +28,33 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
*
|
||||
* The intention of the Builder pattern is to find a solution to the telescoping constructor
|
||||
* anti-pattern. The telescoping constructor anti-pattern occurs when the increase of object
|
||||
* constructor parameter combination leads to an exponential list of constructors. Instead of using
|
||||
* numerous constructors, the builder pattern uses another object, a builder, that receives each
|
||||
* initialization parameter step by step and then returns the resulting constructed object at once.
|
||||
* <p>
|
||||
* The Builder pattern has another benefit. It can be used for objects that contain flat data (html
|
||||
* code, SQL query, X.509 certificate...), that is to say, data that can't be easily edited. This
|
||||
* type of data cannot be edited step by step and must be edited at once. The best way to construct
|
||||
* such an object is to use a builder class.
|
||||
* <p>
|
||||
* In this example we have the Builder pattern variation as described by Joshua Bloch in Effective
|
||||
* Java 2nd Edition.
|
||||
* <p>
|
||||
* We want to build {@link Hero} objects, but its construction is complex because of the many
|
||||
* parameters needed. To aid the user we introduce {@link Builder} class. {@link Hero.Builder}
|
||||
* takes the minimum parameters to build {@link Hero} object in its constructor. After that
|
||||
* additional configuration for the {@link Hero} object can be done using the fluent
|
||||
* {@link Builder} interface. When configuration is ready the build method is called to receive
|
||||
* the final {@link Hero} object.
|
||||
*
|
||||
*
|
||||
* <p>The Builder pattern has another benefit. It can be used for objects that contain flat data
|
||||
* (html code, SQL query, X.509 certificate...), that is to say, data that can't be easily edited.
|
||||
* This type of data cannot be edited step by step and must be edited at once. The best way to
|
||||
* construct such an object is to use a builder class.
|
||||
*
|
||||
* <p>In this example we have the Builder pattern variation as described by Joshua Bloch in
|
||||
* Effective Java 2nd Edition.
|
||||
*
|
||||
* <p>We want to build {@link Hero} objects, but its construction is complex because of the many
|
||||
* parameters needed. To aid the user we introduce {@link Builder} class. {@link Hero.Builder} takes
|
||||
* the minimum parameters to build {@link Hero} object in its constructor. After that additional
|
||||
* configuration for the {@link Hero} object can be done using the fluent {@link Builder} interface.
|
||||
* When configuration is ready the build method is called to receive the final {@link Hero} object.
|
||||
*/
|
||||
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) {
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Armor enumeration
|
||||
*
|
||||
* Armor enumeration.
|
||||
*/
|
||||
public enum Armor {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* HairColor enumeration
|
||||
*
|
||||
* HairColor enumeration.
|
||||
*/
|
||||
public enum HairColor {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* HairType enumeration
|
||||
*
|
||||
* HairType enumeration.
|
||||
*/
|
||||
public enum HairType {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Hero, the class with many parameters.
|
||||
*
|
||||
*/
|
||||
public final class Hero {
|
||||
|
||||
@ -75,9 +73,9 @@ public final class Hero {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("This is a ")
|
||||
.append(profession)
|
||||
.append(" named ")
|
||||
.append(name);
|
||||
.append(profession)
|
||||
.append(" named ")
|
||||
.append(name);
|
||||
if (hairColor != null || hairType != null) {
|
||||
sb.append(" with ");
|
||||
if (hairColor != null) {
|
||||
@ -99,9 +97,7 @@ public final class Hero {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* The builder class.
|
||||
*
|
||||
*/
|
||||
public static class Builder {
|
||||
|
||||
@ -113,7 +109,7 @@ public final class Hero {
|
||||
private Weapon weapon;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Constructor.
|
||||
*/
|
||||
public Builder(Profession profession, String name) {
|
||||
if (profession == null || name == null) {
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Profession enumeration
|
||||
*
|
||||
* Profession enumeration.
|
||||
*/
|
||||
public enum Profession {
|
||||
|
||||
|
@ -24,9 +24,7 @@
|
||||
package com.iluwatar.builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* Weapon enumeration
|
||||
*
|
||||
* Weapon enumeration.
|
||||
*/
|
||||
public enum Weapon {
|
||||
|
||||
|
Reference in New Issue
Block a user