Package com.tngtech.archunit.base
Class DescribedPredicate<T>
java.lang.Object
com.tngtech.archunit.base.DescribedPredicate<T>
- Type Parameters:
T- The type of objects the predicate applies to
- All Implemented Interfaces:
Predicate<T>
- Direct Known Subclasses:
PackageMatchers
@PublicAPI(usage=INHERITANCE)
public abstract class DescribedPredicate<T>
extends Object
implements Predicate<T>
A predicate holding a description.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> DescribedPredicate<Iterable<T>>allElements(DescribedPredicate<? super T> predicate) static <T> DescribedPredicate<T>static <T> DescribedPredicate<T>and(DescribedPredicate<? super T> other) static <T> DescribedPredicate<T>and(DescribedPredicate<? super T>... predicates) static <T> DescribedPredicate<T>and(Iterable<? extends DescribedPredicate<? super T>> predicates) static <T> DescribedPredicate<Iterable<? extends T>>anyElementThat(DescribedPredicate<? super T> predicate) Overwrites the description of thisDescribedPredicate.static <T> DescribedPredicate<T>static <T> DescribedPredicate<T>doesNot(DescribedPredicate<? super T> predicate) Same asnot(DescribedPredicate)but with a different descriptionstatic <T> DescribedPredicate<T>doNot(DescribedPredicate<? super T> predicate) Same asnot(DescribedPredicate)but with a different descriptionstatic DescribedPredicate<Iterable<?>>empty()static <T> DescribedPredicate<T>equalTo(T object) final <U extends T>
DescribedPredicate<U>Convenience method to downcast the predicate.static <T extends Comparable<T>>
DescribedPredicate<T>greaterThan(T value) static <T extends Comparable<T>>
DescribedPredicate<T>greaterThanOrEqualTo(T value) static <T extends Comparable<T>>
DescribedPredicate<T>lessThan(T value) static <T extends Comparable<T>>
DescribedPredicate<T>lessThanOrEqualTo(T value) static <T> DescribedPredicate<T>not(DescribedPredicate<? super T> predicate) <F> DescribedPredicate<F>onResultOf(Function<? super F, ? extends T> function) static <T> DescribedPredicate<Optional<T>>optionalContains(DescribedPredicate<? super T> predicate) static <T> DescribedPredicate<Optional<T>>or(DescribedPredicate<? super T> other) static <T> DescribedPredicate<T>or(DescribedPredicate<? super T>... predicates) static <T> DescribedPredicate<T>or(Iterable<? extends DescribedPredicate<? super T>> predicates) toString()
-
Constructor Details
-
DescribedPredicate
-
-
Method Details
-
getDescription
-
as
Overwrites the description of thisDescribedPredicate. E.g.
would then yieldclasses().that(predicate.as("some customized description with '%s'", "parameter")).should().bePublic()classes that some customized description with 'parameter' should be public.- Parameters:
description- The new description of thisDescribedPredicateparams- Optional arguments to fill into the description viaString.format(String, Object...)- Returns:
- An
DescribedPredicatewith adjusteddescription.
-
and
-
or
-
onResultOf
-
forSubtype
Convenience method to downcast the predicate.DescribedPredicatesare contravariant by nature, i.e. anDescribedPredicate<T>is an instance ofDescribedPredicate<V>, if and only ifVis an instance ofT.
Take for exampleObject > String. Obviously aDescribedPredicate<Object>is also aDescribedPredicate<String>.
Unfortunately, the Java type system does not allow us to express this property of the type parameter ofDescribedPredicate. So to avoid forcing users to cast everywhere it is possible to use this method which also documents the intention and reasoning.- Type Parameters:
U- A subtype of theDescribedPredicate'stype parameterT- Returns:
- A
DescribedPredicateaccepting a subtype of the predicate's actual type parameterT
-
toString
-
alwaysTrue
-
alwaysFalse
-
equalTo
-
lessThan
@PublicAPI(usage=ACCESS) public static <T extends Comparable<T>> DescribedPredicate<T> lessThan(T value) -
greaterThan
@PublicAPI(usage=ACCESS) public static <T extends Comparable<T>> DescribedPredicate<T> greaterThan(T value) -
lessThanOrEqualTo
@PublicAPI(usage=ACCESS) public static <T extends Comparable<T>> DescribedPredicate<T> lessThanOrEqualTo(T value) -
greaterThanOrEqualTo
@PublicAPI(usage=ACCESS) public static <T extends Comparable<T>> DescribedPredicate<T> greaterThanOrEqualTo(T value) -
describe
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> describe(String description, Predicate<? super T> predicate) -
doesNot
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> doesNot(DescribedPredicate<? super T> predicate) Same asnot(DescribedPredicate)but with a different description -
doNot
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> doNot(DescribedPredicate<? super T> predicate) Same asnot(DescribedPredicate)but with a different description -
not
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> not(DescribedPredicate<? super T> predicate) - Type Parameters:
T- The type of object thepredicateapplies to- Parameters:
predicate- AnyDescribedPredicate- Returns:
- A predicate that will return
truewhenever the original predicate would returnfalseand vice versa.
-
and
@SafeVarargs @PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> and(DescribedPredicate<? super T>... predicates) - See Also:
-
and
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> and(Iterable<? extends DescribedPredicate<? super T>> predicates) - Type Parameters:
T- The type of object thepredicateapplies to- Parameters:
predicates- Any number ofpredicatesto join together via *AND*- Returns:
- A
predicatethat returnstrue, if all the supplied predicates returntrue. Otherwise, it returnsfalse. If an emptyIterableis passed to this method the resulting predicate will always returnfalse.
-
or
@SafeVarargs @PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> or(DescribedPredicate<? super T>... predicates) - See Also:
-
or
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<T> or(Iterable<? extends DescribedPredicate<? super T>> predicates) - Type Parameters:
T- The type of object thepredicateapplies to- Parameters:
predicates- Any number ofpredicatesto join together via *OR*- Returns:
- A
predicatethat returnstrue, if any of the supplied predicates returnstrue. Otherwise, it returnsfalse. If an emptyIterableis passed to this method the resulting predicate will always returnfalse.
-
empty
-
optionalContains
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<Optional<T>> optionalContains(DescribedPredicate<? super T> predicate) -
optionalEmpty
-
anyElementThat
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<Iterable<? extends T>> anyElementThat(DescribedPredicate<? super T> predicate) -
allElements
@PublicAPI(usage=ACCESS) public static <T> DescribedPredicate<Iterable<T>> allElements(DescribedPredicate<? super T> predicate)
-