Skip to content

Commit 7f06f3b

Browse files
anuragagarwal561994iluwatar
authored andcommitted
Resolves checkstyle errors for intercepting-filter, interpreter, iterator (iluwatar#1065)
* Reduces checkstyle errors in intercepting-filter * Reduces checkstyle errors in interpreter * Reduces checkstyle errors in iterator
1 parent dda0953 commit 7f06f3b

27 files changed

+99
-122
lines changed

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/AbstractFilter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
/**
2727
* Base class for order processing filters. Handles chain management.
28-
*
2928
*/
3029
public abstract class AbstractFilter implements Filter {
3130

3231
private Filter next;
3332

34-
public AbstractFilter() {}
33+
public AbstractFilter() {
34+
}
3535

3636
public AbstractFilter(Filter next) {
3737
this.next = next;

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/AddressFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
/**
2727
* Concrete implementation of filter This filter is responsible for checking/filtering the input in
2828
* the address field.
29-
*
30-
* @author joshzambales
3129
*
30+
* @author joshzambales
3231
*/
3332
public class AddressFilter extends AbstractFilter {
3433

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/App.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,33 @@
2424
package com.iluwatar.intercepting.filter;
2525

2626
/**
27-
*
2827
* When a request enters a Web application, it often must pass several entrance tests prior to the
2928
* main processing stage. For example, - Has the client been authenticated? - Does the client have a
3029
* valid session? - Is the client's IP address from a trusted network? - Does the request path
3130
* violate any constraints? - What encoding does the client use to send the data? - Do we support
3231
* the browser type of the client? Some of these checks are tests, resulting in a yes or no answer
3332
* that determines whether processing will continue. Other checks manipulate the incoming data
3433
* stream into a form suitable for processing.
35-
* <p>
36-
* The classic solution consists of a series of conditional checks, with any failed check aborting
37-
* the request. Nested if/else statements are a standard strategy, but this solution leads to code
38-
* fragility and a copy-and-paste style of programming, because the flow of the filtering and the
39-
* action of the filters is compiled into the application.
40-
* <p>
41-
* The key to solving this problem in a flexible and unobtrusive manner is to have a simple
34+
*
35+
* <p>The classic solution consists of a series of conditional checks, with any failed check
36+
* aborting the request. Nested if/else statements are a standard strategy, but this solution leads
37+
* to code fragility and a copy-and-paste style of programming, because the flow of the filtering
38+
* and the action of the filters is compiled into the application.
39+
*
40+
* <p>The key to solving this problem in a flexible and unobtrusive manner is to have a simple
4241
* mechanism for adding and removing processing components, in which each component completes a
4342
* specific filtering action. This is the Intercepting Filter pattern in action.
44-
* <p>
45-
* In this example we check whether the order request is valid through pre-processing done via
46-
* {@link Filter}. Each field has its own corresponding {@link Filter}
47-
* <p>
48-
*
49-
* @author joshzambales
5043
*
44+
* <p>In this example we check whether the order request is valid through pre-processing done via
45+
* {@link Filter}. Each field has its own corresponding {@link Filter}.
46+
*
47+
* @author joshzambales
5148
*/
5249
public class App {
5350

5451
/**
55-
* Program entry point
56-
*
52+
* Program entry point.
53+
*
5754
* @param args command line args
5855
*/
5956
public static void main(String[] args) {

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Client.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
package com.iluwatar.intercepting.filter;
2525

26+
import java.awt.BorderLayout;
27+
import java.awt.GridLayout;
28+
2629
import javax.swing.JButton;
2730
import javax.swing.JFrame;
2831
import javax.swing.JLabel;
@@ -32,18 +35,15 @@
3235
import javax.swing.JTextField;
3336
import javax.swing.SwingUtilities;
3437
import javax.swing.WindowConstants;
35-
import java.awt.BorderLayout;
36-
import java.awt.GridLayout;
3738

3839
/**
39-
* The Client class is responsible for handling the input and running them through filters inside the
40-
* {@link FilterManager}.
40+
* The Client class is responsible for handling the input and running them through filters inside
41+
* the {@link FilterManager}.
4142
*
42-
* This is where {@link Filter}s come to play as the client pre-processes the request before being displayed in the
43-
* {@link Target}.
44-
*
45-
* @author joshzambales
43+
* <p>This is where {@link Filter}s come to play as the client pre-processes the request before
44+
* being displayed in the {@link Target}.
4645
*
46+
* @author joshzambales
4747
*/
4848
public class Client extends JFrame { // NOSONAR
4949

@@ -57,7 +57,7 @@ public class Client extends JFrame { // NOSONAR
5757
private JButton processButton;
5858

5959
/**
60-
* Constructor
60+
* Constructor.
6161
*/
6262
public Client() {
6363
super("Client System");
@@ -107,8 +107,10 @@ private void setup() {
107107
});
108108

109109
processButton.addActionListener(e -> {
110-
Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(),
111-
jtAreas[1].getText());
110+
Order order =
111+
new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2]
112+
.getText(),
113+
jtAreas[1].getText());
112114
jl.setText(sendRequest(order));
113115
});
114116

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/ContactFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
/**
2727
* Concrete implementation of filter This filter checks for the contact field in which it checks if
2828
* the input consist of numbers and it also checks if the input follows the length constraint (11
29-
* digits)
30-
*
31-
* @author joshzambales
29+
* digits).
3230
*
31+
* @author joshzambales
3332
*/
3433
public class ContactFilter extends AbstractFilter {
3534

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/DepositFilter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@
2424
package com.iluwatar.intercepting.filter;
2525

2626
/**
27-
* Concrete implementation of filter This checks for the deposit code
28-
*
29-
* @author joshzambales
27+
* Concrete implementation of filter This checks for the deposit code.
3028
*
29+
* @author joshzambales
3130
*/
3231
public class DepositFilter extends AbstractFilter {
3332

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Filter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
/**
2727
* Filters perform certain tasks prior or after execution of request by request handler. In this
2828
* case, before the request is handled by the target, the request undergoes through each Filter
29-
*
30-
* @author joshzambales
3129
*
30+
* @author joshzambales
3231
*/
3332
public interface Filter {
3433

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterChain.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
/**
2828
* Filter Chain carries multiple filters and help to execute them in defined order on target.
29-
*
29+
*
3030
* @author joshzambales
3131
*/
3232
public class FilterChain {
@@ -35,7 +35,7 @@ public class FilterChain {
3535

3636

3737
/**
38-
* Adds filter
38+
* Adds filter.
3939
*/
4040
public void addFilter(Filter filter) {
4141
if (chain == null) {
@@ -46,7 +46,7 @@ public void addFilter(Filter filter) {
4646
}
4747

4848
/**
49-
* Execute filter chain
49+
* Execute filter chain.
5050
*/
5151
public String execute(Order order) {
5252
if (chain != null) {

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/FilterManager.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
/**
2727
* Filter Manager manages the filters and {@link FilterChain}.
28-
*
29-
* @author joshzambales
3028
*
29+
* @author joshzambales
3130
*/
3231
public class FilterManager {
3332

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/NameFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@
2626
/**
2727
* Concrete implementation of filter. This filter checks if the input in the Name field is valid.
2828
* (alphanumeric)
29-
*
30-
* @author joshzambales
3129
*
30+
* @author joshzambales
3231
*/
3332
public class NameFilter extends AbstractFilter {
3433

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Order.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
/**
2727
* Order class carries the order data.
28-
*
2928
*/
3029
public class Order {
3130

@@ -35,12 +34,16 @@ public class Order {
3534
private String depositNumber;
3635
private String orderItem;
3736

38-
public Order() {}
37+
public Order() {
38+
}
3939

4040
/**
41-
* Constructor
41+
* Constructor.
4242
*/
43-
public Order(String name, String contactNumber, String address, String depositNumber, String order) {
43+
public Order(
44+
String name, String contactNumber, String address,
45+
String depositNumber, String order
46+
) {
4447
this.name = name;
4548
this.contactNumber = contactNumber;
4649
this.address = address;

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/OrderFilter.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
/**
2727
* Concrete implementation of filter. This checks for the order field.
28-
*
29-
* @author joshzambales
3028
*
29+
* @author joshzambales
3130
*/
3231
public class OrderFilter extends AbstractFilter {
3332

intercepting-filter/src/main/java/com/iluwatar/intercepting/filter/Target.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323

2424
package com.iluwatar.intercepting.filter;
2525

26+
import java.awt.BorderLayout;
27+
import java.awt.Dimension;
28+
import java.awt.event.ActionEvent;
29+
import java.awt.event.ActionListener;
30+
2631
import javax.swing.JButton;
2732
import javax.swing.JFrame;
2833
import javax.swing.JPanel;
@@ -32,16 +37,11 @@
3237
import javax.swing.SwingUtilities;
3338
import javax.swing.WindowConstants;
3439
import javax.swing.table.DefaultTableModel;
35-
import java.awt.BorderLayout;
36-
import java.awt.Dimension;
37-
import java.awt.event.ActionEvent;
38-
import java.awt.event.ActionListener;
3940

4041
/**
4142
* This is where the requests are displayed after being validated by filters.
42-
*
43-
* @author mjoshzambales
4443
*
44+
* @author mjoshzambales
4545
*/
4646
public class Target extends JFrame { //NOSONAR
4747

@@ -52,14 +52,14 @@ public class Target extends JFrame { //NOSONAR
5252
private JButton del;
5353

5454
/**
55-
* Constructor
55+
* Constructor.
5656
*/
5757
public Target() {
5858
super("Order System");
5959
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
6060
setSize(640, 480);
6161
dtm =
62-
new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number",
62+
new DefaultTableModel(new Object[]{"Name", "Contact Number", "Address", "Deposit Number",
6363
"Order"}, 0);
6464
jt = new JTable(dtm);
6565
del = new JButton("Delete");
@@ -85,7 +85,7 @@ private void setup() {
8585
}
8686

8787
public void execute(String[] request) {
88-
dtm.addRow(new Object[] {request[0], request[1], request[2], request[3], request[4]});
88+
dtm.addRow(new Object[]{request[0], request[1], request[2], request[3], request[4]});
8989
}
9090

9191
class DListener implements ActionListener {

interpreter/src/main/java/com/iluwatar/interpreter/App.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,35 +23,30 @@
2323

2424
package com.iluwatar.interpreter;
2525

26+
import java.util.Stack;
2627
import org.slf4j.Logger;
2728
import org.slf4j.LoggerFactory;
2829

29-
import java.util.Stack;
30-
3130
/**
32-
*
3331
* The Interpreter pattern is a design pattern that specifies how to evaluate sentences in a
3432
* language. The basic idea is to have a class for each symbol (terminal or nonterminal) in a
3533
* specialized computer language. The syntax tree of a sentence in the language is an instance of
3634
* the composite pattern and is used to evaluate (interpret) the sentence for a client.
37-
* <p>
38-
* In this example we use the Interpreter pattern to break sentences into expressions (
39-
* {@link Expression}) that can be evaluated and as a whole form the result.
40-
*
35+
*
36+
* <p>In this example we use the Interpreter pattern to break sentences into expressions ({@link
37+
* Expression}) that can be evaluated and as a whole form the result.
4138
*/
4239
public class App {
4340

4441
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
4542

4643
/**
47-
*
4844
* Program entry point.
49-
* <p>
50-
* Expressions can be evaluated using prefix, infix or postfix notations This sample uses postfix,
51-
* where operator comes after the operands
52-
*
45+
*
46+
* <p>Expressions can be evaluated using prefix, infix or postfix notations This sample uses
47+
* postfix, where operator comes after the operands.
48+
*
5349
* @param args command line args
54-
*
5550
*/
5651
public static void main(String[] args) {
5752
String tokenString = "4 3 2 - 1 + *";
@@ -84,7 +79,7 @@ public static boolean isOperator(String s) {
8479
}
8580

8681
/**
87-
* Get expression for string
82+
* Get expression for string.
8883
*/
8984
public static Expression getOperatorInstance(String s, Expression left, Expression right) {
9085
switch (s) {

interpreter/src/main/java/com/iluwatar/interpreter/Expression.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.interpreter;
2525

2626
/**
27-
*
28-
* Expression
29-
*
27+
* Expression.
3028
*/
3129
public abstract class Expression {
3230

interpreter/src/main/java/com/iluwatar/interpreter/MinusExpression.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.interpreter;
2525

2626
/**
27-
*
28-
* MinusExpression
29-
*
27+
* MinusExpression.
3028
*/
3129
public class MinusExpression extends Expression {
3230

interpreter/src/main/java/com/iluwatar/interpreter/MultiplyExpression.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@
2424
package com.iluwatar.interpreter;
2525

2626
/**
27-
*
28-
* MultiplyExpression
29-
*
27+
* MultiplyExpression.
3028
*/
3129
public class MultiplyExpression extends Expression {
3230

0 commit comments

Comments
 (0)