From 6d37fd70bb7ae71f09ab3ff53e82bd174cd9c2f6 Mon Sep 17 00:00:00 2001 From: ant Date: Thu, 4 May 2017 18:10:42 -0400 Subject: [PATCH 1/6] Finished first part of Part 1 --- .idea/compiler.xml | 16 + .idea/kotlinc.xml | 7 + .idea/libraries/Maven__junit_junit_4_12.xml | 13 + .../Maven__org_hamcrest_hamcrest_core_1_3.xml | 13 + .idea/misc.xml | 63 ++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 737 ++++++++++++++++++ TypeInformation.iml | 17 + pom.xml | 18 + src/main/java/PartOne.java | 25 + src/test/java/testPartOne.java | 48 ++ 12 files changed, 971 insertions(+) create mode 100644 .idea/compiler.xml create mode 100644 .idea/kotlinc.xml create mode 100644 .idea/libraries/Maven__junit_junit_4_12.xml create mode 100644 .idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 TypeInformation.iml create mode 100644 pom.xml create mode 100644 src/main/java/PartOne.java create mode 100644 src/test/java/testPartOne.java diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..61bbb77 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml new file mode 100644 index 0000000..1c24f9a --- /dev/null +++ b/.idea/kotlinc.xml @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__junit_junit_4_12.xml b/.idea/libraries/Maven__junit_junit_4_12.xml new file mode 100644 index 0000000..d411041 --- /dev/null +++ b/.idea/libraries/Maven__junit_junit_4_12.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml new file mode 100644 index 0000000..f58bbc1 --- /dev/null +++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.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..0f82c90 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + 1.8 + + + + + + + + 1.8 + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1ee38f5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ 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/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..6af4f63 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,737 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1493925013918 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/TypeInformation.iml b/TypeInformation.iml new file mode 100644 index 0000000..9c26698 --- /dev/null +++ b/TypeInformation.iml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..49db78f --- /dev/null +++ b/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + com.anthony.typeinformation + TypeInformation + 1.0-SNAPSHOT + + + + junit + junit + 4.12 + + + \ No newline at end of file diff --git a/src/main/java/PartOne.java b/src/main/java/PartOne.java new file mode 100644 index 0000000..c82f408 --- /dev/null +++ b/src/main/java/PartOne.java @@ -0,0 +1,25 @@ +import java.util.Currency; + +/** + * Created by anthonyjones on 5/4/17. + */ +public class PartOne { + + public boolean classImplementsInterface(Object classObject, String interfaceName) { + + String testForInterface = classObject.getClass().getInterfaces()[0].getSimpleName(); + if (testForInterface.equals(interfaceName)) { + return true; + } + return false; + + } + + + public String listAllMember(Object o) { + + + return ""; + } + +} diff --git a/src/test/java/testPartOne.java b/src/test/java/testPartOne.java new file mode 100644 index 0000000..4b08049 --- /dev/null +++ b/src/test/java/testPartOne.java @@ -0,0 +1,48 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Currency; + +/** + * Created by anthonyjones on 5/4/17. + */ +public class testPartOne { + + + @Test + public void testClassImplementsInterface() { + + //given + Class className = Currency.class; + String interfaceName = Serializable.class.getSimpleName(); + PartOne testingMethods = new PartOne(); + + //when + boolean actualAnswer = testingMethods.classImplementsInterface(className, interfaceName); + + //then + Assert.assertEquals(true, actualAnswer); + + } + + @Test + public void testListAllMember() { + + Class className = Currency.class; + ArrayList listOfObjectFields = new ArrayList(); + ArrayList listOfObjectMethod = new ArrayList(); + ArrayList listOfObjectConstructors = new ArrayList(); + + className.getSuperclass().getFields(); + className.getModifiers(); + className.getConstructors(); + + className.getFields(); + + + } + + +} From 267606ad544da9fdff8ea76e876cb885c77a27da Mon Sep 17 00:00:00 2001 From: ant Date: Fri, 5 May 2017 08:01:34 -0400 Subject: [PATCH 2/6] Started on ClassHierarchy --- .idea/compiler.xml | 2 +- .idea/misc.xml | 50 ----- .idea/workspace.xml | 328 +++++++++++++++++++++++++++------ TypeInformation.iml | 2 +- src/main/java/PartOne.java | 37 +++- src/test/java/testPartOne.java | 33 +++- 6 files changed, 338 insertions(+), 114 deletions(-) diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 61bbb77..d82a6ed 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -10,7 +10,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 0f82c90..e8942bd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -10,54 +10,4 @@ - - - - - - - - - - - - 1.8 - - - - - - - - 1.8 - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6af4f63..9c538d5 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -1,7 +1,14 @@ - + + + + + + + + + + + + + + + - - + + - - + + @@ -26,12 +48,14 @@ - + - - - + + + + + @@ -45,6 +69,12 @@ + + + Object + fields + + @@ -57,8 +87,8 @@ @@ -89,9 +119,6 @@ - - - @@ -152,11 +179,14 @@ + + + - - + + @@ -174,7 +204,7 @@ - + @@ -217,6 +247,63 @@ + + + + + + + + + + + + + + + + + + + @@ -582,6 +670,12 @@ + project + + + + + @@ -597,14 +691,20 @@ - + + + + - - - + + + + + + @@ -618,44 +718,54 @@ - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - + + + + + + + + @@ -664,7 +774,7 @@ - + @@ -678,6 +788,7 @@ + @@ -685,10 +796,9 @@ - - + @@ -699,7 +809,9 @@ \ No newline at end of file diff --git a/TypeInformation.iml b/TypeInformation.iml index 9c26698..319f82b 100644 --- a/TypeInformation.iml +++ b/TypeInformation.iml @@ -1,6 +1,6 @@ - + diff --git a/src/main/java/PartOne.java b/src/main/java/PartOne.java index c82f408..9d85894 100644 --- a/src/main/java/PartOne.java +++ b/src/main/java/PartOne.java @@ -1,3 +1,7 @@ +import javax.naming.ldap.BasicControl; +import java.awt.*; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.Currency; /** @@ -15,8 +19,39 @@ public boolean classImplementsInterface(Object classObject, String interfaceName } + public String listAllMember(Object classObject) { - public String listAllMember(Object o) { + System.out.println("Fields"); + for (int i = 0; i < classObject.getClass().getFields().length; i++) { + System.out.print(classObject.getClass().getFields()[i].getDeclaringClass().getSimpleName() + " "); + System.out.println(classObject.getClass().getFields()[i]); + } + + System.out.println("Constructors"); + for (int i = 0; i < classObject.getClass().getConstructors().length; i++) { + System.out.print(classObject.getClass().getConstructors()[i].getDeclaringClass().getSimpleName() + " "); + System.out.println(classObject.getClass().getConstructors()[i]); + } + + System.out.println("Methods"); + for (int i = 0; i < classObject.getClass().getMethods().length; i++) { + System.out.print(classObject.getClass().getMethods()[i].getDeclaringClass().getSimpleName() + " "); + System.out.println(classObject.getClass().getMethods()[i]); + + + if (classObject.getClass().getMethods()[i].toString().equals("public final native void java.lang.Object.notifyAll()")) { + return classObject.getClass().getMethods()[classObject.getClass().getMethods().length - 1].toString(); + } + } + return ""; + } + + public String getClassHierarchy(Object classObject) { + + for (int i = 0; i < 3; i++) { +// classObject.getClass(). + System.out.println(classObject.getClass().getSuperclass()); + } return ""; diff --git a/src/test/java/testPartOne.java b/src/test/java/testPartOne.java index 4b08049..68b3b7e 100644 --- a/src/test/java/testPartOne.java +++ b/src/test/java/testPartOne.java @@ -1,7 +1,12 @@ import org.junit.Assert; import org.junit.Test; +import java.awt.*; import java.io.Serializable; +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.math.BigDecimal; +import java.math.BigInteger; import java.util.ArrayList; import java.util.Currency; @@ -29,17 +34,29 @@ public void testClassImplementsInterface() { @Test public void testListAllMember() { + //given + String stringThatShouldAppear = "public final native void java.lang.Object.notifyAll()"; + Object objectName = new Button(); + PartOne testingMemberExistence = new PartOne(); + //when + String actualAnswer = testingMemberExistence.listAllMember(objectName); + //then + Assert.assertEquals(stringThatShouldAppear, actualAnswer); - Class className = Currency.class; - ArrayList listOfObjectFields = new ArrayList(); - ArrayList listOfObjectMethod = new ArrayList(); - ArrayList listOfObjectConstructors = new ArrayList(); - className.getSuperclass().getFields(); - className.getModifiers(); - className.getConstructors(); + } + + @Test + public void testGetClassHierarchy() { + //given + Object objectName = new Button(); + String expectedString = " Button"; + PartOne testing = new PartOne(); + //when + String actualAnswer = testing.getClassHierarchy(objectName); - className.getFields(); + //then + Assert.assertEquals(expectedString,actualAnswer); } From 20100ee6d5bd9aab31da41aeb93149adcfeaa6af Mon Sep 17 00:00:00 2001 From: ant Date: Fri, 5 May 2017 14:35:27 -0400 Subject: [PATCH 3/6] Working on Class Hierarchy still --- .idea/workspace.xml | 37 ++++++++++++++++--------------------- src/main/java/PartOne.java | 36 +++++++++++++++++++++++++++++------- 2 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 9c538d5..7f74fa4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,7 @@ - - - - - @@ -51,8 +46,8 @@ - - + + @@ -719,44 +714,44 @@ - + - + - + - + - + - + - + - + - + - + - @@ -859,8 +854,8 @@ - - + + diff --git a/src/main/java/PartOne.java b/src/main/java/PartOne.java index 9d85894..363d4c2 100644 --- a/src/main/java/PartOne.java +++ b/src/main/java/PartOne.java @@ -1,8 +1,7 @@ -import javax.naming.ldap.BasicControl; -import java.awt.*; -import java.math.BigDecimal; +import java.lang.reflect.Array; import java.util.ArrayList; -import java.util.Currency; +import java.util.List; +import java.util.stream.Collectors; /** * Created by anthonyjones on 5/4/17. @@ -48,12 +47,35 @@ public String listAllMember(Object classObject) { public String getClassHierarchy(Object classObject) { - for (int i = 0; i < 3; i++) { -// classObject.getClass(). - System.out.println(classObject.getClass().getSuperclass()); + Object holdObject = classObject; + Object C = classObject.getClass(); + + List listOfMethods = new ArrayList<>(); + + System.out.println(classObject.getClass().getSuperclass().getClasses().length); + for (int i = 0; C != null; i++) { + listOfMethods.add(holdObject);// classObject +// System.out.println(holdObject); + holdObject = listOfMethods.get(i).getClass().getSuperclass(); + + C = C.getClass().getSuperclass(); + } + // System.out.println(listOfMethods.get(2)); + + // System.out.println(listOfMethods.stream().distinct().collect(Collectors.toList())); + + + //holdObject = classObject.getClass().getMethods()[i].getDeclaringClass().getSimpleName(); + +// +// String[] a= listOfMethods.stream().distinct().collect(Collectors.toList()).toString().split(" "); +// System.out.println(a[0]); +// System.out.println(listOfMethods.stream().distinct().collect(Collectors.toList())); + + return ""; } From 50569f78170fd16a89cc7bdc87956c680ff054a1 Mon Sep 17 00:00:00 2001 From: ant Date: Fri, 5 May 2017 17:04:49 -0400 Subject: [PATCH 4/6] Still working on Heirarchy --- .idea/workspace.xml | 32 ++++++++++++++++---------------- src/main/java/PartOne.java | 26 ++++++++++++++++---------- 2 files changed, 32 insertions(+), 26 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7f74fa4..f3782f2 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -46,8 +46,8 @@ - - + + @@ -714,44 +714,44 @@ - - + + diff --git a/src/main/java/PartOne.java b/src/main/java/PartOne.java index 363d4c2..91e9b61 100644 --- a/src/main/java/PartOne.java +++ b/src/main/java/PartOne.java @@ -1,3 +1,4 @@ +import java.awt.*; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; @@ -37,7 +38,6 @@ public String listAllMember(Object classObject) { System.out.print(classObject.getClass().getMethods()[i].getDeclaringClass().getSimpleName() + " "); System.out.println(classObject.getClass().getMethods()[i]); - if (classObject.getClass().getMethods()[i].toString().equals("public final native void java.lang.Object.notifyAll()")) { return classObject.getClass().getMethods()[classObject.getClass().getMethods().length - 1].toString(); } @@ -48,20 +48,26 @@ public String listAllMember(Object classObject) { public String getClassHierarchy(Object classObject) { Object holdObject = classObject; - Object C = classObject.getClass(); + Class thisClass = classObject.getClass(); - List listOfMethods = new ArrayList<>(); + List listOfClasses = new ArrayList<>(); - System.out.println(classObject.getClass().getSuperclass().getClasses().length); - for (int i = 0; C != null; i++) { - listOfMethods.add(holdObject);// classObject -// System.out.println(holdObject); - holdObject = listOfMethods.get(i).getClass().getSuperclass(); + listOfClasses.add(thisClass); + while (thisClass.getSuperclass() != null) { + thisClass = thisClass.getSuperclass(); + listOfClasses.add(thisClass); + } - C = C.getClass().getSuperclass(); + for (int i = listOfClasses.size(); i > 0; i--) { - } + System.out.println(listOfClasses.get(i - 1).getSimpleName()); + while(i>1){ + System.out.print(" "); + } + + + } // System.out.println(listOfMethods.get(2)); From 4c126f976faf9b7722fd50ce8c61e69b3719c4a8 Mon Sep 17 00:00:00 2001 From: ant Date: Fri, 5 May 2017 17:36:44 -0400 Subject: [PATCH 5/6] Finished Hierarchy for now --- .idea/workspace.xml | 116 ++++++++++++++++++++++++++------- src/main/java/PartOne.java | 26 ++------ src/test/java/testPartOne.java | 2 +- 3 files changed, 96 insertions(+), 48 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index f3782f2..8d2c1bf 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,7 +2,9 @@ + + @@ -34,8 +36,8 @@ - - + + @@ -43,11 +45,11 @@ - + - - + + @@ -55,6 +57,16 @@ + + + + + + + + + + @@ -82,8 +94,8 @@ @@ -99,6 +111,9 @@ - - + + - + - + - + - - + - - - - - + + + + + - - - - - + + + + + @@ -752,14 +752,11 @@ 1493925013918 - + - - - @@ -787,9 +784,12 @@ + + + - @@ -813,7 +813,7 @@ - + @@ -821,6 +821,7 @@ + @@ -832,7 +833,6 @@ - @@ -843,7 +843,7 @@ - @@ -900,10 +900,18 @@ + + + + + + + + - - + + @@ -912,22 +920,14 @@ - - + + - - - - - - - - diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..949edf0 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,11 @@ +import java.awt.*; + +/** + * Created by anthonyjones on 5/5/17. + */ +public class Main { + public static void main(String[] args) { + PartOne a = new PartOne(); + + } +} diff --git a/src/main/java/PartOne.java b/src/main/java/PartOne.java index 30bd283..1c3e933 100644 --- a/src/main/java/PartOne.java +++ b/src/main/java/PartOne.java @@ -1,8 +1,5 @@ -import java.awt.*; -import java.lang.reflect.Array; import java.util.ArrayList; import java.util.List; -import java.util.stream.Collectors; /** * Created by anthonyjones on 5/4/17. @@ -67,4 +64,15 @@ public String getClassHierarchy(Object classObject) { return ""; } + + public ArrayList instantiateClassHierarchy(Object o) { + + ArrayList emptyList = new ArrayList<>(); + ArrayList listOfConcreteClasses = new ArrayList<>(); + + + + return emptyList; + } + } diff --git a/src/test/java/testPartOne.java b/src/test/java/testPartOne.java index 8ce6c0e..8bf3c8d 100644 --- a/src/test/java/testPartOne.java +++ b/src/test/java/testPartOne.java @@ -3,10 +3,6 @@ import java.awt.*; import java.io.Serializable; -import java.lang.reflect.Array; -import java.lang.reflect.Field; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.ArrayList; import java.util.Currency; @@ -56,8 +52,26 @@ public void testGetClassHierarchy() { String actualAnswer = testing.getClassHierarchy(objectName); //then - Assert.assertEquals(expectedString,actualAnswer); + Assert.assertEquals(expectedString, actualAnswer); + } + + @Test + public void testInstantiateClassHierarchy() { + //given + + Object objectName = new ArrayList(); + ArrayList listOfConcreteClasses = new ArrayList(); + PartOne testing = new PartOne(); + listOfConcreteClasses.add(objectName); + ArrayList expectedAnswer = listOfConcreteClasses; + + //when + + ArrayList actualAnswer = testing.instantiateClassHierarchy(objectName); + + //then + Assert.assertEquals(actualAnswer, expectedAnswer); }