net.sf.javagimmicks.collections.event.ObservableEventNavigableSet 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.NavigableSet;
import java.util.SortedSet;
import net.sf.javagimmicks.collections.event.NavigableSetEvent.Type;
import net.sf.javagimmicks.event.EventListener;
import net.sf.javagimmicks.event.Observable;
import net.sf.javagimmicks.event.ObservableBase;
/**
* A {@link NavigableSet} decorator that serves as an {@link Observable} for
* {@link NavigableSetEvent}s.
*/
public class ObservableEventNavigableSet extends AbstractEventNavigableSet implements
Observable>
{
private static final long serialVersionUID = -6812183248508925850L;
protected final ObservableBase> _helper = new ObservableBase>();
/**
* Wraps a new {@link ObservableEventNavigableSet} around a given
* {@link NavigableSet}.
*
* @param decorated
* the {@link NavigableSet} to wrap around
*/
public ObservableEventNavigableSet(final NavigableSet decorated)
{
super(decorated);
}
@Override
public >> void addEventListener(final L listener)
{
_helper.addEventListener(listener);
}
@Override
public >> void removeEventListener(final L listener)
{
_helper.removeEventListener(listener);
}
@Override
public ObservableEventNavigableSet descendingSet()
{
return new ObservableEventSubNavigableSet(this, getDecorated().descendingSet());
}
@Override
public ObservableEventNavigableSet headSet(final E toElement, final boolean inclusive)
{
return new ObservableEventSubNavigableSet(this, getDecorated().headSet(toElement, inclusive));
}
@Override
public ObservableEventNavigableSet subSet(final E fromElement, final boolean fromInclusive, final E toElement,
final boolean toInclusive)
{
return new ObservableEventSubNavigableSet(this, getDecorated().subSet(fromElement, fromInclusive, toElement,
toInclusive));
}
@Override
public ObservableEventNavigableSet tailSet(final E fromElement, final boolean inclusive)
{
return new ObservableEventSubNavigableSet(this, getDecorated().tailSet(fromElement, inclusive));
}
@Override
public ObservableEventSortedSet headSet(final E toElement)
{
return new ObservableEventSubSortedSet(this, getDecorated().headSet(toElement));
}
@Override
public ObservableEventSortedSet subSet(final E fromElement, final E toElement)
{
return new ObservableEventSubSortedSet(this, getDecorated().subSet(fromElement, toElement));
}
@Override
public ObservableEventSortedSet tailSet(final E fromElement)
{
return new ObservableEventSubSortedSet(this, getDecorated().tailSet(fromElement));
}
@Override
protected void fireElementAdded(final E element)
{
_helper.fireEvent(new NavigableSetEventImpl(Type.ADDED, element));
}
@Override
protected void fireElementReadded(final E element)
{
_helper.fireEvent(new NavigableSetEventImpl(Type.READDED, element));
}
@Override
protected void fireElementRemoved(final E element)
{
_helper.fireEvent(new NavigableSetEventImpl(Type.REMOVED, element));
}
private class NavigableSetEventImpl implements NavigableSetEvent
{
protected final Type _type;
protected final E _element;
public NavigableSetEventImpl(final Type type, final E element)
{
_type = type;
_element = element;
}
@Override
public Type getType()
{
return _type;
}
@Override
public E getElement()
{
return _element;
}
@Override
public ObservableEventNavigableSet getSource()
{
return ObservableEventNavigableSet.this;
}
}
protected static class ObservableEventSubNavigableSet extends ObservableEventNavigableSet
{
private static final long serialVersionUID = -4787480179100005627L;
protected final ObservableEventNavigableSet _parent;
protected ObservableEventSubNavigableSet(final ObservableEventNavigableSet parent,
final NavigableSet decorated)
{
super(decorated);
_parent = parent;
}
@Override
protected void fireElementAdded(final E element)
{
super.fireElementAdded(element);
_parent.fireElementAdded(element);
}
@Override
protected void fireElementReadded(final E element)
{
super.fireElementReadded(element);
_parent.fireElementReadded(element);
}
@Override
protected void fireElementRemoved(final E element)
{
super.fireElementRemoved(element);
_parent.fireElementRemoved(element);
}
}
protected static class ObservableEventSubSortedSet extends ObservableEventSortedSet
{
private static final long serialVersionUID = -4787480179100005627L;
protected final ObservableEventNavigableSet _parent;
protected ObservableEventSubSortedSet(final ObservableEventNavigableSet parent, final SortedSet decorated)
{
super(decorated);
_parent = parent;
}
@Override
protected void fireElementAdded(final E element)
{
super.fireElementAdded(element);
_parent.fireElementAdded(element);
}
@Override
protected void fireElementReadded(final E element)
{
super.fireElementReadded(element);
_parent.fireElementReadded(element);
}
@Override
protected void fireElementRemoved(final E element)
{
super.fireElementRemoved(element);
_parent.fireElementRemoved(element);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy