go to eclipse-> preferences->Java -> Editor->Save Actions and give the below checkbox options as looks in picture below.
also do the advanced level setting by clicking configure button
package com.johnjustin; public class AttendExam { public void writeTest(final String ExamName, final String subject) { System.out.printf("writeTest : %s, %s%n", ExamName, subject); } }
package com.johnjustin; public class Student { private AttendExam attendExam = new AttendExam(); public void writeTest(){ attendExam.writeTest("Engineering", "Mathematics"); } }This is the simplest way to fulfill the requirement but we know that this has some limitations
package com.johnjustin; public interface AssessmentService { void writeTest(String subject, String testName); }
package com.johnjustin; /** * @author John Justin * */ public class WrittenExamService implements AssessmentService{ public void writeTest(final String ExamName, final String subject) { System.out.printf("Written Exam for : %s, %s%n", ExamName, subject); } }
package com.johnjustin; /** * @author John Justin * */ public class OnlineExamService implements AssessmentService{ public void writeTest(final String ExamName, final String subject) { System.out.printf("Online Exam for : %s, %s%n", ExamName, subject); } }Use interfaces to reduce loosely couple the classes. We have to use this AssessmentService in our Student class and implement required type of assessment(Online/Written) according to the need.This is a key element in the design. It improves modularity, extendibility.
package com.johnjustin; import com.johnjustin.AssessmentService; import com.google.inject.Inject; /** * @author John Justin * */ public class Student { private final AssessmentService assessmentService; @Inject private Student(AssessmentService assessmentService){ this.assessmentService = assessmentService; } public void attendExam() { assessmentService.writeTest("Engineering", "Mathematics"); } }The Student class is not dependent on any implementation, but on a service defined by an interface. This means that we can use the Student class without having to worry about the underlying implementation of the assessment service. Furthermore, different Student instances can be instantiated using different assessment services.
AbstractModule
class) as illustrated below. package com.johnjustin; import com.google.inject.AbstractModule; /** * @author John Justin * */ public class ProjectModule extends AbstractModule { @Override protected void configure() { bind(AssessmentService.class).to(OnlineExamService.class); } }
package com.johnjustin; import com.johnjustin.AssessmentService; import com.google.inject.Inject; /** * @author John Justin * */ public class Student { private final AssessmentService assessmentService; @Inject private Student(AssessmentService assessmentService){ this.assessmentService = assessmentService; } public void attendExam() { assessmentService.writeTest("Engineering", "Mathematics"); } }Now we can create the main class and create its injection in it.
package com.johnjustin; import com.google.inject.Guice; import com.google.inject.Injector; /** * @author John Justin * */ public class Main { public static void main(final String[] args) { final Injector injector = Guice.createInjector(new ProjectModule()); final Student student = injector.getInstance(Student.class); student.attendExam(); } }
ProjectModule
class to map the AssessmentService class to the WrittenExamService class as highlighted below.This one change will affect all classes initialised with the dependency injection framework without having to change any of these classes.package com.johnjustin; import com.google.inject.AbstractModule; /** * @author John Justin * */ public class ProjectModule extends AbstractModule { @Override protected void configure() { bind(AssessmentService.class).to(WrittenExamService.class); } }The whole example is easily clonable or download from GitHub repository.Enjoy !!!!!
public class Test { public static void main(String[] args) { HashSet<Object> testSet= new HashSet<Object>(); testSet.add(100); testSet.add("hello"); System.out.println("Result "+testSet); } }
public class Test { public static void main(String[] args) { HashSet<Object> testSet= new HashSet<Object>(); testSet.add(100); testSet.add("hello");
testSet.add(100);testSet.add("hello");System.out.println("Result "+testSet); } }
enrich
assumes you want to use an incoming Exchange as a parameter to an another service request. for example, your incoming Exchange could be a userID, but you really need the entire User object, so you could enrich
it by passing the userID to a REST service that returns the User object which becomes the Exchange, etc.pollEnrich
assumes the incoming Exchange is a simple trigger that tell a PollingConsumer to look for data and create an Exchange (ignoring the contents of the incoming Exchange). For example, you could have a timer or other business process event that requires picking up a file for processing, etc. that said, the incoming Exchange data is NOT used to dynamically configure the PollingConsumer...only the URI is used for this.