Skip to content

Commit f03016b

Browse files
jirka.pinkas@gmail.comjirka.pinkas@gmail.com
authored andcommitted
added *Generator.addPage(Supplier<String>)
1 parent 17040bf commit f03016b

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/main/java/cz/jiripinkas/jsitemapgenerator/AbstractGenerator.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ public I addPage(String name) {
7373
return addPage(WebPage.of(name));
7474
}
7575

76+
/**
77+
* Add single page to sitemap.
78+
* @param supplier Supplier method which sneaks any checked exception
79+
* https://www.baeldung.com/java-sneaky-throws
80+
* Allows for calling method which performs some operation and then returns name of page.
81+
* @return this
82+
*/
83+
public I addPage(StringSupplierWithException<String> supplier) {
84+
try {
85+
addPage(supplier.get());
86+
} catch (Exception e) {
87+
sneakyThrow(e);
88+
}
89+
return getThis();
90+
}
91+
92+
7693
/**
7794
* This method is called before adding a page to urls.
7895
* It can be used to change webPage attributes
@@ -223,6 +240,10 @@ public interface GeneratorConsumerWithException<T> {
223240
void accept(T t) throws Exception;
224241
}
225242

243+
public interface StringSupplierWithException<String> {
244+
String get() throws Exception;
245+
}
246+
226247
/**
227248
* Sneak exception https://www.baeldung.com/java-sneaky-throws
228249
* @param e Exception

0 commit comments

Comments
 (0)