[fix] SymmetricComponent.get{Next|Prev}SymmetricComponent simply retrieves next symmetric *sibling*.

This commit is contained in:
Daniel_M_Williams 2020-05-02 11:56:40 -04:00
parent 8288de651f
commit 3e3b5dc655
2 changed files with 44 additions and 46 deletions

View File

@ -1630,9 +1630,26 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
}
return null;
}
// TODO: Move these methods elsewhere (used only in SymmetricComponent)
public final RocketComponent getNextComponent() {
checkState();
if (getChildCount() > 0)
return getChild(0);
RocketComponent current = this;
RocketComponent nextParent = this.parent;
while (nextParent != null) {
int pos = nextParent.getChildPosition(current);
if (pos < nextParent.getChildCount() - 1)
return nextParent.getChild(pos + 1);
current = nextParent;
nextParent = current.parent;
}
return null;
}
public final RocketComponent getPreviousComponent() {
checkState();
this.checkComponentStructure();
@ -1662,28 +1679,7 @@ public abstract class RocketComponent implements ChangeSource, Cloneable, Iterab
c = c.getChild(c.getChildCount() - 1);
return c;
}
// TODO: Move these methods elsewhere (used only in SymmetricComponent)
public final RocketComponent getNextComponent() {
checkState();
if (getChildCount() > 0)
return getChild(0);
RocketComponent current = this;
RocketComponent nextParent = this.parent;
while (nextParent != null) {
int pos = nextParent.getChildPosition(current);
if (pos < nextParent.getChildCount() - 1)
return nextParent.getChild(pos + 1);
current = nextParent;
nextParent = current.parent;
}
return null;
}
/////////// Event handling //////////
//
// Listener lists are provided by the root Rocket component,

View File

@ -566,17 +566,17 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial
* @return the previous SymmetricComponent, or null.
*/
public final SymmetricComponent getPreviousSymmetricComponent() {
RocketComponent c;
for (c = this.getPreviousComponent(); c != null; c = c.getPreviousComponent()) {
if (c instanceof PodSet) {
return null;
}
if (c instanceof SymmetricComponent) {
return (SymmetricComponent) c;
}
if (!(c instanceof AxialStage) &&
(c.axialMethod == AxialMethod.AFTER)) {
return null; // Bad component type as "parent"
if(null == this.parent) {
return null;
}
int pos = parent.getChildPosition(this);
while( 0 < pos ) {
--pos;
final RocketComponent comp = parent.getChild(pos);
if (comp instanceof SymmetricComponent) {
return (SymmetricComponent) comp;
}
}
return null;
@ -588,17 +588,19 @@ public abstract class SymmetricComponent extends BodyComponent implements Radial
* @return the next SymmetricComponent, or null.
*/
public final SymmetricComponent getNextSymmetricComponent() {
RocketComponent c;
for (c = this.getNextComponent(); c != null; c = c.getNextComponent()) {
if (c instanceof PodSet) {
return null;
if(null == this.parent) {
return null;
}
int pos = parent.getChildPosition(this);
++pos;
while( pos < parent.getChildCount() ) {
final RocketComponent comp = parent.getChild(pos);
++pos;
if (comp instanceof SymmetricComponent) {
return (SymmetricComponent) comp;
}
if (c instanceof SymmetricComponent) {
return (SymmetricComponent) c;
}
if (!(c instanceof AxialStage) &&
(c.axialMethod == AxialMethod.AFTER))
return null; // Bad component type as "parent"
}
return null;
}