Checking directory for processing
It should be at least one .swf, .gif or .jpg processing to occur. If not, it's not an allowed file format.


The way try to check this is not so good:


    String files = allFiles.toString();
    if (files.contains("swf") || files.contains("jpg") || files.contains("gif")) {
        return false;
    }



You should not rely on the .toString() implementation to verify values.
You should use the values. I suggest to rewrite like this or similar:

for (String filename : allFiles.values()) {
    if (filename.endsWith(".swf") || filename.endsWith(".jpg") || filename.endsWith("gif")) {
        return false;
    }
}


This loop iterates over the values, and I replaced the .contains check with .endsWith, which seems to be more accurately matching what you really want to check. Another alternative to write the condition:

if (filename.matches(".*(\\.swf|\\.jpg)$")) {
    return false;
}



  I described the best in the code but I have cyclomatic complexity. Any idea on how I can reduce?


It seems you want to reduce cyclomatic complexity of the method.
The main contributors to the high cyclomatic complexity in your example:


many return statements
many if conditions
many &amp;&amp; and || operators


One way to reduce cyclomatic complexity is to extract some parts of the method to another method, for example:

if (allFiles.isEmpty() &amp;&amp; validacao.getSpec() == null) {
    return true;
} else if (validacao.getSpec() != null) {
    return false;
} else if (!allFiles.isEmpty()) {
    if (containsMediaFiles(allFiles)) {
        return false;
    }
}
return true;


I just invented the helper method containsMediaFiles,
and eliminated a for loop and some || conditions.

But in this particular example, there's an even easier way.
Realize that you don't really need to check if allFiles is not empty.
You can just loop over it, and if it's empty,
there will be nothing to loop over, so the empty case will be automatically handled, like this:

private boolean directoryIsEmpty(OldValidacao validacao) {
    Map&lt;String, String&gt; allFiles = validacaoService.getFilenameMap(validacao.getArquivoPath());

    if (allFiles.isEmpty() &amp;&amp; validacao.getSpec() == null) {
        return true;
    }

    if (validacao.getSpec() != null) {
        return false;
    }

    for (String filename : allFiles.values()) {
        if (filename.matches(".*\\.(swf|jpg|gif)$")) {
            return false;
        }
    }

    return true;
}


@ismael-miguel made a good point in comments that probably you want to match extensions like "JPG", and even "JPg". An easy way to do that is to convert filename to lowercase before the .matches call above. And you might want to add more patterns, for example jpeg, or use the pattern jpe?g to take care of both "jpeg" and "jpg" at the same time.