com.vaadin.data.util.converter
Class ReverseConverter<PRESENTATION,MODEL>

java.lang.Object
  extended by com.vaadin.data.util.converter.ReverseConverter<PRESENTATION,MODEL>
Type Parameters:
MODEL - The source type
PRESENTATION - The target type
All Implemented Interfaces:
Converter<PRESENTATION,MODEL>, java.io.Serializable

public class ReverseConverter<PRESENTATION,MODEL>
extends java.lang.Object
implements Converter<PRESENTATION,MODEL>

A converter that wraps another Converter and reverses source and target types.

Since:
7.0
Author:
Vaadin Ltd
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface com.vaadin.data.util.converter.Converter
Converter.ConversionException
 
Constructor Summary
ReverseConverter(Converter<MODEL,PRESENTATION> converter)
          Creates a converter from source to target based on a converter that converts from target to source.
 
Method Summary
 MODEL convertToModel(PRESENTATION value, java.lang.Class<? extends MODEL> targetType, java.util.Locale locale)
          Converts the given value from target type to source type.
 PRESENTATION convertToPresentation(MODEL value, java.lang.Class<? extends PRESENTATION> targetType, java.util.Locale locale)
          Converts the given value from source type to target type.
 java.lang.Class<MODEL> getModelType()
          The source type of the converter.
 java.lang.Class<PRESENTATION> getPresentationType()
          The target type of the converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReverseConverter

public ReverseConverter(Converter<MODEL,PRESENTATION> converter)
Creates a converter from source to target based on a converter that converts from target to source.

Parameters:
converter - The converter to use in a reverse fashion
Method Detail

convertToModel

public MODEL convertToModel(PRESENTATION value,
                            java.lang.Class<? extends MODEL> targetType,
                            java.util.Locale locale)
                     throws Converter.ConversionException
Description copied from interface: Converter
Converts the given value from target type to source type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining Converter.convertToPresentation(Object, Class, Locale) and Converter.convertToModel(Object, Class, Locale) should return the original value.

Specified by:
convertToModel in interface Converter<PRESENTATION,MODEL>
Parameters:
value - The value to convert, compatible with the target type. Can be null
targetType - The requested type of the return value
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

convertToPresentation

public PRESENTATION convertToPresentation(MODEL value,
                                          java.lang.Class<? extends PRESENTATION> targetType,
                                          java.util.Locale locale)
                                   throws Converter.ConversionException
Description copied from interface: Converter
Converts the given value from source type to target type.

A converter can optionally use locale to do the conversion.

A converter should in most cases be symmetric so chaining Converter.convertToPresentation(Object, Class, Locale) and Converter.convertToModel(Object, Class, Locale) should return the original value.

Specified by:
convertToPresentation in interface Converter<PRESENTATION,MODEL>
Parameters:
value - The value to convert, compatible with the target type. Can be null
targetType - The requested type of the return value
locale - The locale to use for conversion. Can be null.
Returns:
The converted value compatible with the source type
Throws:
Converter.ConversionException - If the value could not be converted

getModelType

public java.lang.Class<MODEL> getModelType()
Description copied from interface: Converter
The source type of the converter. Values of this type can be passed to Converter.convertToPresentation(Object, Class, Locale).

Specified by:
getModelType in interface Converter<PRESENTATION,MODEL>
Returns:
The source type

getPresentationType

public java.lang.Class<PRESENTATION> getPresentationType()
Description copied from interface: Converter
The target type of the converter. Values of this type can be passed to Converter.convertToModel(Object, Class, Locale).

Specified by:
getPresentationType in interface Converter<PRESENTATION,MODEL>
Returns:
The target type


Copyright © 2000-2014 Vaadin Ltd. All Rights Reserved.