/** * Runtime-optimized reimplementation of {@link String#indexOf(String)} and {@link String#lastIndexOf(String)}. * <p> * This method returns an implementation that performs at least as well as the {@link String} methods by * analyzing the <var>needle</var> (the string to search for). * </p> * * @param needle The string to search for */ public static IndexOf indexOf(char[] needle) { return StringUtil.indexOf(CharSequences.from(needle)); }
@Override public boolean evaluate(Integer subject) { Object unicodeScript2 = Characters.UNICODE_SCRIPT_OF.invoke(null, subject); return unicodeScript1 == unicodeScript2; }
/** * Equivalent with {@link #getSubresourcesOf(URL, String, boolean, boolean)} with the <var>recurse</var> * parameter set to {@code true}. */ public static Map<String, URL> getSubresourcesOf(URL root, String rootName, boolean includeDirectories) throws IOException { return ClassLoaders.getSubresourcesOf(root, rootName, includeDirectories, true); }
private void checkException() throws IOException { if (this.exception == null) return; if (this.exception instanceof IOException) { throw ExceptionUtil.wrap(null, (IOException) this.exception); } else if (this.exception instanceof RuntimeException) { throw ExceptionUtil.wrap(null, (RuntimeException) this.exception); } else { throw ExceptionUtil.wrap(null, this.exception, IOException.class); } }
private static Stoppable copyInBackground(final InputStream in, final boolean closeIn, final OutputStream out, final boolean closeOut) { return ThreadUtil.runInBackground(new Runnable() { @Override public void run() { try { ProcessUtil.copy(in, closeIn, out, closeOut); } catch (IOException e) { ; } } }, "copy-in-background"); }
@Override public Iterator<Character> iterator() { return StringUtil.iterator(subject); } };
@Override public String toString() { return "naiveIndexOf(" + PrettyPrinter.toJavaArrayInitializer(needle) + ")"; } };
/** * Returns a wrapper for a zero-parameter method of the </var>declaringClass</var>, based on the * <var>methodName</var>. If that method does not exist, a wrapper is returned that will throw an {@link * UnsupportedOperationException} when invoked. * * @param <DC> The class that declares the method * @param <R> The return type of the method */ public static <DC, R> MethodWrapper0<DC, R, RuntimeException> get0(final Class<DC> declaringClass, final String methodName) { return OptionalMethods.get0(declaringClass, methodName, RuntimeException.class); }
/** * Returns a wrapper for a single-parameter method of the </var>declaringClass</var>, based on * <var>methodName</var> and <var>parameterType</var>. If that method does not exist, a wrapper is returned that * will throw an {@link UnsupportedOperationException} when invoked. * * @param <DC> The class that declares the wrapped method * @param <R> The return type of the wrapped method * @param <P> The type of the single parameter of the wrapped method */ public static <DC, R, P> MethodWrapper1<DC, R, P, RuntimeException> get1(final Class<DC> declaringClass, final String methodName, Class<P> parameterType) { return OptionalMethods.get1(declaringClass, methodName, parameterType, RuntimeException.class); }
@Override public CharSequence subSequence(int start2, int end2) { return CharSequences.subSequence(delegate, start + start2, start + end2); }
@Override public String toString() { return "naive(" + PrettyPrinter.toJavaStringLiteral(needle) + ")"; } };
/** * Returns a wrapper for a two-parameter method of the </var>declaringClass</var>, based on * <var>methodName</var>, <var>parameterType1</var> and <var>parameterType2</var>. If that method does not exist, * a wrapper is returned that will throw an {@link UnsupportedOperationException} when invoked. * * @param <DC> The class that declares the wrapped method * @param <R> The return type of the wrapped method * @param <P1> The type of the first parameter of the wrapped method * @param <P2> The type of the second parameter of the wrapped method */ public static <DC, R, P1, P2> MethodWrapper2<DC, R, P1, P2, RuntimeException> get2(final Class<DC> declaringClass, final String methodName, Class<P1> parameterType1, Class<P2> parameterType2) { return OptionalMethods.get2(declaringClass, methodName, parameterType1, parameterType2, RuntimeException.class); }
@Override public boolean evaluate(Integer subject) { return Characters.isAlphabetic(subject); } };
@Override public int indexOf(CharSequence haystack) { return this.indexOf(haystack, 0, Integer.MAX_VALUE); } // SUPPRESS CHECKSTYLE LineLength:3 @Override public int indexOf(CharSequence haystack, int minIndex) { return this.indexOf(haystack, minIndex, Integer.MAX_VALUE); }
@Override public boolean evaluate(Integer subject) { return Characters.isWordCharacter(subject); } };
private void checkException() throws IOException { if (this.exception == null) return; if (this.exception instanceof IOException) { throw ExceptionUtil.wrap(null, (IOException) this.exception); } else if (this.exception instanceof RuntimeException) { throw ExceptionUtil.wrap(null, (RuntimeException) this.exception); } else { throw ExceptionUtil.wrap(null, this.exception, IOException.class); } }
private static Stoppable copyInBackground(final InputStream in, final boolean closeIn, final OutputStream out, final boolean closeOut) { return ThreadUtil.runInBackground(new Runnable() { @Override public void run() { try { ProcessUtil.copy(in, closeIn, out, closeOut); } catch (IOException e) { ; } } }, "copy-in-background"); }
/** * Calls {@code java.lang.Character.isAlphabetic(int)}, which is available only sind JRE 1.7. * * @throws UnsupportedOperationException The JRE is pre-1.7 */ @SuppressWarnings("null") public static boolean isAlphabetic(Integer codePoint) { return Characters.CHARACTER_IS_ALPHABETIC.invoke(null, codePoint); }
@Override public String toString() { return "boyerMooreHorspool(" + PrettyPrinter.toJavaArrayInitializer(needle) + ")"; } };
@SuppressWarnings("null") @Override public boolean evaluate(Integer subject) { return Characters.CHARACTER_IS_IDEOGRAPHIC.invoke(null, subject); } };