I have the following HashMap:
Map<String, String[]> aMap = new HashMap<String, String[]>()
and a method with the following signature:
private boolean verifyFileName(String fileName, String[] allowableValues)
I invoke the method like this:
Map.Entry<String, String[]> pair = (Map.Entry)it.next();
...
verifyFileName(file.getName(), pair.getValue())
The problem is that verifyFileName
throws an error saying that its second argument is an ArrayList
. When I change the signature of verifyFileName
to (String fileName, ArrayList<String> allowableValues)
the error disappears.
What's going on here?
EDIT: Here's the JUnit test I use the HashMap in (written in Groovy):
@Test
public void verifyGeneratedAndCompiledFiles() {
Iterator it = DIRECTORIES_TO_CHECK.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, String[]> pair = it.next();
int count = 0
File createdFolder = new File(pair.getKey())
for (File file: createdFolder.listFiles()) {
println('checking for ' + file.getName())
if (file.length() == 0) {
fail(createdFolder.getPath() + ' folder contains an empty file')
}
if (!verifyFileName(file.getName(), pair.getValue())) {
fail(createdFolder.getPath() + ' folder is missing ' + file.getName())
}
count++
}
if (count != 2) {
fail(createdFolder.getName() + " folder contains an incorrect number of files")
}
count = 0
}
}
and here's where I declare and initialize DIRECTORIES_TO_CHECK
:
private static final Map<String, String[]> DIRECTORIES_TO_CHECK
static {
Map<String, String[]> aMap = new HashMap<String, String[]>()
aMap.put(DIRECTORIES_ROOT + "subproj/build/classes/generatedSource", ["Subproj.class", "Subproj2.class"])
aMap.put(DIRECTORIES_ROOT + "sub2/build/classes/generatedSource", ["Sub2.class", "Sub22.class"])
aMap.put(DIRECTORIES_ROOT + "subproj/generated/java", ["Subproj.java, Subproj2.java"])
aMap.put(DIRECTORIES_ROOT + "sub2/generated/java", ["Sub2.java", "Sub22.java"])
DIRECTORIES_TO_CHECK = Collections.unmodifiableMap(aMap)
}