r3415 - trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services
Author: tchemit Date: 2012-06-03 13:15:13 +0200 (Sun, 03 Jun 2012) New Revision: 3415 Url: http://chorem.org/repositories/revision/pollen/3415 Log: fix format code + usage of for-each Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java Modified: trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java =================================================================== --- trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java 2012-06-03 09:40:52 UTC (rev 3414) +++ trunk/pollen-votecounting/src/main/java/org/chorem/pollen/votecounting/services/ServiceExportImpl.java 2012-06-03 11:15:13 UTC (rev 3415) @@ -23,12 +23,6 @@ */ package org.chorem.pollen.votecounting.services; -import java.io.File; -import java.io.FileOutputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.chorem.pollen.common.ChoiceType; @@ -50,6 +44,11 @@ import org.jdom.output.Format; import org.jdom.output.XMLOutputter; +import java.io.File; +import java.io.FileOutputStream; +import java.util.ArrayList; +import java.util.List; + /** * Implémentation du service d'export. * @@ -57,7 +56,6 @@ * @author rannou * @version $Id$ */ -@SuppressWarnings("unchecked") public class ServiceExportImpl implements ServiceExport { private PollDTO poll; @@ -71,9 +69,7 @@ /** log. */ private static final Log log = LogFactory.getLog(ServiceExportImpl.class); - /** - * Constructor - */ + /** Constructor */ public ServiceExportImpl() { } @@ -121,8 +117,7 @@ /** * Construction du document XML à partir du sondage. * - * @param le chemin du fichier à créer - * @return le fichier créé + * @param filePath le chemin du fichier à créer */ private void savePoll(String filePath) { @@ -138,16 +133,16 @@ pollElm.setAttribute("voteCounting", poll.getVoteCounting().name()); pollElm.setAttribute("closed", poll.isClosed() ? "true" : "false"); pollElm.setAttribute("choiceAddAllowed", - poll.isChoiceAddAllowed() ? "true" : "false"); + poll.isChoiceAddAllowed() ? "true" : "false"); pollElm.setAttribute("anonymousVoteAllowed", poll - .isAnonymousVoteAllowed() ? "true" : "false"); + .isAnonymousVoteAllowed() ? "true" : "false"); pollElm .setAttribute("anonymous", poll.isAnonymous() ? "true" - : "false"); + : "false"); pollElm.setAttribute("publicResults", poll.isPublicResults() ? "true" - : "false"); + : "false"); pollElm.setAttribute("continuousResults", - poll.isContinuousResults() ? "true" : "false"); + poll.isContinuousResults() ? "true" : "false"); Element titleElm = new Element("title"); titleElm.setText(poll.getTitle()); @@ -172,9 +167,8 @@ // Création des commentaires Element commentsElm = new Element("comments"); - Iterator iteratorComment = poll.getComments().listIterator(); - while (iteratorComment.hasNext()) { - Element commentElm = save((CommentDTO) iteratorComment.next()); + for (CommentDTO commentDTO : poll.getComments()) { + Element commentElm = save(commentDTO); commentsElm.addContent(commentElm); } @@ -183,9 +177,8 @@ // Création des groupes de votants Element groupsElm = new Element("groups"); - Iterator iteratorGroup = poll.getVotingGroups().listIterator(); - while (iteratorGroup.hasNext()) { - Element groupElm = save((VotingGroupDTO) iteratorGroup.next()); + for (VotingGroupDTO votingGroupDTO : poll.getVotingGroups()) { + Element groupElm = save(votingGroupDTO); groupsElm.addContent(groupElm); } @@ -194,9 +187,8 @@ // Création des choix Element pollChoicesElm = new Element("pollChoices"); - Iterator itPollChoices = poll.getChoices().listIterator(); - while (itPollChoices.hasNext()) { - Element pollChoiceElm = save((PollChoiceDTO) itPollChoices.next()); + for (PollChoiceDTO pollChoiceDTO : poll.getChoices()) { + Element pollChoiceElm = save(pollChoiceDTO); pollChoicesElm.addContent(pollChoiceElm); } pollElm.addContent(pollChoicesElm); @@ -204,11 +196,8 @@ // Création des résultats Element voteCountingResultsElm = new Element("voteCountingResults"); - Iterator iteratorvoteCountingResults = voteCountingResults - .listIterator(); - while (iteratorvoteCountingResults.hasNext()) { - Element voteCountingResult = save((VoteCountingResultDTO) iteratorvoteCountingResults - .next()); + for (VoteCountingResultDTO voteCountingResult1 : voteCountingResults) { + Element voteCountingResult = save(voteCountingResult1); voteCountingResultsElm.addContent(voteCountingResult); } @@ -242,11 +231,8 @@ Element votingPersonsElm = new Element("votingPersons"); - Iterator iteratorVotingPersons = group.getVotingPersons() - .listIterator(); - while (iteratorVotingPersons.hasNext()) { - Element votingPersonElm = save((VotingPersonDTO) iteratorVotingPersons - .next()); + for (VotingPersonDTO votingPersonDTO : group.getVotingPersons()) { + Element votingPersonElm = save(votingPersonDTO); votingPersonsElm.addContent(votingPersonElm); } groupElm.addContent(votingPersonsElm); @@ -259,7 +245,7 @@ votingPersonElm.setAttribute("votingId", votingPerson.getVotingId()); votingPersonElm.setAttribute("weight", Double.toString(votingPerson - .getWeight())); + .getWeight())); Element emailElm = new Element("email"); emailElm.setText(votingPerson.getEmail()); @@ -271,14 +257,11 @@ Element choicesElm = new Element("choices"); - Iterator iteratorChoices = votingPerson.getChoices().listIterator(); - while (iteratorChoices.hasNext()) { - VoteToChoiceDTO voteToChoice = (VoteToChoiceDTO) iteratorChoices - .next(); + for (VoteToChoiceDTO voteToChoice : votingPerson.getChoices()) { Element choiceElm = new Element("choice"); choiceElm.setAttribute("idChoice", voteToChoice.getIdChoice()); choiceElm.setAttribute("value", Double.toString(voteToChoice - .getValue())); + .getValue())); choicesElm.addContent(choiceElm); } @@ -323,10 +306,8 @@ Element choicesElm = new Element("choices"); - Iterator iteratorChoices = voteCountingResults.getChoices() - .listIterator(); - while (iteratorChoices.hasNext()) { - Element choiceElm = save((ChoiceDTO) iteratorChoices.next()); + for (ChoiceDTO choiceDTO : voteCountingResults.getChoices()) { + Element choiceElm = save(choiceDTO); choicesElm.addContent(choiceElm); } @@ -371,7 +352,7 @@ sortie.output(document, new FileOutputStream(file)); } catch (java.io.IOException e) { log.error("Erreur lors de l'enregistrement du document : " - + filePath, e); + + filePath, e); } } @@ -391,25 +372,25 @@ poll.setCreatorId(pollElm.getChild("creatorId").getText()); poll.setCreatorEmail(pollElm.getChild("creatorEmail").getText()); poll.setMaxChoiceNb(Integer.parseInt(pollElm.getChild("maxChoiceNb") - .getText())); + .getText())); poll.setPollType(PollType - .valueOf(pollElm.getAttributeValue("pollType"))); + .valueOf(pollElm.getAttributeValue("pollType"))); poll.setChoiceType(ChoiceType.valueOf(pollElm - .getAttributeValue("choiceType"))); + .getAttributeValue("choiceType"))); poll.setVoteCounting(VoteCountingType.valueOf(pollElm - .getAttributeValue("voteCounting"))); + .getAttributeValue("voteCounting"))); poll.setClosed(Boolean.valueOf(pollElm.getAttributeValue("closed"))); poll.setChoiceAddAllowed(Boolean.valueOf(pollElm - .getAttributeValue("choiceAddAllowed"))); + .getAttributeValue("choiceAddAllowed"))); poll.setAnonymousVoteAllowed(Boolean.valueOf(pollElm - .getAttributeValue("anonymousVoteAllowed"))); + .getAttributeValue("anonymousVoteAllowed"))); poll.setAnonymous(Boolean.valueOf(pollElm - .getAttributeValue("anonymous"))); + .getAttributeValue("anonymous"))); poll.setPublicResults(Boolean.valueOf(pollElm - .getAttributeValue("publicResults"))); + .getAttributeValue("publicResults"))); poll.setContinuousResults(Boolean.valueOf(pollElm - .getAttributeValue("continuousResults"))); + .getAttributeValue("continuousResults"))); // Ajout des commentaires Element commentsElm = pollElm.getChild("comments"); @@ -451,11 +432,10 @@ private List loadComments(List<Element> listComments) { List vectorComments = new ArrayList<CommentDTO>(); - Iterator i = listComments.listIterator(); - while (i.hasNext()) { - Element commentElm = (Element) i.next(); - CommentDTO comment = new CommentDTO(commentElm - .getAttributeValue("votingId"), commentElm.getText()); + for (Element commentElm : listComments) { + CommentDTO comment = new CommentDTO( + commentElm.getAttributeValue("votingId"), + commentElm.getText()); vectorComments.add(comment); } @@ -465,12 +445,10 @@ private List loadGroups(List<Element> listGroups) { List vectorGroups = new ArrayList<VotingGroupDTO>(); - Iterator i = listGroups.listIterator(); - while (i.hasNext()) { - Element groupElm = (Element) i.next(); - VotingGroupDTO group = new VotingGroupDTO(groupElm - .getAttributeValue("idGroup"), Double.parseDouble((groupElm - .getAttributeValue("weight")))); + for (Element groupElm : listGroups) { + VotingGroupDTO group = new VotingGroupDTO( + groupElm.getAttributeValue("idGroup"), + Double.parseDouble((groupElm.getAttributeValue("weight")))); group.setName(groupElm.getAttributeValue("name")); @@ -490,16 +468,14 @@ private List loadVotingPersons(List<Element> listVotingPersons) { List vectorVotingPersons = new ArrayList<VotingPersonDTO>(); - Iterator i = listVotingPersons.listIterator(); - while (i.hasNext()) { - Element votingPersonElm = (Element) i.next(); - VotingPersonDTO votingPerson = new VotingPersonDTO(votingPersonElm - .getAttributeValue("votingId"), Double + for (Element votingPersonElm : listVotingPersons) { + VotingPersonDTO votingPerson = new VotingPersonDTO( + votingPersonElm.getAttributeValue("votingId"), Double .parseDouble((votingPersonElm.getAttributeValue("weight")))); votingPerson.setEmail(votingPersonElm.getChild("email").getValue()); - votingPerson.setComment(votingPersonElm.getChild("comment") - .getValue()); + votingPerson.setComment( + votingPersonElm.getChild("comment").getValue()); Element choicesElm = votingPersonElm.getChild("choices"); @@ -516,12 +492,9 @@ private List loadVoteToChoices(List<Element> listVoteToChoices) { List vectorVoteToChoices = new ArrayList<VotingPersonDTO>(); - Iterator i = listVoteToChoices.listIterator(); - while (i.hasNext()) { - Element voteToChoiceElm = (Element) i.next(); - - VoteToChoiceDTO voteToChoice = new VoteToChoiceDTO(voteToChoiceElm - .getAttributeValue("idChoice"), Double + for (Element voteToChoiceElm : listVoteToChoices) { + VoteToChoiceDTO voteToChoice = new VoteToChoiceDTO( + voteToChoiceElm.getAttributeValue("idChoice"), Double .parseDouble(voteToChoiceElm.getAttributeValue("value"))); vectorVoteToChoices.add(voteToChoice); } @@ -532,19 +505,17 @@ private List loadPollChoices(List<Element> listPollChoices) { List vectorPollChoices = new ArrayList<PollChoiceDTO>(); - Iterator i = listPollChoices.listIterator(); - while (i.hasNext()) { - Element pollChoiceElm = (Element) i.next(); - PollChoiceDTO pollChoice = new PollChoiceDTO(pollChoiceElm - .getAttributeValue("idChoice")); + for (Element pollChoiceElm : listPollChoices) { + PollChoiceDTO pollChoice = new PollChoiceDTO( + pollChoiceElm.getAttributeValue("idChoice")); String pollChoiceName = pollChoiceElm.getChild("name").getValue(); pollChoice.setName(pollChoiceName); pollChoice.setHidden(pollChoiceName != null - && pollChoiceName.startsWith(NumberMethod.HIDDEN_PREFIX)); + && pollChoiceName.startsWith(NumberMethod.HIDDEN_PREFIX)); - pollChoice.setDescription(pollChoiceElm.getChild("description") - .getValue()); + pollChoice.setDescription( + pollChoiceElm.getChild("description").getValue()); vectorPollChoices.add(pollChoice); } @@ -555,20 +526,18 @@ private List loadVoteCountingResults(List<Element> listVoteCountingResults) { List vectorVoteCountingResults = new ArrayList<VoteCountingResultDTO>(); - Iterator i = listVoteCountingResults.listIterator(); - while (i.hasNext()) { - Element voteCountingResultElm = (Element) i.next(); + for (Element voteCountingResultElm : listVoteCountingResults) { VoteCountingResultDTO voteCountingResult = new VoteCountingResultDTO(); - voteCountingResult.setIdPoll(voteCountingResultElm - .getAttributeValue("idPoll")); - voteCountingResult.setNbVotes(Integer - .parseInt(voteCountingResultElm.getChild("nbVotes") - .getValue())); + voteCountingResult.setIdPoll( + voteCountingResultElm.getAttributeValue("idPoll")); + voteCountingResult.setNbVotes( + Integer.parseInt(voteCountingResultElm.getChild("nbVotes") + .getValue())); voteCountingResult.setChoiceResult(voteCountingResultElm.getChild( "choiceResult").getValue()); - voteCountingResult.setByGroup(Boolean - .parseBoolean((voteCountingResultElm.getChild("isByGroup") - .getValue()))); + voteCountingResult.setByGroup( + Boolean.parseBoolean( + voteCountingResultElm.getChild("isByGroup").getValue())); Element choicesElm = voteCountingResultElm.getChild("choices"); List<Element> listChoices = choicesElm.getChildren("choice"); @@ -583,14 +552,12 @@ private List loadChoices(List<Element> listChoices) { List vectorChoices = new ArrayList<ChoiceDTO>(); - Iterator i = listChoices.listIterator(); - while (i.hasNext()) { - Element choiceElm = (Element) i.next(); - ChoiceDTO choice = new ChoiceDTO(choiceElm.getAttribute("idChoice") - .getName(), Double.parseDouble(choiceElm.getAttribute( - "value").getValue()), Double.parseDouble(choiceElm - .getChild("percentage").getValue()), Integer - .parseInt((choiceElm.getChild("nbVotes").getValue()))); + for (Element choiceElm : listChoices) { + ChoiceDTO choice = new ChoiceDTO( + choiceElm.getAttribute("idChoice").getName(), + Double.parseDouble(choiceElm.getAttribute("value").getValue()), + Double.parseDouble(choiceElm.getChild("percentage").getValue()), + Integer.parseInt((choiceElm.getChild("nbVotes").getValue()))); vectorChoices.add(choice); }
participants (1)
-
tchemit@users.chorem.org