Package repast.simphony.freezedry
Enum ArrayValueHandler
- java.lang.Object
-
- java.lang.Enum<ArrayValueHandler>
-
- repast.simphony.freezedry.ArrayValueHandler
-
- All Implemented Interfaces:
Serializable
,Comparable<ArrayValueHandler>
public enum ArrayValueHandler extends Enum<ArrayValueHandler>
This is an enum for working with string representation of primitive arrays.- Author:
- Jerry Vos
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Object
createArray(String arrayType, int size)
Creates an array of the specified type and size.static ArrayValueHandler
getHandler(String arrayType)
Retrieves a handler for the specified array type.abstract Object
getValue(String value)
Converts the string value to a value for the type of array.boolean
handles(String arrayType)
Retrieves if this handler handles the specified type of array.static Object
readArray(String arrayType, String arrayString, char delimiter)
Reads in an array from the given array string and returns it.static ArrayValueHandler
valueOf(String name)
Returns the enum constant of this type with the specified name.static ArrayValueHandler[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.static String
writeArray(Object array, char delimiter)
Writes an array of a type to a String.
-
-
-
Enum Constant Detail
-
DOUBLE
public static final ArrayValueHandler DOUBLE
-
FLOAT
public static final ArrayValueHandler FLOAT
-
INTEGER
public static final ArrayValueHandler INTEGER
-
BOOLEAN
public static final ArrayValueHandler BOOLEAN
-
CHARACTER
public static final ArrayValueHandler CHARACTER
-
LONG
public static final ArrayValueHandler LONG
-
SHORT
public static final ArrayValueHandler SHORT
-
STRING
public static final ArrayValueHandler STRING
-
-
Method Detail
-
values
public static ArrayValueHandler[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ArrayValueHandler c : ArrayValueHandler.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ArrayValueHandler valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- 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 arraysize
- 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 isnew 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 arraydelimiter
- 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 isnew String[] { "a", "b" }
the resultant string will be like""a", "b""
.- Parameters:
array
- the array to turn into a stringdelimiter
- the delimiter between array elements- Returns:
- a string representation of the specified array
-
-