Commit 29fa3dfc authored by Harshitha Sai Muppala's avatar Harshitha Sai Muppala

added the logs

parent e9dfb3c3
...@@ -7,5 +7,6 @@ ...@@ -7,5 +7,6 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="slf4j-api-2.0.7" level="project" />
</component> </component>
</module> </module>
\ No newline at end of file
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class FunctionalInterfaceExample { public class FunctionalInterfaceExample {
private static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
public static void main(String[] args) { public static void main(String[] args) {
List<Person> people = new ArrayList<>(); List<Person> people = new ArrayList<>();
people.add(new Person("harshitha",1)); people.add(new Person("harshitha",1));
...@@ -15,7 +23,7 @@ public class FunctionalInterfaceExample { ...@@ -15,7 +23,7 @@ public class FunctionalInterfaceExample {
return person1.getAge() - person2.getAge(); return person1.getAge() - person2.getAge();
}); });
for(Person person: people){ for(Person person: people){
System.out.println(person.getName()+ " " +person.getAge()); logger.info(person.getName()+ " " +person.getAge());
} }
} }
......
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public interface FunctionalTest { public interface FunctionalTest {
static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
void abstractTest(int x); void abstractTest(int x);
default void Message(){ default void Message(){
System.out.println("hello"); logger.info("hello");
} }
} }
......
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class PredicateExample { public class PredicateExample {
private static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
public static void main(String[] args) { public static void main(String[] args) {
Display i = () -> System.out.println("This is predicate example"); Display i = () -> System.out.println("This is predicate example");
i.hello(); i.hello();
SumOfTwoIntegers s = (a, b) -> (a+b); SumOfTwoIntegers s = (a, b) -> String.valueOf((a+b));
System.out.println(s.sum(5,6)); logger.info(s.sum(5,6));
System.out.println(s.sum(7,7)); logger.info(s.sum(7,7));
} }
} }
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.*; import java.util.*;
...@@ -8,6 +11,8 @@ import java.util.function.Predicate; ...@@ -8,6 +11,8 @@ import java.util.function.Predicate;
public class PredicateExample1 { public class PredicateExample1 {
private static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
public static void main(String[] args) { public static void main(String[] args) {
List<User> users = new ArrayList<User>(); List<User> users = new ArrayList<User>();
users.add(new User("dev","Harshitha")); users.add(new User("dev","Harshitha"));
...@@ -15,7 +20,7 @@ public class PredicateExample1 { ...@@ -15,7 +20,7 @@ public class PredicateExample1 {
users.add(new User("QA","Anusha")); users.add(new User("QA","Anusha"));
List devs = process(users,(User u)->u.getRole().equals("dev")); List devs = process(users,(User u)->u.getRole().equals("dev"));
System.out.println(devs); logger.info(devs.toString());
} }
......
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Predicate; import java.util.function.Predicate;
public class PredicateStringComparing { public class PredicateStringComparing {
private static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
public static void main(String[] args) { public static void main(String[] args) {
String s1="hello"; String s1="hello";
String s2="hello"; String s2="hello";
Predicate<String> p = s->s.equals(s2); Predicate<String> p = s->s.equals(s2);
if(p.test(s1)){ if(p.test(s1)){
System.out.println("equal"); logger.info("equal");
} }
else{ else{
System.out.println("not equal"); logger.info("not equal");
} }
} }
......
...@@ -3,5 +3,5 @@ package Lambda; ...@@ -3,5 +3,5 @@ package Lambda;
public interface SumOfTwoIntegers public interface SumOfTwoIntegers
{ {
public abstract int sum(int a,int b); public abstract String sum(int a, int b);
} }
package Lambda; package Lambda;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Supplier; import java.util.function.Supplier;
public class SupplierExample { public class SupplierExample {
public static void main(String[] args) {
private static final Logger logger = LoggerFactory.getLogger(FunctionalInterfaceExample.class);
public static void main(String[] args) {
//example of supplier //example of supplier
Supplier<String> supplier = () -> { Supplier<String> supplier = () -> {
System.out.println("inside the supplier"); logger.info("inside the supplier");
return "hello"; return "hello";
}; };
String string = supplier.get(); String string = supplier.get();
System.out.println(string); logger.info(string);
//example of consumer //example of consumer
Consumer<String> consumer = (String s) -> { Consumer<String> consumer = (String s) -> {
System.out.println("Inside the consumer"); logger.info("Inside the consumer");
System.out.println(s); logger.info(s);
}; };
consumer.accept("hello"); consumer.accept("hello");
Supplier<String> supplier1 = () -> { Supplier<String> supplier1 = () -> {
System.out.println("Supplier"); logger.info("Supplier");
return "hello"; return "hello";
}; };
String s = supplier1.get(); String s = supplier1.get();
System.out.println(s); logger.info(s);
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment