diff --git a/src/HierarchicalSystem.java b/src/HierarchicalSystem.java index 88cb36c..46faa55 100644 --- a/src/HierarchicalSystem.java +++ b/src/HierarchicalSystem.java @@ -1,5 +1,7 @@ import codedraw.CodeDraw; +import java.util.NoSuchElementException; + /** * A cosmic system that is composed of a central named body (of type 'NamedBodyForcePair') * and an arbitrary number of subsystems (of type 'CosmicSystem') in its orbit. @@ -136,6 +138,7 @@ public class HierarchicalSystem implements CosmicSystem, MassiveIterable { @Override public Massive next() { + if (!hasNext()) throw new NoSuchElementException(); if (cur != null && cur.hasNext()) return cur.next(); while (i < all.length) { diff --git a/src/MassiveForceTreeMap.java b/src/MassiveForceTreeMap.java index 8b3036e..523fdb1 100644 --- a/src/MassiveForceTreeMap.java +++ b/src/MassiveForceTreeMap.java @@ -1,5 +1,7 @@ import codedraw.CodeDraw; +import java.util.NoSuchElementException; + /** * A map that associates an object of 'Massive' with a Vector3. The number of key-value pairs * is not limited. @@ -124,7 +126,8 @@ public class MassiveForceTreeMap implements MassiveSet { @Override public Massive next() { - if (next == null) return null; + if (!hasNext()) throw new NoSuchElementException(); + Massive m = next.key; Item newNext = (next.right != null) ? next.right.getLeftLeaf() : next.parent; while (newNext != null && newNext.right == next) { diff --git a/src/MassiveLinkedList.java b/src/MassiveLinkedList.java index ebe08c0..31e97d9 100644 --- a/src/MassiveLinkedList.java +++ b/src/MassiveLinkedList.java @@ -1,4 +1,5 @@ import java.util.Iterator; +import java.util.NoSuchElementException; /** * A list of massive objects implemented as a linked list. @@ -184,6 +185,7 @@ public class MassiveLinkedList implements MassiveIterable { @Override public Massive next() { + if (!hasNext()) throw new NoSuchElementException(); if (!yieldedFirst) { yieldedFirst = true; } else {