### Question:
CollQueryFunctions { public static boolean like(final String str, String like) { final StringBuilder pattern = new StringBuilder(like.length() + 4); for (int i = 0; i < like.length(); i++) { final char ch = like.charAt(i); if (ch == '%') { pattern.append(".*"); continue; } else if (ch == '_') { pattern.append('.'); continue; } else if (ch == '.' || ch == '$' || ch == '^') { pattern.append('\\'); } pattern.append(ch); } if (pattern.toString().equals(like)) { return str.equals(like); } else { return str.matches(pattern.toString()); } } private  CollQueryFunctions(); static boolean equals(Object o1, Object o2); static int compareTo(T c1, T c2); static boolean between(A a, A b, A c); static double cot(double x); static double coth(double x); static double degrees(double x); static double radians(double x); static double log(double x, int y); @Nullable static T coalesce(T... args); static T nullif(T first, T second); static int getYearMonth(Date date); static int getDayOfMonth(Date date); static int getDayOfWeek(Date date); static int getDayOfYear(Date date); static int getHour(Date date); static int getMilliSecond(Date date); static int getMinute(Date date); static int getMonth(Date date); static int getSecond(Date date); static int getWeek(Date date); static int getYear(Date date); static int getYearWeek(Date date); static Collection<T> leftJoin(Collection<T> coll); static Number aggregate(Collection<Number> source, Expression<?> expr, Operator aggregator); static boolean like(final String str, String like); static boolean like(String str, String like, char escape); static boolean likeIgnoreCase(String str, String like); static boolean likeIgnoreCase(String str, String like, char escape); static T get(Object parent, String f);  }### Answer:
@Test @Ignore public void likeSpeed() { final int iterations = 1000000; long start = System.currentTimeMillis(); for (int i = 0; i < iterations; i++) { CollQueryFunctions.like("abcDOG", "%DOG"); CollQueryFunctions.like("DOGabc", "DOG%"); CollQueryFunctions.like("abcDOGabc", "%DOG%"); } long duration = System.currentTimeMillis() - start; System.err.println(duration); }
@Test public void like() { assertTrue(CollQueryFunctions.like("abcDOG", "%DOG")); assertTrue(CollQueryFunctions.like("DOGabc", "DOG%")); assertTrue(CollQueryFunctions.like("abcDOGabc", "%DOG%")); }
@Test public void like_with_special_chars() { assertTrue(CollQueryFunctions.like("$DOG", "$DOG")); assertTrue(CollQueryFunctions.like("$DOGabc", "$DOG%")); }