summaryrefslogtreecommitdiffstats
path: root/ex1
diff options
context:
space:
mode:
authorKostya <mail@sartin.in>2026-07-22 09:21:23 +0000
committerKostya <mail@sartin.in>2026-07-22 09:21:23 +0000
commit0f676f68c13d5e18864f7bc9f4a022ff6291ff22 (patch)
treebf0039f9319da21a8858e2135417f7499e9b42e8 /ex1
parente8825b8c125e6006a97fca3b5ec2b3c2a8ba6f53 (diff)
downloadjava-course-0f676f68c13d5e18864f7bc9f4a022ff6291ff22.tar.gz
java-course-0f676f68c13d5e18864f7bc9f4a022ff6291ff22.tar.xz
java-course-0f676f68c13d5e18864f7bc9f4a022ff6291ff22.zip
project bootstrap
Diffstat (limited to 'ex1')
-rw-r--r--ex1/.mvn/jvm.config0
-rw-r--r--ex1/.mvn/maven.config0
-rw-r--r--ex1/pom.xml90
-rw-r--r--ex1/reflection/api/Investigator.java145
-rw-r--r--ex1/src/main/java/com/reflection/api/App.java10
-rw-r--r--ex1/src/test/java/com/reflection/api/AppTest.java19
6 files changed, 119 insertions, 145 deletions
diff --git a/ex1/.mvn/jvm.config b/ex1/.mvn/jvm.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ex1/.mvn/jvm.config
diff --git a/ex1/.mvn/maven.config b/ex1/.mvn/maven.config
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/ex1/.mvn/maven.config
diff --git a/ex1/pom.xml b/ex1/pom.xml
new file mode 100644
index 0000000..3962137
--- /dev/null
+++ b/ex1/pom.xml
@@ -0,0 +1,90 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4 <modelVersion>4.0.0</modelVersion>
5
6 <groupId>com.reflection.api</groupId>
7 <artifactId>ex1</artifactId>
8 <version>1.0-SNAPSHOT</version>
9
10 <name>ex1</name>
11 <!-- FIXME change it to the project's website -->
12 <url>http://www.example.com</url>
13
14 <properties>
15 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16 <maven.compiler.release>17</maven.compiler.release>
17 </properties>
18
19 <dependencyManagement>
20 <dependencies>
21 <dependency>
22 <groupId>org.junit</groupId>
23 <artifactId>junit-bom</artifactId>
24 <version>5.11.0</version>
25 <type>pom</type>
26 <scope>import</scope>
27 </dependency>
28 </dependencies>
29 </dependencyManagement>
30
31 <dependencies>
32 <dependency>
33 <groupId>org.junit.jupiter</groupId>
34 <artifactId>junit-jupiter-api</artifactId>
35 <scope>test</scope>
36 </dependency>
37 <!-- Optionally: parameterized tests support -->
38 <dependency>
39 <groupId>org.junit.jupiter</groupId>
40 <artifactId>junit-jupiter-params</artifactId>
41 <scope>test</scope>
42 </dependency>
43 </dependencies>
44
45 <build>
46 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
47 <plugins>
48 <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
49 <plugin>
50 <artifactId>maven-clean-plugin</artifactId>
51 <version>3.4.0</version>
52 </plugin>
53 <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
54 <plugin>
55 <artifactId>maven-resources-plugin</artifactId>
56 <version>3.3.1</version>
57 </plugin>
58 <plugin>
59 <artifactId>maven-compiler-plugin</artifactId>
60 <version>3.13.0</version>
61 </plugin>
62 <plugin>
63 <artifactId>maven-surefire-plugin</artifactId>
64 <version>3.3.0</version>
65 </plugin>
66 <plugin>
67 <artifactId>maven-jar-plugin</artifactId>
68 <version>3.4.2</version>
69 </plugin>
70 <plugin>
71 <artifactId>maven-install-plugin</artifactId>
72 <version>3.1.2</version>
73 </plugin>
74 <plugin>
75 <artifactId>maven-deploy-plugin</artifactId>
76 <version>3.1.2</version>
77 </plugin>
78 <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
79 <plugin>
80 <artifactId>maven-site-plugin</artifactId>
81 <version>3.12.1</version>
82 </plugin>
83 <plugin>
84 <artifactId>maven-project-info-reports-plugin</artifactId>
85 <version>3.6.1</version>
86 </plugin>
87 </plugins>
88 </pluginManagement>
89 </build>
90</project>
diff --git a/ex1/reflection/api/Investigator.java b/ex1/reflection/api/Investigator.java
deleted file mode 100644
index 53e4fab..0000000
--- a/ex1/reflection/api/Investigator.java
+++ /dev/null
@@ -1,145 +0,0 @@
1package reflection.api;
2
3import java.util.Set;
4
5public interface Investigator {
6
7 /**
8 * loads in instance of a given class, which you will need to investigate through means of reflection
9 * and supply information on...
10 *
11 * @param anInstanceOfSomething an instance of an unknown type...
12 */
13 void load(Object anInstanceOfSomething);
14
15 /**
16 * returns the total number of the current class methods (not including the super class methods)
17 * the total number of methods includes all sorts of modifiers: private, public, static, protected etc.
18 * it does not contains constructors of any sort
19 *
20 * @return total number of methods
21 */
22 int getTotalNumberOfMethods();
23
24 /**
25 * returns the total number of constructors that this class has. (not including the super class constructors)
26 * the total number of constructors includes all sorts of modifiers: private, public, protected, default etc.
27 *
28 * @return total number of constructors
29 */
30 int getTotalNumberOfConstructors();
31
32 /**
33 * returns the total number of fields that this class has.
34 * the total number of fields DOES NOT include fields inherited from super class, if such exists
35 * and includes all fields of any type (final, static etc.)
36 *
37 * @return the total number of fields
38 */
39 int getTotalNumberOfFields();
40
41 /**
42 * returns the names of all the interfaces that this class implements
43 * (and NOT the ones that are being implemented by it's ancestor in the inheritance chain)
44 * Note that by name I mean simple, short Name that is only the interface name,
45 * and not its fully qualified name including the package it is located within...
46 *
47 * @return set of interfaces names
48 */
49 Set<String> getAllImplementedInterfaces();
50
51 /**
52 * returns total number of constant fields (=final), of any type (private, public, static etc.)
53 * (not including the super class fields)
54 * @return total number of constant fields
55 */
56 int getCountOfConstantFields();
57
58 /**
59 * returns total number of static methods, of any type (private, public etc.),
60 * that are declared on the instance itself (and not part of its inheritance chain)
61 *
62 * @return total number of static methods
63 */
64 int getCountOfStaticMethods();
65
66 /**
67 * checks if the given class extends a super class, that is not Object (which all extend by default, implicitly)
68 *
69 * @return true if the class extends, false otherwise
70 */
71 boolean isExtending();
72
73 /**
74 * get the name of the direct parent class
75 * the name of the class is the short, simple name and not the fully qualified name
76 *
77 * @return the name of the parent class. null if this class doesn't extend other class
78 */
79 String getParentClassSimpleName();
80
81 /**
82 * checks if the given class parent is of type abstract
83 *
84 * @return true if the parent class is abstract, false otherwise (also in case the given class does not extends any other class)
85 */
86 boolean isParentClassAbstract();
87
88 /**
89 * get all the names of all fields, including the ones coming from the inheritance chain
90 * all fields of any type should exists: private, public, protected, static etc.
91 *
92 * @return set of fields names
93 */
94 Set<String> getNamesOfAllFieldsIncludingInheritanceChain();
95
96 /**
97 * invokes a method that returns an int value, on the given instance.
98 * the method to invoke will be given by its name only.
99 * You can assume that there is exactly one such method and that
100 * the method is declared on the instance itself and not as part of its inheritance chain
101 *
102 * @param methodName the name of the method to invoke
103 * @param args the arguments to pass to the method, if such exists.
104 * Note: You should not use the arguments in order to extract and identify the method.
105 * You can do that only (and simply) by its name.
106 * You just need to pass the arguments AS IS to the method invocation...
107 *
108 * @return the result returned from the method invocation
109 */
110 int invokeMethodThatReturnsInt(String methodName, Object... args);
111
112 /**
113 * creates a new instance of the given class, using a specific constructor,
114 * to be determined by the number of given arguments.
115 * No worries: there will be no ambiguity, i.e. two constructors that gets in 2 arguments each one of them...
116 * This method should act as a standalone and without any side effects, that is, the newly created
117 * instance SHOULD NOT replace the original given instance.
118 * @param numberOfArgs number of arguments that a specific constructor has. can be 0.
119 * @param args arguments to pass to the constructor
120 *
121 * @return the newly created instance
122 */
123 Object createInstance(int numberOfArgs, Object... args);
124
125 /**
126 * changes access control of a method and invokes it (== invokes a private method...)
127 * you can assume that the method exists by it's name, and matched by the relevant parameters types.
128 *
129 * @param name name of the method to change its access modifier
130 * @param parametersTypes the types of parameters the method accepts
131 * @param args arguments to pass to the method invocation AS IS (once elevated)
132 *
133 * @return the result from the method invocation
134 */
135 Object elevateMethodAndInvoke(String name, Class<?>[] parametersTypes, Object... args);
136
137 /**
138 * explores the inheritance chain of the object. returns a string representing the list of
139 * parents this class has, starting from Object, and ending at the class name.
140 * all classes names in the list should appear in their simple short name
141 * @param delimiter a string to put between each two classes in the chain (e.g. "->")
142 * @return a string denotes the inheritance chain.
143 * It can look like this (given a decimeter of "->"): Object-><class name>->...-><class name>
144 */
145 String getInheritanceChain(String delimiter);}
diff --git a/ex1/src/main/java/com/reflection/api/App.java b/ex1/src/main/java/com/reflection/api/App.java
new file mode 100644
index 0000000..04cd919
--- /dev/null
+++ b/ex1/src/main/java/com/reflection/api/App.java
@@ -0,0 +1,10 @@
1package com.reflection.api;
2
3/**
4 * Hello world!
5 */
6public class App {
7 public static void main(String[] args) {
8 System.out.println("Hello World!");
9 }
10}
diff --git a/ex1/src/test/java/com/reflection/api/AppTest.java b/ex1/src/test/java/com/reflection/api/AppTest.java
new file mode 100644
index 0000000..70f7e97
--- /dev/null
+++ b/ex1/src/test/java/com/reflection/api/AppTest.java
@@ -0,0 +1,19 @@
1package com.reflection.api;
2
3import static org.junit.jupiter.api.Assertions.assertTrue;
4
5import org.junit.jupiter.api.Test;
6
7/**
8 * Unit test for simple App.
9 */
10public class AppTest {
11
12 /**
13 * Rigorous Test :-)
14 */
15 @Test
16 public void shouldAnswerWithTrue() {
17 assertTrue(true);
18 }
19}