Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves checkstyle errors for remaining m #1090

Merged
merged 12 commits into from
Nov 16, 2019
Merged
Prev Previous commit
Next Next commit
Reduces checkstyle errors in mute-idiom
  • Loading branch information
anuragagarwal561994 committed Nov 15, 2019
commit 1b5d3b2ffca158c981780a84806e5a97d475608d
21 changes: 9 additions & 12 deletions mute-idiom/src/main/java/com/iluwatar/mute/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,17 @@

package com.iluwatar.mute;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Mute pattern is utilized when we need to suppress an exception due to an API flaw or in
* situation when all we can do to handle the exception is to log it.
* This pattern should not be used everywhere. It is very important to logically handle the
* exceptions in a system, but some situations like the ones described above require this pattern,
* so that we don't need to repeat
* Mute pattern is utilized when we need to suppress an exception due to an API flaw or in situation
* when all we can do to handle the exception is to log it. This pattern should not be used
* everywhere. It is very important to logically handle the exceptions in a system, but some
* situations like the ones described above require this pattern, so that we don't need to repeat
* <pre>
* <code>
* try {
Expand All @@ -45,15 +43,14 @@
* }
* </code>
* </pre> every time we need to ignore an exception.
*
*/
public class App {

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

/**
* Program entry point.
*
*
* @param args command line args.
* @throws Exception if any exception occurs
*/
Expand All @@ -65,7 +62,7 @@ public static void main(String[] args) throws Exception {
}

/*
* Typically used when the API declares some exception but cannot do so. Usually a
* Typically used when the API declares some exception but cannot do so. Usually a
* signature mistake.In this example out is not supposed to throw exception as it is a
* ByteArrayOutputStream. So we utilize mute, which will throw AssertionError if unexpected
* exception occurs.
Expand Down Expand Up @@ -98,7 +95,7 @@ private static void utilizeResource(Resource resource) throws SQLException {

private static Resource acquireResource() throws SQLException {
return new Resource() {

@Override
public void close() throws IOException {
throw new IOException("Error in closing resource: " + this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@

/**
* A runnable which may throw exception on execution.
*
*/
@FunctionalInterface
public interface CheckedRunnable {
/**
* Same as {@link Runnable#run()} with a possibility of exception in execution.
*
* @throws Exception if any exception occurs.
*/
void run() throws Exception;
Expand Down
27 changes: 14 additions & 13 deletions mute-idiom/src/main/java/com/iluwatar/mute/Mute.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@
* A utility class that allows you to utilize mute idiom.
*/
public final class Mute {

// The constructor is never meant to be called.
private Mute() {}
private Mute() {
}

/**
* Executes the <code>runnable</code> and throws the exception occurred within a {@link AssertionError}.
* This method should be utilized to mute the operations that are guaranteed not to throw an exception.
* For instance {@link ByteArrayOutputStream#write(byte[])} declares in it's signature that it can throw
* an {@link IOException}, but in reality it cannot. This is because the bulk write method is not overridden
* in {@link ByteArrayOutputStream}.
*
* Executes the <code>runnable</code> and throws the exception occurred within a {@link
* AssertionError}. This method should be utilized to mute the operations that are guaranteed not
* to throw an exception. For instance {@link ByteArrayOutputStream#write(byte[])} declares in
* it's signature that it can throw an {@link IOException}, but in reality it cannot. This is
* because the bulk write method is not overridden in {@link ByteArrayOutputStream}.
*
* @param runnable a runnable that should never throw an exception on execution.
*/
public static void mute(CheckedRunnable runnable) {
Expand All @@ -52,11 +53,11 @@ public static void mute(CheckedRunnable runnable) {
}

/**
* Executes the <code>runnable</code> and logs the exception occurred on {@link System#err}.
* This method should be utilized to mute the operations about which most you can do is log.
* For instance while closing a connection to database, or cleaning up a resource,
* all you can do is log the exception occurred.
*
* Executes the <code>runnable</code> and logs the exception occurred on {@link System#err}. This
* method should be utilized to mute the operations about which most you can do is log. For
* instance while closing a connection to database, or cleaning up a resource, all you can do is
* log the exception occurred.
*
* @param runnable a runnable that may throw an exception on execution.
*/
public static void loggedMute(CheckedRunnable runnable) {
Expand Down
5 changes: 2 additions & 3 deletions mute-idiom/src/main/java/com/iluwatar/mute/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
import java.io.Closeable;

/**
* Represents any resource that the application might acquire and that must be closed
* after it is utilized. Example of such resources can be a database connection, open
* files, sockets.
* Represents any resource that the application might acquire and that must be closed after it is
* utilized. Example of such resources can be a database connection, open files, sockets.
*/
public interface Resource extends Closeable {

Expand Down