Java - Problema con TreeMap

 
Vista:
Imágen de perfil de Juan José
Val: 54
Ha mantenido su posición en Java (en relación al último mes)
Gráfica de Java

Problema con TreeMap

Publicado por Juan José (20 intervenciones) el 12/12/2020 20:19:00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public void testSubject() {
		Subject sujeto1 = new Subject("@oswald");
		Subject sujeto2 = new Subject("@edwarD");
		Subject sujeto3 = new Subject("@Alfred");
 
		assertTrue(sujeto1.add("prueba01", 2.0, 5.0, 8.9, 7.2, 0., .0));
		assertFalse(sujeto1.add("prueba01", 6.0, 5.0, 0., 2.0, 2.0)); //Como prueba01 ya existe, se insertan las nuevas puntuaciones
		assertTrue(sujeto2.add("prueba01", 3.0, 2.0, 5.0, 8.0, 5.0));
		assertTrue(sujeto3.add("prueba02", 4., 5., .4, .4));
		assertTrue(sujeto3.add("prueba03", 4., 4., 9.));
 
 
		assertTrue(sujeto1.getMaxPunctuation().equals("8.90"));
		assertEquals(sujeto2.getMaxPunctuation(), "8.00");
		assertEquals(sujeto3.getMaxPunctuation(), "9.00");
 
		assertTrue(sujeto2.getMaxPunctuation("prueba03") == null);
		assertEquals(sujeto1.getMaxPunctuation("prueba01"), "8.90");
		assertTrue(sujeto2.getMaxPunctuation().equals(sujeto2.getMaxPunctuation("prueba01")));
 
		assertEquals(sujeto3.getMaxPunctuation("prueba0"), null);
		assertEquals(sujeto3.getMaxPunctuation("prueba02"), "5.00");
		assertEquals(sujeto3.getMaxPunctuation("prueba03"), "9.00");
}

Mi problema es a la hora de buscar el valor mas alto en el sujeto 3. Sólo puedo leer prueba02, prueba03 es como si no existiera. tengo en la Clase Subject esto:

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
package org.eda1.actividad03;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
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)
		// ...
		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 + " claves = " + this.testsPunctuations.entrySet(); // ...
	}
}

He conseguido leer los otros dos anteriores, pero no puedo leer todas las pruebas de los sujetos. De hecho si probamos:

1
2
3
4
5
6
7
public String getMaxPunctuation() {
		double candidate = Double.MIN_VALUE;
		// 1 for() --> haced uso de Collections.max(array)
		// ...
                System.err.println(this.testsPunctuations.entrySet());
		return String.format(Locale.US, "%.2f", candidate);
	}
Solo encuentra en el sujeto 3 una sola prueba.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder