package game.objects; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Field; import java.util.Arrays; import java.util.Date; /** * Why have an uninitializer? Simple. For the same reason that you would * initialize the objects yourself! Recommended for use when exiting the game. * * @author Link_The_Programmer * @version 1.0 */ public final class Uninitializer extends ClassLoader { private static final String version = "1.0"; private static transient Exception e; private static transient int numOfObjects = 0; private static transient Date date = new Date(); static { System.out.println("~Uninitializer.java version " + version); System.out.println(); } public Uninitializer() { } //[Constructor] public Uninitializer(Object obj) { uninitialize(obj); } public Uninitializer(Object[] obj) throws NoSuchFieldException, Exception { int mill1; int mill2; System.out.println("--[" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + System.currentTimeMillis() / date.getSeconds() + "] Uninitializing objects..."); mill1 = (int) (System.currentTimeMillis() / date.getSeconds()); uninitialize(obj); System.out.println("--[" + date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds() + ":" + System.currentTimeMillis() / date.getSeconds() + "] Objects uninitialized. Total quantity: " + numOfObjects); mill2 = (int) (mill1 - System.currentTimeMillis() / date.getSeconds()); System.out.println("--Time Elapsed: " + Math.abs(mill2) + " millisecond(s)"); System.out.println(); for (Object object : obj) { if (object == null) { System.err.println(e.getStackTrace()[e.getStackTrace().length - 1].getClassName() + ".Field" + Arrays.toString(e.getStackTrace()[e.getStackTrace().length - 1].getClassName().getBytes()) + "] never initialized or already uninitialized."); } } } //[/Constructor] private void uninitialize(Object obj) { try { obj = null; } catch (NullPointerException e) { System.err.println(e + ": This object is already null."); } } private synchronized void uninitialize(Object[] obj) throws ClassNotFoundException, NoSuchFieldException, Exception { if (obj != null) { try { throw new Exception(); } catch (Exception e) { for (Object object : obj) { uninitialize(object); this.e = e; if (object instanceof Field || object instanceof Class) { if (object instanceof Field) { Field.setAccessible((AccessibleObject[]) obj, true); System.out.println(object + " uninitialized."); numOfObjects += 1; Field.setAccessible((AccessibleObject[]) obj, false); } else { System.out.println(((Class) object).getCanonicalName() + " uninitialized."); numOfObjects += 1; } } else { System.out.println(Initializer.getContainingClass(object) + ".Field" + Arrays.toString(e.getStackTrace()[Initializer.getStackSize() - 1].getClassName().getBytes()) + "] initialized."); numOfObjects += 1; } } } } } }