Skip to content

Commit 8747f1f

Browse files
committed
iluwatar#1021 enforce Checkstyle rules in the build
1 parent 9e58edf commit 8747f1f

File tree

17 files changed

+237
-206
lines changed

17 files changed

+237
-206
lines changed

abstract-factory/src/test/java/com/iluwatar/abstractfactory/AbstractFactoryTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.junit.jupiter.api.Test;
3333

3434
/**
35-
* Test for abstract factory
35+
* Test for abstract factory.
3636
*/
3737
public class AbstractFactoryTest {
3838

composite/src/main/java/com/iluwatar/composite/Word.java

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ public Word(List<Letter> letters) {
3737
letters.forEach(this::add);
3838
}
3939

40+
/**
41+
* Constructor.
42+
* @param letters to include
43+
*/
4044
public Word(char... letters) {
4145
for (char letter : letters) {
4246
this.add(new Letter(letter));

layers/src/main/java/com/iluwatar/layers/service/CakeBakingServiceImpl.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
package com.iluwatar.layers.service;
2525

26-
import com.iluwatar.layers.dto.CakeInfo;
27-
import com.iluwatar.layers.dto.CakeLayerInfo;
28-
import com.iluwatar.layers.dto.CakeToppingInfo;
2926
import com.iluwatar.layers.dao.CakeDao;
3027
import com.iluwatar.layers.dao.CakeLayerDao;
3128
import com.iluwatar.layers.dao.CakeToppingDao;
29+
import com.iluwatar.layers.dto.CakeInfo;
30+
import com.iluwatar.layers.dto.CakeLayerInfo;
31+
import com.iluwatar.layers.dto.CakeToppingInfo;
3232
import com.iluwatar.layers.entity.Cake;
3333
import com.iluwatar.layers.entity.CakeLayer;
3434
import com.iluwatar.layers.entity.CakeTopping;
@@ -40,7 +40,6 @@
4040
import java.util.Optional;
4141
import java.util.Set;
4242
import java.util.stream.Collectors;
43-
4443
import org.springframework.context.support.AbstractApplicationContext;
4544
import org.springframework.context.support.ClassPathXmlApplicationContext;
4645
import org.springframework.stereotype.Service;

page-object/src/main/java/com/iluwatar/pageobject/App.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ public static void main(String[] args) {
7070
File applicationFile =
7171
new File(App.class.getClassLoader().getResource("sample-ui/login.html").getPath());
7272

73-
// should work for unix like OS (mac, unix etc...)
73+
// Should work for unix like OS (mac, unix etc...)
7474
if (Desktop.isDesktopSupported()) {
7575
Desktop.getDesktop().open(applicationFile);
7676

7777
} else {
78-
// java Desktop not supported - above unlikely to work for Windows so try following instead...
78+
// Java Desktop not supported - above unlikely to work for Windows so try the
79+
// following instead...
7980
Runtime.getRuntime().exec("cmd.exe start " + applicationFile);
8081
}
8182

pom.xml

+2-4
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,6 @@
384384
</pluginManagement>
385385

386386
<plugins>
387-
<!--checkstyle plug-in. checking against googles styles
388-
see config at checkstyle.xml
389-
-->
390387
<plugin>
391388
<groupId>org.apache.maven.plugins</groupId>
392389
<artifactId>maven-checkstyle-plugin</artifactId>
@@ -403,7 +400,8 @@
403400
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
404401
<encoding>UTF-8</encoding>
405402
<failOnViolation>true</failOnViolation>
406-
<includeTestSourceDirectory>true</includeTestSourceDirectory>
403+
<violationSeverity>warning</violationSeverity>
404+
<includeTestSourceDirectory>false</includeTestSourceDirectory>
407405
</configuration>
408406
</execution>
409407
</executions>

producer-consumer/src/main/java/com/iluwatar/producer/consumer/App.java

+12-10
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@
2323

2424
package com.iluwatar.producer.consumer;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
2926
import java.util.concurrent.ExecutorService;
3027
import java.util.concurrent.Executors;
3128
import java.util.concurrent.TimeUnit;
3229

30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
32+
3333
/**
34-
* Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces coupling between
35-
* Producer and Consumer by separating Identification of work with Execution of Work.
36-
* <p>
37-
* In producer consumer design pattern a shared queue is used to control the flow and this separation allows you to code
38-
* producer and consumer separately. It also addresses the issue of different timing require to produce item or
39-
* consuming item. by using producer consumer pattern both Producer and Consumer Thread can work with different speed.
34+
* Producer Consumer Design pattern is a classic concurrency or threading pattern which reduces
35+
* coupling between Producer and Consumer by separating Identification of work with
36+
* Execution of Work.
37+
*
38+
* <p>In producer consumer design pattern a shared queue is used to control the flow and this
39+
* separation allows you to code producer and consumer separately. It also addresses the issue
40+
* of different timing require to produce item or consuming item. by using producer consumer
41+
* pattern both Producer and Consumer Thread can work with different speed.
4042
*
4143
*/
4244
public class App {
4345

4446
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
4547

4648
/**
47-
* Program entry point
49+
* Program entry point.
4850
*
4951
* @param args
5052
* command line args

producer-consumer/src/main/java/com/iluwatar/producer/consumer/Consumer.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import org.slf4j.LoggerFactory;
2828

2929
/**
30-
* Class responsible for consume the {@link Item} produced by {@link Producer}
30+
* Class responsible for consume the {@link Item} produced by {@link Producer}.
3131
*/
3232
public class Consumer {
3333

@@ -43,12 +43,13 @@ public Consumer(String name, ItemQueue queue) {
4343
}
4444

4545
/**
46-
* Consume item from the queue
46+
* Consume item from the queue.
4747
*/
4848
public void consume() throws InterruptedException {
4949

5050
Item item = queue.take();
51-
LOGGER.info("Consumer [{}] consume item [{}] produced by [{}]", name, item.getId(), item.getProducer());
51+
LOGGER.info("Consumer [{}] consume item [{}] produced by [{}]", name,
52+
item.getId(), item.getProducer());
5253

5354
}
5455
}

producer-consumer/src/main/java/com/iluwatar/producer/consumer/Producer.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
/**
2929
* Class responsible for producing unit of work that can be expressed as {@link Item} and submitted
30-
* to queue
30+
* to queue.
3131
*/
3232
public class Producer {
3333

@@ -45,7 +45,7 @@ public Producer(String name, ItemQueue queue) {
4545
}
4646

4747
/**
48-
* Put item in the queue
48+
* Put item in the queue.
4949
*/
5050
public void produce() throws InterruptedException {
5151

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

+9-10
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
*/
2323

2424
package com.iluwatar.promise;
25-
import org.slf4j.Logger;
26-
import org.slf4j.LoggerFactory;
2725

2826
import java.util.Map;
2927
import java.util.concurrent.CompletableFuture;
@@ -32,10 +30,12 @@
3230
import java.util.concurrent.ExecutorService;
3331
import java.util.concurrent.Executors;
3432

33+
import org.slf4j.Logger;
34+
import org.slf4j.LoggerFactory;
35+
3536
/**
36-
*
37-
* The Promise object is used for asynchronous computations. A Promise represents an operation
38-
* that hasn't completed yet, but is expected in the future.
37+
* The Promise object is used for asynchronous computations. A Promise represents an operation
38+
* that hasn't completed yet, but is expected in the future.
3939
*
4040
* <p>A Promise represents a proxy for a value not necessarily known when the promise is created. It
4141
* allows you to associate dependent promises to an asynchronous action's eventual success value or
@@ -49,15 +49,14 @@
4949
* <li> Prevents callback hell and provides callback aggregation
5050
* </ul>
5151
*
52-
* <p>
53-
* In this application the usage of promise is demonstrated with two examples:
52+
* <p>In this application the usage of promise is demonstrated with two examples:
5453
* <ul>
5554
* <li>Count Lines: In this example a file is downloaded and its line count is calculated.
5655
* The calculated line count is then consumed and printed on console.
5756
* <li>Lowest Character Frequency: In this example a file is downloaded and its lowest frequency
5857
* character is found and printed on console. This happens via a chain of promises, we start with
59-
* a file download promise, then a promise of character frequency, then a promise of lowest frequency
60-
* character which is finally consumed and result is printed on console.
58+
* a file download promise, then a promise of character frequency, then a promise of lowest
59+
* frequency character which is finally consumed and result is printed on console.
6160
* </ul>
6261
*
6362
* @see CompletableFuture
@@ -76,7 +75,7 @@ private App() {
7675
}
7776

7877
/**
79-
* Program entry point
78+
* Program entry point.
8079
* @param args arguments
8180
* @throws InterruptedException if main thread is interrupted.
8281
* @throws ExecutionException if an execution error occurs.

promise/src/main/java/com/iluwatar/promise/Utility.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323

2424
package com.iluwatar.promise;
2525

26-
import org.slf4j.Logger;
27-
import org.slf4j.LoggerFactory;
28-
2926
import java.io.BufferedReader;
3027
import java.io.File;
3128
import java.io.FileReader;
@@ -39,8 +36,11 @@
3936
import java.util.Map;
4037
import java.util.Map.Entry;
4138

39+
import org.slf4j.Logger;
40+
import org.slf4j.LoggerFactory;
41+
4242
/**
43-
* Utility to perform various operations
43+
* Utility to perform various operations.
4444
*/
4545
public class Utility {
4646

@@ -71,7 +71,8 @@ public static Map<Character, Integer> characterFrequency(String fileLocation) {
7171
}
7272

7373
/**
74-
* @return the character with lowest frequency if it exists, {@code Optional.empty()} otherwise.
74+
* Return the character with the lowest frequency, if exists.
75+
* @return the character, {@code Optional.empty()} otherwise.
7576
*/
7677
public static Character lowestFrequencyChar(Map<Character, Integer> charFrequency) {
7778
Character lowestFrequencyChar = null;
@@ -92,7 +93,8 @@ public static Character lowestFrequencyChar(Map<Character, Integer> charFrequenc
9293
}
9394

9495
/**
95-
* @return number of lines in the file at provided location. 0 if file does not exist.
96+
* Count the number of lines in a file.
97+
* @return number of lines, 0 if file does not exist.
9698
*/
9799
public static Integer countLines(String fileLocation) {
98100
int lineCount = 0;

role-object/src/main/java/com/iluwatar/roleobject/ApplicationRoleObject.java

+46-39
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2121
* THE SOFTWARE.
2222
*/
23+
2324
package com.iluwatar.roleobject;
2425

26+
import static com.iluwatar.roleobject.Role.Borrower;
27+
import static com.iluwatar.roleobject.Role.Investor;
28+
2529
import org.slf4j.Logger;
2630
import org.slf4j.LoggerFactory;
2731

28-
import static com.iluwatar.roleobject.Role.*;
29-
3032
/**
3133
* The Role Object pattern suggests to model context-specific views
3234
* of an object as separate role objects which are
@@ -39,55 +41,60 @@
3941
* investor, respectively. Both roles could as well be played by a single {@link Customer} object.
4042
* The common superclass for customer-specific roles is provided by {@link CustomerRole},
4143
* which also supports the {@link Customer} interface.
42-
* <p>
43-
* The {@link CustomerRole} class is abstract and not meant to be instantiated.
44-
* Concrete subclasses of {@link CustomerRole}, for example {@link BorrowerRole} or {@link InvestorRole},
45-
* define and implement the interface for specific roles. It is only
44+
*
45+
* <p>The {@link CustomerRole} class is abstract and not meant to be instantiated.
46+
* Concrete subclasses of {@link CustomerRole}, for example {@link BorrowerRole}
47+
* or {@link InvestorRole}, define and implement the interface for specific roles. It is only
4648
* these subclasses which are instantiated at runtime.
47-
* The {@link BorrowerRole} class defines the context-specific view of {@link Customer} objects as needed by the loan department.
49+
* The {@link BorrowerRole} class defines the context-specific view of {@link Customer}
50+
* objects as needed by the loan department.
4851
* It defines additional operations to manage the customer’s
4952
* credits and securities. Similarly, the {@link InvestorRole} class adds operations specific
5053
* to the investment department’s view of customers.
51-
* A client like the loan application may either work with objects of the {@link CustomerRole} class, using the interface class
52-
* {@link Customer}, or with objects of concrete {@link CustomerRole} subclasses. Suppose the loan application knows a particular
53-
* {@link Customer} instance through its {@link Customer} interface. The loan application may want to check whether the {@link Customer}
54-
* object plays the role of Borrower.
55-
* To this end it calls {@link Customer#hasRole(Role)} with a suitable role specification. For the purpose of
56-
* our example, let’s assume we can name roles with enum.
57-
* If the {@link Customer} object can play the role named “Borrower,” the loan application will ask it
58-
* to return a reference to the corresponding object.
54+
* A client like the loan application may either work with objects of the {@link CustomerRole}
55+
* class, using the interface class {@link Customer}, or with objects of concrete
56+
* {@link CustomerRole} subclasses. Suppose the loan application knows a particular
57+
* {@link Customer} instance through its {@link Customer} interface. The loan application
58+
* may want to check whether the {@link Customer} object plays the role of Borrower.
59+
* To this end it calls {@link Customer#hasRole(Role)} with a suitable role specification. For
60+
* the purpose of our example, let’s assume we can name roles with enum.
61+
* If the {@link Customer} object can play the role named “Borrower,” the loan application will
62+
* ask it to return a reference to the corresponding object.
5963
* The loan application may now use this reference to call Borrower-specific operations.
6064
*/
6165
public class ApplicationRoleObject {
6266

63-
private static final Logger logger = LoggerFactory.getLogger(Role.class);
64-
65-
public static void main(String[] args) {
66-
Customer customer = Customer.newCustomer(Borrower, Investor);
67-
68-
logger.info(" the new customer created : {}", customer);
67+
private static final Logger logger = LoggerFactory.getLogger(Role.class);
6968

70-
boolean hasBorrowerRole = customer.hasRole(Borrower);
71-
logger.info(" customer has a borrowed role - {}", hasBorrowerRole);
72-
boolean hasInvestorRole = customer.hasRole(Investor);
73-
logger.info(" customer has an investor role - {}", hasInvestorRole);
69+
/**
70+
* Main entry point.
71+
*
72+
* @param args program arguments
73+
*/
74+
public static void main(String[] args) {
75+
Customer customer = Customer.newCustomer(Borrower, Investor);
7476

75-
customer.getRole(Investor, InvestorRole.class)
76-
.ifPresent(inv -> {
77-
inv.setAmountToInvest(1000);
78-
inv.setName("Billy");
79-
});
80-
customer.getRole(Borrower, BorrowerRole.class)
81-
.ifPresent(inv -> inv.setName("Johny"));
77+
logger.info(" the new customer created : {}", customer);
8278

83-
customer.getRole(Investor, InvestorRole.class)
84-
.map(InvestorRole::invest)
85-
.ifPresent(logger::info);
79+
boolean hasBorrowerRole = customer.hasRole(Borrower);
80+
logger.info(" customer has a borrowed role - {}", hasBorrowerRole);
81+
boolean hasInvestorRole = customer.hasRole(Investor);
82+
logger.info(" customer has an investor role - {}", hasInvestorRole);
8683

87-
customer.getRole(Borrower, BorrowerRole.class)
88-
.map(BorrowerRole::borrow)
89-
.ifPresent(logger::info);
90-
}
84+
customer.getRole(Investor, InvestorRole.class)
85+
.ifPresent(inv -> {
86+
inv.setAmountToInvest(1000);
87+
inv.setName("Billy");
88+
});
89+
customer.getRole(Borrower, BorrowerRole.class)
90+
.ifPresent(inv -> inv.setName("Johny"));
9191

92+
customer.getRole(Investor, InvestorRole.class)
93+
.map(InvestorRole::invest)
94+
.ifPresent(logger::info);
9295

96+
customer.getRole(Borrower, BorrowerRole.class)
97+
.map(BorrowerRole::borrow)
98+
.ifPresent(logger::info);
99+
}
93100
}

0 commit comments

Comments
 (0)