diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e891fab --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,4 @@ +# Default ignored files +/workspace.xml +# Project exclude paths +/../ \ No newline at end of file diff --git a/.idea/Lambdas2-ZCW.iml b/.idea/Lambdas2-ZCW.iml new file mode 100644 index 0000000..b8ca93c --- /dev/null +++ b/.idea/Lambdas2-ZCW.iml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..7105f96 --- /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..89d2930 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..fe257e2 --- /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..ccdb0fd --- /dev/null +++ b/Lambdas2ZCW/Lambdas2ZCW.iml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Lambdas2ZCW/pom.xml b/Lambdas2ZCW/pom.xml new file mode 100644 index 0000000..23e0ca3 --- /dev/null +++ b/Lambdas2ZCW/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + + com.zipcodewilmington + Lambdas2ZCW + 1.0-SNAPSHOT + + + junit + junit + 4.9 + test + + + com.github.stefanbirkner + system-rules + 1.19.0 + test + + + + + \ No newline at end of file diff --git a/rocks/zipcode/CheckOlderThan40.class b/rocks/zipcode/CheckOlderThan40.class new file mode 100644 index 0000000..dd1679f Binary files /dev/null and b/rocks/zipcode/CheckOlderThan40.class differ diff --git a/rocks/zipcode/CheckPerson.class b/rocks/zipcode/CheckPerson.class new file mode 100644 index 0000000..e182034 Binary files /dev/null and b/rocks/zipcode/CheckPerson.class differ diff --git a/rocks/zipcode/LocalSearch.class b/rocks/zipcode/LocalSearch.class new file mode 100644 index 0000000..47acffa Binary files /dev/null and b/rocks/zipcode/LocalSearch.class differ diff --git a/rocks/zipcode/Main$1Under30.class b/rocks/zipcode/Main$1Under30.class new file mode 100644 index 0000000..bd61d9f Binary files /dev/null and b/rocks/zipcode/Main$1Under30.class differ diff --git a/rocks/zipcode/Main.class b/rocks/zipcode/Main.class new file mode 100644 index 0000000..7b4ed64 Binary files /dev/null and b/rocks/zipcode/Main.class differ diff --git a/rocks/zipcode/Person$Sex.class b/rocks/zipcode/Person$Sex.class new file mode 100644 index 0000000..0246a44 Binary files /dev/null and b/rocks/zipcode/Person$Sex.class differ diff --git a/rocks/zipcode/Person.class b/rocks/zipcode/Person.class new file mode 100644 index 0000000..a5e8f9f Binary files /dev/null and b/rocks/zipcode/Person.class differ diff --git a/rocks/zipcode/PersonTest.class b/rocks/zipcode/PersonTest.class new file mode 100644 index 0000000..ed26373 Binary files /dev/null and b/rocks/zipcode/PersonTest.class differ diff --git a/rocks/zipcode/Searches.class b/rocks/zipcode/Searches.class new file mode 100644 index 0000000..f58c26e Binary files /dev/null and b/rocks/zipcode/Searches.class differ diff --git a/rocks/zipcode/SearchesTest$1Under30.class b/rocks/zipcode/SearchesTest$1Under30.class new file mode 100644 index 0000000..e0fe62b Binary files /dev/null and b/rocks/zipcode/SearchesTest$1Under30.class differ diff --git a/rocks/zipcode/SearchesTest.class b/rocks/zipcode/SearchesTest.class new file mode 100644 index 0000000..1881eb0 Binary files /dev/null and b/rocks/zipcode/SearchesTest.class differ diff --git a/rocks/zipcode/SocialNetworks.class b/rocks/zipcode/SocialNetworks.class new file mode 100644 index 0000000..074fee4 Binary files /dev/null and b/rocks/zipcode/SocialNetworks.class differ diff --git a/rocks/zipcode/SocialNetworksTest.class b/rocks/zipcode/SocialNetworksTest.class new file mode 100644 index 0000000..2a43057 Binary files /dev/null and b/rocks/zipcode/SocialNetworksTest.class differ diff --git a/src/main/java/rocks/zipcode/CheckOlderThan40.java b/src/main/java/rocks/zipcode/CheckOlderThan40.java new file mode 100644 index 0000000..8dd6b29 --- /dev/null +++ b/src/main/java/rocks/zipcode/CheckOlderThan40.java @@ -0,0 +1,13 @@ +package rocks.zipcode; + +public class CheckOlderThan40 implements CheckPerson { + + @Override + public boolean test(Person person) { + if (person.getAge() >= 40) { + return true; + } + return false; + } + +} diff --git a/src/main/java/rocks/zipcode/CheckPerson.java b/src/main/java/rocks/zipcode/CheckPerson.java new file mode 100644 index 0000000..430bd27 --- /dev/null +++ b/src/main/java/rocks/zipcode/CheckPerson.java @@ -0,0 +1,6 @@ +package rocks.zipcode; + +public interface CheckPerson { + + boolean test (Person person); +} diff --git a/src/main/java/rocks/zipcode/LocalSearch.java b/src/main/java/rocks/zipcode/LocalSearch.java new file mode 100644 index 0000000..38b3cc2 --- /dev/null +++ b/src/main/java/rocks/zipcode/LocalSearch.java @@ -0,0 +1,21 @@ +package rocks.zipcode; + +import java.util.List; + +public class LocalSearch implements CheckPerson{ + public static void printPersons(List roster, CheckPerson tester) { + for (Person p : roster) { + if (tester.test(p)) { + p.printPerson(); + } + } + } + + @Override + public boolean test(Person person) { + return person.gender == Person.Sex.FEMALE && + person.getAge() >= 0 && + person.getAge() <= 80; + + } +} diff --git a/src/main/java/rocks/zipcode/Main.java b/src/main/java/rocks/zipcode/Main.java new file mode 100644 index 0000000..583ff2a --- /dev/null +++ b/src/main/java/rocks/zipcode/Main.java @@ -0,0 +1,57 @@ +package rocks.zipcode; + +import java.time.LocalDate; +import java.util.List; + +public class Main { + + public static void printPersons(List roster, CheckPerson tester) { + for (Person p : roster) { + if (tester.test(p)) { + p.printPerson(); + } + } + } + + public static void main(String[] args) { + SocialNetworks networks = new SocialNetworks(); + + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 11, 10), Person.Sex.FEMALE, "random@email.com"); + Person person3 = new Person("Peoples", LocalDate.of(1983, 6, 20), Person.Sex.MALE, "email30@address.com"); + Person person4 = new Person("Jojo", LocalDate.of(1972, 5, 5), Person.Sex.FEMALE, "random2@email.com"); + Person person5 = new Person("Faye", LocalDate.of(1994, 2, 14), Person.Sex.MALE, "email25@address.com"); + Person person6 = new Person("Boberto", LocalDate.of(2003, 4, 21), Person.Sex.FEMALE, "random45@email.com"); + Person person7 = new Person("Guy", LocalDate.of(1969, 1, 3), Person.Sex.MALE, "email50@address.com"); + Person person8 = new Person("Smiley", LocalDate.of(2008, 12, 8), Person.Sex.FEMALE, "random77@email.com"); + Person[] peeps = {person1, person2, person3, person4, person5, person6, person7, person8}; + + for (int i = 0; i < peeps.length; i++) { + networks.add(peeps[i]); + } + + class Under30 implements CheckPerson { + @Override + public boolean test(Person person) { + return person.getAge() <= 30; + } + } + + + + CheckPerson maleOver30 = new CheckPerson() { + @Override + public boolean test(Person person) { + return person.getAge() >= 15 && person.getAge() <= 50; + } + + }; + + printPersons(networks.get(), new Under30()); + + printPersons(networks.get(),maleOver30); + + printPersons(networks.get(), person -> person.getAge() >= 15 && person.getAge() <= 50 && person.getGender() == Person.Sex.FEMALE); + } +} + diff --git a/src/main/java/rocks/zipcode/Person.java b/src/main/java/rocks/zipcode/Person.java new file mode 100644 index 0000000..78dcb10 --- /dev/null +++ b/src/main/java/rocks/zipcode/Person.java @@ -0,0 +1,87 @@ +package rocks.zipcode; + +import java.time.LocalDate; +import java.time.Period; + +public class Person { + + + public enum Sex { + MALE, FEMALE + } + + String name; + LocalDate birthday; + Sex gender; + String emailAddress; + + public Person() { + this.name = ""; + this.birthday = LocalDate.now(); + this.gender = null; + this.emailAddress = ""; + } + + public Person(String name, LocalDate birthday, Sex gender, String emailAddress) { + this.name = name; + this.birthday = birthday; + this.gender = gender; + this.emailAddress = emailAddress; + } + + public int getAge() { + return Period.between(birthday, LocalDate.now()).getYears(); + } + + // ... + public String toString() { + return "Person = " + name + + ", birthday = " + birthday + + ", gender = " + gender + + ", Age = " + getAge() + + ", emailAddress = " + emailAddress + "\n"; + } + public void printPerson(){ + System.out.println(this.toString()); + } + + 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 Sex getGender() { + return gender; + } + public String getEmailAddress() { + return emailAddress; + } + + public void setEmailAddress(String emailAddress) { + this.emailAddress = emailAddress; + } + + /*public Person createRandomPerson() { + String name = StringUtils.capitalizeFirstChar(RandomUtils.createString('a', 'e', 3)); + String[] aliases = RandomUtils.createStrings('a', 'z', 3, 5); + boolean isMale = RandomUtils.createBoolean(50); + long personalId = System.nanoTime(); + LocalDate birthDate = RandomUtils.createDate(1950, 2010); + + Person randomPerson = new Person(name, isMale, personalId, birthDate, aliases); + return randomPerson; + */ +} + + diff --git a/src/main/java/rocks/zipcode/Searches.java b/src/main/java/rocks/zipcode/Searches.java new file mode 100644 index 0000000..663bf2f --- /dev/null +++ b/src/main/java/rocks/zipcode/Searches.java @@ -0,0 +1,7 @@ +package rocks.zipcode; + +public class Searches { + + + +} diff --git a/src/main/java/rocks/zipcode/SocialNetworks.java b/src/main/java/rocks/zipcode/SocialNetworks.java new file mode 100644 index 0000000..e0d7440 --- /dev/null +++ b/src/main/java/rocks/zipcode/SocialNetworks.java @@ -0,0 +1,29 @@ +package rocks.zipcode; + +import java.util.ArrayList; +import java.util.List; + +public class SocialNetworks { + Listnetwork; + + public SocialNetworks(){ + this.network = new ArrayList<>(); + } + + public List getNetwork() { + return network; + } + + public SocialNetworks(Person person){ + this.network = new ArrayList<>(); + network.add(person); + } + public void add(Person person){ + network.add(person); + } + public List get(){ + return network; + } + + +} diff --git a/src/test/java/rocks/zipcode/PersonTest.java b/src/test/java/rocks/zipcode/PersonTest.java new file mode 100644 index 0000000..e25fa4e --- /dev/null +++ b/src/test/java/rocks/zipcode/PersonTest.java @@ -0,0 +1,98 @@ +package rocks.zipcode; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import java.time.LocalDate; + +public class PersonTest { + + @Before + public void setUp() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + } + + @Test + public void getAge() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + int actual = person1.getAge(); + int expected = 33; + Assert.assertEquals(expected, actual); + + } + + @Test + public void printPerson() { + } + + @Test + public void getName() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + String actual = person1.getName(); + String expected = "Brian"; + Assert.assertEquals(expected, actual); + + } + + @Test + public void setName() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + person2.setName("Muffin"); + String actual = person2.getName(); + String expected = "Muffin"; + Assert.assertEquals(expected, actual); + } + + @Test + public void getBirthday() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + + LocalDate actual = person2.getBirthday(); + LocalDate expected = LocalDate.of(1999, 5, 05); + Assert.assertEquals(expected, actual); + } + + @Test + public void setBirthday() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + person2.setBirthday(LocalDate.of(1998,5,20)); + LocalDate actual = person2.getBirthday(); + LocalDate expected = LocalDate.of(1998, 5, 20); + Assert.assertEquals(expected, actual); + } + + @Test + public void getGender() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + Person.Sex actual = person1.getGender(); + Person.Sex expected = Person.Sex.MALE; + Assert.assertEquals(expected, actual); + } + + @Test + public void getEmailAddress() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + String actual = person1.getEmailAddress(); + String expected = "email@address.com"; + Assert.assertEquals(expected, actual); + } + + @Test + public void setEmailAddress() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 5, 05), Person.Sex.FEMALE, "random@email.com"); + person1.setEmailAddress("emailz@address.com"); + String actual = person1.getEmailAddress(); + String expected = "emailz@address.com"; + Assert.assertEquals(expected, actual); + } +} diff --git a/src/test/java/rocks/zipcode/SearchesTest.java b/src/test/java/rocks/zipcode/SearchesTest.java new file mode 100644 index 0000000..206d0c0 --- /dev/null +++ b/src/test/java/rocks/zipcode/SearchesTest.java @@ -0,0 +1,57 @@ +package rocks.zipcode; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemOutRule; + +import java.time.LocalDate; + +public class SearchesTest { + SocialNetworks networks = new SocialNetworks(); + + + @Before + public void setUp() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 11, 10), Person.Sex.FEMALE, "random@email.com"); + Person person3 = new Person("Peoples", LocalDate.of(1983, 6, 20), Person.Sex.MALE, "email30@address.com"); + Person person4 = new Person("Jojo", LocalDate.of(1972, 5, 5), Person.Sex.FEMALE, "random2@email.com"); + Person person5 = new Person("Faye", LocalDate.of(1994, 2, 14), Person.Sex.MALE, "email25@address.com"); + Person person6 = new Person("Boberto", LocalDate.of(2003, 4, 21), Person.Sex.FEMALE, "random45@email.com"); + Person person7 = new Person("Guy", LocalDate.of(1969, 1, 3), Person.Sex.MALE, "email50@address.com"); + Person person8 = new Person("Smiley", LocalDate.of(2008, 12, 8), Person.Sex.FEMALE, "random77@email.com"); + Person[] peeps = {person1, person2, person3, person4, person5, person6, person7, person8}; + + for (int i = 0; i < peeps.length; i++) { + networks.add(peeps[i]); + } + } + + + @Rule + public final SystemOutRule systemOutRule = new SystemOutRule().enableLog(); + + @Test + public void writesTextToSystemOut() { + class Under30 implements CheckPerson { + @Override + public boolean test(Person person) { + return person.getAge() <= 30; + } + } + Main.printPersons(networks.get(), new Under30()); + String actual = "Person = Rando, birthday = 1999-11-10, gender = FEMALE, Age = 20, emailAddress = random@email.com\n\n" + + "Person = Faye, birthday = 1994-02-14, gender = MALE, Age = 25, emailAddress = email25@address.com\n\n" + + "Person = Boberto, birthday = 2003-04-21, gender = FEMALE, Age = 16, emailAddress = random45@email.com\n\n" + + "Person = Smiley, birthday = 2008-12-08, gender = FEMALE, Age = 10, emailAddress = random77@email.com\n\n"; + + Assert.assertEquals(systemOutRule.getLog(),actual); + + + } + + +} + diff --git a/src/test/java/rocks/zipcode/SocialNetworksTest.java b/src/test/java/rocks/zipcode/SocialNetworksTest.java new file mode 100644 index 0000000..03f7952 --- /dev/null +++ b/src/test/java/rocks/zipcode/SocialNetworksTest.java @@ -0,0 +1,39 @@ +package rocks.zipcode; + +import org.junit.Before; +import org.junit.Test; + +import java.time.LocalDate; +import java.util.ArrayList; + +public class SocialNetworksTest { + SocialNetworks networks = new SocialNetworks(); + LocalSearch search = new LocalSearch(); + + + @Before + public void setUp() { + Person person1 = new Person("Brian", LocalDate.of(1986, 8, 30), Person.Sex.MALE, "email1@address.com"); + Person person2 = new Person("Rando", LocalDate.of(1999, 11, 10), Person.Sex.FEMALE, "random@email.com"); + Person person3 = new Person("Peoples", LocalDate.of(1983, 6, 20), Person.Sex.MALE, "email30@address.com"); + Person person4 = new Person("Jojo", LocalDate.of(1972, 5, 5), Person.Sex.FEMALE, "random2@email.com"); + Person person5 = new Person("Faye", LocalDate.of(1994, 2, 14), Person.Sex.MALE, "email25@address.com"); + Person person6 = new Person("Boberto", LocalDate.of(2003, 4, 21), Person.Sex.FEMALE, "random45@email.com"); + Person person7 = new Person("Guy", LocalDate.of(1969, 1, 3), Person.Sex.MALE, "email50@address.com"); + Person person8 = new Person("Smiley", LocalDate.of(2008, 12, 8), Person.Sex.FEMALE, "random77@email.com"); + Person[] peeps = {person1, person2, person3, person4, person5, person6, person7, person8}; + for (int i = 0; i < peeps.length; i++) { + } + for (int i = 0; i < peeps.length; i++) { + networks.add(peeps[i]); + } + } + + @Test + public void searchTest1() { + LocalSearch.printPersons(networks.get(), search); + + + } + +} \ No newline at end of file