Skip to content

Commit ea7752c

Browse files
committed
checkstyle errors removed
checkstyle errors removed
1 parent 7ba6cb4 commit ea7752c

File tree

7 files changed

+425
-499
lines changed

7 files changed

+425
-499
lines changed

module/etc/module.urm.puml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
@startuml
2+
package com.iluwatar.module {
3+
class App {
4+
+ consoleLoggerModule : ConsoleLoggerModule {static}
5+
+ fileLoggerModule : FileLoggerModule {static}
6+
- App()
7+
+ execute(args : String[]) {static}
8+
+ main(args : String[]) {static}
9+
+ prepare() {static}
10+
+ unprepare() {static}
11+
}
12+
class ConsoleLoggerModule {
13+
- LOGGER : Logger {static}
14+
+ error : PrintStream
15+
+ output : PrintStream
16+
- singleton : ConsoleLoggerModule {static}
17+
- ConsoleLoggerModule()
18+
+ getSingleton() : ConsoleLoggerModule {static}
19+
+ prepare()
20+
+ printErrorString(value : String)
21+
+ printString(value : String)
22+
+ unprepare()
23+
}
24+
class FileLoggerModule {
25+
- ERROR_FILE : String {static}
26+
- LOGGER : Logger {static}
27+
- OUTPUT_FILE : String {static}
28+
+ error : PrintStream
29+
+ output : PrintStream
30+
- singleton : FileLoggerModule {static}
31+
- FileLoggerModule()
32+
+ getSingleton() : FileLoggerModule {static}
33+
+ prepare()
34+
+ printErrorString(value : String)
35+
+ printString(value : String)
36+
+ unprepare()
37+
}
38+
}
39+
FileLoggerModule --> "-singleton" FileLoggerModule
40+
App --> "-consoleLoggerModule" ConsoleLoggerModule
41+
ConsoleLoggerModule --> "-singleton" ConsoleLoggerModule
42+
App --> "-fileLoggerModule" FileLoggerModule
43+
@enduml

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

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,64 +21,75 @@
2121
import java.io.FileNotFoundException;
2222

2323
/**
24-
* The Module pattern can be considered a Creational pattern and a Structural
25-
* pattern. It manages the creation and organization of other elements, and
26-
* groups them as the structural pattern does. An object that applies this
27-
* pattern can provide the equivalent of a namespace, providing the
28-
* initialization and finalization process of a static class or a class with
29-
* static members with cleaner, more concise syntax and semantics.
24+
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
25+
* the creation and organization of other elements, and groups them as the structural pattern does.
26+
* An object that applies this pattern can provide the equivalent of a namespace, providing the
27+
* initialization and finalization process of a static class or a class with static members with
28+
* cleaner, more concise syntax and semantics.
3029
* <p>
31-
* The below example demonstrates a use case for testing two different modules:
32-
* File Logger and Console Logger
30+
* The below example demonstrates a use case for testing two different modules: File Logger and
31+
* Console Logger
3332
*
3433
*/
3534
public final class App {
3635

37-
public static FileLoggerModule fileLoggerModule = null;
38-
public static ConsoleLoggerModule consoleLoggerModule = null;
36+
public static FileLoggerModule fileLoggerModule = null;
37+
public static ConsoleLoggerModule consoleLoggerModule = null;
3938

40-
public static void prepare() throws FileNotFoundException {
39+
/**
40+
* Following method performs the initialization
41+
*
42+
* @throws FileNotFoundException if program is not able to find log files (output.txt and
43+
* error.txt)
44+
*/
45+
public static void prepare() throws FileNotFoundException {
4146

42-
fileLoggerModule = FileLoggerModule.getSingleton();
43-
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
47+
fileLoggerModule = FileLoggerModule.getSingleton();
48+
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
4449

45-
/* Prepare modules */
46-
fileLoggerModule.prepare();
47-
consoleLoggerModule.prepare();
48-
}
50+
/* Prepare modules */
51+
fileLoggerModule.prepare();
52+
consoleLoggerModule.prepare();
53+
}
4954

50-
public static void unprepare() {
55+
/**
56+
* Following method performs the finalization
57+
*/
58+
public static void unprepare() {
5159

52-
/* Close all resources */
53-
fileLoggerModule.unprepare();
54-
consoleLoggerModule.unprepare();
55-
}
60+
/* Close all resources */
61+
fileLoggerModule.unprepare();
62+
consoleLoggerModule.unprepare();
63+
}
5664

57-
public static final void execute(final String... args) {
65+
/**
66+
* Following method is main executor
67+
*
68+
* @param args for providing default program arguments
69+
*/
70+
public static void execute(final String... args) {
5871

59-
/* Send logs on file system */
60-
fileLoggerModule.printString("Message");
61-
fileLoggerModule.printErrorString("Error");
72+
/* Send logs on file system */
73+
fileLoggerModule.printString("Message");
74+
fileLoggerModule.printErrorString("Error");
6275

63-
/* Send logs on console */
64-
consoleLoggerModule.printString("Message");
65-
consoleLoggerModule.printErrorString("Error");
66-
}
76+
/* Send logs on console */
77+
consoleLoggerModule.printString("Message");
78+
consoleLoggerModule.printErrorString("Error");
79+
}
6780

68-
/**
69-
* Program entry point.
70-
*
71-
* @param args
72-
* command line args.
73-
* @throws FileNotFoundException
74-
*/
75-
public static final void main(final String... args)
76-
throws FileNotFoundException {
77-
prepare();
78-
execute(args);
79-
unprepare();
80-
}
81+
/**
82+
* Program entry point.
83+
*
84+
* @param args command line args.
85+
* @throws FileNotFoundException if program is not able to find log files (output.txt and
86+
* error.txt)
87+
*/
88+
public static void main(final String... args) throws FileNotFoundException {
89+
prepare();
90+
execute(args);
91+
unprepare();
92+
}
8193

82-
private App() {
83-
}
94+
private App() {}
8495
}

module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java

Lines changed: 62 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,89 +18,91 @@
1818
*/
1919
package com.iluwatar.module;
2020

21-
import java.io.FileNotFoundException;
2221
import java.io.PrintStream;
2322

2423
import org.apache.log4j.Logger;
2524

2625
/**
27-
* The Module pattern can be considered a Creational pattern and a Structural
28-
* pattern. It manages the creation and organization of other elements, and
29-
* groups them as the structural pattern does. An object that applies this
30-
* pattern can provide the equivalent of a namespace, providing the
31-
* initialization and finalization process of a static class or a class with
32-
* static members with cleaner, more concise syntax and semantics.
26+
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
27+
* the creation and organization of other elements, and groups them as the structural pattern does.
28+
* An object that applies this pattern can provide the equivalent of a namespace, providing the
29+
* initialization and finalization process of a static class or a class with static members with
30+
* cleaner, more concise syntax and semantics.
3331
* <p>
34-
* The below example demonstrates a Console logger module, which can print
35-
* simple and error messages in two designated formats
32+
* The below example demonstrates a Console logger module, which can print simple and error messages
33+
* in two designated formats
3634
*/
37-
public class ConsoleLoggerModule {
35+
public final class ConsoleLoggerModule {
3836

39-
private static final Logger logger = Logger
40-
.getLogger(ConsoleLoggerModule.class);
37+
private static final Logger LOGGER = Logger.getLogger(ConsoleLoggerModule.class);
4138

42-
private static ConsoleLoggerModule singleton = null;
39+
private static ConsoleLoggerModule singleton = null;
4340

44-
public PrintStream output = null;
45-
public PrintStream error = null;
41+
public PrintStream output = null;
42+
public PrintStream error = null;
4643

47-
private ConsoleLoggerModule() {
48-
}
44+
private ConsoleLoggerModule() {}
4945

50-
public static final ConsoleLoggerModule getSingleton() {
46+
/**
47+
* Static method to get single instance of class
48+
*
49+
* @return singleton instance of ConsoleLoggerModule
50+
*/
51+
public static ConsoleLoggerModule getSingleton() {
5152

52-
if (ConsoleLoggerModule.singleton == null) {
53-
ConsoleLoggerModule.singleton = new ConsoleLoggerModule();
54-
}
53+
if (ConsoleLoggerModule.singleton == null) {
54+
ConsoleLoggerModule.singleton = new ConsoleLoggerModule();
55+
}
5556

56-
return ConsoleLoggerModule.singleton;
57-
}
57+
return ConsoleLoggerModule.singleton;
58+
}
5859

59-
/**
60-
*
61-
* @throws FileNotFoundException
62-
*/
63-
public final void prepare() {
60+
/**
61+
* Following method performs the initialization
62+
*/
63+
public void prepare() {
6464

65-
logger.debug("ConsoleLoggerModule::prepare();");
65+
LOGGER.debug("ConsoleLoggerModule::prepare();");
6666

67-
this.output = new PrintStream(System.out);
68-
this.error = new PrintStream(System.err);
69-
}
67+
this.output = new PrintStream(System.out);
68+
this.error = new PrintStream(System.err);
69+
}
7070

71-
/**
72-
*
73-
*/
74-
public final void unprepare() {
71+
/**
72+
* Following method performs the finalization
73+
*/
74+
public void unprepare() {
7575

76-
if (this.output != null) {
76+
if (this.output != null) {
7777

78-
this.output.flush();
79-
this.output.close();
80-
}
78+
this.output.flush();
79+
this.output.close();
80+
}
8181

82-
if (this.error != null) {
82+
if (this.error != null) {
8383

84-
this.error.flush();
85-
this.error.close();
86-
}
84+
this.error.flush();
85+
this.error.close();
86+
}
8787

88-
logger.debug("ConsoleLoggerModule::unprepare();");
89-
}
88+
LOGGER.debug("ConsoleLoggerModule::unprepare();");
89+
}
9090

91-
/**
92-
*
93-
* @param value
94-
*/
95-
public final void printString(final String value) {
96-
this.output.println(value);
97-
}
91+
/**
92+
* Used to print a message
93+
*
94+
* @param value will be printed on console
95+
*/
96+
public void printString(final String value) {
97+
this.output.println(value);
98+
}
9899

99-
/**
100-
*
101-
* @param value
102-
*/
103-
public final void printErrorString(final String value) {
104-
this.error.println(value);
105-
}
100+
/**
101+
* Used to print a error message
102+
*
103+
* @param value will be printed on error console
104+
*/
105+
public void printErrorString(final String value) {
106+
this.error.println(value);
107+
}
106108
}

0 commit comments

Comments
 (0)