Created
June 17, 2015 01:56
-
-
Save sturgle/4c2e1bcb4145aea093c6 to your computer and use it in GitHub Desktop.
AssignmentGenerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
import java.lang.reflect.Method; | |
import java.lang.reflect.Modifier; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class AssignmentGenerator { | |
public void generate(Class A, Class B) { | |
ArrayList<String> sets = new ArrayList<String>(); | |
Method[] methods = B.getDeclaredMethods(); | |
for (Method m : methods) { | |
if (Modifier.isPublic(m.getModifiers()) && m.getName().startsWith("set")) { | |
sets.add(m.getName()); | |
} | |
} | |
ArrayList<String> gets = new ArrayList<String>(); | |
Method[] methods2 = A.getDeclaredMethods(); | |
for (Method m : methods2) { | |
if (Modifier.isPublic(m.getModifiers()) && m.getName().startsWith("get")) { | |
gets.add(m.getName()); | |
} | |
} | |
for (int i = 0; i < sets.size(); i++) { | |
String set = sets.get(i); | |
for (int j = 0; j < gets.size(); j++) { | |
String get = gets.get(j); | |
String setNorm = set.substring(3).toLowerCase(); | |
String getNorm = get.substring(3).toLowerCase(); | |
if (getNorm.equals(setNorm)) { | |
System.out.println("a." + set + "(b." + get + "());"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment