package reflection.api; import java.lang.reflect.Modifier; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; public class ReflectionInvestigator implements Investigator { private Object subjectInstance; private Class classInfo; public ReflectionInvestigator() {} @Override public void load(Object anInstanceOfSomething) { subjectInstance = anInstanceOfSomething; classInfo = subjectInstance.getClass(); } @Override public int getTotalNumberOfMethods() { return classInfo.getDeclaredMethods().length; } @Override public int getTotalNumberOfConstructors() { return classInfo.getConstructors().length; } @Override public int getTotalNumberOfFields() { return classInfo.getFields().length; } @Override public Set getAllImplementedInterfaces() { return Stream.of(classInfo.getInterfaces()) .map(info -> info.getName()) .collect(Collectors.toSet()); } @Override public int getCountOfConstantFields() { return Stream.of(classInfo.getFields()) .filter(f -> Modifier.isFinal(f.getModifiers())) .toArray() .length; } @Override public int getCountOfStaticMethods() { return Stream.of(classInfo.getMethods()) .filter(m -> Modifier.isStatic(m.getModifiers())) .toArray() .length; } @Override public boolean isExtending() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'isExtending'"); } @Override public String getParentClassSimpleName() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getParentClassSimpleName'"); } @Override public boolean isParentClassAbstract() { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'isParentClassAbstract'"); } @Override public Set getNamesOfAllFieldsIncludingInheritanceChain() { // TODO Auto-generated method stub throw new UnsupportedOperationException( "Unimplemented method 'getNamesOfAllFieldsIncludingInheritanceChain'"); } @Override public int invokeMethodThatReturnsInt(String methodName, Object... args) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'invokeMethodThatReturnsInt'"); } @Override public Object createInstance(int numberOfArgs, Object... args) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'createInstance'"); } @Override public Object elevateMethodAndInvoke(String name, Class[] parametersTypes, Object... args) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'elevateMethodAndInvoke'"); } @Override public String getInheritanceChain(String delimiter) { // TODO Auto-generated method stub throw new UnsupportedOperationException("Unimplemented method 'getInheritanceChain'"); } }