PageRenderTime 45ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Dependencies/boo/lib/antlr-2.7.5/antlr/collections/impl/LLEnumeration.java

https://github.com/w4x/boolangstudio
Java | 54 lines | 26 code | 9 blank | 19 comment | 3 complexity | de372640dd4e9d83afeb5498de2c79bb MD5 | raw file
Possible License(s): GPL-2.0
  1. package antlr.collections.impl;
  2. /* ANTLR Translator Generator
  3. * Project led by Terence Parr at http://www.jGuru.com
  4. * Software rights: http://www.antlr.org/license.html
  5. *
  6. * $Id: //depot/code/org.antlr/release/antlr-2.7.5/antlr/collections/impl/LLEnumeration.java#1 $
  7. */
  8. import antlr.collections.List;
  9. import antlr.collections.Stack;
  10. import java.util.Enumeration;
  11. import java.util.NoSuchElementException;
  12. import antlr.collections.impl.LLCell;
  13. /**An enumeration of a LList. Maintains a cursor through the list.
  14. * bad things would happen if the list changed via another thread
  15. * while we were walking this list.
  16. */
  17. final class LLEnumeration implements Enumeration {
  18. LLCell cursor;
  19. LList list;
  20. /**Create an enumeration attached to a LList*/
  21. public LLEnumeration(LList l) {
  22. list = l;
  23. cursor = list.head;
  24. }
  25. /** Return true/false depending on whether there are more
  26. * elements to enumerate.
  27. */
  28. public boolean hasMoreElements() {
  29. if (cursor != null)
  30. return true;
  31. else
  32. return false;
  33. }
  34. /**Get the next element in the enumeration. Destructive in that
  35. * the returned element is removed from the enumeration. This
  36. * does not affect the list itself.
  37. * @return the next object in the enumeration.
  38. */
  39. public Object nextElement() {
  40. if (!hasMoreElements()) throw new NoSuchElementException();
  41. LLCell p = cursor;
  42. cursor = cursor.next;
  43. return p.data;
  44. }
  45. }