Class GetUtils

java.lang.Object
com.igormaznitsa.meta.common.utils.GetUtils

@Weight(LIGHT) public final class GetUtils extends Object
Auxiliary methods to get values.
Since:
1.0
  • Constructor Details

    • GetUtils

      private GetUtils()
  • Method Details

    • ensureNonNull

      public static <T> T ensureNonNull(T value, T defaultValue)
      Get value and ensure that the value is not null
      Type Parameters:
      T - type of value
      Parameters:
      value - the value
      defaultValue - the default value to be returned if the value is null
      Returns:
      not null value
      Throws:
      AssertionError - if both the value and the default value are null
      Since:
      1.0
    • ensureNonNull

      public static <T> T ensureNonNull(T value)
      Get value if it is not null.
      Type Parameters:
      T - type of value
      Parameters:
      value - the value
      Returns:
      the value if it is not null
      Throws:
      AssertionError - if the value is null
      Since:
      1.0
    • findFirstNonNull

      public static <T> T findFirstNonNull(T... objects)
      Find the first non-null value in an array and return that.
      Type Parameters:
      T - type of value
      Parameters:
      objects - array to find value
      Returns:
      the first non-null value from the array
      Throws:
      AssertionError - if the array is null or it doesn't contain a non-null value
      Since:
      1.0
    • ensureNonNullAndNonEmpty

      public static String ensureNonNullAndNonEmpty(String value, @Constraint("notEmpty(X)") String dflt)
      Get non-null non-empty string.
      Parameters:
      value - a base string
      dflt - default string to be provided if value is null or empty
      Returns:
      non-nullable non-empty string
      Since:
      1.1.1
    • ensureNonNullStr

      public static String ensureNonNullStr(String value)
      Ensure that a string will not be null.
      Parameters:
      value - value to be checked
      Returns:
      the value if it is not null or empty string if the value is null
      Since:
      1.1.1