2 Commits

Author SHA1 Message Date
8f6320e069 Finish Übungstest 6 2022-06-02 14:37:11 +02:00
d718ba90e3 Fix AB6, code style 2022-06-02 14:28:43 +02:00
3 changed files with 27 additions and 12 deletions

View File

@@ -113,4 +113,21 @@ public class Aufgabe6Test {
}
assertEquals(12, count);
}
@Test
public void testIterator() {
NamedBody sun1, mercury1, venus1;
sun1 = new NamedBody(SolSystem4.SUN_NAMED);
mercury1 = new NamedBody(SolSystem4.MERCURY_NAMED);
venus1 = new NamedBody(SolSystem4.VENUS_NAMED);
MassiveForceTreeMap map = new MassiveForceTreeMap();
map.put(sun1, new Vector3());
map.put(mercury1, new Vector3());
map.put(venus1, new Vector3());
for (Massive m : map.getKeys().toList()) {
System.out.println(m);
}
}
}

View File

@@ -138,15 +138,13 @@ public class HierarchicalSystem implements CosmicSystem, MassiveIterable {
public Massive next() {
if (cur != null && cur.hasNext()) return cur.next();
for (; i < all.length; i++) {
CosmicSystem sys = all[i];
while (i < all.length) {
CosmicSystem sys = all[i++];
if (sys instanceof NamedBodyForcePair m) {
i++;
return m.getBody();
} else if (sys instanceof HierarchicalSystem hs) {
cur = hs.iterator();
if (cur.hasNext()) {
i++;
return cur.next();
}
}
@@ -159,14 +157,14 @@ public class HierarchicalSystem implements CosmicSystem, MassiveIterable {
public boolean hasNext() {
if (cur != null && cur.hasNext()) return true;
for (; i < all.length; i++) {
while (i < all.length) {
CosmicSystem sys = all[i];
if (sys instanceof NamedBodyForcePair) {
return true;
} else if (sys instanceof HierarchicalSystem hs) {
if (sys instanceof NamedBodyForcePair) return true;
i++;
if (sys instanceof HierarchicalSystem hs) {
cur = hs.iterator();
if (cur.hasNext()) {
i++;
return true;
}
}

View File

@@ -4,7 +4,7 @@ import java.util.Iterator;
* A list of massive objects implemented as a linked list.
* The number of elements of the list is not limited.
*/
public class MassiveLinkedList implements Iterable<Massive> {
public class MassiveLinkedList implements MassiveIterable {
private int size = 0;
private Item first;
private Item last;
@@ -172,8 +172,8 @@ public class MassiveLinkedList implements Iterable<Massive> {
}
@Override
public Iterator<Massive> iterator() {
return new Iterator<>() {
public MassiveIterator iterator() {
return new MassiveIterator() {
Item ptr = first;
boolean yieldedFirst = false;