Top Description Fields Constructors Methods
com.thoughtworks.xstream.converters.basic

public Class StringConverter

extends AbstractSingleValueConverter
Class Inheritance
Imports
java.util.Collections, .Map, com.thoughtworks.xstream.core.util.WeakCache

Converts a String to a String ;).

Well ok, it doesn't actually do any conversion. The converter uses by default a map with weak references to reuse instances of strings that do not exceed a length limit. This limit is by default 38 characters to cache typical strings containing UUIDs. Only shorter strings are typically repeated more often in XML values.

Authors
Joe Walnes, Rene Schwietzke, Jörg Schaible

Field Summary

Modifier and TypeField and Description
private final Map<K, V>
cache

A Map to store strings as long as needed to map similar strings onto the same instance and conserve memory.

private static final int
private final int

Constructor Summary

AccessConstructor and Description
public
StringConverter(final Map<K, V>
the map to use for the instances to reuse (may be null to not cache at all)
map
,
int
maximum string length of a cached string, -1 to cache all, 0 to turn off the cache
lengthLimit
)

Construct a StringConverter using a map-based cache for strings not exceeding the length limit.

public
StringConverter(final Map<K, V>
the map to use for the instances to reuse (may be null to not cache at all)
map
)

Construct a StringConverter using a map-based cache for strings not exceeding 38 characters.

public
StringConverter(int
maximum string length of a cached string, -1 to cache all, 0 to turn off the cache
lengthLimit
)

Construct a StringConverter using a cache with weak references for strings not exceeding the length limit.

public
StringConverter()

Construct a StringConverter using a cache with weak references for strings not exceeding 38 characters.

Method Summary

Modifier and TypeMethod and Description
public boolean
canConvert(final Class<T>
the Class representing the object type to be converted
type
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.
public Object
fromString(final String
the String with the single value of the Object
str
)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.
Inherited from com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter:
toString

Field Detail

cacheback to summary
private final Map<K, V> cache

A Map to store strings as long as needed to map similar strings onto the same instance and conserve memory. The map can be set from the outside during construction, so it can be a LRU map or a weak map, synchronised or not.

LENGTH_LIMITback to summary
private static final int LENGTH_LIMIT
lengthLimitback to summary
private final int lengthLimit

Constructor Detail

StringConverterback to summary
public StringConverter(final Map<K, V> map, int lengthLimit)

Construct a StringConverter using a map-based cache for strings not exceeding the length limit.

Parameters
map:Map<K, V>

the map to use for the instances to reuse (may be null to not cache at all)

lengthLimit:int

maximum string length of a cached string, -1 to cache all, 0 to turn off the cache

Since
1.4.2
StringConverterback to summary
public StringConverter(final Map<K, V> map)

Construct a StringConverter using a map-based cache for strings not exceeding 38 characters.

Parameters
map:Map<K, V>

the map to use for the instances to reuse (may be null to not cache at all)

StringConverterback to summary
public StringConverter(int lengthLimit)

Construct a StringConverter using a cache with weak references for strings not exceeding the length limit.

Parameters
lengthLimit:int

maximum string length of a cached string, -1 to cache all, 0 to turn off the cache

Since
1.4.2
StringConverterback to summary
public StringConverter()

Construct a StringConverter using a cache with weak references for strings not exceeding 38 characters.

Method Detail

canConvertback to summary
public boolean canConvert(final Class<T> type)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.canConvert.

Implements com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Doc from com.thoughtworks.xstream.converters.ConverterMatcher.canConvert.

Determines whether the converter can marshall a particular type.

Parameters
type:Class<T>

the Class representing the object type to be converted

fromStringback to summary
public Object fromString(final String str)

Implements abstract com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter.fromString.

Implements com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Doc from com.thoughtworks.xstream.converters.SingleValueConverter.fromString.

Unmarshals an Object from its single value representation.

Parameters
str:String

the String with the single value of the Object

Returns:Object

the Object