Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
@SuppressWarnings("serial")
public class CompositeField extends ArrayList<IMagField> implements IMagField {

boolean _hasTorus;
boolean _hasSolenoid;

/**
* Checks whether the field has been set to always return zero.
*
Expand Down Expand Up @@ -43,7 +46,16 @@ public boolean add(IMagField field) {
}
}

return super.add(field);
_hasSolenoid = false;
_hasTorus = false;
if (super.add(field)) {
for (IMagField ifield : this) {
if (ifield instanceof Solenoid) _hasSolenoid = true;
if (ifield instanceof Torus) _hasTorus = true;
}
return true;
}
return false;
}

@Override
Expand All @@ -69,13 +81,7 @@ public String getName() {
* @return <code>true</code> if we have a torus
*/
public boolean hasTorus() {
for (IMagField field : this) {
if (field instanceof Torus) {
return true;
}
}

return false;
return _hasTorus;
}

/**
Expand All @@ -84,13 +90,7 @@ public boolean hasTorus() {
* @return <code>true</code> if we have a solenoid
*/
public boolean hasSolenoid() {
for (IMagField field : this) {
if (field instanceof Solenoid) {
return true;
}
}

return false;
return _hasSolenoid;
}

/**
Expand Down