![JAR search and dependency download from the Maven repository](/logo.png)
com.zipwhip.lifecycle.DestroyableBase Maven / Gradle / Ivy
package com.zipwhip.lifecycle;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.TreeSet;
import com.zipwhip.util.HashCodeComparator;
/**
* Created by IntelliJ IDEA.
* User: Michael
* Date: 12/16/10
* Time: 8:22 PM
*
* An easy to use class that is Destroyable, that you can extend.
*/
public abstract class DestroyableBase implements Destroyable {
private boolean destroyed;
private static final Comparator COMPARATOR = new HashCodeComparator();
protected Collection destroyables = null;
@Override
public void destroy() {
if (this.destroyed) {
return;
}
this.destroyed = true;
if (destroyables != null) {
synchronized (destroyables) {
for (Destroyable destroyable : destroyables) {
destroyable.destroy();
}
destroyables.clear();
}
destroyables = null;
}
this.onDestroy();
}
protected abstract void onDestroy();
@Override
public boolean isDestroyed() {
return this.destroyed;
}
protected synchronized void createDestroyableList()
{
if (destroyables == null) {
destroyables = Collections.synchronizedCollection(new TreeSet(COMPARATOR));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy