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