Assignment #1: Reflection
A class is said to have a property prop of type SomeType
if it has a pair of public non-static methods
with the following signatures (there might also be throws lists):
public void setProp( SomeType x );
public SomeType getProp( );
if SomeType is not boolean,
or as follows for boolean properties:
public void setProp( boolean x );
public boolean isProp( );
For example, class java.awt.Component has several properties:
PROPERTY NAME TYPE
background java.awt.Color
enabled boolean
location java.awt.Point
The derived class java.awt.Container has all those properties plus also:
PROPERTY NAME TYPE
font java.awt.Font
layout java.awt.LayoutManager
The Method to Implement
Implement a class with the public static method shown below. You may add
private helpers as you see fit.
package cop4338;
public class Utilities
{
public static java.util.Map getProperties( Class cl ) throws ClassNotFoundException
{ ... }
}
The getProperties
method returns a Map that stores the
properties (as defined above) of Class cl.
In the map that is returned, the keys are Strings
(each of which represents a property name) and
the values are Class objects
(each of which represents the corresponding property type).
Under no circumstances may it produce any output at all, and you
will receive a huge deduction if you violate this requirement.
What to Submit
Sumbit VIA PRINTOUTS AND NOT FLOPPIES
your complete source code, and the results of testing your method on the following
classes: String, java.awt.Rectangle, java.util.Date,
and
java.util.ArrayList. You will need to write an additional method that iterates
through the Map that is returned by getProperties and outputs the
properties in a style similar to the example above.
Additionally, you should write a class that
you will pass as a parameter to getProperties to show that
getProperties correctly:
- Ignores static methods
- Ignores non-public methods
- Ignores setXX if getXX has a different type
- Ignores setXX if its return type is not void
- Ignores getXX if its parameter list is not empty
- Ignores methods that do not have the correct lower-case upper-case conventions
You will receive a huge deduction if you violate the submission requirements.
Note About Grading Style
I expect well-documented, properly indented code, consistently formatted and spaced code,
with proper naming of methods and variables.
Here
are examples of deductions I will make.