Skip to content

Instantly share code, notes, and snippets.

@huberflores
Created March 28, 2014 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huberflores/9829019 to your computer and use it in GitHub Desktop.
Save huberflores/9829019 to your computer and use it in GitHub Desktop.
package symlab.ust.hk.abstract.profiler;
import java.lang.reflect.Method;
import java.util.Random;
/*
* author Huber Flores
*/
public class ReflectionTest {
public int[] localbubbleSort(int randValue, int sizeArray){
int[] num = new int[sizeArray];
Random r = new Random();
for (int i = 0; i < num.length; i++) {
num[i] = r.nextInt(randValue);
}
int j;
boolean flag = true;
int temp;
while (flag) {
flag = false;
for (j = 0; j < num.length - 1; j++) {
if (num[j] < num[j + 1])
{
temp = num[j];
num[j] = num[j + 1];
num[j + 1] = temp;
flag = true;
}
}
}
return num;
}
public int [] bubbleSort(int randValue, int sizeArray)
{
Method toExecute;
Class<?>[] paramTypes = {int.class, int.class};
Object[] paramValues = {randValue, sizeArray};
int [] result = null;
try{
String className = this.getClass().getName();
Class cls = Class.forName(className);
toExecute = cls.getDeclaredMethod("localbubbleSort", paramTypes);
result = (int[]) toExecute.invoke(this, paramValues);
if(result != null){
System.out.println("Method was executed");
}else{
System.out.println("Method was not executed");
result = localbubbleSort(randValue, sizeArray);
}
} catch (SecurityException se){
} catch (NoSuchMethodException ns){
}catch (Throwable th){
}
System.out.println(result);
return result;
}
public static void main(String[] args) {
ReflectionTest test = new ReflectionTest();
test.bubbleSort(1000000, 9999);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment