ThreeState (@NotNull String path, @NotNull String prefix, boolean strict, boolean isCaseSensitive, boolean checkImmediateParent) { int pathLength = path.length(); int prefixLength = prefix.length(); if (prefixLength == 0) return pathLength == 0 ? ThreeState.YES : ThreeState.UNSURE; if (prefixLength > pathLength) return ThreeState.NO; if (!path.regionMatches(!isCaseSensitive, 0, prefix, 0, prefixLength)) return ThreeState.NO; if (pathLength == prefixLength) { return strict ? ThreeState.NO : ThreeState.YES; } char lastPrefixChar = prefix.charAt(prefixLength - 1); int slashOrSeparatorIdx = prefixLength; if (lastPrefixChar == '/' || lastPrefixChar == File.separatorChar) { slashOrSeparatorIdx = prefixLength - 1; } char next = path.charAt(slashOrSeparatorIdx); if (next == '/' || next == File.separatorChar) { if (!checkImmediateParent) return ThreeState.YES; if (slashOrSeparatorIdx == pathLength - 1) return ThreeState.YES; int idxNext = path.indexOf(next, slashOrSeparatorIdx + 1); idxNext = idxNext == -1 ? path.indexOf(next == '/' ? '\\' : '/', slashOrSeparatorIdx + 1) : idxNext; return idxNext == -1 ? ThreeState.YES : ThreeState.UNSURE; } else { return ThreeState.NO; } }