diff options
Diffstat (limited to 'ex1/src/main/java/reflection')
| -rw-r--r-- | ex1/src/main/java/reflection/api/ReflectionInvestigator.java | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java index 160102a..03e6dab 100644 --- a/ex1/src/main/java/reflection/api/ReflectionInvestigator.java +++ b/ex1/src/main/java/reflection/api/ReflectionInvestigator.java | |||
| @@ -2,6 +2,7 @@ package reflection.api; | |||
| 2 | 2 | ||
| 3 | import java.lang.reflect.InvocationTargetException; | 3 | import java.lang.reflect.InvocationTargetException; |
| 4 | import java.lang.reflect.Modifier; | 4 | import java.lang.reflect.Modifier; |
| 5 | import java.util.HashSet; | ||
| 5 | import java.util.Set; | 6 | import java.util.Set; |
| 6 | import java.util.stream.Collectors; | 7 | import java.util.stream.Collectors; |
| 7 | import java.util.stream.Stream; | 8 | import java.util.stream.Stream; |
| @@ -36,7 +37,7 @@ public class ReflectionInvestigator implements Investigator { | |||
| 36 | @Override | 37 | @Override |
| 37 | public Set<String> getAllImplementedInterfaces() { | 38 | public Set<String> getAllImplementedInterfaces() { |
| 38 | return Stream.of(classInfo.getInterfaces()) | 39 | return Stream.of(classInfo.getInterfaces()) |
| 39 | .map(info -> info.getName()) | 40 | .map(info -> info.getSimpleName()) |
| 40 | .collect(Collectors.toSet()); | 41 | .collect(Collectors.toSet()); |
| 41 | } | 42 | } |
| 42 | 43 | ||
| @@ -116,13 +117,13 @@ public class ReflectionInvestigator implements Investigator { | |||
| 116 | 117 | ||
| 117 | @Override | 118 | @Override |
| 118 | public String getInheritanceChain(String delimiter) { | 119 | public String getInheritanceChain(String delimiter) { |
| 119 | var sb = new StringBuilder(); | 120 | var nameStack = new HashSet<String>(); |
| 120 | sb.append(classInfo.getName()); | 121 | nameStack.add(classInfo.getSimpleName()); |
| 121 | var cursor = classInfo; | 122 | var cursor = classInfo; |
| 122 | while (cursor != null) { | 123 | while (cursor != null) { |
| 123 | sb.append(cursor.getName() + " -> "); | 124 | nameStack.add(cursor.getSimpleName()); |
| 124 | cursor = cursor.getSuperclass(); | 125 | cursor = cursor.getSuperclass(); |
| 125 | } | 126 | } |
| 126 | return sb.toString(); | 127 | return String.join(" >> ", nameStack); |
| 127 | } | 128 | } |
| 128 | } | 129 | } |