Class DataUtils


  • public abstract class DataUtils
    extends java.lang.Object
    Abstract class that contains utility functions for working with data collections like maps or lists.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.text.DecimalFormat DOUBLE_FORMAT
      Standard pattern to format numbers
      private static java.text.DecimalFormat FLOAT_FORMAT  
    • Constructor Summary

      Constructors 
      Constructor Description
      DataUtils()
      Default constructor that prevents creation of class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.List<java.lang.Double> asList​(double[] elements)
      Converts an array of double numbers to a list of Doubles.
      static java.util.List<java.lang.Float> asList​(float[] elements)
      Converts an array of float numbers to a list of Floats.
      static java.lang.String format​(java.lang.Number number)
      Returns a formatted string of the specified number.
      static java.lang.String format​(java.lang.Object obj)
      Returns a formatted string of the specified object.
      static java.lang.String join​(java.lang.String separator, double[] elements)
      Returns a string containing all double numbers concatenated by a specified separator.
      static java.lang.String join​(java.lang.String separator, float[] elements)
      Returns a string containing all float numbers concatenated by a specified separator.
      static java.lang.String join​(java.lang.String separator, java.lang.Object[] elements)
      Returns a string containing all elements concatenated by a specified separator.
      static java.lang.String join​(java.lang.String separator, java.util.List<?> elements)
      Returns a string containing all elements concatenated by a specified separator.
      static <K,​V>
      java.util.Map<K,​V>
      map​(K[] keys, V[] values)
      Creates a mapping from two arrays, one with keys, one with values.
      static int max​(int... values)
      Returns the largest of all specified values.
      static java.lang.String stripTrailing​(java.lang.String s, java.lang.String substr)
      Removes the specified trailing pattern from a string.
      static void transfer​(java.io.InputStream in, java.io.OutputStream out, int bufferSize)
      Copies data from an input stream to an output stream using a buffer of specified size.
      • Methods inherited from class java.lang.Object

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

      • DOUBLE_FORMAT

        private static final java.text.DecimalFormat DOUBLE_FORMAT
        Standard pattern to format numbers
      • FLOAT_FORMAT

        private static final java.text.DecimalFormat FLOAT_FORMAT
    • Constructor Detail

      • DataUtils

        DataUtils()
        Default constructor that prevents creation of class.
    • Method Detail

      • map

        public static <K,​V> java.util.Map<K,​V> map​(K[] keys,
                                                               V[] values)
        Creates a mapping from two arrays, one with keys, one with values.
        Type Parameters:
        K - Data type of the keys.
        V - Data type of the values.
        Parameters:
        keys - Array containing the keys.
        values - Array containing the values.
        Returns:
        Map with keys and values from the specified arrays.
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            java.util.List<?> elements)
        Returns a string containing all elements concatenated by a specified separator.
        Parameters:
        separator - Separator string.
        elements - List of elements that should be concatenated.
        Returns:
        a concatenated string.
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            java.lang.Object[] elements)
        Returns a string containing all elements concatenated by a specified separator.
        Parameters:
        separator - Separator string.
        elements - Array of elements that should be concatenated.
        Returns:
        a concatenated string.
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            double[] elements)
        Returns a string containing all double numbers concatenated by a specified separator.
        Parameters:
        separator - Separator string.
        elements - Array of double numbers that should be concatenated.
        Returns:
        a concatenated string.
      • join

        public static java.lang.String join​(java.lang.String separator,
                                            float[] elements)
        Returns a string containing all float numbers concatenated by a specified separator.
        Parameters:
        separator - Separator string.
        elements - Array of float numbers that should be concatenated.
        Returns:
        a concatenated string.
      • max

        public static int max​(int... values)
        Returns the largest of all specified values.
        Parameters:
        values - Several integer values.
        Returns:
        largest value.
      • transfer

        public static void transfer​(java.io.InputStream in,
                                    java.io.OutputStream out,
                                    int bufferSize)
                             throws java.io.IOException
        Copies data from an input stream to an output stream using a buffer of specified size.
        Parameters:
        in - Input stream.
        out - Output stream.
        bufferSize - Size of the copy buffer.
        Throws:
        java.io.IOException - when an error occurs while copying.
      • format

        public static java.lang.String format​(java.lang.Number number)
        Returns a formatted string of the specified number. All trailing zeroes or decimal points will be stripped.
        Parameters:
        number - Number to convert to a string.
        Returns:
        A formatted string.
      • format

        public static java.lang.String format​(java.lang.Object obj)
        Returns a formatted string of the specified object.
        Parameters:
        obj - Object to convert to a string.
        Returns:
        A formatted string.
      • asList

        public static java.util.List<java.lang.Float> asList​(float[] elements)
        Converts an array of float numbers to a list of Floats. The list will be empty if the array is empty or null.
        Parameters:
        elements - Array of float numbers.
        Returns:
        A list with all numbers as Float.
      • asList

        public static java.util.List<java.lang.Double> asList​(double[] elements)
        Converts an array of double numbers to a list of Doubles. The list will be empty if the array is empty or null.
        Parameters:
        elements - Array of double numbers.
        Returns:
        A list with all numbers as Double.
      • stripTrailing

        public static java.lang.String stripTrailing​(java.lang.String s,
                                                     java.lang.String substr)
        Removes the specified trailing pattern from a string.
        Parameters:
        s - string.
        substr - trailing pattern.
        Returns:
        A string without the trailing pattern.