Merge pull request #379 from awhitford/HashSetLen

Sized the new HashSet to avoid rehashing risk.
This commit is contained in:
Jeremy Long
2015-10-12 06:46:12 -04:00
2 changed files with 6 additions and 10 deletions

View File

@@ -214,7 +214,7 @@ public abstract class AbstractFileTypeAnalyzer extends AbstractAnalyzer implemen
* @return a Set of strings. * @return a Set of strings.
*/ */
protected static Set<String> newHashSet(String... strings) { protected static Set<String> newHashSet(String... strings) {
final Set<String> set = new HashSet<String>(); final Set<String> set = new HashSet<String>(strings.length);
Collections.addAll(set, strings); Collections.addAll(set, strings);
return set; return set;
} }

View File

@@ -19,7 +19,7 @@ package org.owasp.dependencycheck.analyzer;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.apache.lucene.index.CorruptIndexException; import org.apache.lucene.index.CorruptIndexException;
@@ -49,11 +49,9 @@ public class CPEAnalyzerIntegrationTest extends AbstractDatabaseTestCase {
*/ */
@Test @Test
public void testBuildSearch() throws IOException, CorruptIndexException, ParseException { public void testBuildSearch() throws IOException, CorruptIndexException, ParseException {
Set<String> productWeightings = new HashSet<String>(1); Set<String> productWeightings = Collections.singleton("struts2");
productWeightings.add("struts2");
Set<String> vendorWeightings = new HashSet<String>(1); Set<String> vendorWeightings = Collections.singleton("apache");
vendorWeightings.add("apache");
String vendor = "apache software foundation"; String vendor = "apache software foundation";
String product = "struts 2 core"; String product = "struts 2 core";
@@ -238,11 +236,9 @@ public class CPEAnalyzerIntegrationTest extends AbstractDatabaseTestCase {
CPEAnalyzer instance = new CPEAnalyzer(); CPEAnalyzer instance = new CPEAnalyzer();
instance.open(); instance.open();
Set<String> productWeightings = new HashSet<String>(1); Set<String> productWeightings = Collections.singleton("struts2");
productWeightings.add("struts2");
Set<String> vendorWeightings = new HashSet<String>(1); Set<String> vendorWeightings = Collections.singleton("apache");
vendorWeightings.add("apache");
List<IndexEntry> result = instance.searchCPE(vendor, product, productWeightings, vendorWeightings); List<IndexEntry> result = instance.searchCPE(vendor, product, productWeightings, vendorWeightings);
instance.close(); instance.close();