Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

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<String, Object> extractDetails(TreeEntry file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "blob".equals(f.getType()))
 .map(ThisClass::extractDetails)
 .collect(Collectors.toList());

Double brace initialization

This StackOverflow question 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.

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<String, Object> extractDetails(TreeEntry file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

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<String, Object> extractDetails(TreeEntry file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

added 10 characters in body
Source Link
h.j.k.
  • 19.3k
  • 3
  • 37
  • 93

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 FileTreeEntry and gives you the desired Map object:

private Map<String, Object> extractDetails(FileTreeEntry file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

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 File and gives you the desired Map object:

private Map<String, Object> extractDetails(File file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

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<String, Object> extractDetails(TreeEntry file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

added 14 characters in body
Source Link
h.j.k.
  • 19.3k
  • 3
  • 37
  • 93

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 File and gives you the desired Map object:

private Map<String, Object> extractDetails(File file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

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 File and gives you the desired Map object:

private Map<String, Object> extractDetails(File file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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 and final classes.

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 File and gives you the desired Map object:

private Map<String, Object> extractDetails(File file) {
 Map<String, Object> map = new HashMap<>();
 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<Map<String, Object>> files = fileList.stream().filter(f -> "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.

Source Link
h.j.k.
  • 19.3k
  • 3
  • 37
  • 93
Loading
lang-java

AltStyle によって変換されたページ (->オリジナル) /