Thursday, August 28, 2008

Sublime Santeria Cover by Terra Naomi



I really like this cover. My girlfriend turned me on to it and its been keeping me company while I do some random programming. I'm working on a recursive reflection program for fun and a distinct lack of anything else. Here is the ridiculous code for anyone curious...


import java.lang.reflect.Field;
import java.util.HashSet;

public class RecursiveReflection {
  public static void main(final String[] args)
      throws ClassNotFoundException {
    if(args.length != 1) {
      System.out.println("Usage: java " +
        "RecursiveReflection ");
      System.out.println("for example, " +
        "try java.lang.String (it must be fully qualified)");
    } else {
      try {
        recurseClassFields(Class.forName(args[0]));
      }
      catch (ClassNotFoundException cnfe) {
        System.out.println(cnfe);
      }
    }
  }
  
  /* Something I just threw in ;) */
  @SuppressWarnings(value="unused")
  public static void recurseSuperclass(Class klass)
      throws ClassNotFoundException {
    if(klass == null) return;
    System.out.println(klass.getName());
    recurseSuperclass(klass.getSuperclass());
  }
  
  public static void recurseClassFields(Class klass)
      throws ClassNotFoundException {
    recurseClassFields(klass, "", new HashSet());
  }
  
  private static void recurseClassFields(Class klass, String indent,
      HashSet existingClasses)
      throws ClassNotFoundException {
    
    if(existingClasses.contains(klass.getName())) return;
    else existingClasses.add(klass.getName());
        
    System.out.print(indent + klass.getSimpleName());
    
    Field[] fields = klass.getDeclaredFields();
    
    System.out.print(" : " + fields.length +
        " members, ");
    System.out.print(" : " + klass.getMethods().length +
        " methods ");
    System.out.println();
        
    for(Field field : fields) {
      Class fieldClass = field.getType();
      if(fieldClass.isPrimitive()) continue;
      recurseClassFields(fieldClass, indent + " ",
      existingClasses);
    }
  }
}

Labels: , , ,