Skip to content

Commit

Permalink
Add comments and refactor annotationsToHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
buma committed Aug 17, 2015
1 parent 0148a90 commit 64f1a95
Showing 1 changed file with 14 additions and 11 deletions.
Expand Up @@ -45,12 +45,17 @@ public class AnnotationsToHTML implements GraphBuilderModule {
//Path to output folder
private File outPath;

//If there are more then this number annotations are split into multiple files
//This is because browsers aren't made for giant HTML files which can be made with 500k annotations
private int maxNumberOfAnnotationsPerFile;

Set<String> classes;

Multiset<String> classOccurences;
//This counts all occurrences of HTML annotations classes
//If one annotation class is split into two files it has two entries in this Multiset
//IT is used to show numbers in HTML files name and links
Multiset<String> annotationClassOccurences;

//List of writers which are used for actual writing annotations to HTML
List<HTMLWriter> writers;

//Key is classname, value is annotation message
Expand All @@ -61,9 +66,8 @@ public AnnotationsToHTML (File outpath, int maxNumberOfAnnotationsPerFile) {
this.outPath = outpath;
annotations = ArrayListMultimap.create();
this.maxNumberOfAnnotationsPerFile = maxNumberOfAnnotationsPerFile;
this.classes = new TreeSet<>();
this.writers = new ArrayList<>();
this.classOccurences = HashMultiset.create();
this.annotationClassOccurences = HashMultiset.create();
}


Expand Down Expand Up @@ -123,12 +127,12 @@ public void buildGraph(Graph graph, HashMap<Class<?>, Object> extra) {
//Actual writing to the file is made here since
// this is the first place where actual number of files is known (because it depends on annotations count)
for (HTMLWriter writer : writers) {
writer.writeFile(classOccurences, false);
writer.writeFile(annotationClassOccurences, false);
}

try {
HTMLWriter indexFileWriter = new HTMLWriter("index", (Multimap<String, String>)null);
indexFileWriter.writeFile(classOccurences, true);
indexFileWriter.writeFile(annotationClassOccurences, true);
} catch (FileNotFoundException e) {
LOG.error("Index file coudn't be created:{}", e);
}
Expand All @@ -154,22 +158,21 @@ private void addAnnotations(String annotationClassName, List<String> annotations
LOG.debug("Number of annotations is very large. Splitting: {}", annotationClassName);
List<List<String>> partitions = Lists.partition(annotations, maxNumberOfAnnotationsPerFile);
for (List<String> partition: partitions) {
classOccurences.add(annotationClassName);
int labelCount = classOccurences.count(annotationClassName);
annotationClassOccurences.add(annotationClassName);
int labelCount = annotationClassOccurences.count(annotationClassName);
file_writer =new HTMLWriter(annotationClassName+Integer.toString(labelCount), partition);
writers.add(file_writer);
}

} else {
classOccurences.add(annotationClassName);
int labelCount = classOccurences.count(annotationClassName);
annotationClassOccurences.add(annotationClassName);
int labelCount = annotationClassOccurences.count(annotationClassName);
file_writer = new HTMLWriter(annotationClassName + Integer.toString(labelCount),
annotations);
writers.add(file_writer);
}
} catch (FileNotFoundException ex) {
LOG.error("Output folder not found:{} {}", outPath, ex);
return;
}
}

Expand Down

0 comments on commit 64f1a95

Please sign in to comment.