Class MetricsComponents<T>
java.lang.Object
com.tngtech.archunit.base.ForwardingCollection<MetricsComponent<T>>
com.tngtech.archunit.library.metrics.MetricsComponents<T>
- All Implemented Interfaces:
java.lang.Iterable<MetricsComponent<T>>
,java.util.Collection<MetricsComponent<T>>
@PublicAPI(usage=ACCESS) public final class MetricsComponents<T> extends ForwardingCollection<MetricsComponent<T>>
A collection of
MetricsComponent
. Provides factory methods create components from
ArchUnit domain objects like JavaPackage
or to componentize sets of elements.-
Method Summary
Modifier and Type Method Description protected java.util.Collection<MetricsComponent<T>>
delegate()
static <T> MetricsComponents<T>
from(java.util.Collection<T> elements, Function<? super T,java.lang.String> identifierFunction)
Partitions the passed set of elements into components according to the specifiedidentifierFunction
.static MetricsComponents<JavaClass>
fromClasses(java.util.Collection<JavaClass> classes)
Creates oneMetricsComponent
for each passedJavaClass
containing only this class itself.static MetricsComponents<JavaClass>
fromPackages(java.util.Collection<JavaPackage> packages)
Creates oneMetricsComponent
for each passedJavaPackage
containing all classes contained in the respective package or any subpackage.static <T> MetricsComponents<T>
of(MetricsComponent<T>... components)
static <T> MetricsComponents<T>
of(java.util.Collection<MetricsComponent<T>> metricsComponents)
CreatesMetricsComponents
containing the supplied collection ofMetricsComponent
.
Note that the identifiers of the passed components must all be unique.Optional<MetricsComponent<T>>
tryGetComponent(java.lang.String identifier)
Methods inherited from class com.tngtech.archunit.base.ForwardingCollection
add, addAll, clear, contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, spliterator, stream, toArray
Methods inherited from interface java.lang.Iterable
forEach
-
Method Details
-
tryGetComponent
@PublicAPI(usage=ACCESS) public Optional<MetricsComponent<T>> tryGetComponent(java.lang.String identifier)- Parameters:
identifier
- The identifier of a component- Returns:
- The component with the specified identifier if present,
Optional.absent()
otherwise.
-
delegate
- Specified by:
delegate
in classForwardingCollection<MetricsComponent<T>>
-
of
@SafeVarargs @PublicAPI(usage=ACCESS) public static <T> MetricsComponents<T> of(MetricsComponent<T>... components)- See Also:
of(Collection)
-
of
@PublicAPI(usage=ACCESS) public static <T> MetricsComponents<T> of(java.util.Collection<MetricsComponent<T>> metricsComponents)CreatesMetricsComponents
containing the supplied collection ofMetricsComponent
.
Note that the identifiers of the passed components must all be unique.- Type Parameters:
T
- The type of the elements contained within each component- Parameters:
metricsComponents
- The components the result will contain- Returns:
- The created
MetricsComponents
- Throws:
java.lang.IllegalArgumentException
- if any two components have a duplicate identifier
-
from
@PublicAPI(usage=ACCESS) public static <T> MetricsComponents<T> from(java.util.Collection<T> elements, Function<? super T,java.lang.String> identifierFunction)Partitions the passed set of elements into components according to the specifiedidentifierFunction
. That is for each element ofelements
the respective component identifier will be derived via the passedidentifierFunction
. For each such identifier a component will be created and all elements with the same identifier will end up in the same component.- Type Parameters:
T
- The type of the elements- Parameters:
elements
- The elements to componentizeidentifierFunction
- A function to create the respective identifier each element belongs to- Returns:
MetricsComponents
containing one component for each unique identifier created this way
-
fromPackages
@PublicAPI(usage=ACCESS) public static MetricsComponents<JavaClass> fromPackages(java.util.Collection<JavaPackage> packages)Creates oneMetricsComponent
for each passedJavaPackage
containing all classes contained in the respective package or any subpackage. Theidentifier
for each component will be the full package name of the respectiveJavaPackage
.- Parameters:
packages
- A collection ofpackages
to derive the components from- Returns:
MetricsComponents
where components mirror the passed packages
-
fromClasses
@PublicAPI(usage=ACCESS) public static MetricsComponents<JavaClass> fromClasses(java.util.Collection<JavaClass> classes)Creates oneMetricsComponent
for each passedJavaClass
containing only this class itself. Theidentifier
for each component will be the fully qualified class name of the containedJavaClass
.- Parameters:
classes
- Theclasses
to created components from- Returns:
MetricsComponents
where components mirror the passed classes one to one
-