java.lang.Object
de.iip_ecosphere.platform.services.spring.Utils

public class Utils extends Object
Some utility functions. [public for testing]
Author:
Holger Eichelberger, SSE
  • Constructor Details

    • Utils

      public Utils()
  • Method Details

    • formatToMeBi

      public static String formatToMeBi(long number)
      Formats number to Mebibytes (g/m only) without fractions and bytes as base unit. For input outside the m/g range, the input is returned. Please be aware of number overflow for larger g values. [public for testing]
      Parameters:
      number - the number to be formatted
      Returns:
      the formatted number
      See Also:
    • formatToMeBi

      public static String formatToMeBi(long number, int baseUnit)
      Formats number to Mebibytes (g/m only) without fractions. For input outside the m/g range (including t in terms of g), the input is returned. [public for testing]
      Parameters:
      number - the number to be formatted
      baseUnit - 0 = bytes, 1 = kByte, 2 = mByte, 3 = gByte, ...
      Returns:
      the formatted number
    • addPropertyIfPositiveToMeBi

      public static void addPropertyIfPositiveToMeBi(Map<String,String> properties, String key, Number value, String deflt)
      Checks, formats and adds a long megabyte value as Mebibytes property.
      Parameters:
      properties - the properties to be modified as a side effect
      key - the key in Properties to modify
      value - the number as value in megabytes to be added
      deflt - the formatted default if number is not positive, may be null for no property at all
      See Also:
    • addPropertyIfPositiveToInt

      public static void addPropertyIfPositiveToInt(Map<String,String> properties, String key, Number value, String deflt)
      Checks, formats and adds an integer deployer property.
      Parameters:
      properties - the properties to be modified as a side effect
      key - the key in Properties to modify
      value - the number as value to be added
      deflt - the formatted default if number is not positive, may be null for no property at all
      See Also:
    • addProperty

      public static void addProperty(Map<String,String> properties, String key, Number value, String deflt, Predicate<Number> cond, Function<Number,String> formatter)
      Checks, formats and adds a deployer property.
      Parameters:
      properties - the properties to be modified as a side effect
      key - the key in Properties to modify
      value - the value to be added
      deflt - the formatted default if number is not acceptable, may be null to add nothing as default value
      cond - checks value, if true format via formatter and add as key to properties, else (if deflt is not null, add deflt as key to properties
      formatter - the formatter for number
    • initialize

      public static void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext)
      Sets up an application context.
      Parameters:
      applicationContext - the application context
    • initialize

      public static void initialize(org.springframework.context.ConfigurableApplicationContext applicationContext, Map<String,Object> overwrite)
      Sets up an application context.
      Parameters:
      applicationContext - the application context
      overwrite - overwriting property values, may be null for none
    • initialize

      public static void initialize(org.springframework.core.env.ConfigurableEnvironment env)
      Sets up a configurable environment.
      Parameters:
      env - the environment
    • initialize

      public static void initialize(org.springframework.core.env.ConfigurableEnvironment env, Iterable<String> ignores)
      Sets up a configurable environment.
      Parameters:
      env - the environment
      ignores - the properties for not to return any value although defined or overridden, may be null or empty for none
    • initialize

      public static void initialize(org.springframework.core.env.ConfigurableEnvironment env, Map<String,Object> overwrite, Iterable<String> ignores)
      Sets up a configurable environment.
      Parameters:
      env - the environment
      overwrite - overwriting property values, may be null for none
      ignores - the properties for not to return any value although defined or overridden, may be null or empty for none