Class ArrayParser

java.lang.Object
com.illumon.iris.utils.ArrayParser

public class ArrayParser
extends Object
A simple wrapper for string-to-array parsing. Parsers are kept in a cache per-delimiter so that we avoid recompiling the pattern regex.
  • Method Details

    • getInstance

      public static ArrayParser getInstance​(String delimiter)
    • getDoubleArray

      public double[] getDoubleArray​(String value, boolean strict)
      Parse the given string as an array of doubles, based upon the delimiter.
      Parameters:
      value - string to parse
      strict - enforce format strictly
      Returns:
      array of parsed values
    • getLongArray

      public long[] getLongArray​(String value, boolean strict)
      Parse the given string as an array of longs, based upon the delimiter.
      Parameters:
      value - string the to parse
      strict - enforce format strictly
      Returns:
      array of parsed values
    • getArray

      public <T> T getArray​(String value, boolean strict, Function<Stream<String>,​T> elementSupplier)
      Create a properly typed array from the input string based upon the delimiter, given a supplier.
      Type Parameters:
      T - the type
      Parameters:
      value - The array string value
      strict - if strict processing should be used
      elementSupplier - a supplier to convert a stream of element strings to items of the correct types
      Returns:
      an array of values of the specified type
    • toStringArray

      public String[] toStringArray​(String value, boolean strict)
      Split the input string into an array of strings based on the delimiter.
      Parameters:
      value - the array as a string
      strict - if strict processing should be used
      Returns:
      an array of strings
    • encodeArray

      public String encodeArray​(double[] array)
      Convert the given array to a String.
      Parameters:
      array - the array
      Returns:
      array encoded as string
    • encodeArray

      public String encodeArray​(long[] array)
      Convert the given array to a String.
      Parameters:
      array - the array
      Returns:
      array encoded as string