package nl.dykam.dev.reutil.data;

import nl.dykam.dev.reutil.data.annotations.Defaults;

import java.lang.ref.WeakReference;

@Defaults
public abstract class Component<T> {
    private transient WeakReference<T> object;
    private transient Class<?> objectType;
    private transient ComponentManager context;

    public T getObject() {
        return object.get();
    }

    @SuppressWarnings("unchecked")
    final void initialize(Object object, Class<?> objectType, ComponentManager context) {
        this.objectType = objectType;
        this.object = new WeakReference<>((T)object);
        this.context = context;

        onInitialize();
    }

    protected void onInitialize() {}

    public ComponentManager getContext() {
        return context;
    }

    /**
     * The type of the object this Component is meant to support. This can be a superclass of #getObject()
     * @return The type of the object this Component is meant to support
     */
    public Class<?> getObjectType() {
        return objectType;
    }
}

@@ -28,16 +28,61 @@
 .data;%0A%0A
+import com.google.common.base.Preconditions;%0A
 import n
@@ -535,24 +535,161 @@
  context) %7B%0A
+        Preconditions.checkNotNull(object);%0A        Preconditions.checkNotNull(objectType);%0A        Preconditions.checkNotNull(context);%0A
         this

Precondition.notnull