Resolves checkstyle errors for intercepting-filter, interpreter, iterator (#1065)

* Reduces checkstyle errors in intercepting-filter

* Reduces checkstyle errors in interpreter

* Reduces checkstyle errors in iterator
This commit is contained in:
Anurag Agarwal
2019-11-10 22:35:05 +05:30
committed by Ilkka Seppälä
parent dda09535e6
commit 7f06f3b78c
27 changed files with 99 additions and 122 deletions

View File

@ -25,13 +25,13 @@ package com.iluwatar.intercepting.filter;
/** /**
* Base class for order processing filters. Handles chain management. * Base class for order processing filters. Handles chain management.
*
*/ */
public abstract class AbstractFilter implements Filter { public abstract class AbstractFilter implements Filter {
private Filter next; private Filter next;
public AbstractFilter() {} public AbstractFilter() {
}
public AbstractFilter(Filter next) { public AbstractFilter(Filter next) {
this.next = next; this.next = next;

View File

@ -28,7 +28,6 @@ package com.iluwatar.intercepting.filter;
* the address field. * the address field.
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class AddressFilter extends AbstractFilter { public class AddressFilter extends AbstractFilter {

View File

@ -24,7 +24,6 @@
package com.iluwatar.intercepting.filter; package com.iluwatar.intercepting.filter;
/** /**
*
* When a request enters a Web application, it often must pass several entrance tests prior to the * When a request enters a Web application, it often must pass several entrance tests prior to the
* main processing stage. For example, - Has the client been authenticated? - Does the client have a * main processing stage. For example, - Has the client been authenticated? - Does the client have a
* valid session? - Is the client's IP address from a trusted network? - Does the request path * valid session? - Is the client's IP address from a trusted network? - Does the request path
@ -32,27 +31,25 @@ package com.iluwatar.intercepting.filter;
* the browser type of the client? Some of these checks are tests, resulting in a yes or no answer * the browser type of the client? Some of these checks are tests, resulting in a yes or no answer
* that determines whether processing will continue. Other checks manipulate the incoming data * that determines whether processing will continue. Other checks manipulate the incoming data
* stream into a form suitable for processing. * stream into a form suitable for processing.
* <p> *
* The classic solution consists of a series of conditional checks, with any failed check aborting * <p>The classic solution consists of a series of conditional checks, with any failed check
* the request. Nested if/else statements are a standard strategy, but this solution leads to code * aborting the request. Nested if/else statements are a standard strategy, but this solution leads
* fragility and a copy-and-paste style of programming, because the flow of the filtering and the * to code fragility and a copy-and-paste style of programming, because the flow of the filtering
* action of the filters is compiled into the application. * and the action of the filters is compiled into the application.
* <p> *
* The key to solving this problem in a flexible and unobtrusive manner is to have a simple * <p>The key to solving this problem in a flexible and unobtrusive manner is to have a simple
* mechanism for adding and removing processing components, in which each component completes a * mechanism for adding and removing processing components, in which each component completes a
* specific filtering action. This is the Intercepting Filter pattern in action. * specific filtering action. This is the Intercepting Filter pattern in action.
* <p> *
* In this example we check whether the order request is valid through pre-processing done via * <p>In this example we check whether the order request is valid through pre-processing done via
* {@link Filter}. Each field has its own corresponding {@link Filter} * {@link Filter}. Each field has its own corresponding {@link Filter}.
* <p>
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class App { public class App {
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */

View File

@ -23,6 +23,9 @@
package com.iluwatar.intercepting.filter; package com.iluwatar.intercepting.filter;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;
@ -32,18 +35,15 @@ import javax.swing.JTextArea;
import javax.swing.JTextField; import javax.swing.JTextField;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.GridLayout;
/** /**
* The Client class is responsible for handling the input and running them through filters inside the * The Client class is responsible for handling the input and running them through filters inside
* {@link FilterManager}. * the {@link FilterManager}.
* *
* This is where {@link Filter}s come to play as the client pre-processes the request before being displayed in the * <p>This is where {@link Filter}s come to play as the client pre-processes the request before
* {@link Target}. * being displayed in the {@link Target}.
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class Client extends JFrame { // NOSONAR public class Client extends JFrame { // NOSONAR
@ -57,7 +57,7 @@ public class Client extends JFrame { // NOSONAR
private JButton processButton; private JButton processButton;
/** /**
* Constructor * Constructor.
*/ */
public Client() { public Client() {
super("Client System"); super("Client System");
@ -107,7 +107,9 @@ public class Client extends JFrame { // NOSONAR
}); });
processButton.addActionListener(e -> { processButton.addActionListener(e -> {
Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(), Order order =
new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2]
.getText(),
jtAreas[1].getText()); jtAreas[1].getText());
jl.setText(sendRequest(order)); jl.setText(sendRequest(order));
}); });

View File

@ -26,10 +26,9 @@ package com.iluwatar.intercepting.filter;
/** /**
* Concrete implementation of filter This filter checks for the contact field in which it checks if * Concrete implementation of filter This filter checks for the contact field in which it checks if
* the input consist of numbers and it also checks if the input follows the length constraint (11 * the input consist of numbers and it also checks if the input follows the length constraint (11
* digits) * digits).
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class ContactFilter extends AbstractFilter { public class ContactFilter extends AbstractFilter {

View File

@ -24,10 +24,9 @@
package com.iluwatar.intercepting.filter; package com.iluwatar.intercepting.filter;
/** /**
* Concrete implementation of filter This checks for the deposit code * Concrete implementation of filter This checks for the deposit code.
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class DepositFilter extends AbstractFilter { public class DepositFilter extends AbstractFilter {

View File

@ -28,7 +28,6 @@ package com.iluwatar.intercepting.filter;
* case, before the request is handled by the target, the request undergoes through each Filter * case, before the request is handled by the target, the request undergoes through each Filter
* *
* @author joshzambales * @author joshzambales
*
*/ */
public interface Filter { public interface Filter {

View File

@ -35,7 +35,7 @@ public class FilterChain {
/** /**
* Adds filter * Adds filter.
*/ */
public void addFilter(Filter filter) { public void addFilter(Filter filter) {
if (chain == null) { if (chain == null) {
@ -46,7 +46,7 @@ public class FilterChain {
} }
/** /**
* Execute filter chain * Execute filter chain.
*/ */
public String execute(Order order) { public String execute(Order order) {
if (chain != null) { if (chain != null) {

View File

@ -27,7 +27,6 @@ package com.iluwatar.intercepting.filter;
* Filter Manager manages the filters and {@link FilterChain}. * Filter Manager manages the filters and {@link FilterChain}.
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class FilterManager { public class FilterManager {

View File

@ -28,7 +28,6 @@ package com.iluwatar.intercepting.filter;
* (alphanumeric) * (alphanumeric)
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class NameFilter extends AbstractFilter { public class NameFilter extends AbstractFilter {

View File

@ -25,7 +25,6 @@ package com.iluwatar.intercepting.filter;
/** /**
* Order class carries the order data. * Order class carries the order data.
*
*/ */
public class Order { public class Order {
@ -35,12 +34,16 @@ public class Order {
private String depositNumber; private String depositNumber;
private String orderItem; private String orderItem;
public Order() {} public Order() {
}
/** /**
* Constructor * Constructor.
*/ */
public Order(String name, String contactNumber, String address, String depositNumber, String order) { public Order(
String name, String contactNumber, String address,
String depositNumber, String order
) {
this.name = name; this.name = name;
this.contactNumber = contactNumber; this.contactNumber = contactNumber;
this.address = address; this.address = address;

View File

@ -27,7 +27,6 @@ package com.iluwatar.intercepting.filter;
* Concrete implementation of filter. This checks for the order field. * Concrete implementation of filter. This checks for the order field.
* *
* @author joshzambales * @author joshzambales
*
*/ */
public class OrderFilter extends AbstractFilter { public class OrderFilter extends AbstractFilter {

View File

@ -23,6 +23,11 @@
package com.iluwatar.intercepting.filter; package com.iluwatar.intercepting.filter;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
@ -32,16 +37,11 @@ import javax.swing.JTable;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import javax.swing.table.DefaultTableModel; import javax.swing.table.DefaultTableModel;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/** /**
* This is where the requests are displayed after being validated by filters. * This is where the requests are displayed after being validated by filters.
* *
* @author mjoshzambales * @author mjoshzambales
*
*/ */
public class Target extends JFrame { //NOSONAR public class Target extends JFrame { //NOSONAR
@ -52,14 +52,14 @@ public class Target extends JFrame { //NOSONAR
private JButton del; private JButton del;
/** /**
* Constructor * Constructor.
*/ */
public Target() { public Target() {
super("Order System"); super("Order System");
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setSize(640, 480); setSize(640, 480);
dtm = dtm =
new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number", new DefaultTableModel(new Object[]{"Name", "Contact Number", "Address", "Deposit Number",
"Order"}, 0); "Order"}, 0);
jt = new JTable(dtm); jt = new JTable(dtm);
del = new JButton("Delete"); del = new JButton("Delete");
@ -85,7 +85,7 @@ public class Target extends JFrame { //NOSONAR
} }
public void execute(String[] request) { public void execute(String[] request) {
dtm.addRow(new Object[] {request[0], request[1], request[2], request[3], request[4]}); dtm.addRow(new Object[]{request[0], request[1], request[2], request[3], request[4]});
} }
class DListener implements ActionListener { class DListener implements ActionListener {

View File

@ -23,35 +23,30 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
import java.util.Stack;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.util.Stack;
/** /**
*
* The Interpreter pattern is a design pattern that specifies how to evaluate sentences in a * The Interpreter pattern is a design pattern that specifies how to evaluate sentences in a
* language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a * language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a
* specialized computer language. The syntax tree of a sentence in the language is an instance of * specialized computer language. The syntax tree of a sentence in the language is an instance of
* the composite pattern and is used to evaluate (interpret) the sentence for a client. * the composite pattern and is used to evaluate (interpret) the sentence for a client.
* <p>
* In this example we use the Interpreter pattern to break sentences into expressions (
* {@link Expression}) that can be evaluated and as a whole form the result.
* *
* <p>In this example we use the Interpreter pattern to break sentences into expressions ({@link
* Expression}) that can be evaluated and as a whole form the result.
*/ */
public class App { public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class); private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
/** /**
*
* Program entry point. * Program entry point.
* <p> *
* Expressions can be evaluated using prefix, infix or postfix notations This sample uses postfix, * <p>Expressions can be evaluated using prefix, infix or postfix notations This sample uses
* where operator comes after the operands * postfix, where operator comes after the operands.
* *
* @param args command line args * @param args command line args
*
*/ */
public static void main(String[] args) { public static void main(String[] args) {
String tokenString = "4 3 2 - 1 + *"; String tokenString = "4 3 2 - 1 + *";
@ -84,7 +79,7 @@ public class App {
} }
/** /**
* Get expression for string * Get expression for string.
*/ */
public static Expression getOperatorInstance(String s, Expression left, Expression right) { public static Expression getOperatorInstance(String s, Expression left, Expression right) {
switch (s) { switch (s) {

View File

@ -24,9 +24,7 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
/** /**
* * Expression.
* Expression
*
*/ */
public abstract class Expression { public abstract class Expression {

View File

@ -24,9 +24,7 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
/** /**
* * MinusExpression.
* MinusExpression
*
*/ */
public class MinusExpression extends Expression { public class MinusExpression extends Expression {

View File

@ -24,9 +24,7 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
/** /**
* * MultiplyExpression.
* MultiplyExpression
*
*/ */
public class MultiplyExpression extends Expression { public class MultiplyExpression extends Expression {

View File

@ -24,9 +24,7 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
/** /**
* * NumberExpression.
* NumberExpression
*
*/ */
public class NumberExpression extends Expression { public class NumberExpression extends Expression {

View File

@ -24,9 +24,7 @@
package com.iluwatar.interpreter; package com.iluwatar.interpreter;
/** /**
* * PlusExpression.
* PlusExpression
*
*/ */
public class PlusExpression extends Expression { public class PlusExpression extends Expression {

View File

@ -39,8 +39,8 @@ import org.slf4j.LoggerFactory;
/** /**
* The Iterator pattern is a design pattern in which an iterator is used to traverse a container and * The Iterator pattern is a design pattern in which an iterator is used to traverse a container and
* access the container's elements. The Iterator pattern decouples algorithms from containers. * access the container's elements. The Iterator pattern decouples algorithms from containers.
* <p> *
* In this example the Iterator ({@link Iterator}) adds abstraction layer on top of a collection * <p>In this example the Iterator ({@link Iterator}) adds abstraction layer on top of a collection
* ({@link TreasureChest}). This way the collection can change its internal implementation without * ({@link TreasureChest}). This way the collection can change its internal implementation without
* affecting its clients. * affecting its clients.
*/ */
@ -85,7 +85,7 @@ public class App {
} }
/** /**
* Program entry point * Program entry point.
* *
* @param args command line args * @param args command line args
*/ */

View File

@ -24,7 +24,8 @@
package com.iluwatar.iterator; package com.iluwatar.iterator;
/** /**
* Iterator interface to be implemented by iterators over various data structures * Iterator interface to be implemented by iterators over various data structures.
*
* @param <T> generically typed for various objects * @param <T> generically typed for various objects
*/ */
public interface Iterator<T> { public interface Iterator<T> {

View File

@ -46,7 +46,7 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
/** /**
* This BstIterator manages to use O(h) extra space, where h is the height of the tree It achieves * This BstIterator manages to use O(h) extra space, where h is the height of the tree It achieves
* this by maintaining a stack of the nodes to handle (pushing all left nodes first), before * this by maintaining a stack of the nodes to handle (pushing all left nodes first), before
* handling self or right node * handling self or right node.
* *
* @param node TreeNode that acts as root of the subtree we're interested in. * @param node TreeNode that acts as root of the subtree we're interested in.
*/ */
@ -58,6 +58,8 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
} }
/** /**
* Checks if there exists next element.
*
* @return true if this iterator has a "next" element * @return true if this iterator has a "next" element
*/ */
@Override @Override
@ -66,6 +68,8 @@ public class BstIterator<T extends Comparable<T>> implements Iterator<TreeNode<T
} }
/** /**
* Gets the next element.
*
* @return TreeNode next. The next element according to our in-order traversal of the given BST * @return TreeNode next. The next element according to our in-order traversal of the given BST
* @throws NoSuchElementException if this iterator does not have a next element * @throws NoSuchElementException if this iterator does not have a next element
*/ */

View File

@ -36,7 +36,7 @@ public class TreeNode<T extends Comparable<T>> {
private TreeNode<T> right; private TreeNode<T> right;
/** /**
* Creates a TreeNode with a given value, and null children * Creates a TreeNode with a given value, and null children.
* *
* @param val The value of the given node * @param val The value of the given node
*/ */
@ -67,7 +67,7 @@ public class TreeNode<T extends Comparable<T>> {
} }
/** /**
* Inserts new TreeNode based on a given value into the subtree represented by self * Inserts new TreeNode based on a given value into the subtree represented by self.
* *
* @param valToInsert The value to insert as a new TreeNode * @param valToInsert The value to insert as a new TreeNode
*/ */

View File

@ -24,9 +24,7 @@
package com.iluwatar.iterator.list; package com.iluwatar.iterator.list;
/** /**
* * Item.
* Item
*
*/ */
public class Item { public class Item {

View File

@ -24,9 +24,7 @@
package com.iluwatar.iterator.list; package com.iluwatar.iterator.list;
/** /**
* * ItemType enumeration.
* ItemType enumeration
*
*/ */
public enum ItemType { public enum ItemType {

View File

@ -28,16 +28,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
*
* TreasureChest, the collection class. * TreasureChest, the collection class.
*
*/ */
public class TreasureChest { public class TreasureChest {
private List<Item> items; private List<Item> items;
/** /**
* Constructor * Constructor.
*/ */
public TreasureChest() { public TreasureChest() {
items = List.of( items = List.of(
@ -58,7 +56,7 @@ public class TreasureChest {
} }
/** /**
* Get all items * Get all items.
*/ */
public List<Item> getItems() { public List<Item> getItems() {
return new ArrayList<>(items); return new ArrayList<>(items);

View File

@ -27,9 +27,7 @@ import com.iluwatar.iterator.Iterator;
import java.util.List; import java.util.List;
/** /**
* * TreasureChestItemIterator.
* TreasureChestItemIterator
*
*/ */
public class TreasureChestItemIterator implements Iterator<Item> { public class TreasureChestItemIterator implements Iterator<Item> {
@ -38,7 +36,7 @@ public class TreasureChestItemIterator implements Iterator<Item> {
private ItemType type; private ItemType type;
/** /**
* Constructor * Constructor.
*/ */
public TreasureChestItemIterator(TreasureChest chest, ItemType type) { public TreasureChestItemIterator(TreasureChest chest, ItemType type) {
this.chest = chest; this.chest = chest;