-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCriterio2.cpp
93 lines (83 loc) · 3.14 KB
/
Criterio2.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "Criterio2.h"
#include "interfaces/ICollection.h"
#include "interfaces/IIterator.h"
#include "ManejadorEstudiante.h"
#include "DataEstudiante.h"
#include "Integer.h"
#include "collections/OrderedDictionary.h"
// constructor
Criterio2::Criterio2()
{
}
// destructor
Criterio2::~Criterio2()
{
}
// Sugiere una materia de las asignaturas seleccionadas tal que algun Estudiante haya aprobada.
// En caso que no exista se retorna un ICollection vacio (List).
IDictionary *Criterio2::devolverListaAsignatura(IDictionary* asigsUsuario)
{
// pedimos los estudiantes al manejador y vamos recorriendo uno a uno hasta encontrar alguno que tenga materias
// aprobadas, en ese caso retornamos esa lista
ManejadorEstudiante *eMgr = ManejadorEstudiante::getInstance();
IDictionary *e = eMgr->getEstudiantes();
bool found = false;
ICollection *aprobadas;
IDictionary *asignaturasNuevas = new OrderedDictionary();
IIterator * it = e->getIterator();
Estudiante *est;
ICollectible *col;
ICollectible *col2;
ICollectible *col3;
while(it->hasCurrent() && !found)
{
col = it->getCurrent();
if ((est = dynamic_cast<Estudiante*> (col)) != NULL)
{
if(est->getAprobadas() != NULL)
{
aprobadas = est->getAprobadas();
IIterator * it2 = aprobadas->getIterator();
while(it2->hasCurrent() && !found)
{
col2 = it2->getCurrent();
Aprobacion* apro;
if ((apro = dynamic_cast<Aprobacion*> (col2)) != NULL)
{
Asignatura* asig = apro->getAsignatura();
IIterator * it3 = asigsUsuario->getIterator();
while(it3->hasCurrent() && !found)
{
col3 = it3->getCurrent();
Asignatura* asigUsu;
if ((asigUsu = dynamic_cast<Asignatura*> (col3)) != NULL)
{
if(asig->getCodigo() == asigUsu->getCodigo())
{
Integer* cod = new Integer(asig->getCodigo());
asignaturasNuevas->add(cod, asigUsu);
found = true;
}
} else {
throw "Criterio1: el parametro no es del tipo Asignatura";
}
it3->next();
}
delete it3;
} else {
throw "Criterio1: el parametro no es del tipo Aprobacion";
}
it2->next();
}
delete it2;
}
} else {
throw "Criterio1: el parametro no es del tipo Estudiante";
}
it->next();
}
delete it;
//if(!found)
//asignaturas = new OrderedDictionary();
return asignaturasNuevas;
}