Skip to content

Commit

Permalink
Merge pull request #313 from hazendaz/java
Browse files Browse the repository at this point in the history
[java] Use diamond operator
  • Loading branch information
mathieucarbou authored Mar 24, 2022
2 parents ce49063 + f79cd3a commit 0cbbf00
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Map<String, String> getAdditionalProperties(AbstractLicenseMojo mojo, Pro
Document document) {

try {
Map<String, String> result = new HashMap<String, String>(3);
Map<String, String> result = new HashMap<>(3);
GitLookup gitLookup = getGitLookup(mojo, document.getFile(), properties);

result.put(COPYRIGHT_CREATION_AUTHOR_NAME_KEY, gitLookup.getAuthorNameOfCreation(document.getFile()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public Map<String, String> getAdditionalProperties(AbstractLicenseMojo mojo, Pro
+ document.getFile().getAbsolutePath());
}
try {
Map<String, String> result = new HashMap<String, String>(4);
Map<String, String> result = new HashMap<>(4);
GitLookup gitLookup = getGitLookup(mojo, document.getFile(), properties);
int copyrightEnd = gitLookup.getYearOfLastChange(document.getFile());
result.put(COPYRIGHT_LAST_YEAR_KEY, Integer.toString(copyrightEnd));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* @author Matthieu Brouillard
*/
public class SVNPropertiesProvider implements PropertiesProvider {
ThreadLocal<SVNClientManager> svnClientThreadLocal = new ThreadLocal<SVNClientManager>();
ThreadLocal<SVNClientManager> svnClientThreadLocal = new ThreadLocal<>();
ThreadLocal<SimpleDateFormat> sdfTimestampThreadLocal = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
Expand Down Expand Up @@ -74,7 +74,7 @@ protected SimpleDateFormat initialValue() {
*/
@Override
public Map<String, String> getAdditionalProperties(final AbstractLicenseMojo mojo, Properties currentProperties, Document document) {
final Map<String, String> newProperties = new HashMap<String, String>();
final Map<String, String> newProperties = new HashMap<>();
final File documentFile = document.getFile();

initThreadLocalObjects(mojo, currentProperties.getProperty(SVN_SERVER_ID_PLUGIN_KEY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ protected abstract class AbstractCallback implements Callback {
/**
* Related to {@link #failIfUnknown}.
*/
private final Collection<File> unknownFiles = new ConcurrentLinkedQueue<File>();
private final Collection<File> unknownFiles = new ConcurrentLinkedQueue<>();

@Override
public void onUnknownFile(Document document, Header header) {
Expand Down Expand Up @@ -753,7 +753,7 @@ private String[] listSelectedFiles(final LicenseSet licenseSet) {
}

private String[] buildExcludes(final LicenseSet licenseSet) {
List<String> ex = new ArrayList<String>();
List<String> ex = new ArrayList<>();
ex.addAll(asList(licenseSet.excludes));
if (project != null && project.getModules() != null && !aggregate) {
for (String module : (List<String>) project.getModules()) {
Expand Down Expand Up @@ -782,7 +782,7 @@ public final void warn(String format, Object... params) {
}

private Map<String, String> buildMapping() {
Map<String, String> extensionMapping = new LinkedHashMap<String, String>();
Map<String, String> extensionMapping = new LinkedHashMap<>();
// force inclusion of unknown item to manage unknown files
extensionMapping.put(DocumentType.UNKNOWN.getExtension(), DocumentType.UNKNOWN.getDefaultHeaderTypeName());
for (Map.Entry<String, String> entry : mapping.entrySet()) {
Expand All @@ -800,7 +800,7 @@ private Map<String, String> buildMapping() {

private Map<String, HeaderDefinition> buildHeaderDefinitions(final LicenseSet licenseSet, final ResourceFinder finder) throws MojoFailureException {
// like mappings, first get default definitions
final Map<String, HeaderDefinition> headers = new HashMap<String, HeaderDefinition>(HeaderType.defaultDefinitions());
final Map<String, HeaderDefinition> headers = new HashMap<>(HeaderType.defaultDefinitions());

// and then override them with those provided in base config
for (final String headerDefiniton : defaultHeaderDefinitions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public class LicenseSet {
* command line, in the POM and in system environment.
*/
@Parameter
public Map<String, String> properties = new HashMap<String, String>();
public Map<String, String> properties = new HashMap<>();

/**
* Specifies files, which are included in the check. By default, all files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private Set<LicensePolicyEnforcer> getEnforcers(final LicensePolicy.Rule rule) {
*/
@SuppressWarnings("unchecked")
private Map<Artifact, LicensePolicyEnforcerResult> apply(final License license, final Set<Artifact> artifacts, final LicensePolicyEnforcer enforcer) {
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<Artifact, LicensePolicyEnforcerResult>();
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<>();

final LicensePolicy.Rule filter = enforcer.getPolicy().getRule();

Expand Down Expand Up @@ -115,7 +115,7 @@ private Map<Artifact, LicensePolicyEnforcerResult> apply(final License license,
* @return
*/
private Map<Artifact, LicensePolicyEnforcerResult> apply(final Map<License, Set<Artifact>> licenseMap, final LicensePolicyEnforcer enforcer) {
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<Artifact, LicensePolicyEnforcerResult>();
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<>();

licenseMap.forEach((license, artifactSet) -> {
results.putAll(apply(license, artifactSet, enforcer));
Expand All @@ -134,7 +134,7 @@ private Map<Artifact, LicensePolicyEnforcerResult> apply(final Map<License, Set<
*/
@SuppressWarnings("unchecked")
public Map<Artifact, LicensePolicyEnforcerResult> apply(final Map<License, Set<Artifact>> licenseMap) {
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<Artifact, LicensePolicyEnforcerResult>();
final Map<Artifact, LicensePolicyEnforcerResult> results = new HashMap<>();

// apply the default policy to all artifacts, populating the map
licenseMap.entrySet().stream().forEach(entry -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static ProjectBuildingRequest getBuildingRequestWithDefaults(final Maven
* Return a set of licenses attributed to a single artifact.
*/
protected Set<License> getLicensesFromArtifact(final Artifact artifact) {
Set<License> licenses = new HashSet<License>();
Set<License> licenses = new HashSet<>();
try {
MavenProject project = getProjectBuilder().build(artifact, getBuildingRequest()).getProject();
licenses.addAll(project.getLicenses());
Expand All @@ -125,13 +125,13 @@ protected Set<License> getLicensesFromArtifact(final Artifact artifact) {
* License.
*/
protected Map<License, Set<Artifact>> getLicenseMapFromArtifacts(final Set<Artifact> dependencies) {
final ConcurrentMap<License, Set<Artifact>> map = new ConcurrentHashMap<License, Set<Artifact>>();
final ConcurrentMap<License, Set<Artifact>> map = new ConcurrentHashMap<>();

// license:artifact is a many-to-many relationship.
// Each artifact may have several licenses.
// Each artifact may appear multiple times in the map.
dependencies.parallelStream().forEach(artifact -> getLicensesFromArtifact(artifact).forEach(license -> {
map.putIfAbsent(license, new HashSet<Artifact>());
map.putIfAbsent(license, new HashSet<>());
Set<Artifact> artifacts = map.get(license);
artifacts.add(artifact);
map.put(license, artifacts);
Expand All @@ -149,8 +149,8 @@ public Map<License, Set<Artifact>> getLicenseMap() {
* Return the Set of all direct and transitive Artifact dependencies.
*/
private Set<Artifact> getDependencies() {
final Set<Artifact> artifacts = new HashSet<Artifact>();
final Set<DependencyNode> dependencies = new HashSet<DependencyNode>();
final Set<Artifact> artifacts = new HashSet<>();
final Set<DependencyNode> dependencies = new HashSet<>();

// build the set of maven dependencies for each module in the reactor (might
// only be the single one) and all its transitives
Expand Down Expand Up @@ -190,7 +190,7 @@ protected Set<MavenProject> getProjects() {
}

protected void setProjects(final Set<MavenProject> projects) {
this.projects = Optional.ofNullable(projects).orElse(new HashSet<MavenProject>());
this.projects = Optional.ofNullable(projects).orElse(new HashSet<>());
}

private DependencyGraphBuilder getGraph() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public enum DocumentType {

////////////////////////////////////

private static final Map<String, String> MAPPING = new LinkedHashMap<String, String>(values().length);
private static final Map<String, String> MAPPING = new LinkedHashMap<>(values().length);

static {
for (DocumentType type : values()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
* @author Cedric Pronzato
*/
public final class AdditionalHeaderDefinition {
private final Map<String, HeaderDefinition> definitions = new HashMap<String, HeaderDefinition>();
private final Map<String, HeaderDefinition> definitions = new HashMap<>();

/**
* Construct an <code>AdditionalHeaderDefinition</code> object using the given XML document as header definitions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public boolean isMatchForText(String expected, String potentialFileHeader, Heade
return potentialFileHeader.contains(expected);

List<String> textBetweenSections = buildExpectedTextBetweenSections(expected, sectionsByIndex);
List<HeaderSection> sectionsInOrder = new ArrayList<HeaderSection>(sectionsByIndex.values());
List<HeaderSection> sectionsInOrder = new ArrayList<>(sectionsByIndex.values());
return recursivelyFindMatch(potentialFileHeader, headerDefinition, textBetweenSections, sectionsInOrder, 0, 0);
}

Expand All @@ -190,7 +190,7 @@ public String applyDefinitionAndSections(HeaderDefinition headerDefinition, bool
return expected;

List<String> textBetweenSections = buildExpectedTextBetweenSections(expected, sectionsByIndex);
List<HeaderSection> sectionsInOrder = new ArrayList<HeaderSection>(sectionsByIndex.values());
List<HeaderSection> sectionsInOrder = new ArrayList<>(sectionsByIndex.values());

StringBuilder b = new StringBuilder();
for (int i = 0; i < textBetweenSections.size(); ++i) {
Expand Down Expand Up @@ -236,7 +236,7 @@ private boolean notEmpty(String str) {
*/
private SortedMap<Integer, HeaderSection> computeSectionsByIndex(String expectedHeaderText) {

SortedMap<Integer, HeaderSection> sectionsByIndex = new TreeMap<Integer, HeaderSection>();
SortedMap<Integer, HeaderSection> sectionsByIndex = new TreeMap<>();

if (sections == null)
return sectionsByIndex;
Expand Down Expand Up @@ -300,7 +300,7 @@ private SortedMap<Integer, HeaderSection> computeSectionsByIndex(String expected
private List<String> buildExpectedTextBetweenSections(String expectedHeaderText,
SortedMap<Integer, HeaderSection> sectionsByIndex) {

List<String> textBetweenSections = new ArrayList<String>();
List<String> textBetweenSections = new ArrayList<>();
int currentIndex = 0;

for (Map.Entry<Integer, HeaderSection> entry : sectionsByIndex.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ScanAction visitFile(final String name, final File file) {
}

private String[] findFolderExcludes() { // less we keep, less overhead we get so we only use user excludes there
final List<String> excludes = new ArrayList<String>(excluded.length / 2 /*estimate*/);
final List<String> excludes = new ArrayList<>(excluded.length / 2 /*estimate*/);
for (final String exclude : (userExcluded != null ? userExcluded : excluded)) {
if (isFolderExclusion(exclude)) {
excludes.add(exclude);
Expand All @@ -120,7 +120,7 @@ private boolean isFolderExclusion(final String exclude) {
}

private static String[] buildExclusions(boolean useDefaultExcludes, String[] excludes, String[] overrides) {
List<String> exclusions = new ArrayList<String>();
List<String> exclusions = new ArrayList<>();
if (useDefaultExcludes) {
exclusions.addAll(asList(Default.EXCLUDES));
}
Expand All @@ -136,7 +136,7 @@ private static String[] buildExclusions(boolean useDefaultExcludes, String[] exc

private static String[] buildInclusions(String[] includes, String[] overrides) {
// if we use the default exclusion list, we just remove
List<String> inclusions = new ArrayList<String>(asList(includes != null && includes.length > 0 ? includes : Default.INCLUDE));
List<String> inclusions = new ArrayList<>(asList(includes != null && includes.length > 0 ? includes : Default.INCLUDE));
inclusions.removeAll(asList(overrides));
if (inclusions.isEmpty()) {
inclusions.addAll(asList(Default.INCLUDE));
Expand All @@ -149,7 +149,7 @@ private static String[] buildOverrideInclusions(boolean useDefaultExcludes, Stri
if (!useDefaultExcludes || includes == null || includes.length == 0) {
return new String[0];
}
List<String> overrides = new ArrayList<String>(asList(Default.EXCLUDES));
List<String> overrides = new ArrayList<>(asList(Default.EXCLUDES));
overrides.retainAll(asList(includes));
return overrides.toArray(new String[0]);
}
Expand Down

0 comments on commit 0cbbf00

Please sign in to comment.