net.sf.javagimmicks.collections8.event.AbstractEventSortedMap 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.Comparator;
import java.util.SortedMap;
/**
* A base {@link SortedMap} 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 #fireEntryAdded(Object, Object)}
* - {@link #fireEntryUpdated(Object, Object, Object)}
* - {@link #fireEntryRemoved(Object, Object)}
*
*/
public abstract class AbstractEventSortedMap extends AbstractEventMap implements SortedMap
{
private static final long serialVersionUID = 87301004221670854L;
/**
* Wraps a new instance around a given {@link SortedMap}
*
* @param decorated
* the {@link SortedMap} to wrap
*/
public AbstractEventSortedMap(final SortedMap decorated)
{
super(decorated);
}
@Override
public SortedMap getDecorated()
{
return (SortedMap) super.getDecorated();
}
@Override
public Comparator super K> comparator()
{
return getDecorated().comparator();
}
@Override
public K firstKey()
{
return getDecorated().firstKey();
}
@Override
public K lastKey()
{
return getDecorated().lastKey();
}
@Override
public SortedMap headMap(final K toKey)
{
return new EventSubSortedMap(this, getDecorated().headMap(toKey));
}
@Override
public SortedMap subMap(final K fromKey, final K toKey)
{
return new EventSubSortedMap(this, getDecorated().subMap(fromKey, toKey));
}
@Override
public SortedMap tailMap(final K fromKey)
{
return new EventSubSortedMap(this, getDecorated().tailMap(fromKey));
}
protected static class EventSubSortedMap extends AbstractEventSortedMap
{
private static final long serialVersionUID = -6673032656718478269L;
protected final AbstractEventSortedMap _parent;
protected EventSubSortedMap(final AbstractEventSortedMap parent, final SortedMap decorated)
{
super(decorated);
_parent = parent;
}
@Override
protected void fireEntryAdded(final K key, final V value)
{
_parent.fireEntryAdded(key, value);
}
@Override
protected void fireEntryRemoved(final K key, final V value)
{
_parent.fireEntryRemoved(key, value);
}
@Override
protected void fireEntryUpdated(final K key, final V oldValue, final V newValue)
{
_parent.fireEntryUpdated(key, oldValue, newValue);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy