Package com.jidesoft.converter
Class ArrayConverter
java.lang.Object
com.jidesoft.converter.ArrayConverter
- All Implemented Interfaces:
ObjectConverter
- Direct Known Subclasses:
DefaultArrayConverter
,DimensionConverter
,InsetsConverter
,MultipleEnumConverter
,PointConverter
,RectangleConverter
An abstract class that is extended by any converters that convert to/from an array-like format, such as 1, 2, 3.
Examples are Point. Point(100, 200) can convert to/from "100, 200"
You have the choice of what the separator is; separator is the ", " in the Point example above.
You have the choice of what the separator is; separator is the ", " in the Point example above.
-
Constructor Summary
ConstructorsConstructorDescriptionArrayConverter
(String separator, int size, Class<?> elementClass) Creates an ArrayConverter.ArrayConverter
(String separator, int size, Class<?>[] elementClasses) Creates an ArrayConverter. -
Method Summary
Modifier and TypeMethodDescriptionObject[]
arrayFromString
(String string, ConverterContext context) Converts from string to an array of objects, using separator to separate the string.arrayToString
(Object[] objects, ConverterContext context) Converts from array to string by concating them with separators.protected Object
fromString
(int i, String s, ConverterContext context) Class
<?> Gets the element class for the array.boolean
Gets the flag indicating if the converter will utilize Tokenizer to split the string or just utilize String#split().void
setUseTokenizer
(boolean useTokenizer) Sets the flag indicating if the converter will utilize Tokenizer to split the string or just utilize String#split().protected String
toString
(int i, Object o, ConverterContext context) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.jidesoft.converter.ObjectConverter
fromString, supportFromString, supportToString, toString
-
Constructor Details
-
ArrayConverter
Creates an ArrayConverter.- Parameters:
separator
- separator to separate values. It should contain at least non-empty character.size
- size of the arrayelementClass
- class of the array element. Assume all elements have the same class type. If not, use the constructor which takes Classinvalid input: '<'?>[] as parameter.
-
ArrayConverter
Creates an ArrayConverter.- Parameters:
separator
- separator to separate values. It should contain at least non-empty character.size
- size of the arrayelementClasses
- classes of the array element. The length must be the same as size. If not, IllegalArgumentException will be thrown.
-
-
Method Details
-
arrayToString
Converts from array to string by concating them with separators.- Parameters:
objects
- an array of objectscontext
- converter context- Returns:
- string all objects concatenated with separators
-
toString
-
arrayFromString
Converts from string to an array of objects, using separator to separate the string.- Parameters:
string
- string to be convertedcontext
- converter context- Returns:
- the array
-
fromString
-
getElementClass
Gets the element class for the array.- Returns:
- the element class for the array.
-
isUseTokenizer
public boolean isUseTokenizer()Gets the flag indicating if the converter will utilize Tokenizer to split the string or just utilize String#split().- Returns:
- true if tokenizer is to be used. Otherwise false.
- Since:
- 3.5.0
- See Also:
-
setUseTokenizer
public void setUseTokenizer(boolean useTokenizer) Sets the flag indicating if the converter will utilize Tokenizer to split the string or just utilize String#split(). By default, the flag is false to keep backward compatibility.- Parameters:
useTokenizer
- the flag- Since:
- 3.5.0
-