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

com.github.paganini2008.devtools.beans.streaming.MappedBy Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
package com.github.paganini2008.devtools.beans.streaming;

import java.util.Map;
import java.util.function.Function;

import com.github.paganini2008.devtools.converter.ConvertUtils;

/**
 * 
 * MappedBy
 * 
 * @author Fred Feng
 * 
 * @version 1.0
 */
public class MappedBy implements Function, T> {

	private final String name;
	private final Class requiredType;

	MappedBy(String name, Class requiredType) {
		this.name = name;
		this.requiredType = requiredType;
	}

	public T apply(Map m) {
		Object value = m.get(name);
		try {
			return requiredType.cast(value);
		} catch (RuntimeException e) {
			return ConvertUtils.convertValue(value, requiredType);
		}
	}

	public static  MappedBy forName(String name, Class requiredType) {
		return new MappedBy(name, requiredType);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy