org.springframework.beans.propertyeditors

## 类 CustomCollectionEditor

- java.lang.Object
- - java.beans.PropertyEditorSupport
  - - org.springframework.beans.propertyeditors.CustomCollectionEditor

- 所有已实现的接口:
    PropertyEditor

      public class CustomCollectionEditor
      extends PropertyEditorSupport

  Property editor for Collections, converting any source Collection to a given target Collection type.

  By default registered for Set, SortedSet and List, to automatically convert any given Collection to one of those target types if the type does not match the target property.

  从以下版本开始:
    1.1.3
  作者:
    Juergen Hoeller
  另请参阅:
    `Collection`, `Set`, `SortedSet`, `List`

- - ### 构造器概要

    构造器
    构造器和说明
    `CustomCollectionEditor(Class<? extends Collection> collectionType)` Create a new CustomCollectionEditor for the given target type, keeping an incoming `null` as-is.
    `CustomCollectionEditor(Class<? extends Collection> collectionType, boolean nullAsEmptyCollection)` Create a new CustomCollectionEditor for the given target type.

  - ### 方法概要

    所有方法 实例方法 具体方法
    限定符和类型 | 方法和说明
    --- | ---
    `protected boolean` | `alwaysCreateNewCollection()` Return whether to always create a new Collection, even if the type of the passed-in Collection already matches.
    `protected Object` | `convertElement(Object element)` Hook to convert each encountered Collection/array element.
    `protected Collection<Object>` | `createCollection(Class<? extends Collection> collectionType, int initialCapacity)` Create a Collection of the given type, with the given initial capacity (if supported by the Collection type).
    `String` | `getAsText()` This implementation returns `null` to indicate that there is no appropriate text representation.
    `void` | `setAsText(String text)` Convert the given text value to a Collection with a single element.
    `void` | `setValue(Object value)` Convert the given value to a Collection of the target type.

    - ### 从类继承的方法 java.beans.PropertyEditorSupport

      `addPropertyChangeListener, firePropertyChange, getCustomEditor, getJavaInitializationString, getSource, getTags, getValue, isPaintable, paintValue, removePropertyChangeListener, setSource, supportsCustomEditor`

    - ### 从类继承的方法 java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 构造器详细资料

    - #### CustomCollectionEditor

          public CustomCollectionEditor(Class<? extends Collection> collectionType)

      Create a new CustomCollectionEditor for the given target type, keeping an incoming `null` as-is.
      参数:
        `collectionType` - the target type, which needs to be a sub-interface of Collection or a concrete Collection class
      另请参阅:
        `Collection`, `ArrayList`, `TreeSet`, `LinkedHashSet`

    - #### CustomCollectionEditor

          public CustomCollectionEditor(Class<? extends Collection> collectionType,
                                        boolean nullAsEmptyCollection)

      Create a new CustomCollectionEditor for the given target type.

      If the incoming value is of the given type, it will be used as-is. If it is a different Collection type or an array, it will be converted to a default implementation of the given Collection type. If the value is anything else, a target Collection with that single value will be created.

      The default Collection implementations are: ArrayList for List, TreeSet for SortedSet, and LinkedHashSet for Set.

      参数:
        `collectionType` - the target type, which needs to be a sub-interface of Collection or a concrete Collection class
        `nullAsEmptyCollection` - whether to convert an incoming `null` value to an empty Collection (of the appropriate type)
      另请参阅:
        `Collection`, `ArrayList`, `TreeSet`, `LinkedHashSet`

  - ### 方法详细资料

    - #### setAsText

          public void setAsText(String text)
                         throws IllegalArgumentException

      Convert the given text value to a Collection with a single element.
      指定者:
        `setAsText` 在接口中 `PropertyEditor`
      覆盖:
        `setAsText` 在类中 `PropertyEditorSupport`
      抛出:
        `IllegalArgumentException`

    - #### setValue

          public void setValue(@Nullable
                               Object value)

      Convert the given value to a Collection of the target type.
      指定者:
        `setValue` 在接口中 `PropertyEditor`
      覆盖:
        `setValue` 在类中 `PropertyEditorSupport`

    - #### createCollection

          protected Collection<Object> createCollection(Class<? extends Collection> collectionType,
                                                        int initialCapacity)

      Create a Collection of the given type, with the given initial capacity (if supported by the Collection type).
      参数:
        `collectionType` - a sub-interface of Collection
        `initialCapacity` - the initial capacity
      返回:
        the new Collection instance

    - #### alwaysCreateNewCollection

          protected boolean alwaysCreateNewCollection()

      Return whether to always create a new Collection, even if the type of the passed-in Collection already matches.

      Default is "false"; can be overridden to enforce creation of a new Collection, for example to convert elements in any case.

      另请参阅:
        `convertElement(java.lang.Object)`

    - #### convertElement

          protected Object convertElement(Object element)

      Hook to convert each encountered Collection/array element. The default implementation simply returns the passed-in element as-is.

      Can be overridden to perform conversion of certain elements, for example String to Integer if a String array comes in and should be converted to a Set of Integer objects.

      Only called if actually creating a new Collection! This is by default not the case if the type of the passed-in Collection already matches. Override `alwaysCreateNewCollection()` to enforce creating a new Collection in every case.

      参数:
        `element` - the source element
      返回:
        the element to be used in the target Collection
      另请参阅:
        `alwaysCreateNewCollection()`

    - #### getAsText

          @Nullable
          public String getAsText()

      This implementation returns `null` to indicate that there is no appropriate text representation.
      指定者:
        `getAsText` 在接口中 `PropertyEditor`
      覆盖:
        `getAsText` 在类中 `PropertyEditorSupport`