diff options
| author | Kostya <mail@sartin.in> | 2026-07-22 20:26:21 +0000 |
|---|---|---|
| committer | Kostya <mail@sartin.in> | 2026-07-22 20:26:21 +0000 |
| commit | b75f528e932c079bc71d00066b5432823c02f729 (patch) | |
| tree | 22be08435743092054d31bf1e52b0b2c06a42dbe /ex1/src/main | |
| parent | 51e36d68b0dba2188fcb70981e45935e198486dd (diff) | |
| download | java-course-b75f528e932c079bc71d00066b5432823c02f729.tar.gz java-course-b75f528e932c079bc71d00066b5432823c02f729.tar.xz java-course-b75f528e932c079bc71d00066b5432823c02f729.zip | |
half done
Diffstat (limited to 'ex1/src/main')
| -rw-r--r-- | ex1/src/main/java/reflection/api/App.java | 12 | ||||
| -rw-r--r-- | ex1/src/main/java/reflection/api/ReflectionInvestigator.java | 106 |
2 files changed, 111 insertions, 7 deletions
diff --git a/ex1/src/main/java/reflection/api/App.java b/ex1/src/main/java/reflection/api/App.java index 04cd919..aaead40 100644 --- a/ex1/src/main/java/reflection/api/App.java +++ b/ex1/src/main/java/reflection/api/App.java | |||
| @@ -1,10 +1,8 @@ | |||
| 1 | package com.reflection.api; | 1 | package reflection.api; |
| 2 | 2 | ||
| 3 | /** | 3 | /** Hello world! */ |
| 4 | * Hello world! | ||
| 5 | */ | ||
| 6 | public class App { | 4 | public class App { |
| 7 | public static void main(String[] args) { | 5 | public static void main(String[] args) { |
| 8 | System.out.println("Hello World!"); | 6 | System.out.println("Hello World!"); |
| 9 | } | 7 | } |
| 10 | } | 8 | } |
diff --git a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java new file mode 100644 index 0000000..2d18b34 --- /dev/null +++ b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | package reflection.api; | ||
| 2 | |||
| 3 | import java.lang.reflect.Modifier; | ||
| 4 | import java.util.Set; | ||
| 5 | import java.util.stream.Collectors; | ||
| 6 | import java.util.stream.Stream; | ||
| 7 | |||
| 8 | public class ReflectionInvestigator implements Investigator { | ||
| 9 | private Object subjectInstance; | ||
| 10 | private Class<?> classInfo; | ||
| 11 | |||
| 12 | public ReflectionInvestigator() {} | ||
| 13 | |||
| 14 | @Override | ||
| 15 | public void load(Object anInstanceOfSomething) { | ||
| 16 | subjectInstance = anInstanceOfSomething; | ||
| 17 | classInfo = subjectInstance.getClass(); | ||
| 18 | } | ||
| 19 | |||
| 20 | @Override | ||
| 21 | public int getTotalNumberOfMethods() { | ||
| 22 | return classInfo.getDeclaredMethods().length; | ||
| 23 | } | ||
| 24 | |||
| 25 | @Override | ||
| 26 | public int getTotalNumberOfConstructors() { | ||
| 27 | return classInfo.getConstructors().length; | ||
| 28 | } | ||
| 29 | |||
| 30 | @Override | ||
| 31 | public int getTotalNumberOfFields() { | ||
| 32 | return classInfo.getFields().length; | ||
| 33 | } | ||
| 34 | |||
| 35 | @Override | ||
| 36 | public Set<String> getAllImplementedInterfaces() { | ||
| 37 | return Stream.of(classInfo.getInterfaces()) | ||
| 38 | .map(info -> info.getName()) | ||
| 39 | .collect(Collectors.toSet()); | ||
| 40 | } | ||
| 41 | |||
| 42 | @Override | ||
| 43 | public int getCountOfConstantFields() { | ||
| 44 | return Stream.of(classInfo.getFields()) | ||
| 45 | .filter(f -> Modifier.isFinal(f.getModifiers())) | ||
| 46 | .toArray() | ||
| 47 | .length; | ||
| 48 | } | ||
| 49 | |||
| 50 | @Override | ||
| 51 | public int getCountOfStaticMethods() { | ||
| 52 | return Stream.of(classInfo.getMethods()) | ||
| 53 | .filter(m -> Modifier.isStatic(m.getModifiers())) | ||
| 54 | .toArray() | ||
| 55 | .length; | ||
| 56 | } | ||
| 57 | |||
| 58 | @Override | ||
| 59 | public boolean isExtending() { | ||
| 60 | // TODO Auto-generated method stub | ||
| 61 | throw new UnsupportedOperationException("Unimplemented method 'isExtending'"); | ||
| 62 | } | ||
| 63 | |||
| 64 | @Override | ||
| 65 | public String getParentClassSimpleName() { | ||
| 66 | // TODO Auto-generated method stub | ||
| 67 | throw new UnsupportedOperationException("Unimplemented method 'getParentClassSimpleName'"); | ||
| 68 | } | ||
| 69 | |||
| 70 | @Override | ||
| 71 | public boolean isParentClassAbstract() { | ||
| 72 | // TODO Auto-generated method stub | ||
| 73 | throw new UnsupportedOperationException("Unimplemented method 'isParentClassAbstract'"); | ||
| 74 | } | ||
| 75 | |||
| 76 | @Override | ||
| 77 | public Set<String> getNamesOfAllFieldsIncludingInheritanceChain() { | ||
| 78 | // TODO Auto-generated method stub | ||
| 79 | throw new UnsupportedOperationException( | ||
| 80 | "Unimplemented method 'getNamesOfAllFieldsIncludingInheritanceChain'"); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Override | ||
| 84 | public int invokeMethodThatReturnsInt(String methodName, Object... args) { | ||
| 85 | // TODO Auto-generated method stub | ||
| 86 | throw new UnsupportedOperationException("Unimplemented method 'invokeMethodThatReturnsInt'"); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Override | ||
| 90 | public Object createInstance(int numberOfArgs, Object... args) { | ||
| 91 | // TODO Auto-generated method stub | ||
| 92 | throw new UnsupportedOperationException("Unimplemented method 'createInstance'"); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Override | ||
| 96 | public Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args) { | ||
| 97 | // TODO Auto-generated method stub | ||
| 98 | throw new UnsupportedOperationException("Unimplemented method 'elevateMethodAndInvoke'"); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Override | ||
| 102 | public String getInheritanceChain(String delimiter) { | ||
| 103 | // TODO Auto-generated method stub | ||
| 104 | throw new UnsupportedOperationException("Unimplemented method 'getInheritanceChain'"); | ||
| 105 | } | ||
| 106 | } | ||