ExtSequence.java 985 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (c) 2003 Per M.A. Bothner and Brainfood Inc.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.lists;
  4. /** Abstract helper class for Sequences that use an ExtPosition.
  5. * That is sequences where it is inefficient to represent a position
  6. * just using a Pos int.
  7. */
  8. public abstract class ExtSequence<E> extends AbstractSequence<E>
  9. {
  10. public int copyPos (int ipos)
  11. {
  12. if (ipos <= 0)
  13. return ipos;
  14. return PositionManager.manager.register(PositionManager.getPositionObject(ipos).copy());
  15. }
  16. protected void releasePos(int ipos)
  17. {
  18. if (ipos > 0)
  19. PositionManager.manager.release(ipos);
  20. }
  21. protected boolean isAfterPos (int ipos)
  22. {
  23. if (ipos <= 0)
  24. return ipos < 0;
  25. return (PositionManager.getPositionObject(ipos).ipos & 1) != 0;
  26. }
  27. protected int nextIndex(int ipos)
  28. {
  29. return ipos == -1 ? size() : ipos == 0 ? 0
  30. : PositionManager.getPositionObject(ipos).nextIndex();
  31. }
  32. }