Nantes Université

Skip to content
Extraits de code Groupes Projets
Valider c386554e rédigé par Guillaume DOEUVRE's avatar Guillaume DOEUVRE :yawning_face:
Parcourir les fichiers

Merge branch '#58_refactor_mudul-c_Question.java' into 'main'

refactor #58 smell

Closes #58

See merge request !4
parents e9be4a36 f9332e6c
Aucune branche associée trouvée
Aucune étiquette associée trouvée
1 requête de fusion!4refactor #58 smell
......@@ -5,77 +5,70 @@ import java.util.HashMap;
import java.util.Set;
import java.util.Map.Entry;
public class Question implements Serializable
{
public class Question implements Serializable {
private static final long serialVersionUID = 1L;
private String author;
private String statement;
private Category category;
private HashMap<String,Boolean>choices;
public Question(String author,String statement,Category category)
{
private HashMap<String, Boolean> choices;
public Question(String author, String statement, Category category) {
this.author = author;
this.statement = statement;
this.category = category;
this.choices = new HashMap<>(4);
}
/**
* Methode which allows to add a choice of answer for the question.
* @author Rochez Adrien
* @param String
* @param boolean
* @return boolean
*
* @param choice
* @param result
* @return
* @author
*/
public Boolean addChoice(String choice,boolean result)
{
if(result && choices.containsValue(true))
public Boolean addChoice(String choice, boolean result) {
if (result && choices.containsValue(true))
return false;
return choices.put(choice,result);
return choices.put(choice, result);
}
/**
* Methode wich allows to delete a choice of answer for the question
* @param String - statement of the question
*
* @param text - statement of the question
*/
public boolean removeChoice(String text)
{
public boolean removeChoice(String text) {
return choices.remove(text);
}
/**
* M�thode qui v�rifie qu'il existe une r�ponse correcte et qu'il n'y en a pas trop pour la question
* @return boolean
* Méthode qui vérifie qu'il existe une réponse correcte et qu'il n'y en a pas trop pour la question
*
* @return
*/
public boolean verify()
{
int i=0; // Nombre de r�ponse vraie
for(boolean a : choices.values())
{
if(a)
{
public boolean verify() {
int i = 0; // Nombre de réponse vraie
for (boolean a : choices.values()) {
if (a) {
i++;
}
}
switch(i)
{
case 1:
return true;
default:
return false;
switch (i) {
case 1:
return true;
default:
return false;
}
}
public boolean equals(Object o)
{
if(o instanceof Question)
{
Question q = (Question)o;
public boolean equals(Object o) {
if (o instanceof Question) {
Question q = (Question) o;
return this.statement.equals(q.statement);
}
return false;
......@@ -84,72 +77,67 @@ public class Question implements Serializable
public String getAuthor() {
return author;
}
public String getStatement() {
return statement;
}
public Category getCategory(){
public Category getCategory() {
return category;
}
public void setAuthor(String author) {
this.author = author;
}
public void setStatement(String statement) {
this.statement = statement;
}
public void setCategory(Category category){
public void setCategory(Category category) {
this.category = category;
}
public void setChoices(HashMap<String, Boolean> choices) {
this.choices = choices;
}
public HashMap<String, Boolean> getChoices()
{
public HashMap<String, Boolean> getChoices() {
HashMap<String, Boolean> map = new HashMap<>(4);
Set<Entry<String,Boolean>> entrees = choices.entrySet();
for(Entry<String, Boolean> e : entrees){
map.put(new String(e.getKey()), new Boolean(e.getValue()));
Set<Entry<String, Boolean>> entries = choices.entrySet();
for (Entry<String, Boolean> e : entries) {
map.put(e.getKey(), e.getValue());
}
return map;
}
public String toString()
{
String tmp;
int i=0;
tmp = " {\n";
tmp += " \"author\": \"" + author + "\",\n";
tmp += " \"statement\": \"" + statement + "\",\n";
tmp += " \"category\": \"" + category + "\",\n";
tmp += " \"choices\": {\n";
Set<Entry<String,Boolean>> entrees = choices.entrySet();
for(Entry<String, Boolean> e : entrees){
i++;
tmp += " \"" + e.getKey() + "\": " + e.getValue();
if(choices.size()!=i){
tmp += ",";
public String toString() {
final String SEPARATOR = "\",\n";
StringBuilder tmp = new StringBuilder();
tmp.append(" {\n");
tmp.append(" \"author\": \"").append(author).append(SEPARATOR);
tmp.append(" \"statement\": \"").append(statement).append(SEPARATOR);
tmp.append(" \"category\": \"").append(category).append(SEPARATOR);
tmp.append(" \"choices\": {\n");
Set<Entry<String, Boolean>> val = choices.entrySet();
int taille = val.size();
int compteur = 0;
for (Entry<String, Boolean> entry : val) {
tmp.append(" \"").append(entry.getKey()).append("\": ").append(entry.getValue());
if (++compteur < taille) {
tmp.append(SEPARATOR);
} else {
tmp.append("\n");
}
tmp += "\n";
}
tmp += " }\n";
tmp += " },";
return tmp;
tmp.append(" }\n");
tmp.append(" },\n");
return tmp.toString();
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter