Skip to content

Commit ae71b6c

Browse files
committed
switch to indexed loops
1 parent af7674d commit ae71b6c

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

‎common-tools/cnuphys/magfield/src/main/java/cnuphys/magfield/CompositeField.java‎

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ public String getName() {
6969
* @return <code>true</code> if we have a torus
7070
*/
7171
public boolean hasTorus() {
72-
for (IMagField field : this) {
73-
if (field instanceof Torus) {
74-
return true;
75-
}
76-
}
77-
78-
return false;
72+
for (int i=0; i<this.size(); i++) {
73+
if (this.get(i) instanceof Torus) {
74+
return true;
75+
}
76+
}
77+
return false;
7978
}
8079

8180
/**
@@ -84,12 +83,11 @@ public boolean hasTorus() {
8483
* @return <code>true</code> if we have a solenoid
8584
*/
8685
public boolean hasSolenoid() {
87-
for (IMagField field : this) {
88-
if (field instanceof Solenoid) {
86+
for (int i=0; i<this.size(); i++) {
87+
if (this.get(i) instanceof Solenoid) {
8988
return true;
9089
}
9190
}
92-
9391
return false;
9492
}
9593

@@ -99,8 +97,8 @@ public boolean hasSolenoid() {
9997
* @return <code>true</code> if we have a transverse solenoid
10098
*/
10199
public boolean hasTransverseSolenoid() {
102-
for (IMagField field : this) {
103-
if (field instanceof TransverseSolenoid) {
100+
for (int i=0; i<this.size(); i++) {
101+
if (this.get(i) instanceof TransverseSolenoid) {
104102
return true;
105103
}
106104
}
@@ -111,35 +109,35 @@ public boolean hasTransverseSolenoid() {
111109
@Override
112110
public float getB1(int index) {
113111
float b = 0f;
114-
for (IMagField field : this) {
115-
b += field.getB1(index);
112+
for (int i=0; i<this.size(); i++) {
113+
b += this.get(i).getB1(index);
116114
}
117115
return b;
118116
}
119117

120118
@Override
121119
public float getB2(int index) {
122120
float b = 0f;
123-
for (IMagField field : this) {
124-
b += field.getB2(index);
121+
for (int i=0; i<this.size(); i++) {
122+
b += this.get(i).getB2(index);
125123
}
126124
return b;
127125
}
128126

129127
@Override
130128
public float getB3(int index) {
131129
float b = 0f;
132-
for (IMagField field : this) {
133-
b += field.getB3(index);
130+
for (int i=0; i<this.size(); i++) {
131+
b += this.get(i).getB3(index);
134132
}
135133
return b;
136134
}
137135

138136
@Override
139137
public float getMaxFieldMagnitude() {
140138
float max = 0;
141-
for (IMagField field : this) {
142-
max = Math.max(max, field.getMaxFieldMagnitude());
139+
for (int i=0; i<this.size(); i++) {
140+
max = Math.max(max, this.get(i).getMaxFieldMagnitude());
143141
}
144142
return max;
145143
}
@@ -157,16 +155,15 @@ public double getScaleFactor() {
157155
@Override
158156
public void printConfiguration(PrintStream ps) {
159157
ps.println("COMPOSITE FIELD");
160-
for (IMagField field : this) {
161-
field.printConfiguration(ps);
162-
158+
for (int i=0; i<this.size(); i++) {
159+
this.get(i).printConfiguration(ps);
163160
}
164161
}
165162

166163
@Override
167164
public boolean contains(double x, double y, double z) {
168-
for (IMagField field : this) {
169-
if (field.contains(x, y, z)) {
165+
for (int i=0; i<this.size(); i++) {
166+
if (this.get(i).contains(x, y, z)) {
170167
return true;
171168
}
172169
}

0 commit comments

Comments
 (0)