Пример #1
0
  public static Collection<Statistic> merge(Collection<Statistic>... results) {
    Collection<Statistic> newResults = new ArrayList<Statistic>();
    if (results.length == 0) {
      return Collections.emptySet();
    } else if (results.length == 1) {
      return results[0];
    } else {

      List<String> indivNames = new ArrayList<String>();
      for (Collection<Statistic> result : results) {
        for (Statistic individual : result) {
          if (!indivNames.contains(individual.name)) {
            indivNames.add(individual.name);
          }
        }
      }

      for (String indivName : indivNames) {
        Statistic indivStat = new Statistic(indivName);
        for (Collection<Statistic> result : results) {
          for (Statistic individual : result) {
            if (indivName.equals(individual.name)) {
              indivStat.add(individual);
            }
          }
        }
        newResults.add(indivStat);
      }
      return newResults;
    }
  }
Пример #2
0
 public static Statistic total(Collection<Statistic>... results) {
   Collection<Statistic> merged = merge(results);
   Statistic total = new Statistic("");
   for (Statistic individual : merged) {
     total.add(individual);
   }
   return total;
 }