diff --git a/.idea/$PRODUCT_WORKSPACE_FILE$ b/.idea/$PRODUCT_WORKSPACE_FILE$ new file mode 100644 index 0000000..79be354 --- /dev/null +++ b/.idea/$PRODUCT_WORKSPACE_FILE$ @@ -0,0 +1,19 @@ + + + + + + + 11 + + + + + + + + \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..5c98b42 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml \ No newline at end of file diff --git a/.idea/Lambdas2-ZCW.iml b/.idea/Lambdas2-ZCW.iml new file mode 100644 index 0000000..7997eab --- /dev/null +++ b/.idea/Lambdas2-ZCW.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..bd60617 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__com_github_stefanbirkner_system_rules_1_19_0.xml b/.idea/libraries/Maven__com_github_stefanbirkner_system_rules_1_19_0.xml new file mode 100644 index 0000000..638bae2 --- /dev/null +++ b/.idea/libraries/Maven__com_github_stefanbirkner_system_rules_1_19_0.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_9.xml b/.idea/libraries/Maven__junit_junit_4_9.xml new file mode 100644 index 0000000..c42d5ab --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_9.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml new file mode 100644 index 0000000..acdf443 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_1.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..083dfca --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..b8d5b83 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/lambdas2zcw/lambdas2zcw.iml b/lambdas2zcw/lambdas2zcw.iml new file mode 100644 index 0000000..8cc58e2 --- /dev/null +++ b/lambdas2zcw/lambdas2zcw.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/lambdas2zcw/pom.xml b/lambdas2zcw/pom.xml new file mode 100644 index 0000000..839351c --- /dev/null +++ b/lambdas2zcw/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + com.zipcodewilmington + lambdas2zcw + 1.0-SNAPSHOT + + + junit + junit + 4.9 + test + + + com.github.stefanbirkner + system-rules + 1.19.0 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + + + + + + \ No newline at end of file diff --git a/lambdas2zcw/src/main/java/CheckPerson.java b/lambdas2zcw/src/main/java/CheckPerson.java new file mode 100644 index 0000000..5365dc6 --- /dev/null +++ b/lambdas2zcw/src/main/java/CheckPerson.java @@ -0,0 +1,4 @@ +public interface CheckPerson { + + Boolean test(Person person); +} diff --git a/lambdas2zcw/src/main/java/Main.java b/lambdas2zcw/src/main/java/Main.java new file mode 100644 index 0000000..1356cba --- /dev/null +++ b/lambdas2zcw/src/main/java/Main.java @@ -0,0 +1,46 @@ +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; + +public class Main { + + public static void printPeople(List roster, CheckPerson tester) { + for (Person p : roster) { + if (tester.test(p)) { + p.printPerson(); + } + } + } + + public static void main(String[] args) { + Person aswomeSister, secondBestSister, thirdBestSister, olderSister; + ArrayList myFamily = new ArrayList<>(); + + aswomeSister = new Person("Charlotte Beale", LocalDate.of(1982, java.time.Month.AUGUST, 20), Person.Sex.FEMALE, "cbeale2000@gmail.com"); + secondBestSister = new Person("Ruth Beale", LocalDate.of(1980, java.time.Month.MARCH, 07), Person.Sex.FEMALE, "rbeale@gmail.com"); + thirdBestSister = new Person("Kesha Beale", LocalDate.of(1978, java.time.Month.AUGUST, 17), Person.Sex.FEMALE, "kbeale@gmail.com"); + olderSister = new Person("Kathleen Beale", LocalDate.of(1976, java.time.Month.FEBRUARY, 23), Person.Sex.FEMALE, "kbeale@hotmail.com"); + myFamily.add(aswomeSister); + myFamily.add(secondBestSister); + myFamily.add(thirdBestSister); + myFamily.add(olderSister); + + + class checkForOver18 implements CheckPerson { + + @Override + public Boolean test(Person person) { + return person.getAge() >= 18; + } + } + printPeople(myFamily, new checkForOver18()); + + printPeople(myFamily, new CheckPerson() { + @Override + public Boolean test(Person person) { + return person.getAge() >= 18; + } + }); + printPeople(myFamily, person -> person.getAge() >= 45); + } +} diff --git a/lambdas2zcw/src/main/java/Person.java b/lambdas2zcw/src/main/java/Person.java new file mode 100644 index 0000000..9500beb --- /dev/null +++ b/lambdas2zcw/src/main/java/Person.java @@ -0,0 +1,63 @@ +import java.time.LocalDate; +import java.time.Period; +import java.util.ArrayList; + +public class Person { + String name; + LocalDate birthday; + Sex gender; + String emailAddress; + ArrayList personList = new java.util.ArrayList<>(); + + + public Person(String name, LocalDate birthday, Sex gender, String emailAddress) { + this.name = name; + this.birthday = birthday; + this.gender = gender; + this.emailAddress = emailAddress; + } + + public enum Sex { + MALE, FEMALE + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public LocalDate getBirthday() { + return birthday; + } + + public void setBirthday(LocalDate birthday) { + this.birthday = birthday; + } + + public Person.Sex getGender() { + return gender; + } + + public void setGender(Sex gender) { + this.gender = gender; + } + + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + public int getAge() { + return Period.between(birthday, LocalDate.now()).getYears(); + } + + public void printPerson() { + System.out.println(String.format("{ Name: %s, Birthday: %s, Gender: %s, EmailAddress: %s}\n", name, birthday, gender, emailAddress)); + } +} diff --git a/lambdas2zcw/src/test/java/PersonTest.java b/lambdas2zcw/src/test/java/PersonTest.java new file mode 100644 index 0000000..13d05a4 --- /dev/null +++ b/lambdas2zcw/src/test/java/PersonTest.java @@ -0,0 +1,48 @@ +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.After; +import org.junit.Test; +import org.junit.Assert; +import org.junit.contrib.java.lang.system.SystemOutRule; +import java.rmi.server.RemoteServer; +import org.junit.Rule; + +public class PersonTest { + Person aswomeSister, secondBestSister, thirdBestSister, olderSister; + java.util.ArrayList myFamily = new java.util.ArrayList<>(); + + @Before + public void setUp() throws Exception { + aswomeSister = new Person("Charlotte Beale", java.time.LocalDate.of(1982, java.time.Month.AUGUST, 20), Person.Sex.FEMALE, "cbeale2000@gmail.com"); + secondBestSister = new Person("Ruth Beale", java.time.LocalDate.of(1980, java.time.Month.MARCH, 07), Person.Sex.FEMALE, "rbeale@gmail.com"); + thirdBestSister = new Person("Kesha Beale", java.time.LocalDate.of(1978, java.time.Month.AUGUST, 17), Person.Sex.FEMALE, "kbeale@gmail.com"); + olderSister = new Person("Kathleen Beale", java.time.LocalDate.of(1976, java.time.Month.FEBRUARY, 23), Person.Sex.FEMALE, "kbeale@hotmail.com"); + myFamily.add(aswomeSister); + myFamily.add(secondBestSister); + myFamily.add(thirdBestSister); + myFamily.add(olderSister); + + + } + + @Rule + public final SystemOutRule systemOutRule= new SystemOutRule().enableLog(); + + @Test + public void printPersons() { + String expected = "{ Name: Ruth Beale, Birthday: 1980-03-07, Gender: FEMALE, EmailAddress: rbeale@gmail.com}\n\n"; + Main.printPeople(myFamily, new CheckPerson() { + @Override + public Boolean test (Person person){ + return person.getAge() <= 18; + } + }); + Assert.assertEquals(expected, systemOutRule.getLog()); + } + @Test + public void printPersonLambda() { + String expected = "{ Name: Charlotte Beale, Birthday: 1982-08-20, Gender: FEMALE, EmailAddress: cbeale2000@gmail.com}\n\n"; + Main.printPeople(myFamily, person -> person.getAge() >= 45 && person.getGender() == Person.Sex.FEMALE); + Assert.assertEquals(expected, systemOutRule.getLog()); + } +} \ No newline at end of file diff --git a/lambdas2zcw/target/classes/CheckPerson.class b/lambdas2zcw/target/classes/CheckPerson.class new file mode 100644 index 0000000..e7a0a49 Binary files /dev/null and b/lambdas2zcw/target/classes/CheckPerson.class differ diff --git a/lambdas2zcw/target/classes/Main$1.class b/lambdas2zcw/target/classes/Main$1.class new file mode 100644 index 0000000..98e7a4e Binary files /dev/null and b/lambdas2zcw/target/classes/Main$1.class differ diff --git a/lambdas2zcw/target/classes/Main$1checkForOver18.class b/lambdas2zcw/target/classes/Main$1checkForOver18.class new file mode 100644 index 0000000..762c710 Binary files /dev/null and b/lambdas2zcw/target/classes/Main$1checkForOver18.class differ diff --git a/lambdas2zcw/target/classes/Main.class b/lambdas2zcw/target/classes/Main.class new file mode 100644 index 0000000..42c9d26 Binary files /dev/null and b/lambdas2zcw/target/classes/Main.class differ diff --git a/lambdas2zcw/target/classes/Person$Sex.class b/lambdas2zcw/target/classes/Person$Sex.class new file mode 100644 index 0000000..db534eb Binary files /dev/null and b/lambdas2zcw/target/classes/Person$Sex.class differ diff --git a/lambdas2zcw/target/classes/Person.class b/lambdas2zcw/target/classes/Person.class new file mode 100644 index 0000000..1dcd7b3 Binary files /dev/null and b/lambdas2zcw/target/classes/Person.class differ