diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..d82a6ed --- /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..e8942bd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,13 @@ + + + + + + + + + \ 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..ec30bc9 --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,1020 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Object + fields + + + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + project + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1493925013918 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + TypeInformation + + + + + + + + 1.8 + + + + + + + + Maven: junit:junit:4.12 + + + + + + + + \ No newline at end of file diff --git a/TypeInformation.iml b/TypeInformation.iml new file mode 100644 index 0000000..319f82b --- /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/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 new file mode 100644 index 0000000..1c3e933 --- /dev/null +++ b/src/main/java/PartOne.java @@ -0,0 +1,78 @@ +import java.util.ArrayList; +import java.util.List; + +/** + * 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 classObject) { + + 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) { + + Class thisClass = classObject.getClass(); + List listOfClasses = new ArrayList<>(); + + listOfClasses.add(thisClass); + while (thisClass.getSuperclass() != null) { + thisClass = thisClass.getSuperclass(); + listOfClasses.add(thisClass); + } + + for (int i = listOfClasses.size(), k = 1; i > 0 && k <= listOfClasses.size(); i--, k++) { + for (int j = 1; j < k; j++) { + System.out.print(" "); + } + + return listOfClasses.get(i - 1).getSimpleName().toString(); + } + + 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 new file mode 100644 index 0000000..8bf3c8d --- /dev/null +++ b/src/test/java/testPartOne.java @@ -0,0 +1,79 @@ +import org.junit.Assert; +import org.junit.Test; + +import java.awt.*; +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() { + //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); + + + } + + @Test + public void testGetClassHierarchy() { + //given + Object objectName = new Button(); + String expectedString = "Object"; + PartOne testing = new PartOne(); + //when + String actualAnswer = testing.getClassHierarchy(objectName); + + //then + 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); + + } + + +}