From 8b3a13d4966d844786c742fcb02cf63f732a6c15 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Tue, 14 Feb 2017 12:55:50 -0500 Subject: [PATCH 01/45] Add files via upload --- guice-intro/pom.xml | 21 +++++++ .../java/com/baeldung/examples/RunGuice.java | 39 ++++++++++++ .../examples/guice/Communication.java | 61 +++++++++++++++++++ .../examples/guice/CommunicationMode.java | 16 +++++ .../examples/guice/DefaultCommunicator.java | 55 +++++++++++++++++ .../guice/EmailCommunicationMode.java | 28 +++++++++ .../examples/guice/IMCommunicationMode.java | 34 +++++++++++ .../examples/guice/SMSCommunicationMode.java | 34 +++++++++++ .../examples/guice/aop/MessageLogger.java | 28 +++++++++ .../guice/aop/MessageSentLoggable.java | 21 +++++++ .../examples/guice/binding/AOPModule.java | 27 ++++++++ .../examples/guice/binding/BasicModule.java | 41 +++++++++++++ .../guice/constant/CommunicationModel.java | 21 +++++++ .../examples/guice/marker/Communicator.java | 14 +++++ .../examples/guice/modules/BasicModule.java | 42 +++++++++++++ 15 files changed, 482 insertions(+) create mode 100644 guice-intro/pom.xml create mode 100644 guice-intro/src/main/java/com/baeldung/examples/RunGuice.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java create mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml new file mode 100644 index 000000000000..0cb3a8b8e204 --- /dev/null +++ b/guice-intro/pom.xml @@ -0,0 +1,21 @@ + + + 4.0.0 + com.baeldung.examples.guice + GuiceExample + 1.0-SNAPSHOT + jar + + + com.google.inject + guice + 4.1.0 + + + + UTF-8 + 1.7 + 1.7 + + guice-intro + \ No newline at end of file diff --git a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java new file mode 100644 index 000000000000..a433d78cb85f --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java @@ -0,0 +1,39 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.binding.AOPModule; +import com.baeldung.examples.guice.modules.BasicModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import java.util.Scanner; + +/** + * + * @author Tayo + */ +public class RunGuice { + + public static void main(String[] args) { + Injector injector = Guice.createInjector(new BasicModule(), new AOPModule()); + Communication comms = injector.getInstance(Communication.class); + Scanner scanner = new Scanner(System.in); + while (true) { + String input = scanner.nextLine(); + if (input.equalsIgnoreCase("q")) { + System.exit(0); + } + if (input.equalsIgnoreCase("p")) { + comms.print(); + } else { + comms.sendMessage(input); + } + + } + + } +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java new file mode 100644 index 000000000000..47b5b763fe78 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java @@ -0,0 +1,61 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import java.util.Date; +import java.util.LinkedList; +import java.util.Queue; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +public class Communication { + + final Date start = new Date(); + + @Inject + private Logger logger; + + private Queue messageLog; + + @Named("CommsUUID") + private String commsID; + + @Inject + private DefaultCommunicator communicator; + + public Communication(Boolean keepRecords) { + if (keepRecords) { + messageLog = new LinkedList(); + } + } + + public boolean sendMessage(String message) { + if (!message.isEmpty() && messageLog != null) { + messageLog.add(message); + } + return communicator.sendMessage(message); + } + + public void print() { + if (messageLog != null) { + for (String message : messageLog) { + logger.info(message); + } + } else { + logger.info("Message logging wasn't enabled"); + } + } + + public DefaultCommunicator getCommunicator() { + return this.communicator; + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java new file mode 100644 index 000000000000..6e4e8002bf82 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java @@ -0,0 +1,16 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.constant.CommunicationModel; + +public interface CommunicationMode { + + public CommunicationModel getMode(); + + public boolean sendMessage(String message); + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java new file mode 100644 index 000000000000..61bf6da61d52 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java @@ -0,0 +1,55 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.marker.Communicator; +import com.google.inject.Inject; +import com.google.inject.name.Named; + +/** + * + * @author Tayo + */ +public class DefaultCommunicator implements Communicator { + + private CommunicationMode defaultCommsMode; + @Inject + @Named("SMSComms") + CommunicationMode smsCommsMode; + @Inject + @Named("EmailComms") + CommunicationMode emailCommsMode; + @Inject + @Named("IMComms") + CommunicationMode imCommsMode; + + protected DefaultCommunicator(CommunicationMode defaultComms) { + this.defaultCommsMode = defaultComms; + } + + public DefaultCommunicator() { + + } + + public boolean sendMessage(String message) { + boolean sent = false; + if (defaultCommsMode != null) { + sent = sendMessageByDefault(message); + } else { + sent = smsCommsMode.sendMessage(message); + } + return sent; + } + + private boolean sendMessageByDefault(String message) { + boolean sent = false; + if (message != null && !message.trim().equals("")) { + return defaultCommsMode.sendMessage(message); + } + return sent; + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java new file mode 100644 index 000000000000..f85a37e0f50a --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; + +/** + * + * @author Tayo + */ +public class EmailCommunicationMode implements CommunicationMode { + + @Override + public CommunicationModel getMode() { + return CommunicationModel.EMAIL; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String Message) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java new file mode 100644 index 000000000000..2d8213d995f7 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; +import com.google.inject.Inject; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +public class IMCommunicationMode implements CommunicationMode { + + @Inject + private Logger logger; + + @Override + public CommunicationModel getMode() { + return CommunicationModel.IM; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String message) { + logger.info("IM Message Sent"); + return true; + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java new file mode 100644 index 000000000000..e34d15bb8bc6 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java @@ -0,0 +1,34 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; +import com.google.inject.Inject; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +public class SMSCommunicationMode implements CommunicationMode { + + @Inject + private Logger logger; + + @Override + public CommunicationModel getMode() { + return CommunicationModel.SMS; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String message) { + logger.info("SMS message sent"); + return true; + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java new file mode 100644 index 000000000000..64b71efbbdfb --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java @@ -0,0 +1,28 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.aop; + +import com.google.inject.Inject; +import java.util.logging.Logger; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +/** + * + * @author Tayo + */ +public class MessageLogger implements MethodInterceptor { + + @Override + public Object invoke(MethodInvocation invocation) throws Throwable { + Object[] objectArray = invocation.getArguments(); + int i = 0; + for (Object object : objectArray) { + Logger.getAnonymousLogger().info("Sending message: " + object.toString()); + } + return invocation.proceed(); + } +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java new file mode 100644 index 000000000000..020e89d8ba9b --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java @@ -0,0 +1,21 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author Tayo + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface MessageSentLoggable { + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java new file mode 100644 index 000000000000..db966e7f9ed8 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.binding; + +import com.baeldung.examples.guice.aop.MessageLogger; +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.google.inject.AbstractModule; +import com.google.inject.matcher.Matchers; + +/** + * + * @author Tayo + */ +public class AOPModule extends AbstractModule { + + @Override + protected void configure() { + bindInterceptor(Matchers.any(), + Matchers.annotatedWith(MessageSentLoggable.class), + new MessageLogger() + ); + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java new file mode 100644 index 000000000000..beca0d1f41a4 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java @@ -0,0 +1,41 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.binding; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.CommunicationMode; +import com.baeldung.examples.guice.DefaultCommunicator; +import com.baeldung.examples.guice.EmailCommunicationMode; +import com.baeldung.examples.guice.IMCommunicationMode; +import com.baeldung.examples.guice.SMSCommunicationMode; +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +public class BasicModule extends AbstractModule { + + @Override + protected void configure() { + try { + bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.TYPE)); + } catch (NoSuchMethodException ex) { + Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } + bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); + + bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); + } + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java b/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java new file mode 100644 index 000000000000..3acd02d56ac0 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java @@ -0,0 +1,21 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.constant; + +/** + * + * @author Tayo + */ +public enum CommunicationModel { + + EMAIL("Email"), SMS("SMS"), IM("IM"), PHONE("Phone"); + + final String name; + + CommunicationModel(String name) { + this.name = name; + } +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java new file mode 100644 index 000000000000..7425f1c28395 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.marker; + +/** + * + * @author Tayo + */ +public interface Communicator { + +} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java new file mode 100644 index 000000000000..98c46c34f763 --- /dev/null +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java @@ -0,0 +1,42 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.modules; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.CommunicationMode; +import com.baeldung.examples.guice.DefaultCommunicator; +import com.baeldung.examples.guice.EmailCommunicationMode; +import com.baeldung.examples.guice.IMCommunicationMode; +import com.baeldung.examples.guice.SMSCommunicationMode; +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author Tayo + */ +public class BasicModule extends AbstractModule { + + @Override + protected void configure() { + try { + bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.class)); + bind(Boolean.class).toInstance(true); + } catch (NoSuchMethodException ex) { + Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } + bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); + + bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); + } + +} From 39ab2017546444a55cdf1f4d291523d76318c7af Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:28:16 -0500 Subject: [PATCH 02/45] Update pom.xml --- guice-intro/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index 0cb3a8b8e204..95d0e7610718 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.baeldung.examples.guice - GuiceExample + guice-intro 1.0-SNAPSHOT jar @@ -18,4 +18,4 @@ 1.7 guice-intro - \ No newline at end of file + From b8051b07c1c564028c102d2e4ddbcc209e5df43e Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:28:48 -0500 Subject: [PATCH 03/45] Update RunGuice.java --- .../src/main/java/com/baeldung/examples/RunGuice.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java index a433d78cb85f..73d09bbaab45 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java +++ b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java @@ -1,8 +1,4 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ + package com.baeldung.examples; import com.baeldung.examples.guice.Communication; @@ -14,7 +10,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class RunGuice { From 1122e932b6b84c27dc52271a48d3c282a8cd81c0 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:29:12 -0500 Subject: [PATCH 04/45] Update Communication.java --- .../java/com/baeldung/examples/guice/Communication.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java index 47b5b763fe78..c4b17b57d2b6 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java @@ -1,8 +1,4 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ + package com.baeldung.examples.guice; import com.google.inject.Inject; @@ -14,7 +10,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class Communication { From efc2d27a84435647e60578ceb194dd4603842259 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:29:27 -0500 Subject: [PATCH 05/45] Update CommunicationMode.java --- .../java/com/baeldung/examples/guice/CommunicationMode.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java index 6e4e8002bf82..444b77547888 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java @@ -1,8 +1,4 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ + package com.baeldung.examples.guice; import com.baeldung.examples.guice.constant.CommunicationModel; From e9281a8de586ecaa432a8edfe22bf96389cf8bb2 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:29:45 -0500 Subject: [PATCH 06/45] Update DefaultCommunicator.java --- .../baeldung/examples/guice/DefaultCommunicator.java | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java index 61bf6da61d52..423c24f7895b 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java @@ -1,18 +1,11 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ + package com.baeldung.examples.guice; import com.baeldung.examples.guice.marker.Communicator; import com.google.inject.Inject; import com.google.inject.name.Named; -/** - * - * @author Tayo - */ + public class DefaultCommunicator implements Communicator { private CommunicationMode defaultCommsMode; From 0e02029bc8059d7726b00879acbcb870b8c4d984 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:30:09 -0500 Subject: [PATCH 07/45] Update EmailCommunicationMode.java --- .../baeldung/examples/guice/EmailCommunicationMode.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java index f85a37e0f50a..642ee7ace062 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice; import com.baeldung.examples.guice.aop.MessageSentLoggable; @@ -10,7 +5,7 @@ /** * - * @author Tayo + * @author Baekdung */ public class EmailCommunicationMode implements CommunicationMode { From 24acd84d53957cd90eec5275dad8582985672a5c Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:30:37 -0500 Subject: [PATCH 08/45] Update IMCommunicationMode.java --- .../com/baeldung/examples/guice/IMCommunicationMode.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java index 2d8213d995f7..9f34e9a241ce 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java @@ -1,8 +1,4 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ + package com.baeldung.examples.guice; import com.baeldung.examples.guice.aop.MessageSentLoggable; @@ -12,7 +8,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class IMCommunicationMode implements CommunicationMode { From 023d1dac9811f1846f3adee385c32d888c990220 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:30:55 -0500 Subject: [PATCH 09/45] Update SMSCommunicationMode.java --- .../com/baeldung/examples/guice/SMSCommunicationMode.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java index e34d15bb8bc6..251e2499713c 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice; import com.baeldung.examples.guice.aop.MessageSentLoggable; @@ -12,7 +7,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class SMSCommunicationMode implements CommunicationMode { From 6d46dfe4c0932f9602c37ba51e73eef4616ca8e7 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:31:13 -0500 Subject: [PATCH 10/45] Update MessageLogger.java --- .../com/baeldung/examples/guice/aop/MessageLogger.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java index 64b71efbbdfb..8d8298761933 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.aop; import com.google.inject.Inject; @@ -12,7 +7,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class MessageLogger implements MethodInterceptor { From d5bd1214a7481bfcb77f2c8298641d865af8717a Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:31:31 -0500 Subject: [PATCH 11/45] Update MessageSentLoggable.java --- .../baeldung/examples/guice/aop/MessageSentLoggable.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java index 020e89d8ba9b..cacf3bde7cdf 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.aop; import java.lang.annotation.ElementType; @@ -12,7 +7,7 @@ /** * - * @author Tayo + * @author Baeldung */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) From 156c7a2458a223859a6d1abccdd7c6513b06c015 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:31:51 -0500 Subject: [PATCH 12/45] Update AOPModule.java --- .../com/baeldung/examples/guice/binding/AOPModule.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java index db966e7f9ed8..dc9d258efa0f 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.binding; import com.baeldung.examples.guice.aop.MessageLogger; @@ -12,7 +7,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class AOPModule extends AbstractModule { From e1226d125df47957984f61772db105d8079ca14e Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:32:10 -0500 Subject: [PATCH 13/45] Update BasicModule.java --- .../com/baeldung/examples/guice/binding/BasicModule.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java index beca0d1f41a4..916819513060 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.binding; import com.baeldung.examples.guice.Communication; @@ -18,7 +13,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class BasicModule extends AbstractModule { From 67c0dd6da0a36445f5bc3221e600d866297cd449 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:32:27 -0500 Subject: [PATCH 14/45] Update CommunicationModel.java --- .../examples/guice/constant/CommunicationModel.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java b/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java index 3acd02d56ac0..b9fa604a32d1 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java @@ -1,13 +1,8 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.constant; /** * - * @author Tayo + * @author Baeldung */ public enum CommunicationModel { From 43c3b521583faaa6c5d089acf9bc25d70bf07e7f Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:32:43 -0500 Subject: [PATCH 15/45] Update Communicator.java --- .../com/baeldung/examples/guice/marker/Communicator.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java index 7425f1c28395..3e6c3d6ea7c1 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java @@ -1,13 +1,8 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.marker; /** * - * @author Tayo + * @author Baeldung */ public interface Communicator { From c634e0b66fb76816652ac7263deb9d5628c1bba8 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sat, 18 Feb 2017 00:33:01 -0500 Subject: [PATCH 16/45] Update BasicModule.java --- .../com/baeldung/examples/guice/modules/BasicModule.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java index 98c46c34f763..47b3e2e57313 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java @@ -1,8 +1,3 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ package com.baeldung.examples.guice.modules; import com.baeldung.examples.guice.Communication; @@ -18,7 +13,7 @@ /** * - * @author Tayo + * @author Baeldung */ public class BasicModule extends AbstractModule { From cae5eb72c5ef1aa6d52c24ffb3c01994ffe1102b Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 23 Feb 2017 18:25:48 -0500 Subject: [PATCH 17/45] Update RunGuice.java --- guice-intro/src/main/java/com/baeldung/examples/RunGuice.java | 1 + 1 file changed, 1 insertion(+) diff --git a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java index 73d09bbaab45..b4b3e8571e5a 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java +++ b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java @@ -18,6 +18,7 @@ public static void main(String[] args) { Injector injector = Guice.createInjector(new BasicModule(), new AOPModule()); Communication comms = injector.getInstance(Communication.class); Scanner scanner = new Scanner(System.in); + System.out.println("Enter your message to be sent; press Q to quit and P to print the message log"); while (true) { String input = scanner.nextLine(); if (input.equalsIgnoreCase("q")) { From 1517f8948fc8e94b55e56b93258b0119bf4de865 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 23 Feb 2017 18:26:58 -0500 Subject: [PATCH 18/45] Update MessageLogger.java --- .../main/java/com/baeldung/examples/guice/aop/MessageLogger.java | 1 - 1 file changed, 1 deletion(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java index 8d8298761933..8926dfa7143e 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java @@ -1,6 +1,5 @@ package com.baeldung.examples.guice.aop; -import com.google.inject.Inject; import java.util.logging.Logger; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; From 54683ed52f60e8f0b40e0aff406ecb730695b690 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 23 Feb 2017 18:28:18 -0500 Subject: [PATCH 19/45] Update Communicator.java --- .../java/com/baeldung/examples/guice/marker/Communicator.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java index 3e6c3d6ea7c1..239666b6ab16 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java @@ -6,4 +6,6 @@ */ public interface Communicator { + public boolean sendMessage(String message); + } From d9bb20a2f7b9e42127d84c661a03572da6d6817c Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 23 Feb 2017 18:30:24 -0500 Subject: [PATCH 20/45] Update pom.xml --- guice-intro/pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index 95d0e7610718..e305c706951e 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -9,13 +9,14 @@ com.google.inject guice - 4.1.0 + ${guice.version} UTF-8 - 1.7 - 1.7 + 1.8 + 1.8 + 4.1.0 guice-intro From 51580ab3b255df2dbf876cbac1a1049a093f58af Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sat, 25 Feb 2017 16:22:39 -0600 Subject: [PATCH 21/45] BAEL-278: Updated README.md --- algorithms/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms/README.md b/algorithms/README.md index 4789768fad27..42f696d9be14 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -1,3 +1,4 @@ ## Relevant articles: - [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra) +- [Introduction to Cobertura](http://www.baeldung.com/cobertura) From 9f87c074baa3162d27d6aaaa52f4cfa1cc71a77d Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 26 Feb 2017 17:58:46 -0600 Subject: [PATCH 22/45] BAEL-554: Add and update README.md files --- spring-remoting/README.md | 3 ++- spring-remoting/remoting-hessian-burlap/README.md | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 spring-remoting/remoting-hessian-burlap/README.md diff --git a/spring-remoting/README.md b/spring-remoting/README.md index 1aafdaf6f594..41bbd59f012e 100644 --- a/spring-remoting/README.md +++ b/spring-remoting/README.md @@ -1,7 +1,8 @@ -## Spring Remoting Tutorials Project +## Spring Remoting Tutorials ### Relevant Articles - [Intro to Spring Remoting with HTTP Invokers](http://www.baeldung.com/spring-remoting-http-invoker) +- [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) ### Overview This Maven project contains the Java source code for various modules used in the Spring Remoting series of articles. diff --git a/spring-remoting/remoting-hessian-burlap/README.md b/spring-remoting/remoting-hessian-burlap/README.md new file mode 100644 index 000000000000..bf90c9676f75 --- /dev/null +++ b/spring-remoting/remoting-hessian-burlap/README.md @@ -0,0 +1,9 @@ +## Spring Remoting with Hessian and Burlap Tutorial + +### Relevant Articles +- [Spring Remoting with Hessian and Burlap](http://www.baeldung.com/spring-remoting-hessian-burlap) + +### Overview +This Maven project contains the Java source code for the Hessian and Burlap modules + used in the [Spring Remoting](https://github.com/eugenp/tutorials/tree/master/spring-remoting) + series of articles. From 53c06f8820b524bd168c6fc1dfd8735950b48546 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Mon, 27 Feb 2017 21:40:54 -0500 Subject: [PATCH 23/45] Update pom.xml --- guice-intro/pom.xml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index e305c706951e..0e9db13238f9 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -12,6 +12,31 @@ ${guice.version} + + + maven-compiler-plugin + + 1.8 + 1.8 + + + + default-compile + compile + + compile + + + + default-testCompile + test-compile + + testCompile + + + + + UTF-8 1.8 From 4883ae3457878a94e4f9931b15dddf2170a5a901 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Mon, 27 Feb 2017 21:44:55 -0500 Subject: [PATCH 24/45] Update pom.xml --- guice-intro/pom.xml | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index 0e9db13238f9..2d34dd4d5f6d 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -14,28 +14,13 @@ - maven-compiler-plugin - - 1.8 - 1.8 - - - - default-compile - compile - - compile - - - - default-testCompile - test-compile - - testCompile - - - - + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + UTF-8 From 9b3e96dd9c2be204512fc8a741731530ef6dc63d Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Mon, 27 Feb 2017 21:53:48 -0500 Subject: [PATCH 25/45] Update pom.xml --- guice-intro/pom.xml | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index 2d34dd4d5f6d..1f0d7679b7fb 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -13,14 +13,16 @@ - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + UTF-8 From 1f28625dbcd57d5e400c9b6ec6998745f5abf1a8 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Mon, 27 Feb 2017 22:27:56 -0600 Subject: [PATCH 26/45] BAEL-345: fixed assertion --- .../java/com/baeldung/solrjava/SolrJavaIntegrationTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apache-solrj/src/test/java/com/baeldung/solrjava/SolrJavaIntegrationTest.java b/apache-solrj/src/test/java/com/baeldung/solrjava/SolrJavaIntegrationTest.java index 7f4599a91d0c..8b5fe77c6f67 100644 --- a/apache-solrj/src/test/java/com/baeldung/solrjava/SolrJavaIntegrationTest.java +++ b/apache-solrj/src/test/java/com/baeldung/solrjava/SolrJavaIntegrationTest.java @@ -33,7 +33,7 @@ public void whenAdd_thenVerifyAddedByQueryOnId() throws SolrServerException, IOE response = solrJavaIntegration.getSolrClient().query(query); SolrDocumentList docList = response.getResults(); - assertEquals(docList.getNumFound(), 1); + assertEquals(1, docList.getNumFound()); for (SolrDocument doc : docList) { assertEquals("Kenmore Dishwasher", (String) doc.getFieldValue("name")); From 54aceaa0a7adaa3ba53cec785c3483bc112f1bcf Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Wed, 1 Mar 2017 12:01:40 -0600 Subject: [PATCH 27/45] BAEL-109: Updated README.md --- spring-data-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 4e8828a68847..f77c4dc202b1 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -15,3 +15,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: ###Relevant Articles: - [Guide to Spring Data REST Validators](http://www.baeldung.com/spring-data-rest-validators) +- [Working with Relationships in Spring Data REST](http://www.baeldung.com/spring-data-rest-relationships) From 2e6ce4b4774db4e8a36459df567053bdfae2fca3 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Wed, 1 Mar 2017 22:37:48 -0600 Subject: [PATCH 28/45] BAEL-345: Added README.md --- apache-solrj/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 apache-solrj/README.md diff --git a/apache-solrj/README.md b/apache-solrj/README.md new file mode 100644 index 000000000000..7a32becb644e --- /dev/null +++ b/apache-solrj/README.md @@ -0,0 +1,4 @@ +## Apache Solrj Tutorials Project + +### Relevant Articles +- [Guide to Solr in Java with Apache Solrj](http://www.baeldung.com/apache-solrj) From e27be0eaf191203b435f9831d23955b11e9b25fb Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Thu, 2 Mar 2017 09:16:57 -0600 Subject: [PATCH 29/45] Reinstating reactor-core module in root-level pom --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 16dc0a50d0bb..b0156a428903 100644 --- a/pom.xml +++ b/pom.xml @@ -95,6 +95,7 @@ querydsl + reactor-core redis rest-assured rest-testing From ca24d5afda9301b4c77e9ea860d7fd1a07e65fdd Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Thu, 2 Mar 2017 22:30:41 -0600 Subject: [PATCH 30/45] BAEL-393: Adding guide-intro module to root pom --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index b0156a428903..d859f529da1e 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,7 @@ guava guava18 guava19 + guice-intro disruptor handling-spring-static-resources From e2a2f5b20519272fbef21c62988a634abe65c774 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 5 Mar 2017 18:45:38 -0600 Subject: [PATCH 31/45] BAEL-9: Updated README.md --- spring-boot/README.MD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 78ef3c843cc7..9fe18aaacc73 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -10,4 +10,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [The @ServletComponentScan Annotation in Spring Boot](http://www.baeldung.com/spring-servletcomponentscan) - [A Custom Data Binder in Spring MVC](http://www.baeldung.com/spring-mvc-custom-data-binder) - [Intro to Building an Application with Spring Boot](http://www.baeldung.com/intro-to-spring-boot) -- [How to Register a Servlet in a Java Web Application](http://www.baeldung.com/how-to-register-a-servlet-in-a-java-web-application/) +- [How to Register a Servlet in a Java Web Application](http://www.baeldung.com/register-servlet) From caaf98ae7002541702fe9f708ea2ffd26697de37 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Wed, 8 Mar 2017 09:12:20 -0600 Subject: [PATCH 32/45] BAEL-157: README.md updated --- spring-data-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index f77c4dc202b1..241f2e3bcf5d 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -16,3 +16,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: ###Relevant Articles: - [Guide to Spring Data REST Validators](http://www.baeldung.com/spring-data-rest-validators) - [Working with Relationships in Spring Data REST](http://www.baeldung.com/spring-data-rest-relationships) +- [AngularJS CRUD Application with Spring Data REST](http://www.baeldung.com/angularjs-crud-with-spring-data-rest) From 7a2730750c1b11cb4a6bf97d0992428d3bbf14d0 Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 9 Mar 2017 08:26:38 -0500 Subject: [PATCH 33/45] Changed project name --- guice-intro/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml index 1f0d7679b7fb..df870217943f 100644 --- a/guice-intro/pom.xml +++ b/guice-intro/pom.xml @@ -2,7 +2,7 @@ 4.0.0 com.baeldung.examples.guice - guice-intro + guice 1.0-SNAPSHOT jar @@ -30,5 +30,5 @@ 1.8 4.1.0 - guice-intro + guice From 6d5c8bb6bca4d18b80d73f5310564d2f19e051aa Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 9 Mar 2017 08:36:09 -0500 Subject: [PATCH 34/45] Update RunGuice.java Removed references to message logging and output --- .../src/main/java/com/baeldung/examples/RunGuice.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java index b4b3e8571e5a..94ad04446e45 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java +++ b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java @@ -18,15 +18,13 @@ public static void main(String[] args) { Injector injector = Guice.createInjector(new BasicModule(), new AOPModule()); Communication comms = injector.getInstance(Communication.class); Scanner scanner = new Scanner(System.in); - System.out.println("Enter your message to be sent; press Q to quit and P to print the message log"); + System.out.println("Enter your message to be sent; press Q to quit"); while (true) { String input = scanner.nextLine(); if (input.equalsIgnoreCase("q")) { System.exit(0); } - if (input.equalsIgnoreCase("p")) { - comms.print(); - } else { + else { comms.sendMessage(input); } From 774d1268c415de092b44913c49daf8f4e92523ac Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Thu, 9 Mar 2017 08:39:26 -0500 Subject: [PATCH 35/45] Update Communication.java Removed message logging-related code --- .../examples/guice/Communication.java | 25 +------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java index c4b17b57d2b6..b1a86af29391 100644 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java +++ b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java @@ -3,9 +3,6 @@ import com.google.inject.Inject; import com.google.inject.name.Named; -import java.util.Date; -import java.util.LinkedList; -import java.util.Queue; import java.util.logging.Logger; /** @@ -14,42 +11,22 @@ */ public class Communication { - final Date start = new Date(); - @Inject private Logger logger; - private Queue messageLog; - - @Named("CommsUUID") - private String commsID; - @Inject private DefaultCommunicator communicator; public Communication(Boolean keepRecords) { if (keepRecords) { - messageLog = new LinkedList(); + System.out.println("message logging enabled"); } } public boolean sendMessage(String message) { - if (!message.isEmpty() && messageLog != null) { - messageLog.add(message); - } return communicator.sendMessage(message); } - public void print() { - if (messageLog != null) { - for (String message : messageLog) { - logger.info(message); - } - } else { - logger.info("Message logging wasn't enabled"); - } - } - public DefaultCommunicator getCommunicator() { return this.communicator; } From a3dc28331658cad3b1717b20acdfa873e505a0d7 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sat, 11 Mar 2017 18:09:30 -0600 Subject: [PATCH 36/45] BAEL-566: Updated README.md --- algorithms/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms/README.md b/algorithms/README.md index 42f696d9be14..77ef0209c0a1 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -2,3 +2,4 @@ - [Dijkstra Algorithm in Java](http://www.baeldung.com/java-dijkstra) - [Introduction to Cobertura](http://www.baeldung.com/cobertura) +- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization) From 1c582737b78c8c49eb8a511017787e2207a7073c Mon Sep 17 00:00:00 2001 From: k0l0ssus Date: Sun, 12 Mar 2017 09:48:15 -0400 Subject: [PATCH 37/45] New project name --- guice/pom.xml | 34 +++++++++++++ .../java/com/baeldung/examples/RunGuice.java | 32 ++++++++++++ .../examples/guice/Communication.java | 40 +++++++++++++++ .../examples/guice/CommunicationMode.java | 12 +++++ .../examples/guice/DefaultCommunicator.java | 51 +++++++++++++++++++ .../guice/EmailCommunicationMode.java | 24 +++++++++ .../examples/guice/IMCommunicationMode.java | 30 +++++++++++ .../examples/guice/SMSCommunicationMode.java | 30 +++++++++++ .../examples/guice/aop/MessageLogger.java | 24 +++++++++ .../guice/aop/MessageSentLoggable.java | 17 +++++++ .../examples/guice/binding/AOPModule.java | 23 +++++++++ .../examples/guice/binding/BasicModule.java | 37 ++++++++++++++ .../guice/constant/CommunicationModel.java | 17 +++++++ .../examples/guice/marker/Communicator.java | 14 +++++ .../examples/guice/modules/BasicModule.java | 38 ++++++++++++++ 15 files changed, 423 insertions(+) create mode 100644 guice/pom.xml create mode 100644 guice/src/main/java/com/baeldung/examples/RunGuice.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/Communication.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/CommunicationMode.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/marker/Communicator.java create mode 100644 guice/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java diff --git a/guice/pom.xml b/guice/pom.xml new file mode 100644 index 000000000000..df870217943f --- /dev/null +++ b/guice/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + com.baeldung.examples.guice + guice + 1.0-SNAPSHOT + jar + + + com.google.inject + guice + ${guice.version} + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + UTF-8 + 1.8 + 1.8 + 4.1.0 + + guice + diff --git a/guice/src/main/java/com/baeldung/examples/RunGuice.java b/guice/src/main/java/com/baeldung/examples/RunGuice.java new file mode 100644 index 000000000000..a07447cde8cb --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/RunGuice.java @@ -0,0 +1,32 @@ + +package com.baeldung.examples; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.binding.AOPModule; +import com.baeldung.examples.guice.modules.BasicModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import java.util.Scanner; + +/** + * + * @author baeldung + */ +public class RunGuice { + + public static void main(String[] args) { + Injector injector = Guice.createInjector(new BasicModule(), new AOPModule()); + Communication comms = injector.getInstance(Communication.class); + Scanner scanner = new Scanner(System.in); + while (true) { + String input = scanner.nextLine(); + if (input.equalsIgnoreCase("q")) { + System.exit(0); + } else { + comms.sendMessage(input); + } + + } + + } +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/Communication.java b/guice/src/main/java/com/baeldung/examples/guice/Communication.java new file mode 100644 index 000000000000..7f7cb822d86b --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/Communication.java @@ -0,0 +1,40 @@ + +package com.baeldung.examples.guice; + +import com.google.inject.Inject; +import com.google.inject.name.Named; +import java.util.Date; +import java.util.LinkedList; +import java.util.Queue; +import java.util.logging.Logger; + +/** + * + * @author baeldung + */ +public class Communication { + + final Date start = new Date(); + + @Inject + private Logger logger; + + @Inject + private DefaultCommunicator communicator; + + public Communication(Boolean keepRecords) { + if (keepRecords) { + System.out.println("keeping records"); + } + } + + public boolean sendMessage(String message) { + + return communicator.sendMessage(message); + } + + public DefaultCommunicator getCommunicator() { + return this.communicator; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/CommunicationMode.java b/guice/src/main/java/com/baeldung/examples/guice/CommunicationMode.java new file mode 100644 index 000000000000..444b77547888 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/CommunicationMode.java @@ -0,0 +1,12 @@ + +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.constant.CommunicationModel; + +public interface CommunicationMode { + + public CommunicationModel getMode(); + + public boolean sendMessage(String message); + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java b/guice/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java new file mode 100644 index 000000000000..c65644646a87 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java @@ -0,0 +1,51 @@ + +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.marker.Communicator; +import com.google.inject.Inject; +import com.google.inject.name.Named; + +/** + * + * @author baeldung + */ +public class DefaultCommunicator implements Communicator { + + private CommunicationMode defaultCommsMode; + @Inject + @Named("SMSComms") + CommunicationMode smsCommsMode; + @Inject + @Named("EmailComms") + CommunicationMode emailCommsMode; + @Inject + @Named("IMComms") + CommunicationMode imCommsMode; + + protected DefaultCommunicator(CommunicationMode defaultComms) { + this.defaultCommsMode = defaultComms; + } + + public DefaultCommunicator() { + + } + + public boolean sendMessage(String message) { + boolean sent = false; + if (defaultCommsMode != null) { + sent = sendMessageByDefault(message); + } else { + sent = smsCommsMode.sendMessage(message); + } + return sent; + } + + private boolean sendMessageByDefault(String message) { + boolean sent = false; + if (message != null && !message.trim().equals("")) { + return defaultCommsMode.sendMessage(message); + } + return sent; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java b/guice/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java new file mode 100644 index 000000000000..3caca0edccbd --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java @@ -0,0 +1,24 @@ + +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; + +/** + * + * @author baeldung + */ +public class EmailCommunicationMode implements CommunicationMode { + + @Override + public CommunicationModel getMode() { + return CommunicationModel.EMAIL; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String Message) { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java b/guice/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java new file mode 100644 index 000000000000..bc9bd6144917 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java @@ -0,0 +1,30 @@ + +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; +import com.google.inject.Inject; +import java.util.logging.Logger; + +/** + * + * @author baeldung + */ +public class IMCommunicationMode implements CommunicationMode { + + @Inject + private Logger logger; + + @Override + public CommunicationModel getMode() { + return CommunicationModel.IM; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String message) { + logger.info("IM Message Sent"); + return true; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java b/guice/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java new file mode 100644 index 000000000000..28475839dd0e --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java @@ -0,0 +1,30 @@ + +package com.baeldung.examples.guice; + +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.baeldung.examples.guice.constant.CommunicationModel; +import com.google.inject.Inject; +import java.util.logging.Logger; + +/** + * + * @author baeldung + */ +public class SMSCommunicationMode implements CommunicationMode { + + @Inject + private Logger logger; + + @Override + public CommunicationModel getMode() { + return CommunicationModel.SMS; + } + + @Override + @MessageSentLoggable + public boolean sendMessage(String message) { + logger.info("SMS message sent"); + return true; + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java b/guice/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java new file mode 100644 index 000000000000..2ad5f8b92e9e --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java @@ -0,0 +1,24 @@ + +package com.baeldung.examples.guice.aop; + +import com.google.inject.Inject; +import java.util.logging.Logger; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; + +/** + * + * @author baeldung + */ +public class MessageLogger implements MethodInterceptor { + + @Override + public Object invoke(MethodInvocation invocation) throws Throwable { + Object[] objectArray = invocation.getArguments(); + int i = 0; + for (Object object : objectArray) { + Logger.getAnonymousLogger().info("Sending message: " + object.toString()); + } + return invocation.proceed(); + } +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java b/guice/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java new file mode 100644 index 000000000000..5e5a411d0ee5 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java @@ -0,0 +1,17 @@ + +package com.baeldung.examples.guice.aop; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * + * @author baeldung + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface MessageSentLoggable { + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java b/guice/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java new file mode 100644 index 000000000000..109d9a63895e --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java @@ -0,0 +1,23 @@ + +package com.baeldung.examples.guice.binding; + +import com.baeldung.examples.guice.aop.MessageLogger; +import com.baeldung.examples.guice.aop.MessageSentLoggable; +import com.google.inject.AbstractModule; +import com.google.inject.matcher.Matchers; + +/** + * + * @author baeldung + */ +public class AOPModule extends AbstractModule { + + @Override + protected void configure() { + bindInterceptor(Matchers.any(), + Matchers.annotatedWith(MessageSentLoggable.class), + new MessageLogger() + ); + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java b/guice/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java new file mode 100644 index 000000000000..93f0fe54bab7 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java @@ -0,0 +1,37 @@ + +package com.baeldung.examples.guice.binding; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.CommunicationMode; +import com.baeldung.examples.guice.DefaultCommunicator; +import com.baeldung.examples.guice.EmailCommunicationMode; +import com.baeldung.examples.guice.IMCommunicationMode; +import com.baeldung.examples.guice.SMSCommunicationMode; +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author baeldung + */ +public class BasicModule extends AbstractModule { + + @Override + protected void configure() { + try { + bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.TYPE)); + } catch (NoSuchMethodException ex) { + Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } + bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); + + bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); + } + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java b/guice/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java new file mode 100644 index 000000000000..d12420a0db00 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java @@ -0,0 +1,17 @@ + +package com.baeldung.examples.guice.constant; + +/** + * + * @author baeldung + */ +public enum CommunicationModel { + + EMAIL("Email"), SMS("SMS"), IM("IM"), PHONE("Phone"); + + final String name; + + CommunicationModel(String name) { + this.name = name; + } +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/marker/Communicator.java b/guice/src/main/java/com/baeldung/examples/guice/marker/Communicator.java new file mode 100644 index 000000000000..7425f1c28395 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/marker/Communicator.java @@ -0,0 +1,14 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.examples.guice.marker; + +/** + * + * @author Tayo + */ +public interface Communicator { + +} diff --git a/guice/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java b/guice/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java new file mode 100644 index 000000000000..ed83cf364941 --- /dev/null +++ b/guice/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java @@ -0,0 +1,38 @@ + +package com.baeldung.examples.guice.modules; + +import com.baeldung.examples.guice.Communication; +import com.baeldung.examples.guice.CommunicationMode; +import com.baeldung.examples.guice.DefaultCommunicator; +import com.baeldung.examples.guice.EmailCommunicationMode; +import com.baeldung.examples.guice.IMCommunicationMode; +import com.baeldung.examples.guice.SMSCommunicationMode; +import com.google.inject.AbstractModule; +import com.google.inject.name.Names; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * + * @author baeldung + */ +public class BasicModule extends AbstractModule { + + @Override + protected void configure() { + try { + bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.class)); + bind(Boolean.class).toInstance(true); + } catch (NoSuchMethodException ex) { + Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } catch (SecurityException ex) { + Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); + } + bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); + + bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); + bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); + } + +} From e09ba44e473c27fcdc9a17a9f5fdff68cab1f644 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 12 Mar 2017 20:51:09 -0500 Subject: [PATCH 38/45] BAEL-393: removing guice-intro directory --- guice-intro/pom.xml | 35 -------------- .../java/com/baeldung/examples/RunGuice.java | 36 -------------- .../examples/guice/Communication.java | 35 -------------- .../examples/guice/CommunicationMode.java | 12 ----- .../examples/guice/DefaultCommunicator.java | 48 ------------------- .../guice/EmailCommunicationMode.java | 23 --------- .../examples/guice/IMCommunicationMode.java | 30 ------------ .../examples/guice/SMSCommunicationMode.java | 29 ----------- .../examples/guice/aop/MessageLogger.java | 22 --------- .../guice/aop/MessageSentLoggable.java | 16 ------- .../examples/guice/binding/AOPModule.java | 22 --------- .../examples/guice/binding/BasicModule.java | 36 -------------- .../guice/constant/CommunicationModel.java | 16 ------- .../examples/guice/marker/Communicator.java | 11 ----- .../examples/guice/modules/BasicModule.java | 37 -------------- 15 files changed, 408 deletions(-) delete mode 100644 guice-intro/pom.xml delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/RunGuice.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java delete mode 100644 guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java diff --git a/guice-intro/pom.xml b/guice-intro/pom.xml deleted file mode 100644 index d44db9707db9..000000000000 --- a/guice-intro/pom.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - 4.0.0 - com.baeldung.examples.guice - guice - - 1.0-SNAPSHOT - jar - - - com.google.inject - guice - ${guice.version} - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - - - - - UTF-8 - 1.8 - 1.8 - 4.1.0 - - guice - diff --git a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java b/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java deleted file mode 100644 index 166c4d255928..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/RunGuice.java +++ /dev/null @@ -1,36 +0,0 @@ - -package com.baeldung.examples; - -import com.baeldung.examples.guice.Communication; -import com.baeldung.examples.guice.binding.AOPModule; -import com.baeldung.examples.guice.modules.BasicModule; -import com.google.inject.Guice; -import com.google.inject.Injector; -import java.util.Scanner; - -/** - * - * @author Baeldung - */ -public class RunGuice { - - public static void main(String[] args) { - Injector injector = Guice.createInjector(new BasicModule(), new AOPModule()); - Communication comms = injector.getInstance(Communication.class); - Scanner scanner = new Scanner(System.in); - - System.out.println("Enter your message to be sent; press Q to quit"); - - while (true) { - String input = scanner.nextLine(); - if (input.equalsIgnoreCase("q")) { - System.exit(0); - } - else { - comms.sendMessage(input); - } - - } - - } -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java b/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java deleted file mode 100644 index 59f6813780a6..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/Communication.java +++ /dev/null @@ -1,35 +0,0 @@ - -package com.baeldung.examples.guice; - -import com.google.inject.Inject; -import com.google.inject.name.Named; -import java.util.logging.Logger; - -/** - * - * @author Baeldung - */ -public class Communication { - - - @Inject - private Logger logger; - - @Inject - private DefaultCommunicator communicator; - - public Communication(Boolean keepRecords) { - if (keepRecords) { - System.out.println("message logging enabled"); - } - } - - public boolean sendMessage(String message) { - return communicator.sendMessage(message); - } - - public DefaultCommunicator getCommunicator() { - return this.communicator; - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java deleted file mode 100644 index 444b77547888..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/CommunicationMode.java +++ /dev/null @@ -1,12 +0,0 @@ - -package com.baeldung.examples.guice; - -import com.baeldung.examples.guice.constant.CommunicationModel; - -public interface CommunicationMode { - - public CommunicationModel getMode(); - - public boolean sendMessage(String message); - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java deleted file mode 100644 index 423c24f7895b..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/DefaultCommunicator.java +++ /dev/null @@ -1,48 +0,0 @@ - -package com.baeldung.examples.guice; - -import com.baeldung.examples.guice.marker.Communicator; -import com.google.inject.Inject; -import com.google.inject.name.Named; - - -public class DefaultCommunicator implements Communicator { - - private CommunicationMode defaultCommsMode; - @Inject - @Named("SMSComms") - CommunicationMode smsCommsMode; - @Inject - @Named("EmailComms") - CommunicationMode emailCommsMode; - @Inject - @Named("IMComms") - CommunicationMode imCommsMode; - - protected DefaultCommunicator(CommunicationMode defaultComms) { - this.defaultCommsMode = defaultComms; - } - - public DefaultCommunicator() { - - } - - public boolean sendMessage(String message) { - boolean sent = false; - if (defaultCommsMode != null) { - sent = sendMessageByDefault(message); - } else { - sent = smsCommsMode.sendMessage(message); - } - return sent; - } - - private boolean sendMessageByDefault(String message) { - boolean sent = false; - if (message != null && !message.trim().equals("")) { - return defaultCommsMode.sendMessage(message); - } - return sent; - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java deleted file mode 100644 index 642ee7ace062..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/EmailCommunicationMode.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.examples.guice; - -import com.baeldung.examples.guice.aop.MessageSentLoggable; -import com.baeldung.examples.guice.constant.CommunicationModel; - -/** - * - * @author Baekdung - */ -public class EmailCommunicationMode implements CommunicationMode { - - @Override - public CommunicationModel getMode() { - return CommunicationModel.EMAIL; - } - - @Override - @MessageSentLoggable - public boolean sendMessage(String Message) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java deleted file mode 100644 index 9f34e9a241ce..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/IMCommunicationMode.java +++ /dev/null @@ -1,30 +0,0 @@ - -package com.baeldung.examples.guice; - -import com.baeldung.examples.guice.aop.MessageSentLoggable; -import com.baeldung.examples.guice.constant.CommunicationModel; -import com.google.inject.Inject; -import java.util.logging.Logger; - -/** - * - * @author Baeldung - */ -public class IMCommunicationMode implements CommunicationMode { - - @Inject - private Logger logger; - - @Override - public CommunicationModel getMode() { - return CommunicationModel.IM; - } - - @Override - @MessageSentLoggable - public boolean sendMessage(String message) { - logger.info("IM Message Sent"); - return true; - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java b/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java deleted file mode 100644 index 251e2499713c..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/SMSCommunicationMode.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.examples.guice; - -import com.baeldung.examples.guice.aop.MessageSentLoggable; -import com.baeldung.examples.guice.constant.CommunicationModel; -import com.google.inject.Inject; -import java.util.logging.Logger; - -/** - * - * @author Baeldung - */ -public class SMSCommunicationMode implements CommunicationMode { - - @Inject - private Logger logger; - - @Override - public CommunicationModel getMode() { - return CommunicationModel.SMS; - } - - @Override - @MessageSentLoggable - public boolean sendMessage(String message) { - logger.info("SMS message sent"); - return true; - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java deleted file mode 100644 index 8926dfa7143e..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageLogger.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.examples.guice.aop; - -import java.util.logging.Logger; -import org.aopalliance.intercept.MethodInterceptor; -import org.aopalliance.intercept.MethodInvocation; - -/** - * - * @author Baeldung - */ -public class MessageLogger implements MethodInterceptor { - - @Override - public Object invoke(MethodInvocation invocation) throws Throwable { - Object[] objectArray = invocation.getArguments(); - int i = 0; - for (Object object : objectArray) { - Logger.getAnonymousLogger().info("Sending message: " + object.toString()); - } - return invocation.proceed(); - } -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java b/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java deleted file mode 100644 index cacf3bde7cdf..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/aop/MessageSentLoggable.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.examples.guice.aop; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * @author Baeldung - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface MessageSentLoggable { - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java deleted file mode 100644 index dc9d258efa0f..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/AOPModule.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.examples.guice.binding; - -import com.baeldung.examples.guice.aop.MessageLogger; -import com.baeldung.examples.guice.aop.MessageSentLoggable; -import com.google.inject.AbstractModule; -import com.google.inject.matcher.Matchers; - -/** - * - * @author Baeldung - */ -public class AOPModule extends AbstractModule { - - @Override - protected void configure() { - bindInterceptor(Matchers.any(), - Matchers.annotatedWith(MessageSentLoggable.class), - new MessageLogger() - ); - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java deleted file mode 100644 index 916819513060..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/binding/BasicModule.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.examples.guice.binding; - -import com.baeldung.examples.guice.Communication; -import com.baeldung.examples.guice.CommunicationMode; -import com.baeldung.examples.guice.DefaultCommunicator; -import com.baeldung.examples.guice.EmailCommunicationMode; -import com.baeldung.examples.guice.IMCommunicationMode; -import com.baeldung.examples.guice.SMSCommunicationMode; -import com.google.inject.AbstractModule; -import com.google.inject.name.Names; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Baeldung - */ -public class BasicModule extends AbstractModule { - - @Override - protected void configure() { - try { - bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.TYPE)); - } catch (NoSuchMethodException ex) { - Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); - } catch (SecurityException ex) { - Logger.getLogger(BasicModule.class.getName()).log(Level.SEVERE, null, ex); - } - bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); - - bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); - } - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java b/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java deleted file mode 100644 index b9fa604a32d1..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/constant/CommunicationModel.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.examples.guice.constant; - -/** - * - * @author Baeldung - */ -public enum CommunicationModel { - - EMAIL("Email"), SMS("SMS"), IM("IM"), PHONE("Phone"); - - final String name; - - CommunicationModel(String name) { - this.name = name; - } -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java b/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java deleted file mode 100644 index 239666b6ab16..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/marker/Communicator.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.examples.guice.marker; - -/** - * - * @author Baeldung - */ -public interface Communicator { - - public boolean sendMessage(String message); - -} diff --git a/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java b/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java deleted file mode 100644 index 47b3e2e57313..000000000000 --- a/guice-intro/src/main/java/com/baeldung/examples/guice/modules/BasicModule.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.examples.guice.modules; - -import com.baeldung.examples.guice.Communication; -import com.baeldung.examples.guice.CommunicationMode; -import com.baeldung.examples.guice.DefaultCommunicator; -import com.baeldung.examples.guice.EmailCommunicationMode; -import com.baeldung.examples.guice.IMCommunicationMode; -import com.baeldung.examples.guice.SMSCommunicationMode; -import com.google.inject.AbstractModule; -import com.google.inject.name.Names; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author Baeldung - */ -public class BasicModule extends AbstractModule { - - @Override - protected void configure() { - try { - bind(Communication.class).toConstructor(Communication.class.getConstructor(Boolean.class)); - bind(Boolean.class).toInstance(true); - } catch (NoSuchMethodException ex) { - Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); - } catch (SecurityException ex) { - Logger.getLogger(com.baeldung.examples.guice.binding.BasicModule.class.getName()).log(Level.SEVERE, null, ex); - } - bind(DefaultCommunicator.class).annotatedWith(Names.named("AnotherCommunicator")).to(DefaultCommunicator.class).asEagerSingleton(); - - bind(CommunicationMode.class).annotatedWith(Names.named("IMComms")).to(IMCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("EmailComms")).to(EmailCommunicationMode.class); - bind(CommunicationMode.class).annotatedWith(Names.named("SMSComms")).to(SMSCommunicationMode.class); - } - -} From 5fae580bc447ace9a52e83c43b37d438d373a45e Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 12 Mar 2017 21:04:16 -0500 Subject: [PATCH 39/45] BAEL-393: renamed module guice-intro to guice in root pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index ee7e75d3cfab..c12562551f6f 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ guava guava18 guava19 - guice-intro + guice disruptor handling-spring-static-resources From 3f605bd33a494d29921989a2dd7524266fd025cc Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Tue, 14 Mar 2017 22:56:58 -0500 Subject: [PATCH 40/45] BAEL-393 and BAEL-541 README.md files --- guice/README.md | 4 ++++ spring-security-mvc-boot/README.MD | 1 + 2 files changed, 5 insertions(+) create mode 100644 guice/README.md diff --git a/guice/README.md b/guice/README.md new file mode 100644 index 000000000000..d1bd1ff8833c --- /dev/null +++ b/guice/README.md @@ -0,0 +1,4 @@ +## Google Guice Tutorials Project + +### Relevant Articles +- [Guide to Google Guice](http://www.baeldung.com/guice) diff --git a/spring-security-mvc-boot/README.MD b/spring-security-mvc-boot/README.MD index 3e789dedadee..70b0f23cbbc1 100644 --- a/spring-security-mvc-boot/README.MD +++ b/spring-security-mvc-boot/README.MD @@ -6,3 +6,4 @@ The "REST With Spring" Classes: http://github.learnspringsecurity.com - [Custom AccessDecisionVoters in Spring Security](http://www.baeldung.com/spring-security-custom-voter) - [Spring Security: Authentication with a Database-backed UserDetailsService](http://www.baeldung.com/spring-security-authentication-with-a-database) - [Two Login Pages with Spring Security](http://www.baeldung.com/spring-security-two-login-pages) +- [Multiple Entry Points in Spring Security](http://www.baeldung.com/spring-security-multiple-entry-points) From 91d8ef0a3faddccb3ecd730eddffbf51236874f8 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Sun, 19 Mar 2017 13:28:12 -0500 Subject: [PATCH 41/45] BAEL-731: Updated README.md --- spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index d70e83525b9e..8aa5957bad9c 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -14,4 +14,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [How to Register a Servlet in a Java Web Application](http://www.baeldung.com/register-servlet) - [Guide to Spring WebUtils and ServletRequestUtils](http://www.baeldung.com/spring-webutils-servletrequestutils) - [Using Custom Banners in Spring Boot](http://www.baeldung.com/spring-boot-custom-banners) +- [Guide to Internationalization in Spring Boot](http://www.baeldung.com/spring-boot-internationalization) From 9d49637fda5f4f1476d8d88c964efb1bbef4e625 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Tue, 21 Mar 2017 13:21:56 -0500 Subject: [PATCH 42/45] BAEL-680: renamed test methods --- .../java8/comparator/Java8ComparatorTest.java | 60 ++++--------------- 1 file changed, 12 insertions(+), 48 deletions(-) diff --git a/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java b/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java index 5c338101d83b..57e389827459 100644 --- a/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java +++ b/core-java/src/test/java/com/baeldung/java8/comparator/Java8ComparatorTest.java @@ -60,7 +60,7 @@ public void initData() { } @Test - public void givenEmployeeArray_whenUsingComparing_thenCheckingSort() { + public void whenComparing_thenSortedByName() { Comparator employeeNameComparator = Comparator.comparing(Employee::getName); Arrays.sort(employees, employeeNameComparator); // System.out.println(Arrays.toString(employees)); @@ -68,7 +68,7 @@ public void givenEmployeeArray_whenUsingComparing_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingComparingWithComparator_thenCheckingSort() { + public void whenComparingWithComparator_thenSortedByNameDesc() { Comparator employeeNameComparator = Comparator.comparing(Employee::getName, (s1, s2) -> { return s2.compareTo(s1); }); @@ -78,7 +78,7 @@ public void givenEmployeeArray_whenUsingComparingWithComparator_thenCheckingSort } @Test - public void givenEmployeeArray_whenUsingComparingInt_thenCheckingSort() { + public void whenComparingInt_thenSortedByAge() { Comparator employeeAgeComparator = Comparator.comparingInt(Employee::getAge); Arrays.sort(employees, employeeAgeComparator); // System.out.println(Arrays.toString(employees)); @@ -86,7 +86,7 @@ public void givenEmployeeArray_whenUsingComparingInt_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingComparingLong_thenCheckingSort() { + public void whenComparingLong_thenSortedByMobile() { Comparator employeeMobileComparator = Comparator.comparingLong(Employee::getMobile); Arrays.sort(employees, employeeMobileComparator); // System.out.println(Arrays.toString(employees)); @@ -94,7 +94,7 @@ public void givenEmployeeArray_whenUsingComparingLong_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingComparingDouble_thenCheckingSort() { + public void whenComparingDouble_thenSortedBySalary() { Comparator employeeSalaryComparator = Comparator.comparingDouble(Employee::getSalary); Arrays.sort(employees, employeeSalaryComparator); // System.out.println(Arrays.toString(employees)); @@ -102,7 +102,7 @@ public void givenEmployeeArray_whenUsingComparingDouble_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingNaturalOrder_thenCheckingSort() { + public void whenNaturalOrder_thenSortedByName() { Comparator employeeNameComparator = Comparator. naturalOrder(); Arrays.sort(employees, employeeNameComparator); // System.out.println(Arrays.toString(employees)); @@ -110,7 +110,7 @@ public void givenEmployeeArray_whenUsingNaturalOrder_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingReverseOrder_thenCheckingSort() { + public void whenReverseOrder_thenSortedByNameDesc() { Comparator employeeNameComparator = Comparator. reverseOrder(); Arrays.sort(employees, employeeNameComparator); // System.out.println(Arrays.toString(employees)); @@ -118,7 +118,7 @@ public void givenEmployeeArray_whenUsingReverseOrder_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingNullFirst_thenCheckingSort() { + public void whenNullsFirst_thenSortedByNameWithNullsFirst() { Comparator employeeNameComparator = Comparator.comparing(Employee::getName); Comparator employeeNameComparator_nullFirst = Comparator.nullsFirst(employeeNameComparator); Arrays.sort(employeesArrayWithNulls, employeeNameComparator_nullFirst); @@ -127,7 +127,7 @@ public void givenEmployeeArray_whenUsingNullFirst_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingNullLast_thenCheckingSort() { + public void whenNullsLast_thenSortedByNameWithNullsLast() { Comparator employeeNameComparator = Comparator.comparing(Employee::getName); Comparator employeeNameComparator_nullLast = Comparator.nullsLast(employeeNameComparator); Arrays.sort(employeesArrayWithNulls, employeeNameComparator_nullLast); @@ -136,7 +136,7 @@ public void givenEmployeeArray_whenUsingNullLast_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingThenComparing_thenCheckingSort() { + public void whenThenComparing_thenSortedByAgeName() { Comparator employee_Age_Name_Comparator = Comparator.comparing(Employee::getAge).thenComparing(Employee::getName); Arrays.sort(someMoreEmployees, employee_Age_Name_Comparator); @@ -145,7 +145,7 @@ public void givenEmployeeArray_whenUsingThenComparing_thenCheckingSort() { } @Test - public void givenEmployeeArray_whenUsingThenComparingInt_thenCheckingSort() { + public void whenThenComparing_thenSortedByNameAge() { Comparator employee_Name_Age_Comparator = Comparator.comparing(Employee::getName).thenComparingInt(Employee::getAge); Arrays.sort(someMoreEmployees, employee_Name_Age_Comparator); @@ -153,40 +153,4 @@ public void givenEmployeeArray_whenUsingThenComparingInt_thenCheckingSort() { assertTrue(Arrays.equals(someMoreEmployees, sortedEmployeesByNameAge)); } - @Before - public void printData() { -// System.out.println("employees"); -// System.out.println(Arrays.toString(employees)); - // -// System.out.println("employeesArrayWithNulls"); -// System.out.println(Arrays.toString(employeesArrayWithNulls)); - // - // System.out.println("sortedEmployeesByName"); - // System.out.println(Arrays.toString(sortedEmployeesByName)); - // - // System.out.println("sortedEmployeesByNameDesc"); - // System.out.println(Arrays.toString(sortedEmployeesByNameDesc)); - // - // System.out.println("sortedEmployeesByAge"); - // System.out.println(Arrays.toString(sortedEmployeesByAge)); - // - // System.out.println("sortedEmployeesByMobile"); - // System.out.println(Arrays.toString(sortedEmployeesByMobile)); - // - // System.out.println("sortedEmployeesBySalary"); - // System.out.println(Arrays.toString(sortedEmployeesBySalary)); - // - // System.out.println("sortedEmployeesArray_WithNullsFirst"); - // System.out.println(Arrays.toString(sortedEmployeesArray_WithNullsFirst)); - // - // System.out.println("sortedEmployeesArray_WithNullsLast"); - // System.out.println(Arrays.toString(sortedEmployeesArray_WithNullsLast)); - // - // System.out.println("sortedEmployeesByNameAge"); - // System.out.println(Arrays.toString(sortedEmployeesByNameAge)); - // -// System.out.println("someMoreEmployees"); -// System.out.println(Arrays.toString(someMoreEmployees)); - // - } -} +} \ No newline at end of file From 9a4dd212af80380e1020297c738bb430c1acdaec Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Wed, 22 Mar 2017 15:20:53 -0500 Subject: [PATCH 43/45] BAEL-714: Updated README.md --- spring-mvc-forms/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-forms/README.md b/spring-mvc-forms/README.md index 745851a102e6..86abd7e4c120 100644 --- a/spring-mvc-forms/README.md +++ b/spring-mvc-forms/README.md @@ -3,3 +3,4 @@ ### Relevant Articles - [MaxUploadSizeExceededException in Spring](http://www.baeldung.com/spring-maxuploadsizeexceeded) - [Getting Started with Forms in Spring MVC](http://www.baeldung.com/spring-mvc-form-tutorial) +- [Form Validation with AngularJS and Spring MVC](http://www.baeldung.com/validation-angularjs-spring-mvc) From 05dac22d2e6bd3b04bbcf9dce404b2fd609da211 Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Mon, 27 Mar 2017 08:15:37 -0500 Subject: [PATCH 44/45] BAEL-737: Updated README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index 313865e3f8f8..70f4404f9800 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -13,6 +13,7 @@ - [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache) - [Spring, Hibernate and a JNDI Datasource](http://www.baeldung.com/spring-persistence-jpa-jndi-datasource) - [Deleting Objects with Hibernate](http://www.baeldung.com/delete-with-hibernate) +- [Self-Contained Testing Using an In-Memory Database](http://www.baeldung.com/spring-jpa-test-in-memory-database) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From 8b2e3cf40749a2912d108f35d0993fb64923cb5e Mon Sep 17 00:00:00 2001 From: Kevin Gilmore Date: Thu, 30 Mar 2017 08:14:39 -0500 Subject: [PATCH 45/45] BAEL-680 and BAEL-756 README.md updates --- core-java/README.md | 1 + kotlin/README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/core-java/README.md b/core-java/README.md index 63e3748ec63f..0861ee7c5e65 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -84,4 +84,5 @@ - [Guide to java.util.concurrent.Locks](http://www.baeldung.com/java-concurrent-locks) - [Java Primitive Conversions](http://www.baeldung.com/java-primitive-conversions) - [Java Money and the Currency API](http://www.baeldung.com/java-money-and-currency) +- [Guide to Java 8 Comparator.comparing()](http://www.baeldung.com/java-8-comparator-comparing) diff --git a/kotlin/README.md b/kotlin/README.md index ceebde457333..309aafa4b6f1 100644 --- a/kotlin/README.md +++ b/kotlin/README.md @@ -2,3 +2,4 @@ - [Introduction to the Kotlin Language](http://www.baeldung.com/kotlin) - [A guide to the “when{}” block in Kotlin](http://www.baeldung.com/kotlin-when) +- [Comprehensive Guide to Null Safety in Kotlin](http://www.baeldung.com/kotlin-null-safety)