JIDE 3.5.15

com.jidesoft.converter
Class ArrayConverter

java.lang.Object
  extended by com.jidesoft.converter.ArrayConverter
All Implemented Interfaces:
ObjectConverter
Direct Known Subclasses:
DefaultArrayConverter, DimensionConverter, InsetsConverter, MultipleEnumConverter, PointConverter, RectangleConverter

public abstract class ArrayConverter
extends Object
implements ObjectConverter

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.


Constructor Summary
ArrayConverter(String separator, int size, Class<?> elementClass)
          Creates an ArrayConverter.
ArrayConverter(String separator, int size, Class<?>[] elementClasses)
          Creates an ArrayConverter.
 
Method Summary
 Object[] arrayFromString(String string, ConverterContext context)
          Converts from string to an array of objects, using separator to separate the string.
 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<?> getElementClass()
          Gets the element class for the array.
 boolean isUseTokenizer()
          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 Detail

ArrayConverter

public ArrayConverter(String separator,
                      int size,
                      Class<?> elementClass)
Creates an ArrayConverter.

Parameters:
separator - separator to separate values. It should contain at least non-empty character.
size - size of the array
elementClass - class of the array element. Assume all elements have the same class type. If not, use the constructor which takes Class[] as parameter.

ArrayConverter

public ArrayConverter(String separator,
                      int size,
                      Class<?>[] elementClasses)
Creates an ArrayConverter.

Parameters:
separator - separator to separate values. It should contain at least non-empty character.
size - size of the array
elementClasses - classes of the array element. The length must be the same as size. If not, IllegalArgumentException will be thrown.
Method Detail

arrayToString

public String arrayToString(Object[] objects,
                            ConverterContext context)
Converts from array to string by concating them with separators.

Parameters:
objects - an array of objects
context - converter context
Returns:
string all objects concatenated with separators

toString

protected String toString(int i,
                          Object o,
                          ConverterContext context)

arrayFromString

public Object[] arrayFromString(String string,
                                ConverterContext context)
Converts from string to an array of objects, using separator to separate the string.

Parameters:
string - string to be converted
context - converter context
Returns:
the array

fromString

protected Object fromString(int i,
                            String s,
                            ConverterContext context)

getElementClass

public Class<?> 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(boolean)

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

JIDE 3.5.15