Skip to content

Aurora Part 1 #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.class

.idea/
# Mobile Tools for Java (J2ME)
.mtj.tmp/

Expand Down
17 changes: 17 additions & 0 deletions TypeInformation.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: junit:junit:4.12" level="project" />
<orderEntry type="library" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>
24 changes: 24 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>banuelos.aurora</groupId>
<artifactId>TypeInformation</artifactId>
<version>1.0-SNAPSHOT</version>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>

</project>
21 changes: 21 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collections;

/**
* Created by aurorabanuelos on 5/5/17.
*/
public class Main {

public static void main(String[] args) {
Part1 tst = new Part1();

System.out.println(tst.classImplementsInterface(ArrayList.class, Serializable.class));

tst.getClassHierarchy(ArrayList.class);

tst.listAllMembers(ArrayList.class);
}
}
77 changes: 77 additions & 0 deletions src/main/java/Part1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;

/**
* Created by aurorabanuelos on 5/4/17.
*/
public class Part1{

boolean x;


public boolean classImplementsInterface(Class cls, Class inter) {

Class[] interfaceList = cls.getInterfaces();

for (Class e : interfaceList)
if (e.equals(inter)) {
x = true;
} else {
x = false;
}

return x;


}

public String getClassHierarchy(Class cls) {

ArrayList supercls = new ArrayList();

Class superClass = cls.getSuperclass();
while (superClass != null) {
supercls.add(superClass.getName());
superClass = superClass.getSuperclass();
}

Collections.reverse(supercls);

for(Object e: supercls) {
System.out.printf("\n %s", e);
}

return supercls.toString();

}

public String listAllMembers(Class cls){
Constructor [] ctors = cls.getDeclaredConstructors();
Field[] flds = cls.getDeclaredFields();
Method[] mthds = cls.getDeclaredMethods();

ArrayList members = new ArrayList();

for (Field f: flds){
members.add(cls + " " + Modifier.toString(f.getModifiers()) + " Field: " + f.getName() );
}

for (Constructor c: ctors){
members.add(cls + " " + Modifier.toString(c.getModifiers()) + " Constructor: " + c.getName() );
}

for (Method m: mthds){
members.add(cls + " " + Modifier.toString(m.getModifiers()) + " Method: " + m.getName() );
}

for(Object e: members) {
System.out.println(e);
}

return members.toString();

}
}
60 changes: 60 additions & 0 deletions src/test/java/Part1Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import com.sun.org.apache.xpath.internal.operations.Bool;
import org.junit.Assert;
import org.junit.Test;

import java.io.Serializable;
import java.lang.reflect.Array;
import java.util.AbstractCollection;
import java.util.ArrayList;


/**
* Created by aurorabanuelos on 5/4/17.
*/
public class Part1Test {

@Test
public void classImplementsInterface(){

//Given
Part1 part1 = new Part1();
Class cls = ArrayList.class;
Class inter = Serializable.class;

//When
boolean actual = part1.classImplementsInterface(cls, inter);

//Then
Assert.assertEquals(true, actual);
}

@Test
public void getClassHierarchyTest() {
//Given
Part1 part1 = new Part1();
Class cls = AbstractCollection.class;

//When
String actual = part1.getClassHierarchy(cls);

//Then
Assert.assertEquals("[java.lang.Object]", actual);

}

@Test
public void listAllMembersTest(){

//Given
Part1 part1 = new Part1();
Class cls = Object.class;

//When
String actualResult = part1.listAllMembers(cls);

//Then
Assert.assertEquals("", actualResult);

}

}