java.lang.Object
com.tngtech.archunit.library.dependencies.Slices
All Implemented Interfaces:
DescribedIterable<Slice>, HasDescription, CanOverrideDescription<Slices>, java.lang.Iterable<Slice>

public final class Slices
extends java.lang.Object
implements DescribedIterable<Slice>, CanOverrideDescription<Slices>
Basic collection of Slice for tests of dependencies between different domain packages, e.g. to avoid cycles. Refer to SlicesRuleDefinition for further info on how to form an ArchRule to test slices.
  • Nested Class Summary

    Nested Classes
    Modifier and Type Class Description
    static class  Slices.Transformer
    Specifies how to transform a set of JavaClass into a set of Slice, e.g.

    Nested classes/interfaces inherited from interface com.tngtech.archunit.base.DescribedIterable

    DescribedIterable.From
  • Method Summary

    Modifier and Type Method Description
    Slices as​(java.lang.String description)
    Allows to adjust the description of this object.
    static Slices.Transformer assignedFrom​(SliceAssignment sliceAssignment)
    Supports partitioning a set of JavaClasses into different Slices by the supplied SliceAssignment.
    java.lang.String getDescription()  
    java.util.Iterator<Slice> iterator()  
    static Slices.Transformer matching​(java.lang.String packageIdentifier)
    Supports partitioning a set of JavaClasses into different slices by matching the supplied package identifier.
    Slices namingSlices​(java.lang.String pattern)
    Allows the naming of single slices, where back references to the matching pattern can be denoted by '$' followed by capturing group number.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Method Details

    • iterator

      public java.util.Iterator<Slice> iterator()
      Specified by:
      iterator in interface java.lang.Iterable<Slice>
    • as

      public Slices as​(java.lang.String description)
      Description copied from interface: CanOverrideDescription
      Allows to adjust the description of this object. Note that this method will not modify the current object, but instead return a new object with adjusted description.
      Specified by:
      as in interface CanOverrideDescription<Slices>
      Parameters:
      description - The description the result of this method will hold
      Returns:
      A new equivalent object with adjusted description
    • getDescription

      public java.lang.String getDescription()
      Specified by:
      getDescription in interface HasDescription
    • namingSlices

      @PublicAPI(usage=ACCESS) public Slices namingSlices​(java.lang.String pattern)
      Allows the naming of single slices, where back references to the matching pattern can be denoted by '$' followed by capturing group number.
      E.g. namingSlices("Slice $1") would name a slice matching '*..service.(*)..*' against 'com.some.company.service.hello.something' as 'Slice hello'.
      Likewise, if the slices were created by a SliceAssignment (compare assignedFrom(SliceAssignment)), then the back reference refers to the n-th element of the identifier.
      Parameters:
      pattern - The naming pattern, e.g. 'Slice $1'
      Returns:
      New (equivalent) slices with adjusted description for each single slice
    • matching

      @PublicAPI(usage=ACCESS) public static Slices.Transformer matching​(java.lang.String packageIdentifier)
      Supports partitioning a set of JavaClasses into different slices by matching the supplied package identifier. For identifier syntax, see PackageMatcher.
      The slicing is done according to capturing groups (thus if none are contained in the identifier, no more than a single slice will be the result). For example

      Suppose there are three classes:

      com.example.slice.one.SomeClass
      com.example.slice.one.AnotherClass
      com.example.slice.two.YetAnotherClass

      If slices are created by specifying

      Slices.of(classes).byMatching("..slice.(*)..")

      then the result will be two slices, the slice where the capturing group is 'one' and the slice where the capturing group is 'two'.

      Parameters:
      packageIdentifier - The identifier to match against
      Returns:
      Slices partitioned according the supplied package identifier
    • assignedFrom

      @PublicAPI(usage=ACCESS) public static Slices.Transformer assignedFrom​(SliceAssignment sliceAssignment)
      Supports partitioning a set of JavaClasses into different Slices by the supplied SliceAssignment. This is basically a mapping JavaClass -> SliceIdentifier, i.e. if the SliceAssignment returns the same SliceIdentifier for two classes they will end up in the same slice. A JavaClass will be ignored within the slices, if its SliceIdentifier is SliceIdentifier.ignore(). For example

      Suppose there are four classes:

      com.somewhere.SomeClass
      com.somewhere.AnotherClass
      com.other.elsewhere.YetAnotherClass
      com.randomly.anywhere.AndYetAnotherClass

      If slices are created by specifying

      Slices.of(classes).assignedFrom(customAssignment)

      and the customAssignment maps

      com.somewhere -> SliceIdentifier.of("somewhere")
      com.other.elsewhere -> SliceIdentifier.of("elsewhere")
      com.randomly -> SliceIdentifier.ignore()

      then the result will be two slices, identified by the single strings 'somewhere' (containing SomeClass and AnotherClass) and 'elsewhere' (containing YetAnotherClass). The class AndYetAnotherClass will be missing from all slices.

      Parameters:
      sliceAssignment - The assignment of JavaClass to SliceIdentifier
      Returns:
      Slices partitioned according the supplied assignment