From 9ae723f5ab04cfe9826c6524e10a0d4165c4b409 Mon Sep 17 00:00:00 2001 From: danidemi Date: Mon, 7 Nov 2016 21:21:28 +0100 Subject: [PATCH] Removed redundant interface --- .../com/baeldung/mdc/IBusinessService.java | 9 ---- .../java/com/baeldung/mdc/Transaction.java | 50 ++++++++----------- ...inessService.java => TransferService.java} | 4 +- .../mdc/log4j/Log4JBusinessService.java | 4 +- .../com/baeldung/mdc/log4j/Log4JRunnable.java | 3 -- .../mdc/log4j2/Log4J2BusinessService.java | 4 +- .../baeldung/mdc/log4j2/Log4J2Runnable.java | 2 - .../mdc/slf4j/Slf4jBusinessService.java | 4 +- .../com/baeldung/mdc/slf4j/Slf4jRunnable.java | 1 - 9 files changed, 30 insertions(+), 51 deletions(-) delete mode 100644 log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java rename log-mdc-ndc/src/main/java/com/baeldung/mdc/{BusinessService.java => TransferService.java} (80%) diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java deleted file mode 100644 index a2f2fbfdb3..0000000000 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/IBusinessService.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.baeldung.mdc; - -public interface IBusinessService { - - /** Sample service transferring a given amount of money. - * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ - boolean transfer(long amount); - -} diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java index ac0fe75ac5..1a038512c0 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/Transaction.java @@ -1,35 +1,27 @@ package com.baeldung.mdc; -import java.util.Date; - public class Transaction { - - private String transactionId; - private String owner; - private Date createdAt; - private Long amount; - - public Transaction(String transactionId, String owner, long amount) { - this.transactionId = transactionId; - this.owner = owner; - this.createdAt = new Date(); - this.amount = amount; - } - public String getOwner() { - return owner; - } + private String transactionId; + private String owner; + private Long amount; + + public Transaction(String transactionId, String owner, long amount) { + this.transactionId = transactionId; + this.owner = owner; + this.amount = amount; + } + + public String getOwner() { + return owner; + } + + public String getTransactionId() { + return transactionId; + } + + public Long getAmount() { + return amount; + } - public String getTransactionId() { - return transactionId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public Long getAmount() { - return amount; - } - } diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java similarity index 80% rename from log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java rename to log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java index a5fa940a42..7ab53043d3 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/TransferService.java @@ -3,8 +3,10 @@ package com.baeldung.mdc; /** * A fake {@link IBusinessService} simulating an actual one. */ -public abstract class BusinessService implements IBusinessService { +public abstract class TransferService { + /** Sample service transferring a given amount of money. + * @return {@code true} when the transfer complete successfully, {@code false} otherwise. */ public boolean transfer(long amount) { beforeTransfer(amount); // exchange messages with a remote system to transfer the money diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java index 26633e229e..d8b3a15cc2 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JBusinessService.java @@ -2,9 +2,9 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.Logger; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -public class Log4JBusinessService extends BusinessService { +public class Log4JBusinessService extends TransferService { private Logger logger = Logger.getLogger(Log4JBusinessService.class); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java index ce5d97eddf..817eee1e3c 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j/Log4JRunnable.java @@ -1,10 +1,8 @@ package com.baeldung.mdc.log4j; import org.apache.log4j.MDC; -import org.apache.logging.log4j.ThreadContext; import com.baeldung.mdc.Transaction; -import com.baeldung.mdc.log4j2.Log4J2BusinessService; public class Log4JRunnable implements Runnable { @@ -19,7 +17,6 @@ public class Log4JRunnable implements Runnable { MDC.put("transaction.id", tx.getTransactionId()); MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt()); log4jBusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java index cbfbc5b8a5..66a554ff65 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2BusinessService.java @@ -3,9 +3,9 @@ package com.baeldung.mdc.log4j2; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -public class Log4J2BusinessService extends BusinessService { +public class Log4J2BusinessService extends TransferService { private static final Logger logger = LogManager.getLogger(); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java index 6a3f39ba5b..d76f1346e2 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/log4j2/Log4J2Runnable.java @@ -14,10 +14,8 @@ public class Log4J2Runnable implements Runnable { public void run() { - ThreadContext.put("transaction.id", tx.getTransactionId()); ThreadContext.put("transaction.id", tx.getTransactionId()); ThreadContext.put("transaction.owner", tx.getOwner()); - ThreadContext.put("transaction.createdAt", tx.getCreatedAt().toString()); log4j2BusinessService.transfer(tx.getAmount()); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java index d525965ed5..6cd2df6b46 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jBusinessService.java @@ -3,9 +3,9 @@ package com.baeldung.mdc.slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.baeldung.mdc.BusinessService; +import com.baeldung.mdc.TransferService; -final class Slf4jBusinessService extends BusinessService { +final class Slf4jBusinessService extends TransferService { private static final Logger logger = LoggerFactory.getLogger(Slf4jBusinessService.class); diff --git a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java index 2ef170721c..61bf2c0743 100644 --- a/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java +++ b/log-mdc-ndc/src/main/java/com/baeldung/mdc/slf4j/Slf4jRunnable.java @@ -15,7 +15,6 @@ public class Slf4jRunnable implements Runnable { MDC.put("transaction.id", tx.getTransactionId()); MDC.put("transaction.owner", tx.getOwner()); - MDC.put("transaction.createdAt", tx.getCreatedAt().toString()); new Slf4jBusinessService().transfer(tx.getAmount());