Gathering metadata on files in GitHub I am a relatively new programmer and am currently working on something with the egit GitHub client library which requires me to iterate over a bunch of values and if a condition is met, add a bunch of stuff to a HashMap then add it to a List.

Example:

List&lt;Map&lt;String, Object&gt;&gt; files = new ArrayList&lt;&gt;();

for (TreeEntry file : fileList) {
  if ("blob".equals(file.getType())) {
    files.add(new HashMap&lt;String, Object&gt;() {
      {
        put("sha", file.getSha());
        put("path", file.getPath());
        put("name", GitHubHelper.getNameFromPath(file.getPath()));
        put("size", Objects.toString(file.getSize()));
        put("commits", GitHubHelper.getCommits(config, repo, file.getPath()));
      }
    });
  }
}


As far as I understand it, this is almost the same as

Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
map.put(key, value)


with the only exception that the class is anonymous, which in this case doesn't bother me since I'm adding it to a list and returning it anyway.

Questions:


Is the Double-Brace Initialization example different in performance and, in this case in particular, is there any reason why I might choose to do it the regular way? As far as I understand DBI, this should be about the same in terms of performance or am I wrong?
Same as Question #1, however, what if in addition to all of this, in this end, I want to return two things as opposed to one. Does that change anything? In my case, I also want to return the repository object these files belong to.

return new HashMap&lt;Repository, List&lt;Map&lt;String, Object&gt;&gt;&gt;() {
    {
        put(repo, files);
    }
};

To me, the code looks kind of nice like this. But it kind of feels as if this isn't really the right way. Is there any way I can do this better (tidier/more efficient performance-wise)?
Java 8

Since you are on Java 8, you should consider using its stream-based processing feature to achieve what you need in a more expressive way.

First, you need a method that accepts a TreeEntry and gives you the desired Map object:

private Map&lt;String, Object&gt; extractDetails(TreeEntry file) {
    Map&lt;String, Object&gt; map = new HashMap&lt;&gt;();
    map.put("sha", file.getSha());
    map.put("path", file.getPath());
    map.put("name", GitHubHelper.getNameFromPath(file.getPath()));
    map.put("size", Objects.toString(file.getSize()));
    map.put("commits", GitHubHelper.getCommits(config, repo, file.getPath()));
    return map;
}


The idea here is to be able to use this as a method reference, e.g. ThisClass::extractDetails, for map()-ping the filter()-ed elements, before collect()-ing toList():

// Assuming fileList is a Collection implementation
List&lt;Map&lt;String, Object&gt;&gt; files = fileList.stream().filter(f -&gt; "blob".equals(f.getType()))
                                            .map(ThisClass::extractDetails)
                                            .collect(Collectors.toList());


Double brace initialization

This StackOverflow question shows the pitfalls of using it. In short, yes, there will be a performance impact, and it doesn't end there. Due to the anonymous classes it creates, you may get an unusual number of compiled class files, and not to mention the small but significant gotchas surrounding class equivalence testing (potentially) and final classes.