Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cec9a99

Browse filesBrowse files
committed
Adjust checkstyle rules. Make checkstyle fail the build when violations are found. Correct all current checkstyle violations.
1 parent 9fbb085 commit cec9a99
Copy full SHA for cec9a99

167 files changed

+1,210-937Lines changed: 1210 additions & 937 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree
Open diff view settings
Collapse file
+40-45Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
package com.iluwatar.abstractfactory;
22

3-
43
/**
54
*
6-
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that
7-
* have a common theme without specifying their concrete classes. In normal usage, the client
8-
* software creates a concrete implementation of the abstract factory and then uses the generic
9-
* interface of the factory to create the concrete objects that are part of the theme. The client
10-
* does not know (or care) which concrete objects it gets from each of these internal factories,
11-
* since it uses only the generic interfaces of their products. This pattern separates the details
12-
* of implementation of a set of objects from their general usage and relies on object composition,
13-
* as object creation is implemented in methods exposed in the factory interface.
5+
* The Abstract Factory pattern provides a way to encapsulate a group of individual factories that have a common theme
6+
* without specifying their concrete classes. In normal usage, the client software creates a concrete implementation of
7+
* the abstract factory and then uses the generic interface of the factory to create the concrete objects that are part
8+
* of the theme. The client does not know (or care) which concrete objects it gets from each of these internal
9+
* factories, since it uses only the generic interfaces of their products. This pattern separates the details of
10+
* implementation of a set of objects from their general usage and relies on object composition, as object creation is
11+
* implemented in methods exposed in the factory interface.
1412
* <p>
15-
* The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and
16-
* its implementations ({@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both
17-
* concrete implementations to create a king, a castle and an army.
13+
* The essence of the Abstract Factory pattern is a factory interface ({@link KingdomFactory}) and its implementations (
14+
* {@link ElfKingdomFactory}, {@link OrcKingdomFactory}). The example uses both concrete implementations to create a
15+
* king, a castle and an army.
1816
*
1917
*/
2018
public class App {
@@ -23,11 +21,8 @@ public class App {
2321
private Castle castle;
2422
private Army army;
2523

26-
2724
/**
2825
* Creates kingdom
29-
*
30-
* @param factory
3126
*/
3227
public void createKingdom(final KingdomFactory factory) {
3328
setKing(factory.createKing());
@@ -47,21 +42,17 @@ King getKing(final KingdomFactory factory) {
4742
return factory.createKing();
4843
}
4944

50-
Castle getCastle(final KingdomFactory factory) {
51-
return factory.createCastle();
52-
}
53-
54-
Army getArmy(final KingdomFactory factory) {
55-
return factory.createArmy();
56-
}
57-
5845
public King getKing() {
5946
return king;
6047
}
6148

6249
private void setKing(final King king) {
6350
this.king = king;
6451
}
52+
53+
Castle getCastle(final KingdomFactory factory) {
54+
return factory.createCastle();
55+
}
6556

6657
public Castle getCastle() {
6758
return castle;
@@ -70,6 +61,10 @@ public Castle getCastle() {
7061
private void setCastle(final Castle castle) {
7162
this.castle = castle;
7263
}
64+
65+
Army getArmy(final KingdomFactory factory) {
66+
return factory.createArmy();
67+
}
7368

7469
public Army getArmy() {
7570
return army;
@@ -79,32 +74,32 @@ private void setArmy(final Army army) {
7974
this.army = army;
8075
}
8176

82-
8377
/**
8478
* Program entry point
8579
*
86-
* @param args command line args
80+
* @param args
81+
* command line args
8782
*/
8883
public static void main(String[] args) {
89-
90-
App app = new App();
91-
92-
System.out.println("Elf Kingdom");
93-
KingdomFactory elfKingdomFactory;
94-
elfKingdomFactory = app.getElfKingdomFactory();
95-
app.createKingdom(elfKingdomFactory);
96-
System.out.println(app.getArmy().getDescription());
97-
System.out.println(app.getCastle().getDescription());
98-
System.out.println(app.getKing().getDescription());
99-
100-
System.out.println("\nOrc Kingdom");
101-
KingdomFactory orcKingdomFactory;
102-
orcKingdomFactory = app.getOrcKingdomFactory();
103-
app.createKingdom(orcKingdomFactory);
104-
System.out.println(app.getArmy().getDescription());
105-
System.out.println(app.getCastle().getDescription());
106-
System.out.println(app.getKing().getDescription());
107-
84+
85+
App app = new App();
86+
87+
System.out.println("Elf Kingdom");
88+
KingdomFactory elfKingdomFactory;
89+
elfKingdomFactory = app.getElfKingdomFactory();
90+
app.createKingdom(elfKingdomFactory);
91+
System.out.println(app.getArmy().getDescription());
92+
System.out.println(app.getCastle().getDescription());
93+
System.out.println(app.getKing().getDescription());
94+
95+
System.out.println("\nOrc Kingdom");
96+
KingdomFactory orcKingdomFactory;
97+
orcKingdomFactory = app.getOrcKingdomFactory();
98+
app.createKingdom(orcKingdomFactory);
99+
System.out.println(app.getArmy().getDescription());
100+
System.out.println(app.getCastle().getDescription());
101+
System.out.println(app.getKing().getDescription());
102+
108103
}
109-
104+
110105
}
Collapse file

‎async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java‎

Copy file name to clipboardExpand all lines: async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java
+25-22Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,23 @@
44

55
/**
66
* This application demonstrates the async method invocation pattern. Key parts of the pattern are
7-
* <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated
8-
* value, <code>AsyncCallback</code> which can be provided to be executed on task completion and
9-
* <code>AsyncExecutor</code> that manages the execution of the async tasks.
7+
* <code>AsyncResult</code> which is an intermediate container for an asynchronously evaluated value,
8+
* <code>AsyncCallback</code> which can be provided to be executed on task completion and <code>AsyncExecutor</code>
9+
* that manages the execution of the async tasks.
1010
* <p>
11-
* The main method shows example flow of async invocations. The main thread starts multiple tasks
12-
* with variable durations and then continues its own work. When the main thread has done it's job
13-
* it collects the results of the async tasks. Two of the tasks are handled with callbacks, meaning
14-
* the callbacks are executed immediately when the tasks complete.
11+
* The main method shows example flow of async invocations. The main thread starts multiple tasks with variable
12+
* durations and then continues its own work. When the main thread has done it's job it collects the results of the
13+
* async tasks. Two of the tasks are handled with callbacks, meaning the callbacks are executed immediately when the
14+
* tasks complete.
1515
* <p>
16-
* Noteworthy difference of thread usage between the async results and callbacks is that the async
17-
* results are collected in the main thread but the callbacks are executed within the worker
18-
* threads. This should be noted when working with thread pools.
16+
* Noteworthy difference of thread usage between the async results and callbacks is that the async results are collected
17+
* in the main thread but the callbacks are executed within the worker threads. This should be noted when working with
18+
* thread pools.
1919
* <p>
20-
* Java provides its own implementations of async method invocation pattern. FutureTask,
21-
* CompletableFuture and ExecutorService are the real world implementations of this pattern. But due
22-
* to the nature of parallel programming, the implementations are not trivial. This example does not
23-
* take all possible scenarios into account but rather provides a simple version that helps to
24-
* understand the pattern.
20+
* Java provides its own implementations of async method invocation pattern. FutureTask, CompletableFuture and
21+
* ExecutorService are the real world implementations of this pattern. But due to the nature of parallel programming,
22+
* the implementations are not trivial. This example does not take all possible scenarios into account but rather
23+
* provides a simple version that helps to understand the pattern.
2524
*
2625
* @see AsyncResult
2726
* @see AsyncCallback
@@ -33,6 +32,9 @@
3332
*/
3433
public class App {
3534

35+
/**
36+
* Program entry point
37+
*/
3638
public static void main(String[] args) throws Exception {
3739
// construct a new executor that will run async tasks
3840
AsyncExecutor executor = new ThreadAsyncExecutor();
@@ -41,10 +43,8 @@ public static void main(String[] args) throws Exception {
4143
AsyncResult<Integer> asyncResult1 = executor.startProcess(lazyval(10, 500));
4244
AsyncResult<String> asyncResult2 = executor.startProcess(lazyval("test", 300));
4345
AsyncResult<Long> asyncResult3 = executor.startProcess(lazyval(50L, 700));
44-
AsyncResult<Integer> asyncResult4 =
45-
executor.startProcess(lazyval(20, 400), callback("Callback result 4"));
46-
AsyncResult<String> asyncResult5 =
47-
executor.startProcess(lazyval("callback", 600), callback("Callback result 5"));
46+
AsyncResult<Integer> asyncResult4 = executor.startProcess(lazyval(20, 400), callback("Callback result 4"));
47+
AsyncResult<String> asyncResult5 = executor.startProcess(lazyval("callback", 600), callback("Callback result 5"));
4848

4949
// emulate processing in the current thread while async tasks are running in their own threads
5050
Thread.sleep(350); // Oh boy I'm working hard here
@@ -66,8 +66,10 @@ public static void main(String[] args) throws Exception {
6666
/**
6767
* Creates a callable that lazily evaluates to given value with artificial delay.
6868
*
69-
* @param value value to evaluate
70-
* @param delayMillis artificial delay in milliseconds
69+
* @param value
70+
* value to evaluate
71+
* @param delayMillis
72+
* artificial delay in milliseconds
7173
* @return new callable for lazy evaluation
7274
*/
7375
private static <T> Callable<T> lazyval(T value, long delayMillis) {
@@ -81,7 +83,8 @@ private static <T> Callable<T> lazyval(T value, long delayMillis) {
8183
/**
8284
* Creates a simple callback that logs the complete status of the async result.
8385
*
84-
* @param name callback name
86+
* @param name
87+
* callback name
8588
* @return new async callback
8689
*/
8790
private static <T> AsyncCallback<T> callback(String name) {
Collapse file

‎async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java‎

Copy file name to clipboardExpand all lines: async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/AsyncResult.java
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
/**
66
*
77
* AsyncResult interface
8-
*
9-
* @param <T>
108
*/
119
public interface AsyncResult<T> {
1210

Collapse file

‎async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java‎

Copy file name to clipboardExpand all lines: async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/ThreadAsyncExecutor.java
+12-12Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@ public <T> AsyncResult<T> startProcess(Callable<T> task, AsyncCallback<T> callba
2929
} catch (Exception ex) {
3030
result.setException(ex);
3131
}
32-
}, "executor-" + idx.incrementAndGet()).start();
32+
} , "executor-" + idx.incrementAndGet()).start();
3333
return result;
3434
}
3535

3636
@Override
37-
public <T> T endProcess(AsyncResult<T> asyncResult) throws ExecutionException,
38-
InterruptedException {
37+
public <T> T endProcess(AsyncResult<T> asyncResult) throws ExecutionException, InterruptedException {
3938
if (asyncResult.isCompleted()) {
4039
return asyncResult.getValue();
4140
} else {
@@ -45,9 +44,8 @@ public <T> T endProcess(AsyncResult<T> asyncResult) throws ExecutionException,
4544
}
4645

4746
/**
48-
* Simple implementation of async result that allows completing it successfully with a value or
49-
* exceptionally with an exception. A really simplified version from its real life cousins
50-
* FutureTask and CompletableFuture.
47+
* Simple implementation of async result that allows completing it successfully with a value or exceptionally with an
48+
* exception. A really simplified version from its real life cousins FutureTask and CompletableFuture.
5149
*
5250
* @see java.util.concurrent.FutureTask
5351
* @see java.util.concurrent.CompletableFuture
@@ -71,10 +69,11 @@ private static class CompletableResult<T> implements AsyncResult<T> {
7169
}
7270

7371
/**
74-
* Sets the value from successful execution and executes callback if available. Notifies any
75-
* thread waiting for completion.
72+
* Sets the value from successful execution and executes callback if available. Notifies any thread waiting for
73+
* completion.
7674
*
77-
* @param value value of the evaluated task
75+
* @param value
76+
* value of the evaluated task
7877
*/
7978
void setValue(T value) {
8079
this.value = value;
@@ -86,10 +85,11 @@ void setValue(T value) {
8685
}
8786

8887
/**
89-
* Sets the exception from failed execution and executes callback if available. Notifies any
90-
* thread waiting for completion.
88+
* Sets the exception from failed execution and executes callback if available. Notifies any thread waiting for
89+
* completion.
9190
*
92-
* @param exception exception of the failed task
91+
* @param exception
92+
* exception of the failed task
9393
*/
9494
void setException(Exception exception) {
9595
this.exception = exception;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.