analyseCalc/src/calcul/calculNombrePointEvaluation...

102 lines
3.3 KiB
Java

package calcul;
import java.util.ArrayList;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import nodeAC.nodeAC;
public class calculNombrePointEvaluation {
/**
* Ensemble des points dans les différents node principaux.
* @return
*/
public static ArrayList<String> calculPointDansToutExercice(){
ArrayList<String> ListeNodeEvaluer = new ArrayList<String>();;
for(int i = 0 ; i < calc.commandes.sujet.getNodes().size();i++) {
if(!calc.commandes.sujet.getNodes().get(i).getNomElt().equals("setting")) {
ListeNodeEvaluer.add(calc.commandes.sujet.getNodes().get(i).getNomElt() + " " +
String.valueOf(calculNombreDepoint(calc.commandes.sujet.getNodes().get(i), 0)) + " " +
String.valueOf(calc.commandes.sujet.getNodes().get(i).getAttributs().get("poids")));
}
}
return ListeNodeEvaluer;
}
public static int calculNombreDepoint(nodeAC nod, int point) {
if(nod.getAttributs().get("evaluer")!=null) if(nod.getAttributs().get("evaluer").equalsIgnoreCase("true")){
if(nod.getAttributs().get("allContent")!=null) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get("allContent"));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut allContent");
}
System.out.println("match point pour allcontent = " + s);
}
}
if(nod.getAttributs().get("evalNameInitialCreator")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameInitialCreator"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameInitialCreator");
}
}
if(nod.getAttributs().get("evalNameCreator")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameCreator"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameCreator");
}
}
if(nod.getAttributs().get("evalNameNode")!=null) {
try {
point = point + Integer.valueOf(nod.getAttributs().get("evalNameNode"));
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut evalNameCreator");
}
}
Set<String> key = nod.getAttributs().keySet();
for (String k : key) {
if(nod.getAttributs().get(k).contains("")||nod.getAttributs().get(k).contains("")) {
Pattern pt = Pattern.compile("[0-9]{1,}$");
Matcher match= pt.matcher(nod.getAttributs().get(k));
if(match.find()) {
String s= match.group();
try {
point = point + Integer.valueOf(s);
} catch (Exception e) {
JOptionPane.showInternalMessageDialog(null, "Erreur dans la valeur de l'attribut "+ k);
}
}
}
}
for(int i = 0 ; i < nod.getNodes().size();i++) {
if(nod.getNodes().get(i)!=null) {
point = calculNombreDepoint(nod.getNodes().get(i), point);
}
}
}
return point;
}
}