Package org.apache.commons.jxpath.util

# Class BasicTypeConverter

java.lang.Object
org.apache.commons.jxpath.util.BasicTypeConverter

All Implemented Interfaces:
  `TypeConverter`

Direct Known Subclasses:
  `JXPath11CompatibleTypeConverter`

public class BasicTypeConverter extends Object implements TypeConverter
The default implementation of `TypeConverter`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `BasicTypeConverter()`
  Constructs a new instance.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Collection`
  `allocateCollection(Class type)`
  Create a collection of a given type.
  `protected Number`
  `allocateNumber(Class type, double value)`
  Allocate a number of a given type and value.
  `boolean`
  `canConvert(Object object, Class toType)`
  Tests whether this instance can convert the supplied object to the specified class.
  `protected boolean`
  `canCreateCollection(Class type)`
  Tests whether this BasicTypeConverter can create a collection of the specified type.
  `Object`
  `convert(Object object, Class toType)`
  Converts the supplied object to the specified type.
  `protected Object`
  `convertNullToPrimitive(Class toType)`
  Convert null to a primitive type.
  `protected Object`
  `convertStringToPrimitive(Object object, Class toType)`
  Convert a string to a primitive type.
  `protected <E> Collection<E>`
  `unmodifiableCollection(Collection<E> collection)`
  Gets an unmodifiable version of a collection.

  ### Methods inherited from class java.lang.Object

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

- ## Constructor Details

  - ### BasicTypeConverter

    public BasicTypeConverter()
    Constructs a new instance.

- ## Method Details

  - ### allocateCollection

    protected Collection allocateCollection(Class type)
    Create a collection of a given type.
    Parameters:
      `type` - destination class.
    Returns:
      A new Collection.

  - ### allocateNumber

    protected Number allocateNumber(Class type, double value)
    Allocate a number of a given type and value.
    Parameters:
      `type` - destination class
      `value` - double
    Returns:
      Number A Number, possibly cached.

  - ### canConvert

    public boolean canConvert(Object object, Class toType)
    Tests whether this instance can convert the supplied object to the specified class.
    Specified by:
      `canConvert` in interface `TypeConverter`
    Parameters:
      `object` - to check
      `toType` - prospective destination class
    Returns:
      boolean whether this instance can convert the supplied object to the specified class.

  - ### canCreateCollection

    protected boolean canCreateCollection(Class type)
    Tests whether this BasicTypeConverter can create a collection of the specified type.
    Parameters:
      `type` - prospective destination class
    Returns:
      boolean

  - ### convert

    public Object convert(Object object, Class toType)
    Converts the supplied object to the specified type. Throws a runtime exception if the conversion is not possible.
    Specified by:
      `convert` in interface `TypeConverter`
    Parameters:
      `object` - to convert
      `toType` - destination class
    Returns:
      converted object

  - ### convertNullToPrimitive

    protected Object convertNullToPrimitive(Class toType)
    Convert null to a primitive type.
    Parameters:
      `toType` - destination class
    Returns:
      a wrapper

  - ### convertStringToPrimitive

    protected Object convertStringToPrimitive(Object object, Class toType)
    Convert a string to a primitive type.
    Parameters:
      `object` - String
      `toType` - destination class
    Returns:
      wrapper

  - ### unmodifiableCollection

    protected <E> Collection<E> unmodifiableCollection(Collection<E> collection)
    Gets an unmodifiable version of a collection.
    Type Parameters:
      `E` - the type of elements in this collection.
    Parameters:
      `collection` - to wrap
    Returns:
      Collection