net.sf.javagimmicks.collections.AbstractCursor 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;
/**
* An abstract implementation of {@link Cursor} that provides default
* implementations for some derivable methods.
*
* These are:
*
* - {@link #insertAfter(Iterable)}
* - {@link #insertBefore(Iterable)}
* - {@link #next(int)}
* - {@link #previous(int)}
*
*/
public abstract class AbstractCursor implements Cursor
{
@Override
public void insertAfter(final Iterable extends E> collection)
{
int count = 0;
for (final E value : collection)
{
insertAfter(value);
next();
++count;
}
previous(count);
}
@Override
public void insertBefore(final Iterable extends E> collection)
{
for (final E value : collection)
{
insertBefore(value);
}
}
@Override
public E next(final int count)
{
if (count < 0)
{
return previous(-count);
}
if (count == 0)
{
return get();
}
E result = null;
for (int i = 0; i < count; ++i)
{
result = next();
}
return result;
}
@Override
public E previous(final int count)
{
if (count < 0)
{
return next(-count);
}
if (count == 0)
{
return get();
}
E result = null;
for (int i = 0; i < count; ++i)
{
result = previous();
}
return result;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy