Class ArrayConverter

java.lang.Object
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 Details

    • 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 Details

    • 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

      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