Class Asserted


  • public final class Asserted
    extends Object

    A utility class to assert certain conditions

    Since:
    1.0
    Version:
    1.0 $Revision: 7681 $
    Author:
    "Martin Krischik" «krischik@users.sourceforge.net»
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static Logger Logger
      Class logger instance.
      private static String TAG
      Class logger tag.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Asserted()
      Utility class
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void equal​(long left, long right)
      test if a string lengths is inside the range min … max
      static void equal​(long left, long right, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void greaterEqual​(long left, long right)
      test if a string lengths is inside the range min … max
      static void greaterEqual​(long left, long right, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void isFalse​(boolean value)
      test if a string lengths is inside the range min … max
      static void isFalse​(boolean value, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void isInstance​(@NotNull Object value, @NotNull Class<?> type)
      test if a string lengths is inside the range min … max
      static void isInstance​(@NotNull Object value, @NotNull Class<?> type, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void isNatural​(int value)
      test if a numeric value is greater or equal 0
      static void isNatural​(int value, @NotNull String name)
      test if a numeric value is greater or equal 0
      static void isNull​(@Nullable Object value)
      test if a string lengths is inside the range min … max
      static void isNull​(@Nullable Object value, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void isPositive​(int value)
      test if a numeric value is greater or equal 1
      static void isPositive​(int value, @NotNull String name)
      test if a numeric value is greater or equal 1
      static void isTrue​(boolean value)
      test if a string lengths is inside the range min … max
      static void isTrue​(boolean value, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void notEmpty​(@Nullable String value)
      test if a string lengths is not empty
      static void notEmpty​(@Nullable String value, @NotNull String name)
      test if a string lengths is not empty
      static void notNull​(@Nullable Object value)
      test if a string lengths is inside the range min … max
      static void notNull​(@Nullable Object value, @NotNull String name)
      test if a string lengths is inside the range min … max
      static void range​(byte value, byte min, byte max)
      test if a numeric value is inside the range min … max
      static void range​(byte value, byte min, byte max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(double value, double min, double max)
      test if a numeric value is inside the range min … max
      static void range​(double value, double min, double max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(float value, float min, float max)
      test if a numeric value is inside the range min … max
      static void range​(float value, float min, float max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(int value, int min, int max)
      test if a numeric value is inside the range min … max
      static void range​(int value, int min, int max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(long value, long min, long max)
      test if a numeric value is inside the range min … max
      static void range​(long value, long min, long max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(short value, short min, short max)
      test if a numeric value is inside the range min … max
      static void range​(short value, short min, short max, @NotNull String name)
      test if a numeric value is inside the range min … max
      static void range​(@NotNull CharSequence value, int min, int max)
      test if a string length is inside the range min … max
      static void range​(@NotNull CharSequence value, int min, int max, @NotNull String name)
      test if a string length is inside the range min … max
      static void range​(@NotNull Object @NotNull [] value, int min, int max)
      test if a string length is inside the range min … max
      static void range​(@NotNull Object @NotNull [] value, int min, int max, @NotNull String name)
      test if a string length is inside the range min … max
      static void rangeOrNull​(@Nullable CharSequence value, int min, int max)
      test if a string length is inside the range min … max
      static void rangeOrNull​(@Nullable CharSequence value, int min, int max, @NotNull String name)
      test if a string length is inside the range min … max
    • Field Detail

      • Logger

        private static final Logger Logger

        Class logger instance.

      • TAG

        private static final String TAG

        Class logger tag.

    • Constructor Detail

      • Asserted

        private Asserted()

        Utility class

    • Method Detail

      • equal

        public static void equal​(long left,
                                 long right)

        test if a string lengths is inside the range min … max

        Parameters:
        left - value to test
        right - value to test
        Throws:
        AssertionError - when value is outside min … max
      • equal

        public static void equal​(long left,
                                 long right,
                                 @NotNull
                                 @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        left - value to test
        right - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • greaterEqual

        public static void greaterEqual​(long left,
                                        long right)

        test if a string lengths is inside the range min … max

        Parameters:
        left - value to test
        right - value to test
        Throws:
        AssertionError - when value is outside min … max
      • greaterEqual

        public static void greaterEqual​(long left,
                                        long right,
                                        @NotNull
                                        @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        left - value to test
        right - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • isFalse

        @Contract("true -> fail")
        public static void isFalse​(boolean value)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        Throws:
        AssertionError - when value is outside min … max
      • isFalse

        @Contract("true, _ -> fail")
        public static void isFalse​(boolean value,
                                   @NotNull
                                   @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • isInstance

        public static void isInstance​(@NotNull
                                      @NotNull Object value,
                                      @NotNull
                                      @NotNull Class<?> type)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        type - type to check against
        Throws:
        AssertionError - when value is outside min … max
      • isInstance

        public static void isInstance​(@NotNull
                                      @NotNull Object value,
                                      @NotNull
                                      @NotNull Class<?> type,
                                      @NotNull
                                      @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        type - type to check against
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • isNatural

        public static void isNatural​(int value)

        test if a numeric value is greater or equal 0

        Parameters:
        value - value to test
        Throws:
        IllegalArgumentException - when value is not not greater 0
      • isNatural

        public static void isNatural​(int value,
                                     @NotNull
                                     @NotNull String name)

        test if a numeric value is greater or equal 0

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        IllegalArgumentException - when value is not greater or equal 0
      • isNull

        public static void isNull​(@Nullable
                                  @Nullable Object value)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        Throws:
        AssertionError - when value is outside min … max
      • isNull

        public static void isNull​(@Nullable
                                  @Nullable Object value,
                                  @NotNull
                                  @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • isPositive

        public static void isPositive​(int value)

        test if a numeric value is greater or equal 1

        Parameters:
        value - value to test
        Throws:
        IllegalArgumentException - when value is not greater or equal 1
      • isPositive

        public static void isPositive​(int value,
                                      @NotNull
                                      @NotNull String name)

        test if a numeric value is greater or equal 1

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        IllegalArgumentException - when value is not greater or equal 1
      • isTrue

        @Contract("false -> fail")
        public static void isTrue​(boolean value)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        Throws:
        AssertionError - when value is outside min … max
      • isTrue

        @Contract("false, _ -> fail")
        public static void isTrue​(boolean value,
                                  @NotNull
                                  @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • notEmpty

        public static void notEmpty​(@Nullable
                                    @Nullable String value)

        test if a string lengths is not empty

        Parameters:
        value - value to test
        Throws:
        AssertionError - when value is outside min … max
      • notEmpty

        public static void notEmpty​(@Nullable
                                    @Nullable String value,
                                    @NotNull
                                    @NotNull String name)

        test if a string lengths is not empty

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • notNull

        @Contract("null -> fail")
        public static void notNull​(@Nullable
                                   @Nullable Object value)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        Throws:
        AssertionError - when value is outside min … max
      • notNull

        @Contract("null, _ -> fail")
        public static void notNull​(@Nullable
                                   @Nullable Object value,
                                   @NotNull
                                   @NotNull String name)

        test if a string lengths is inside the range min … max

        Parameters:
        value - value to test
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(byte value,
                                 byte min,
                                 byte max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(byte value,
                                 byte min,
                                 byte max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(@NotNull
                                 @NotNull CharSequence value,
                                 int min,
                                 int max)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(@NotNull
                                 @NotNull CharSequence value,
                                 int min,
                                 int max,
                                 @NotNull
                                 @NotNull String name)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(double value,
                                 double min,
                                 double max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(double value,
                                 double min,
                                 double max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(float value,
                                 float min,
                                 float max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(float value,
                                 float min,
                                 float max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(int value,
                                 int min,
                                 int max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(int value,
                                 int min,
                                 int max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(long value,
                                 long min,
                                 long max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(long value,
                                 long min,
                                 long max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(@NotNull
                                 @NotNull Object @NotNull [] value,
                                 int min,
                                 int max)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(@NotNull
                                 @NotNull Object @NotNull [] value,
                                 int min,
                                 int max,
                                 @NotNull
                                 @NotNull String name)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(short value,
                                 short min,
                                 short max)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • range

        public static void range​(short value,
                                 short min,
                                 short max,
                                 @NotNull
                                 @NotNull String name)

        test if a numeric value is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max
      • rangeOrNull

        public static void rangeOrNull​(@Nullable
                                       @Nullable CharSequence value,
                                       int min,
                                       int max)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        Throws:
        AssertionError - when value is outside min … max
      • rangeOrNull

        public static void rangeOrNull​(@Nullable
                                       @Nullable CharSequence value,
                                       int min,
                                       int max,
                                       @NotNull
                                       @NotNull String name)

        test if a string length is inside the range min … max

        Parameters:
        value - value to test
        min - minimum allowed value
        max - maximum allowed value
        name - value name for better error message
        Throws:
        AssertionError - when value is outside min … max