/** * Returns whether or not this text contains the given substring. * @param sub the substring * @return {@code true} if this has the given substring or the substring is empty, otherwise {@code false} * @throws NullPointerException if this or the substring is {@code null} * @since 0.9.1 */ public boolean contains(String sub) { if (isNull() || sub == null) { throw new NullPointerException(); } if (sub.isEmpty()) { return true; } Text buffer = BUFFER_POOL.get(); buffer.set(sub); return contains(entity, buffer); }
/** * Returns whether or not this text contains the given substring. * @param sub the substring * @return {@code true} if this has the given substring or the substring is empty, otherwise {@code false} * @throws NullPointerException if this or the substring is {@code null} * @since 0.9.1 */ public boolean contains(StringOption sub) { if (isNull() || sub == null || sub.isNull()) { throw new NullPointerException(); } if (sub.isEmpty()) { return true; } return contains(entity, sub.entity); }
/** * contains. */ @Test public void contains() { npe(() -> new StringOption().contains("a")); npe(() -> new StringOption().contains(new StringOption("a"))); npe(() -> new StringOption("a").contains(new StringOption())); BiPredicate<String, String> tester = (string, sub) -> { StringOption opt = new StringOption(string); boolean b0 = opt.contains(sub); boolean b1 = opt.contains(new StringOption(sub)); assertThat(b0, is(b1)); return b0; }; assertThat(tester.test("Hello", "Hello"), is(true)); assertThat(tester.test("Hello", ""), is(true)); assertThat(tester.test("Hello, world!", "a"), is(false)); assertThat(tester.test("Hello, world!", "Hello"), is(true)); assertThat(tester.test("Hello, world!", "world!"), is(true)); assertThat(tester.test("Hello, world!", "ello"), is(true)); assertThat(tester.test("Hello", "Hello, world!"), is(false)); assertThat(tester.test("Hello, world!", "Hello!"), is(false)); assertThat(tester.test("Hello, world!", "world?"), is(false)); assertThat(tester.test("Hello, world!", "Hello, world?"), is(false)); }