Iterable
Publicado por Juan José (20 intervenciones) el 13/12/2020 20:29:52
Tengo este código en un JUnit5, tengo una clase de Sujetos, sujeto1 es una instancia de esta clase.
el problema que tengo es que tengo que recorrerlo.
El error que me da el test es:
java.lang.Error: Unresolved compilation problem:
Can only iterate over an array or an instance of java.lang.Iterable
La clase Sujeto sería esta:
¿Cómo soluciono este error en la clase Subject?
el problema que tengo es que tengo que recorrerlo.
El error que me da el test es:
java.lang.Error: Unresolved compilation problem:
Can only iterate over an array or an instance of java.lang.Iterable
1
2
3
4
ArrayList<Pair<String, ArrayList<Double>>> notas = new ArrayList<Pair<String, ArrayList<Double>>>();
for (Pair<String, ArrayList<Double>> par : sujeto1) {
notas.add(par);
}
La clase Sujeto sería esta:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package org.eda1.actividad03;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
public class Subject {
// code = @nombreSujeto
// testPuntuation = "nombrePrueba" : "[double, double...]"
private String code;
private BSTreeMap<String, ArrayList<Double>> testsPunctuations; // par<testName, punctuations>
public Subject(String code) {
this.code = code;
this.testsPunctuations = new BSTreeMap<String, ArrayList<Double>>();
}
public boolean add(String testName, Double... punctuations) {
ArrayList<Double> values = new ArrayList<Double>(Arrays.asList(punctuations));// haced uso de Arrays.asList()
ArrayList<Double> current = testsPunctuations.get(testName);// ...
if (current != null)
this.testsPunctuations.get(testName).addAll(current);
else
testsPunctuations.put(testName, values);// ...
return current == null;
}
public String getMaxPunctuation() {
double candidate = Double.MIN_VALUE;
// 1 for() --> haced uso de Collections.max(array)
// ...
for (ArrayList<Double> it : this.testsPunctuations.values()) {
candidate = Collections.max(it);
}
return String.format(Locale.US, "%.2f", candidate);
}
public String getMaxPunctuation(String testName) {
if (this.testsPunctuations.get(testName) != null) {
ArrayList<Double> punctuations = this.testsPunctuations.get(testName);
return String.format(Locale.US, "%.2f", (Collections.max(punctuations)));
}
return null;
}
public void clear() {
this.testsPunctuations.clear();
}
@Override
public String toString() {
// "@oswald=<1 prueba>"
return this.code + "=<"
+ ((this.testsPunctuations.keySet().size() == 1) ? this.testsPunctuations.keySet().size() + " prueba>"
: this.testsPunctuations.keySet().size() + " pruebas>"); // ...
}
}
¿Cómo soluciono este error en la clase Subject?
Valora esta pregunta


0