All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.javagimmicks.collections.AbstractCursor Maven / Gradle / Ivy

There is a newer version: 0.99-alpha1
Show newest version
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 collection) { int count = 0; for (final E value : collection) { insertAfter(value); next(); ++count; } previous(count); } @Override public void insertBefore(final Iterable 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