예제 #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;
 }
예제 #3
0
  public static Collection<Statistic> parse(File inFile)
      throws IOException, XmlPullParserException {
    Collection<Statistic> results = new ArrayList<Statistic>();
    FileInputStream fis = null;
    BufferedInputStream bis = null;
    try {
      fis = new FileInputStream(inFile);
      bis = new BufferedInputStream(fis);
      XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
      factory.setNamespaceAware(true);
      factory.setValidating(false);
      XmlPullParser parser = factory.newPullParser();
      parser.setInput(bis, null);

      // check that the first tag is <javancss>
      expectNextTag(parser, "javancss");

      // skip until we get to the <packages> tag
      while (parser.getDepth() > 0
          && (parser.getEventType() != XmlPullParser.START_TAG
              || !"packages".equals(parser.getName()))) {
        parser.next();
      }
      while (parser.getDepth() > 0
          && (parser.getEventType() != XmlPullParser.START_TAG
              || !"package".equals(parser.getName()))) {
        parser.next();
      }
      while (parser.getDepth() >= 2
          && parser.getEventType() == XmlPullParser.START_TAG
          && "package".equals(parser.getName())) {
        Map<String, String> data = new HashMap<String, String>();
        String lastTag = null;
        String lastText = null;
        int depth = parser.getDepth();
        while (parser.getDepth() >= depth) {
          parser.next();
          switch (parser.getEventType()) {
            case XmlPullParser.START_TAG:
              lastTag = parser.getName();
              break;
            case XmlPullParser.TEXT:
              lastText = parser.getText();
              break;
            case XmlPullParser.END_TAG:
              if (parser.getDepth() == 4 && lastTag != null && lastText != null) {
                data.put(lastTag, lastText);
              }
              lastTag = null;
              lastText = null;
              break;
          }
        }
        if (data.containsKey("name")) {
          Statistic s = new Statistic(data.get("name"));
          s.setClasses(Long.valueOf(data.get("classes")));
          s.setFunctions(Long.valueOf(data.get("functions")));
          s.setNcss(Long.valueOf(data.get("ncss")));
          s.setJavadocs(Long.valueOf(data.get("javadocs")));
          s.setJavadocLines(Long.valueOf(data.get("javadoc_lines")));
          s.setSingleCommentLines(Long.valueOf(data.get("single_comment_lines")));
          s.setMultiCommentLines(Long.valueOf(data.get("multi_comment_lines")));
          results.add(s);
        }
        parser.next();
      }

    } catch (XmlPullParserException e) {
      throw new IOException2(e);
    } finally {
      if (bis != null) {
        bis.close();
      }
      if (fis != null) {
        fis.close();
      }
    }
    return results;
  }