ExtPosition.java 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) 2003 Per M.A. Bothner.
  2. // This is free software; for terms and warranty disclaimer see ./COPYING.
  3. package gnu.lists;
  4. /** A SeqPosition for sequences that need more than a Pos int for a position.
  5. * For such sequences, a Pos int is an index into a PositionManager,
  6. * which manages a table of ExtPositions, which may contain more state
  7. * than a regular SeqPosition does.
  8. */
  9. public class ExtPosition<E,ESEQ extends AbstractSequence<E>> extends SeqPosition<E,ESEQ>
  10. {
  11. /** Index into PositionManager.positions, if >= 0.
  12. * This is used if we need a single Pos integer for this position. */
  13. int position = -1;
  14. public int getPos ()
  15. {
  16. if (position < 0)
  17. position = PositionManager.manager.register(this);
  18. return position;
  19. }
  20. public void setPos (AbstractSequence seq, int ipos)
  21. {
  22. throw seq.unsupported("setPos");
  23. }
  24. public final boolean isAfter()
  25. {
  26. return (ipos & 1) != 0;
  27. }
  28. public void release ()
  29. {
  30. if (position >= 0)
  31. PositionManager.manager.release(position);
  32. sequence = null;
  33. }
  34. }