net.sf.javagimmicks.collections8.event.AbstractEventNavigableSet 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.collections8.event;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.SortedSet;
/**
* A base {@link NavigableSet} wrapper that reports changes to internal callback
* methods - these must be overwritten by concrete implementations in order to
* react in any way to the changes.
*
* Methods that must be overwritten:
*
* - {@link #fireElementAdded(Object)}
* - {@link #fireElementReadded(Object)}
* - {@link #fireElementRemoved(Object)}
*
*/
public abstract class AbstractEventNavigableSet extends AbstractEventSortedSet implements NavigableSet
{
private static final long serialVersionUID = 5422669944595136215L;
/**
* Wraps a new instance around a given {@link SortedSet}
*
* @param decorated
* the {@link NavigableSet} to wrap
*/
public AbstractEventNavigableSet(final NavigableSet decorated)
{
super(decorated);
}
@Override
public NavigableSet getDecorated()
{
return (NavigableSet) super.getDecorated();
}
@Override
public E ceiling(final E e)
{
return getDecorated().ceiling(e);
}
@Override
public Iterator descendingIterator()
{
return new EventSetIterator(getDecorated().descendingIterator());
}
@Override
public NavigableSet descendingSet()
{
return new EventSubNavigableSet(this, getDecorated().descendingSet());
}
@Override
public E floor(final E e)
{
return getDecorated().floor(e);
}
@Override
public NavigableSet headSet(final E toElement, final boolean inclusive)
{
return new EventSubNavigableSet(this, getDecorated().headSet(toElement, inclusive));
}
@Override
public E higher(final E e)
{
return getDecorated().higher(e);
}
@Override
public E lower(final E e)
{
return getDecorated().lower(e);
}
@Override
public E pollFirst()
{
final E result = getDecorated().pollFirst();
fireElementRemoved(result);
return result;
}
@Override
public E pollLast()
{
final E result = getDecorated().pollLast();
fireElementRemoved(result);
return result;
}
@Override
public NavigableSet subSet(final E fromElement, final boolean fromInclusive, final E toElement,
final boolean toInclusive)
{
return new EventSubNavigableSet(this, getDecorated()
.subSet(fromElement, fromInclusive, toElement, toInclusive));
}
@Override
public NavigableSet tailSet(final E fromElement, final boolean inclusive)
{
return new EventSubNavigableSet(this, getDecorated().tailSet(fromElement, inclusive));
}
protected static class EventSubNavigableSet extends AbstractEventNavigableSet
{
private static final long serialVersionUID = 7026414183073208442L;
protected final AbstractEventNavigableSet _parent;
protected EventSubNavigableSet(final AbstractEventNavigableSet parent, final NavigableSet decorated)
{
super(decorated);
_parent = parent;
}
@Override
protected void fireElementAdded(final E element)
{
_parent.fireElementAdded(element);
}
@Override
protected void fireElementReadded(final E element)
{
_parent.fireElementReadded(element);
}
@Override
protected void fireElementRemoved(final E element)
{
_parent.fireElementRemoved(element);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy