#1341 - Added Links.addIf(boolean, Link...).

Additional unit tests to increase coverage.
This commit is contained in:
Oliver Drotbohm
2020-07-29 21:41:02 +02:00
parent b4ce7283a5
commit 9b8971a1df
2 changed files with 90 additions and 5 deletions

View File

@@ -76,7 +76,7 @@ public class Links implements Iterable<Link> {
* @param links
*/
public static Links of(Iterable<Link> links) {
return new Links(links);
return Links.class.isInstance(links) ? Links.class.cast(links) : new Links(links);
}
/**
@@ -134,6 +134,26 @@ public class Links implements Iterable<Link> {
return and(Arrays.asList(links));
}
/**
* Adds the given links if the given condition is {@literal true}. The given {@link Link}s will only be resolved if
* the given condition is {@literal true}. Essentially syntactic sugar to write:<br />
* <code>
* if (a > 3) {
* links = links.and(…);
* }
* </code> as <code>
* links = link.andIf(a > 3, …);
* </code>
*
* @param condition
* @param links must not be {@literal null}.
* @return
*/
@SafeVarargs
public final Links andIf(boolean condition, Link... links) {
return condition ? and(links) : this;
}
/**
* Adds the given links if the given condition is {@literal true}. The given {@link Supplier}s will only be resolved
* if the given condition is {@literal true}. Essentially syntactic sugar to write:<br />