All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.stefanbirkner.editors.mapper.CompositeMapper Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.github.stefanbirkner.editors.mapper;

/**
 * A {@code CompositeMapper} allows you to modify the input and output of a
 * arbitrary {@link Mapper}. A second {@code Mapper} is used for mapping the
 * input and output.
 * 
 * @author Stefan Birkner 
 * @param 
 *            the supported type.
 * @since 2.0.0
 */
public class CompositeMapper implements Mapper {
	private Mapper objectMapper;
	private Mapper stringMapper;

	public CompositeMapper(Mapper objectMapper, Mapper stringMapper) {
		this.objectMapper = objectMapper;
		this.stringMapper = stringMapper;
	}

	public T getValueForText(String text) {
		String mappedText = stringMapper.getValueForText(text);
		return objectMapper.getValueForText(mappedText);
	}

	public String getTextForValue(T value) {
		String text = objectMapper.getTextForValue(value);
		return stringMapper.getTextForValue(text);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy