Enum Class ArrayValueHandler

java.lang.Object
java.lang.Enum<ArrayValueHandler>
repast.simphony.freezedry.ArrayValueHandler
All Implemented Interfaces:
Serializable, Comparable<ArrayValueHandler>, java.lang.constant.Constable

public enum ArrayValueHandler extends Enum<ArrayValueHandler>
This is an enum for working with string representation of primitive arrays.
Author:
Jerry Vos
  • Enum Constant Details

  • Method Details

    • values

      public static ArrayValueHandler[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static ArrayValueHandler valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getValue

      public abstract Object getValue(String value)
      Converts the string value to a value for the type of array. So for a double[] this would convert it to a Double.
      Parameters:
      value - the string value of the array element
      Returns:
      the converted value
    • createArray

      public Object createArray(String arrayType, int size)
      Creates an array of the specified type and size.
      Parameters:
      arrayType - the type of the array
      size - the size of the array
      Returns:
      an array of the specified type and size or null if the creation failed
    • handles

      public boolean handles(String arrayType)
      Retrieves if this handler handles the specified type of array.
      Parameters:
      arrayType - the type of the array (the toString of the array's class)
      Returns:
      if it handles the type
    • getHandler

      public static ArrayValueHandler getHandler(String arrayType)
      Retrieves a handler for the specified array type.
      Parameters:
      arrayType - the type of the array
      Returns:
      a handler that handles the specified type, or null if no handler handles that type
    • readArray

      public static Object readArray(String arrayType, String arrayString, char delimiter)
      Reads in an array from the given array string and returns it. This uses the given delimiter to differentiate between elements of the array.

      For string arrays, this expects that each element of the array be enclosed in qoutation marks. So if your array is new String[] { "a", "b" } the passed in string should be like ""a", "b"".

      Parameters:
      arrayType - the type of the array, given by type[].class.getName() (for example double[].class.getName())
      arrayString - the string representing the array
      delimiter - the delimiter between array elements
      Returns:
      the read in array of the given type
    • writeArray

      public static String writeArray(Object array, char delimiter)
      Writes an array of a type to a String. This will use the toString method on the array elements to get the value for each element, and will insert between elements the given delimiter followed by a space.

      For string arrays, this will enclose each element of the array in qoutation marks. So if your array is new String[] { "a", "b" } the resultant string will be like ""a", "b"".

      Parameters:
      array - the array to turn into a string
      delimiter - the delimiter between array elements
      Returns:
      a string representation of the specified array