Class ImmutableTester


  • public final class ImmutableTester
    extends AbstractTester
    This is a utility class to test if a class is really (strict) Immuable. Immutable with this tester means, that all fields must be final.
    Since:
    1.6 (09.02.2016)
    Author:
    oboehm (ob@aosd.de)
    • Constructor Summary

      Constructors 
      Constructor Description
      ImmutableTester()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertImmutable​(java.lang.Class<? extends java.lang.Object> clazz)
      Assert that a class is immutable.
      static void assertImmutable​(java.lang.Package pkg)
      Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.
      static void assertImmutable​(java.lang.Package pkg, java.lang.Class<?>... excluded)
      Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.
      static void assertImmutable​(java.util.Collection<java.lang.Class<? extends java.lang.Object>> classes)
      Checks for each class in the given collection if it is immutable.
      static void assertImmutableOfPackage​(java.lang.String packageName)
      Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.
      static void assertImmutableOfPackage​(java.lang.String packageName, java.lang.Class<?>... excluded)
      Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ImmutableTester

        public ImmutableTester()
    • Method Detail

      • assertImmutable

        public static void assertImmutable​(java.lang.Class<? extends java.lang.Object> clazz)
        Assert that a class is immutable.

        An immutable class cannot be changed. I.e. the attributes of this class should be final - and this is tested by this method. This is a strict form an immutable check. If you don't agree with this strict check do not use this method.

        Parameters:
        clazz - the clazz to be examined
        Since:
        1.6.1
      • assertImmutable

        public static void assertImmutable​(java.lang.Package pkg)
        Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.

        To get a name of a package call Package.getPackage(String). But be sure that you can't get null as result. In this case use assertImmutableOfPackage(String).

        Parameters:
        pkg - the package e.g. "patterntesting.runtime"
        Since:
        1.6.1
        See Also:
        assertImmutableOfPackage(String)
      • assertImmutable

        public static void assertImmutable​(java.lang.Package pkg,
                                           java.lang.Class<?>... excluded)
        Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.

        To get a name of a package call Package.getPackage(String). But be sure that you can't get null as result. In this case use assertImmutableOfPackage(String, Class...).

        Parameters:
        pkg - the package e.g. "patterntesting.runtime"
        excluded - classes which are excluded from the check
        Since:
        1.6.1
        See Also:
        assertImmutableOfPackage(String, Class...)
      • assertImmutableOfPackage

        public static void assertImmutableOfPackage​(java.lang.String packageName)
        Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.

        This method does the same as assertImmutable(Package) but was introduced by Package.getPackage(String) sometimes return null if no class of this package is loaded.

        Parameters:
        packageName - the package name e.g. "patterntesting.runtime"
        Since:
        1.6.1
        See Also:
        assertImmutable(Package)
      • assertImmutableOfPackage

        public static void assertImmutableOfPackage​(java.lang.String packageName,
                                                    java.lang.Class<?>... excluded)
        Check for each class with the Immutable annotation if it is really (strict) Immutable and has on non-final field.
        Parameters:
        packageName - the package name e.g. "patterntesting.runtime"
        excluded - classes which should be excluded from the check
        Since:
        1.6.1
        See Also:
        assertImmutableOfPackage(String)
      • assertImmutable

        public static void assertImmutable​(java.util.Collection<java.lang.Class<? extends java.lang.Object>> classes)
        Checks for each class in the given collection if it is immutable. I.e. if the class has only final fields.
        Parameters:
        classes - the classes