|
18 | 18 | */
|
19 | 19 | package com.iluwatar.module;
|
20 | 20 |
|
21 |
| -import java.io.FileNotFoundException; |
22 | 21 | import java.io.PrintStream;
|
23 | 22 |
|
24 | 23 | import org.apache.log4j.Logger;
|
25 | 24 |
|
26 | 25 | /**
|
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. |
33 | 31 | * <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 |
36 | 34 | */
|
37 |
| -public class ConsoleLoggerModule { |
| 35 | +public final class ConsoleLoggerModule { |
38 | 36 |
|
39 |
| - private static final Logger logger = Logger |
40 |
| - .getLogger(ConsoleLoggerModule.class); |
| 37 | + private static final Logger LOGGER = Logger.getLogger(ConsoleLoggerModule.class); |
41 | 38 |
|
42 |
| - private static ConsoleLoggerModule singleton = null; |
| 39 | + private static ConsoleLoggerModule singleton = null; |
43 | 40 |
|
44 |
| - public PrintStream output = null; |
45 |
| - public PrintStream error = null; |
| 41 | + public PrintStream output = null; |
| 42 | + public PrintStream error = null; |
46 | 43 |
|
47 |
| - private ConsoleLoggerModule() { |
48 |
| - } |
| 44 | + private ConsoleLoggerModule() {} |
49 | 45 |
|
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() { |
51 | 52 |
|
52 |
| - if (ConsoleLoggerModule.singleton == null) { |
53 |
| - ConsoleLoggerModule.singleton = new ConsoleLoggerModule(); |
54 |
| - } |
| 53 | + if (ConsoleLoggerModule.singleton == null) { |
| 54 | + ConsoleLoggerModule.singleton = new ConsoleLoggerModule(); |
| 55 | + } |
55 | 56 |
|
56 |
| - return ConsoleLoggerModule.singleton; |
57 |
| - } |
| 57 | + return ConsoleLoggerModule.singleton; |
| 58 | + } |
58 | 59 |
|
59 |
| - /** |
60 |
| - * |
61 |
| - * @throws FileNotFoundException |
62 |
| - */ |
63 |
| - public final void prepare() { |
| 60 | + /** |
| 61 | + * Following method performs the initialization |
| 62 | + */ |
| 63 | + public void prepare() { |
64 | 64 |
|
65 |
| - logger.debug("ConsoleLoggerModule::prepare();"); |
| 65 | + LOGGER.debug("ConsoleLoggerModule::prepare();"); |
66 | 66 |
|
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 | + } |
70 | 70 |
|
71 |
| - /** |
72 |
| - * |
73 |
| - */ |
74 |
| - public final void unprepare() { |
| 71 | + /** |
| 72 | + * Following method performs the finalization |
| 73 | + */ |
| 74 | + public void unprepare() { |
75 | 75 |
|
76 |
| - if (this.output != null) { |
| 76 | + if (this.output != null) { |
77 | 77 |
|
78 |
| - this.output.flush(); |
79 |
| - this.output.close(); |
80 |
| - } |
| 78 | + this.output.flush(); |
| 79 | + this.output.close(); |
| 80 | + } |
81 | 81 |
|
82 |
| - if (this.error != null) { |
| 82 | + if (this.error != null) { |
83 | 83 |
|
84 |
| - this.error.flush(); |
85 |
| - this.error.close(); |
86 |
| - } |
| 84 | + this.error.flush(); |
| 85 | + this.error.close(); |
| 86 | + } |
87 | 87 |
|
88 |
| - logger.debug("ConsoleLoggerModule::unprepare();"); |
89 |
| - } |
| 88 | + LOGGER.debug("ConsoleLoggerModule::unprepare();"); |
| 89 | + } |
90 | 90 |
|
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 | + } |
98 | 99 |
|
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 | + } |
106 | 108 | }
|
0 commit comments