checkstyle errors removed
checkstyle errors removed
This commit is contained in:
@ -21,64 +21,75 @@ package com.iluwatar.module;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
/**
|
||||
* The Module pattern can be considered a Creational pattern and a Structural
|
||||
* pattern. It manages the creation and organization of other elements, and
|
||||
* groups them as the structural pattern does. An object that applies this
|
||||
* pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with
|
||||
* static members with cleaner, more concise syntax and semantics.
|
||||
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
||||
* the creation and organization of other elements, and groups them as the structural pattern does.
|
||||
* An object that applies this pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with static members with
|
||||
* cleaner, more concise syntax and semantics.
|
||||
* <p>
|
||||
* The below example demonstrates a use case for testing two different modules:
|
||||
* File Logger and Console Logger
|
||||
* The below example demonstrates a use case for testing two different modules: File Logger and
|
||||
* Console Logger
|
||||
*
|
||||
*/
|
||||
public final class App {
|
||||
|
||||
public static FileLoggerModule fileLoggerModule = null;
|
||||
public static ConsoleLoggerModule consoleLoggerModule = null;
|
||||
public static FileLoggerModule fileLoggerModule = null;
|
||||
public static ConsoleLoggerModule consoleLoggerModule = null;
|
||||
|
||||
public static void prepare() throws FileNotFoundException {
|
||||
/**
|
||||
* Following method performs the initialization
|
||||
*
|
||||
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
||||
* error.txt)
|
||||
*/
|
||||
public static void prepare() throws FileNotFoundException {
|
||||
|
||||
fileLoggerModule = FileLoggerModule.getSingleton();
|
||||
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
|
||||
fileLoggerModule = FileLoggerModule.getSingleton();
|
||||
consoleLoggerModule = ConsoleLoggerModule.getSingleton();
|
||||
|
||||
/* Prepare modules */
|
||||
fileLoggerModule.prepare();
|
||||
consoleLoggerModule.prepare();
|
||||
}
|
||||
/* Prepare modules */
|
||||
fileLoggerModule.prepare();
|
||||
consoleLoggerModule.prepare();
|
||||
}
|
||||
|
||||
public static void unprepare() {
|
||||
/**
|
||||
* Following method performs the finalization
|
||||
*/
|
||||
public static void unprepare() {
|
||||
|
||||
/* Close all resources */
|
||||
fileLoggerModule.unprepare();
|
||||
consoleLoggerModule.unprepare();
|
||||
}
|
||||
/* Close all resources */
|
||||
fileLoggerModule.unprepare();
|
||||
consoleLoggerModule.unprepare();
|
||||
}
|
||||
|
||||
public static final void execute(final String... args) {
|
||||
/**
|
||||
* Following method is main executor
|
||||
*
|
||||
* @param args for providing default program arguments
|
||||
*/
|
||||
public static void execute(final String... args) {
|
||||
|
||||
/* Send logs on file system */
|
||||
fileLoggerModule.printString("Message");
|
||||
fileLoggerModule.printErrorString("Error");
|
||||
/* Send logs on file system */
|
||||
fileLoggerModule.printString("Message");
|
||||
fileLoggerModule.printErrorString("Error");
|
||||
|
||||
/* Send logs on console */
|
||||
consoleLoggerModule.printString("Message");
|
||||
consoleLoggerModule.printErrorString("Error");
|
||||
}
|
||||
/* Send logs on console */
|
||||
consoleLoggerModule.printString("Message");
|
||||
consoleLoggerModule.printErrorString("Error");
|
||||
}
|
||||
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args
|
||||
* command line args.
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public static final void main(final String... args)
|
||||
throws FileNotFoundException {
|
||||
prepare();
|
||||
execute(args);
|
||||
unprepare();
|
||||
}
|
||||
/**
|
||||
* Program entry point.
|
||||
*
|
||||
* @param args command line args.
|
||||
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
||||
* error.txt)
|
||||
*/
|
||||
public static void main(final String... args) throws FileNotFoundException {
|
||||
prepare();
|
||||
execute(args);
|
||||
unprepare();
|
||||
}
|
||||
|
||||
private App() {
|
||||
}
|
||||
private App() {}
|
||||
}
|
||||
|
@ -18,89 +18,91 @@
|
||||
*/
|
||||
package com.iluwatar.module;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* The Module pattern can be considered a Creational pattern and a Structural
|
||||
* pattern. It manages the creation and organization of other elements, and
|
||||
* groups them as the structural pattern does. An object that applies this
|
||||
* pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with
|
||||
* static members with cleaner, more concise syntax and semantics.
|
||||
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
||||
* the creation and organization of other elements, and groups them as the structural pattern does.
|
||||
* An object that applies this pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with static members with
|
||||
* cleaner, more concise syntax and semantics.
|
||||
* <p>
|
||||
* The below example demonstrates a Console logger module, which can print
|
||||
* simple and error messages in two designated formats
|
||||
* The below example demonstrates a Console logger module, which can print simple and error messages
|
||||
* in two designated formats
|
||||
*/
|
||||
public class ConsoleLoggerModule {
|
||||
public final class ConsoleLoggerModule {
|
||||
|
||||
private static final Logger logger = Logger
|
||||
.getLogger(ConsoleLoggerModule.class);
|
||||
private static final Logger LOGGER = Logger.getLogger(ConsoleLoggerModule.class);
|
||||
|
||||
private static ConsoleLoggerModule singleton = null;
|
||||
private static ConsoleLoggerModule singleton = null;
|
||||
|
||||
public PrintStream output = null;
|
||||
public PrintStream error = null;
|
||||
public PrintStream output = null;
|
||||
public PrintStream error = null;
|
||||
|
||||
private ConsoleLoggerModule() {
|
||||
}
|
||||
private ConsoleLoggerModule() {}
|
||||
|
||||
public static final ConsoleLoggerModule getSingleton() {
|
||||
/**
|
||||
* Static method to get single instance of class
|
||||
*
|
||||
* @return singleton instance of ConsoleLoggerModule
|
||||
*/
|
||||
public static ConsoleLoggerModule getSingleton() {
|
||||
|
||||
if (ConsoleLoggerModule.singleton == null) {
|
||||
ConsoleLoggerModule.singleton = new ConsoleLoggerModule();
|
||||
}
|
||||
if (ConsoleLoggerModule.singleton == null) {
|
||||
ConsoleLoggerModule.singleton = new ConsoleLoggerModule();
|
||||
}
|
||||
|
||||
return ConsoleLoggerModule.singleton;
|
||||
}
|
||||
return ConsoleLoggerModule.singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public final void prepare() {
|
||||
/**
|
||||
* Following method performs the initialization
|
||||
*/
|
||||
public void prepare() {
|
||||
|
||||
logger.debug("ConsoleLoggerModule::prepare();");
|
||||
LOGGER.debug("ConsoleLoggerModule::prepare();");
|
||||
|
||||
this.output = new PrintStream(System.out);
|
||||
this.error = new PrintStream(System.err);
|
||||
}
|
||||
this.output = new PrintStream(System.out);
|
||||
this.error = new PrintStream(System.err);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final void unprepare() {
|
||||
/**
|
||||
* Following method performs the finalization
|
||||
*/
|
||||
public void unprepare() {
|
||||
|
||||
if (this.output != null) {
|
||||
if (this.output != null) {
|
||||
|
||||
this.output.flush();
|
||||
this.output.close();
|
||||
}
|
||||
this.output.flush();
|
||||
this.output.close();
|
||||
}
|
||||
|
||||
if (this.error != null) {
|
||||
if (this.error != null) {
|
||||
|
||||
this.error.flush();
|
||||
this.error.close();
|
||||
}
|
||||
this.error.flush();
|
||||
this.error.close();
|
||||
}
|
||||
|
||||
logger.debug("ConsoleLoggerModule::unprepare();");
|
||||
}
|
||||
LOGGER.debug("ConsoleLoggerModule::unprepare();");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public final void printString(final String value) {
|
||||
this.output.println(value);
|
||||
}
|
||||
/**
|
||||
* Used to print a message
|
||||
*
|
||||
* @param value will be printed on console
|
||||
*/
|
||||
public void printString(final String value) {
|
||||
this.output.println(value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public final void printErrorString(final String value) {
|
||||
this.error.println(value);
|
||||
}
|
||||
/**
|
||||
* Used to print a error message
|
||||
*
|
||||
* @param value will be printed on error console
|
||||
*/
|
||||
public void printErrorString(final String value) {
|
||||
this.error.println(value);
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,20 @@
|
||||
/**
|
||||
* The MIT License Copyright (c) 2016 Amit Dixit
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
||||
* associated documentation files (the "Software"), to deal in the Software without restriction,
|
||||
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
|
||||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
* The above copyright notice and this permission notice shall be included in all copies or
|
||||
* substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
||||
* NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.iluwatar.module;
|
||||
|
||||
@ -28,86 +25,92 @@ import java.io.PrintStream;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* The Module pattern can be considered a Creational pattern and a Structural
|
||||
* pattern. It manages the creation and organization of other elements, and
|
||||
* groups them as the structural pattern does. An object that applies this
|
||||
* pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with
|
||||
* static members with cleaner, more concise syntax and semantics.
|
||||
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
||||
* the creation and organization of other elements, and groups them as the structural pattern does.
|
||||
* An object that applies this pattern can provide the equivalent of a namespace, providing the
|
||||
* initialization and finalization process of a static class or a class with static members with
|
||||
* cleaner, more concise syntax and semantics.
|
||||
* <p>
|
||||
* The below example demonstrates a File logger module, which can print simple
|
||||
* and error messages in two designated files
|
||||
* The below example demonstrates a File logger module, which can print simple and error messages in
|
||||
* two designated files
|
||||
*/
|
||||
public final class FileLoggerModule {
|
||||
|
||||
private static final Logger logger = Logger
|
||||
.getLogger(FileLoggerModule.class);
|
||||
private static final Logger LOGGER = Logger.getLogger(FileLoggerModule.class);
|
||||
|
||||
private static FileLoggerModule singleton = null;
|
||||
private static FileLoggerModule singleton = null;
|
||||
|
||||
private static final String OUTPUT_FILE = "output.txt";
|
||||
private static final String ERROR_FILE = "error.txt";
|
||||
private static final String OUTPUT_FILE = "output.txt";
|
||||
private static final String ERROR_FILE = "error.txt";
|
||||
|
||||
public PrintStream output = null;
|
||||
public PrintStream error = null;
|
||||
public PrintStream output = null;
|
||||
public PrintStream error = null;
|
||||
|
||||
private FileLoggerModule() {
|
||||
}
|
||||
private FileLoggerModule() {}
|
||||
|
||||
public static final FileLoggerModule getSingleton() {
|
||||
/**
|
||||
* Static method to get single instance of class
|
||||
*
|
||||
* @return singleton instance of FileLoggerModule
|
||||
*/
|
||||
public static FileLoggerModule getSingleton() {
|
||||
|
||||
if (FileLoggerModule.singleton == null) {
|
||||
FileLoggerModule.singleton = new FileLoggerModule();
|
||||
}
|
||||
if (FileLoggerModule.singleton == null) {
|
||||
FileLoggerModule.singleton = new FileLoggerModule();
|
||||
}
|
||||
|
||||
return FileLoggerModule.singleton;
|
||||
}
|
||||
return FileLoggerModule.singleton;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @throws FileNotFoundException
|
||||
*/
|
||||
public final void prepare() throws FileNotFoundException {
|
||||
/**
|
||||
* Following method performs the initialization
|
||||
*
|
||||
* @throws FileNotFoundException if program is not able to find log files (output.txt and
|
||||
* error.txt)
|
||||
*/
|
||||
public void prepare() throws FileNotFoundException {
|
||||
|
||||
logger.debug("FileLoggerModule::prepare();");
|
||||
LOGGER.debug("FileLoggerModule::prepare();");
|
||||
|
||||
this.output = new PrintStream(new FileOutputStream(OUTPUT_FILE));
|
||||
this.error = new PrintStream(new FileOutputStream(ERROR_FILE));
|
||||
}
|
||||
this.output = new PrintStream(new FileOutputStream(OUTPUT_FILE));
|
||||
this.error = new PrintStream(new FileOutputStream(ERROR_FILE));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public final void unprepare() {
|
||||
/**
|
||||
* Following method performs the finalization
|
||||
*/
|
||||
public void unprepare() {
|
||||
|
||||
if (this.output != null) {
|
||||
if (this.output != null) {
|
||||
|
||||
this.output.flush();
|
||||
this.output.close();
|
||||
}
|
||||
this.output.flush();
|
||||
this.output.close();
|
||||
}
|
||||
|
||||
if (this.error != null) {
|
||||
if (this.error != null) {
|
||||
|
||||
this.error.flush();
|
||||
this.error.close();
|
||||
}
|
||||
this.error.flush();
|
||||
this.error.close();
|
||||
}
|
||||
|
||||
logger.debug("FileLoggerModule::unprepare();");
|
||||
}
|
||||
LOGGER.debug("FileLoggerModule::unprepare();");
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public final void printString(final String value) {
|
||||
this.output.println(value);
|
||||
}
|
||||
/**
|
||||
* Used to print a message
|
||||
*
|
||||
* @param value will be printed in file
|
||||
*/
|
||||
public void printString(final String value) {
|
||||
this.output.println(value);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
public final void printErrorString(final String value) {
|
||||
this.error.println(value);
|
||||
}
|
||||
/**
|
||||
* Used to print a error message
|
||||
*
|
||||
* @param value will be printed on error file
|
||||
*/
|
||||
public void printErrorString(final String value) {
|
||||
this.error.println(value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user