net.sf.javagimmicks.collections.event.ObservableEventSet Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gimmicks Show documentation
Show all versions of gimmicks Show documentation
Utility classes, APIs and tools for Java
package net.sf.javagimmicks.collections.event;
import java.util.Set;
import net.sf.javagimmicks.collections.event.SetEvent.Type;
import net.sf.javagimmicks.event.EventListener;
import net.sf.javagimmicks.event.Observable;
import net.sf.javagimmicks.event.ObservableBase;
/**
* A {@link Set} decorator that serves as an {@link Observable} for
* {@link SetEvent}s.
*/
public class ObservableEventSet extends AbstractEventSet implements Observable>
{
private static final long serialVersionUID = 4799365684601532982L;
protected final ObservableBase> _helper = new ObservableBase>();
/**
* Wraps a new {@link ObservableEventSet} around a given {@link Set}.
*
* @param decorated
* the {@link Set} to wrap around
*/
public ObservableEventSet(final Set decorated)
{
super(decorated);
}
@Override
public >> void addEventListener(final L listener)
{
_helper.addEventListener(listener);
}
@Override
public >> void removeEventListener(final L listener)
{
_helper.removeEventListener(listener);
}
@Override
protected void fireElementAdded(final E element)
{
_helper.fireEvent(new SetEventImpl(Type.ADDED, element));
}
@Override
protected void fireElementReadded(final E element)
{
_helper.fireEvent(new SetEventImpl(Type.READDED, element));
}
@Override
protected void fireElementRemoved(final E element)
{
_helper.fireEvent(new SetEventImpl(Type.REMOVED, element));
}
private class SetEventImpl implements SetEvent
{
protected final Type _type;
protected final E _element;
public SetEventImpl(final Type type, final E element)
{
_type = type;
_element = element;
}
@Override
public Type getType()
{
return _type;
}
@Override
public E getElement()
{
return _element;
}
@Override
public ObservableEventSet getSource()
{
return ObservableEventSet.this;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy