Class Utils


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

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void addProperty​(java.util.Map<java.lang.String,​java.lang.String> properties, java.lang.String key, java.lang.Number value, java.lang.String deflt, java.util.function.Predicate<java.lang.Number> cond, java.util.function.Function<java.lang.Number,​java.lang.String> formatter)
      Checks, formats and adds a deployer property.
      static void addPropertyIfPositiveToInt​(java.util.Map<java.lang.String,​java.lang.String> properties, java.lang.String key, java.lang.Number value, java.lang.String deflt)
      Checks, formats and adds an integer deployer property.
      static void addPropertyIfPositiveToMeBi​(java.util.Map<java.lang.String,​java.lang.String> properties, java.lang.String key, java.lang.Number value, java.lang.String deflt)
      Checks, formats and adds a long megabyte value as Mebibytes property.
      static java.lang.String formatToMeBi​(long number)
      Formats number to Mebibytes (g/m only) without fractions and bytes as base unit.
      static java.lang.String formatToMeBi​(long number, int baseUnit)
      Formats number to Mebibytes (g/m only) without fractions.
      • Methods inherited from class java.lang.Object

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

      • Utils

        public Utils()
    • Method Detail

      • formatToMeBi

        public static java.lang.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(long, int)
      • formatToMeBi

        public static java.lang.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​(java.util.Map<java.lang.String,​java.lang.String> properties,
                                                       java.lang.String key,
                                                       java.lang.Number value,
                                                       java.lang.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:
        formatToMeBi(long), addProperty(Map, String, Number, String, Predicate, Function)
      • addPropertyIfPositiveToInt

        public static void addPropertyIfPositiveToInt​(java.util.Map<java.lang.String,​java.lang.String> properties,
                                                      java.lang.String key,
                                                      java.lang.Number value,
                                                      java.lang.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(Map, String, Number, String, Predicate, Function)
      • addProperty

        public static void addProperty​(java.util.Map<java.lang.String,​java.lang.String> properties,
                                       java.lang.String key,
                                       java.lang.Number value,
                                       java.lang.String deflt,
                                       java.util.function.Predicate<java.lang.Number> cond,
                                       java.util.function.Function<java.lang.Number,​java.lang.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