Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. private class DoHloubkyIterator implements Iterator<T> {
  2.  
  3. private Zasobnik<Prvek> zasobnik;
  4. private Prvek next;
  5.  
  6. public DoHloubkyIterator() {
  7. zasobnik = new Zasobnik();
  8. next = koren;
  9. if (next == null) {
  10. throw new NullPointerException();
  11. }
  12. zasobnik.vlozPrvek(next);
  13. }
  14.  
  15. @Override
  16. public boolean hasNext() {
  17. return next != null;
  18. }
  19.  
  20. @Override
  21. public T next() {
  22. Prvek tmp;
  23.  
  24. if (!hasNext()) {
  25. throw new NullPointerException();
  26. }
  27. tmp = zasobnik.odeberPrvek();
  28.  
  29. if (tmp.levy != null) {
  30. zasobnik.vlozPrvek(tmp.levy);
  31. }
  32. if (tmp.pravy != null) {
  33. zasobnik.vlozPrvek(tmp.pravy);
  34. }
  35. return (T) tmp;
  36. }
  37.  
  38. }
  39.  
  40.  
  41. @Test
  42. public void TestIterator() {
  43. zk.vlozKoren(to1);
  44. Iterator<TestClass> prohlidka = zk.iterator(eTypProhlidky.HLOUBKY);
  45. assertTrue(prohlidka.hasNext());
  46. assertEquals(to1, prohlidka.next());
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement