2 Commits

Author SHA1 Message Date
cda144aa2a Refactor List and Tree 2022-04-04 12:48:13 +02:00
4bb1d6a36c AB3: Fix toString() 2022-03-31 22:08:42 +02:00
4 changed files with 88 additions and 85 deletions

View File

@@ -86,13 +86,14 @@ public class BodyForceTreeMap {
return this.size;
}
private String toString(BodyForceTreeMapItem item, String indent) {
private String toString(BodyForceTreeMapItem item) {
String s = "";
if (item == null) {
return "";
return s;
}
String s = String.format("%s{%s: %s}\n", indent, item.key(), item.value());
s += this.toString(item.left(), indent + "| ");
s += this.toString(item.right(), indent + "| ");
s += this.toString(item.right());
s += String.format("{%s: %s}\n", item.key(), item.value());
s += this.toString(item.left());
return s;
}
@@ -101,6 +102,53 @@ public class BodyForceTreeMap {
* descending according to the mass of the bodies.
*/
public String toString() {
return toString(root, "");
return toString(root);
}
}
class BodyForceTreeMapItem {
private final Body key;
private Vector3 value;
private BodyForceTreeMapItem parent;
private BodyForceTreeMapItem left;
private BodyForceTreeMapItem right;
public BodyForceTreeMapItem(Body key, Vector3 value) {
this.key = key;
this.value = value;
}
public Body key() {
return this.key;
}
public void setValue(Vector3 value) {
this.value = value;
}
public Vector3 value() {
return this.value;
}
public BodyForceTreeMapItem left() {
return this.left;
}
public BodyForceTreeMapItem right() {
return this.right;
}
public BodyForceTreeMapItem parent() {
return this.parent;
}
public void setLeft(BodyForceTreeMapItem left) {
this.left = left;
if (left != null) left.parent = this;
}
public void setRight(BodyForceTreeMapItem right) {
this.right = right;
if (right != null) right.parent = this;
}
}

View File

@@ -1,46 +0,0 @@
class BodyForceTreeMapItem {
private final Body key;
private Vector3 value;
private BodyForceTreeMapItem parent;
private BodyForceTreeMapItem left;
private BodyForceTreeMapItem right;
public BodyForceTreeMapItem(Body key, Vector3 value) {
this.key = key;
this.value = value;
}
public Body key() {
return this.key;
}
public void setValue(Vector3 value) {
this.value = value;
}
public Vector3 value() {
return this.value;
}
public BodyForceTreeMapItem left() {
return this.left;
}
public BodyForceTreeMapItem right() {
return this.right;
}
public BodyForceTreeMapItem parent() {
return this.parent;
}
public void setLeft(BodyForceTreeMapItem left) {
this.left = left;
if (left != null) left.parent = this;
}
public void setRight(BodyForceTreeMapItem right) {
this.right = right;
if (right != null) right.parent = this;
}
}

View File

@@ -225,3 +225,37 @@ public class BodyLinkedList implements Iterable<Body> {
};
}
}
class BodyLinkedListItem {
private final Body body;
private BodyLinkedListItem prev;
private BodyLinkedListItem next;
public BodyLinkedListItem(Body body) {
this.body = body;
this.prev = null;
this.next = null;
}
public Body body() {
return body;
}
public BodyLinkedListItem prev() {
return prev;
}
public void setPrev(BodyLinkedListItem prev) {
this.prev = prev;
if (prev != null) prev.next = this;
}
public BodyLinkedListItem next() {
return next;
}
public void setNext(BodyLinkedListItem next) {
this.next = next;
if (next != null) next.prev = this;
}
}

View File

@@ -1,33 +0,0 @@
class BodyLinkedListItem {
private final Body body;
private BodyLinkedListItem prev;
private BodyLinkedListItem next;
public BodyLinkedListItem(Body body) {
this.body = body;
this.prev = null;
this.next = null;
}
public Body body() {
return body;
}
public BodyLinkedListItem prev() {
return prev;
}
public void setPrev(BodyLinkedListItem prev) {
this.prev = prev;
if (prev != null) prev.next = this;
}
public BodyLinkedListItem next() {
return next;
}
public void setNext(BodyLinkedListItem next) {
this.next = next;
if (next != null) next.prev = this;
}
}