Class PackageName

java.lang.Object
org.springframework.modulith.core.PackageName
All Implemented Interfaces:
Comparable<PackageName>

class PackageName extends Object implements Comparable<PackageName>
The name of a Java package. Packages are sortable comparing their individual segments and deeper packages sorted last.
Since:
1.2
Author:
Oliver Drotbohm
  • Method Details

    • ofType

      static PackageName ofType(String fullyQualifiedName)
      Creates a new PackageName for the given fully-qualified type name.
      Parameters:
      fullyQualifiedName - must not be null or empty.
      Returns:
      will never be null.
    • of

      static PackageName of(String name)
      Returns the PackageName with the given name.
      Parameters:
      name - must not be null.
      Returns:
      will never be null.
      Since:
      1.4
    • of

      static PackageName of(String[] segments)
      Returns the PackageName for the given segments.
      Parameters:
      segments - must not be null.
      Returns:
      will never be null.
      Since:
      1.4
    • length

      int length()
      Returns the length of the package name.
      Returns:
      will never be null.
    • getName

      String getName()
      Returns the raw name.
      Returns:
      will never be null.
    • hasName

      boolean hasName(String name)
      Returns whether the PackageName has the given String name.
      Parameters:
      name - must not be null or empty.
    • getLocalName

      String getLocalName()
      Returns the last segment of a package name.
      Returns:
      will never be null.
    • getLocalName

      String getLocalName(String base)
      Returns the nested name in reference to the given base.
      Parameters:
      base - must not be null or empty.
      Returns:
      will never be null.
    • asFilter

      String asFilter(boolean includeNested)
      Returns the filter expression to include all types including from nested packages.
      Returns:
      will never be null.
    • isParentPackageOf

      boolean isParentPackageOf(PackageName reference)
      Returns whether the current PackageName is the name of a parent package of the given one.
      Parameters:
      reference - must not be null.
      Returns:
      will never be null.
    • isDirectParentOf

      boolean isDirectParentOf(PackageName reference)
    • contains

      boolean contains(PackageName reference)
      Returns whether the package name contains the given one, i.e. if the given one either is the current one or a sub-package of it.
      Parameters:
      reference - must not be null.
    • isSubPackageOf

      boolean isSubPackageOf(PackageName reference)
      Returns whether the current PackageName is the name of a sub-package with the given name.
      Parameters:
      reference - must not be null.
      Returns:
      will never be null.
    • isEmpty

      boolean isEmpty()
    • compareTo

      public int compareTo(PackageName o)
      Specified by:
      compareTo in interface Comparable<PackageName>
    • expandUntil

      Stream<PackageName> expandUntil(PackageName reference)
      Returns the names of sub-packages of the current one until the given reference PackageName.
      Parameters:
      reference - must not be null.
      Returns:
      will never be null.
      Since:
      1.4
    • hasParent

      boolean hasParent()
      Returns whether the current PackageName has a parent.
      Since:
      1.4
    • getParent

      @Nullable PackageName getParent()
      Returns the parent PackageName.
      Returns:
      can be null.
      Since:
      1.4
    • 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