Skip to content

Instantly share code, notes, and snippets.

@barik
Last active August 29, 2015 14:09
Show Gist options
  • Save barik/b1cd56f20b6a63e0f30e to your computer and use it in GitHub Desktop.
Save barik/b1cd56f20b6a63e0f30e to your computer and use it in GitHub Desktop.
private static boolean shouldIgnoreOptionalProblems(char[][] folderNames, char[] fileName) {
if (folderNames == null || fileName == null) {
return false;
}
for (int i = 0, max = folderNames.length; i < max; i++) {
char[] folderName = folderNames[i];
if (isParentOf(folderName, fileName)) {
return true;
}
}
return false;
}
private static boolean isParentOf(char[] folderName, char[] fileName) {
if (folderName.length >= fileName.length) {
return false;
}
if (fileName[folderName.length] != '\\' && fileName[folderName.length] != '/') {
return false;
}
for (int i = folderName.length - 1; i >= 0; i--) {
if (folderName[i] != fileName[i]) {
return false;
}
}
return true;
}
@kjlubick
Copy link

private boolean shouldIgnoreOptionalProblems(char[][] folderNames, char[] fileName) {
    if (folderNames == null) {
        return false;
    }
    outerFor:
    for (int i = 0, max = folderNames.length; i < max; i++) {
        char[] folderName = folderNames[i];
        if (folderName.length >= fileName.length) {
            continue;
        }
        if (fileName[folderName.length] != '\\' && fileName[folderName.length] != '/') {
            continue;
        }
        for (int i = folderName.length - 1; i >= 0; i--) {
            if (folderName[i] != fileName[i]) {
                continue outerFor;
            }
        }
        return true;
    }
    return false;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment