示例#1
0
 public static String serialize(Poll... polls) {
   StringBuilder sb = new StringBuilder();
   sb.append("PollTitle;PollDescription");
   sb.append("\r\n");
   for (Poll poll : polls) {
     sb.append(convert(poll.getTitle()));
     sb.append('"').append(poll.getDescription()).append('"');
     sb.append("\r\n");
   }
   return sb.toString();
 }
示例#2
0
 public static boolean toCsv(String fullyNamedPath, Poll poll) {
   StringBuilder sb = new StringBuilder();
   sb.append(String.format("Questions;Answer;Votes;WeightedVotes;%n"));
   for (Question question : poll.getQuestions()) {
     for (Answer answer : question.getAnswers()) {
       int votesCount = answer.getVotes().size();
       int weightedVotesCount = answer.getVotes().size() * answer.getValue();
       String questionTitle = question.getTitle().replace("\"", "\"\"");
       String answerText = answer.getText().replace("\"", "\"\"");
       sb.append(
           String.format(
               "\"%s\";\"%s\";%s;%s;%n",
               questionTitle, answerText, votesCount, weightedVotesCount));
     }
   }
   return write(fullyNamedPath, sb.toString());
 }