Class JavaPackage

java.lang.Object
org.springframework.modulith.core.JavaPackage
All Implemented Interfaces:
com.tngtech.archunit.base.DescribedIterable<com.tngtech.archunit.core.domain.JavaClass>, com.tngtech.archunit.base.HasDescription, Comparable<JavaPackage>, Iterable<com.tngtech.archunit.core.domain.JavaClass>

public class JavaPackage extends Object implements com.tngtech.archunit.base.DescribedIterable<com.tngtech.archunit.core.domain.JavaClass>, Comparable<JavaPackage>
An abstraction of a Java package.
Author:
Oliver Drotbohm
  • Method Details

    • of

      public static JavaPackage of(Classes classes, String name)
      Creates a new JavaPackage for the given classes and name.
      Parameters:
      classes - must not be null.
      name - must not be null or empty.
      Returns:
    • isPackageInfoType

      public static boolean isPackageInfoType(com.tngtech.archunit.core.domain.JavaClass type)
      Returns whether the given type is the package-info.java one.
      Parameters:
      type - must not be null.
    • getName

      public String getName()
      Returns the name of the package.
      Returns:
      will never be null.
    • getTrailingName

      public String getTrailingName(JavaPackage pkg)
      Returns the name of the given JavaPackage with regards to the current one.
      Parameters:
      pkg - must not be null.
      Returns:
      will never be null.
      Since:
      1.3
    • toSingle

      public JavaPackage toSingle()
      Reduces the JavaPackage to only its base package.
      Returns:
      will never be null.
    • getLocalName

      public String getLocalName()
      Returns the local name of the package, i.e. the last segment of the qualified package name.
      Returns:
      will never be null.
    • getDirectSubPackages

      public Collection<JavaPackage> getDirectSubPackages()
      Returns all direct sub-packages of the current one.
      Returns:
      will never be null.
    • getClasses

      public Classes getClasses()
      Returns all classes residing in the current package and potentially in sub-packages if the current package was created to include them.
      Returns:
      will never be null.
    • getExposedClasses

      public Classes getExposedClasses()
      Returns the classes exposed by this package, i.e. only public ones. Also filters the package-info type.
      Returns:
      will never be null.
    • getSubPackagesAnnotatedWith

      public Stream<JavaPackage> getSubPackagesAnnotatedWith(Class<? extends Annotation> annotation)
      Returns all sub-packages that carry the given annotation type.
      Parameters:
      annotation - must not be null.
      Returns:
      will never be null.
    • that

      public Classes that(com.tngtech.archunit.base.DescribedPredicate<? super com.tngtech.archunit.core.domain.JavaClass> predicate)
      Returns all Classes that match the given DescribedPredicate.
      Parameters:
      predicate - must not be null.
      Returns:
      will never be null.
    • contains

      public boolean contains(com.tngtech.archunit.core.domain.JavaClass type)
      Return whether the JavaPackage contains the given type.
      Parameters:
      type - must not be null.
    • contains

      public boolean contains(String typeName)
      Returns whether the JavaPackage contains the type with the given name.
      Parameters:
      typeName - must not be null or empty.
    • stream

      public Stream<com.tngtech.archunit.core.domain.JavaClass> stream()
      Returns a Stream of all JavaClasses contained in the JavaPackage.
      Returns:
      will never be null.
    • getAnnotation

      public <A extends Annotation> Optional<A> getAnnotation(Class<A> annotationType)
      Return the annotation of the given type declared on the package.
      Type Parameters:
      A - the annotation type.
      Parameters:
      annotationType - the annotation type to be found.
      Returns:
      will never be null.
    • getPackageName

      PackageName getPackageName()
      Returns the name of the package.
      Returns:
      will never be null.
      Since:
      1.3
    • asFilter

      String asFilter()
      Returns a filter expression including all types within that package and any nested package.
      Returns:
      will never be null.
      Since:
      1.3
    • andSubPackagesAnnotatedWith

      Stream<JavaPackage> andSubPackagesAnnotatedWith(Class<? extends Annotation> type)
      Returns a new Stream of the current package and all its sub-packages annotated with the given annotation type.
      Parameters:
      type - must not be null.
      Returns:
      will never be null.
      Since:
      1.3
    • isSubPackageOf

      boolean isSubPackageOf(JavaPackage reference)
      Returns whether the given reference package is a sub-package of the current one.
      Parameters:
      reference - must not be null.
      Returns:
      will never be null.
      Since:
      1.3
    • getClasses

      Classes getClasses(Iterable<JavaPackage> exclusions)
      Returns all Classes residing in the current package but not in any of the given sub-packages.
      Parameters:
      exclusions - must not be null.
      Returns:
      will never be null.
      Since:
      1.3
    • getSubPackages

      JavaPackages getSubPackages()
      Returns a JavaPackages instance representing all sub-packages.
      Returns:
      will never be null.
      Since:
      1.3
    • getSubPackage

      Optional<JavaPackage> getSubPackage(String localName)
      Returns the sub-package with the given local name.
      Parameters:
      localName - must not be null or empty.
      Returns:
      will never be null.
      Since:
      1.3
    • findAnnotation

      public <A extends Annotation> Optional<A> findAnnotation(Class<A> annotationType)
      Finds the annotation of the given type declared on the package itself or any type located the direct package's types .
      Type Parameters:
      A - the type of the annotation.
      Parameters:
      annotationType - must not be null.
      Returns:
      will never be null.
      Throws:
      IllegalStateException - in case multiple types in the current package are annotated with the given annotation.
      Since:
      1.2
    • getDescription

      public String getDescription()
      Specified by:
      getDescription in interface com.tngtech.archunit.base.HasDescription
    • iterator

      public Iterator<com.tngtech.archunit.core.domain.JavaClass> iterator()
      Specified by:
      iterator in interface Iterable<com.tngtech.archunit.core.domain.JavaClass>
    • compareTo

      public int compareTo(JavaPackage o)
      Specified by:
      compareTo in interface Comparable<JavaPackage>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • reverse

      static Comparator<JavaPackage> reverse()