Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

done #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/Lambdas2-ZCW.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__junit_junit_4_13_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>groupId</groupId>
<artifactId>Lambdas2-ZCW</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
3 changes: 3 additions & 0 deletions src/main/java/CheckPerson.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface CheckPerson {
boolean test(Person p);
}
59 changes: 59 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import com.sun.jndi.toolkit.dir.SearchFilter;
import com.sun.tools.javac.comp.Check;
import sun.nio.ch.Net;

import javax.naming.directory.SearchControls;
import java.util.ArrayList;
import java.util.List;

public class Main {

public static void printPersons(List<Person> roster, CheckPerson filter) {
for (Person p : roster) {
if (filter.test(p)) {
p.printPerson();
}
}
}

public static void main(String[] args) {

Person p1 = new Person("Bobby", 21, Person.Sex.MALE,"hotmail");
Person p2 = new Person("Ana",25, Person.Sex.FEMALE,"Yahoo");
Person p3 = new Person("Jack",30, Person.Sex.MALE,"Google");
Person[] people = {p1,p2,p3};

Network network = new Network();
network.addArray(people);

//--------------------------LOCAL CLASS-------------------------------
//Creating local class
class Under30 implements CheckPerson{
@Override
public boolean test(Person p) {
return p.getAge() < 30;
}
}
//Testing using local class
System.out.println("===========================LOCAL=========================");
printPersons(network.getList(),new Under30());

//--------------------------ANONYMOUS CLASS---------------------------
//Creating anonymous class
CheckPerson maleUnder30 = new CheckPerson() {
@Override
public boolean test(Person p) {
return p.getGender() == Person.Sex.MALE && p.getAge() < 30;
}
};
//Testing using anonymous class
System.out.println("=========================ANONYMOUS========================");
printPersons(network.getList(), maleUnder30);

//--------------------------LAMBDA EXPRESSION------------------------
//Testing using lambda expression for female under 30
System.out.println("===========================LAMBDA=========================");
printPersons(network.getList(), person ->
person.getGender()== Person.Sex.FEMALE && person.getAge() < 30);
}
}
30 changes: 30 additions & 0 deletions src/main/java/Network.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.ArrayList;
import java.util.List;

public class Network {
private List<Person> list;

public Network() {
this.list = new ArrayList<>();
}

public void add(Person person){
this.list.add(person);
}

public List<Person> getList() {
return list;
}

public void setList(List<Person> list) {
this.list = list;
}

public void addArray(Person[] people){
for (int i = 0; i < people.length; i++) {
this.list.add(people[i]);
}
}


}
Loading