### Question:
WildcardUtils { @Nullable public static PatternApplied applyPattern(String pattern, String str, boolean caseSensitive) { String normalizedText; String normalizedPattern; if (caseSensitive) { normalizedText = str; normalizedPattern = pattern; } else { normalizedText = str.toLowerCase(); normalizedPattern = pattern.toLowerCase(); } List<LinearRange> literalRanges = getLiteralRanges(normalizedPattern); StringBuilder appliedText = new StringBuilder(pattern); int first = -1; int last = 0; int pos = 0; for (LinearRange literalRange: literalRanges) { String literal = normalizedPattern.substring(literalRange.getFrom(), literalRange.getTo()); int index = indexOf(normalizedText, literal, pos); if (index != -1) { if (first == -1) first = index; pos = index+literal.length(); last = pos; String temp = appliedText.toString(); appliedText = new StringBuilder(appliedText.substring(0, literalRange.getFrom())); for (int i=0; i<literal.length(); i++) { if (literal.charAt(i) == '?') appliedText.append('?'); else appliedText.append(str.charAt(index+i)); } appliedText.append(temp.substring(literalRange.getTo())); } else { return null; } } if (first != -1 && pattern.charAt(0) != '*') appliedText = new StringBuilder(str.substring(0, first) + appliedText.toString()); else first = 0; if (pattern.length() == 0 || pattern.charAt(pattern.length()-1) != '*') { String suffix = str.substring(last); last = appliedText.length(); appliedText.append(suffix); } else { last = appliedText.length(); } return new PatternApplied(appliedText.toString(), new LinearRange(first, last)); }  static boolean matchPath(String pattern, String path); static boolean matchString(String pattern, String str); static List<LinearRange> getLiteralRanges(String pattern); @Nullable static PatternApplied applyPattern(String pattern, String str, boolean caseSensitive); @Nullable static LinearRange rangeOfMatch(String pattern, String str);  }### Answer:
@Test public void shouldApplyPattern() { assertEquals("he*?lo:1-5", applyPattern("E*?l", "hello", false).toString()); assertEquals(null, applyPattern("*he ?d", "hello world", false)); assertEquals("*he*ld 2:0-6", applyPattern("*hE*ld", "hello world 2", false).toString()); assertEquals("hello:0-0", applyPattern("", "hello", false).toString()); assertEquals("*:0-1", applyPattern("*", "hello", false).toString()); assertEquals("**:0-2", applyPattern("**", "hello", false).toString()); }