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

org.bbottema.javareflection.valueconverter.ValueFunction Maven / Gradle / Ivy

Go to download

Java Reflection provides a small package with nifty reflection features that will help with finding constructors, methods and value conversions

There is a newer version: 4.1.0
Show newest version
package org.bbottema.javareflection.valueconverter;

import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import org.bbottema.javareflection.util.Function;

/**
 * Can be used to provide optional user converters. User converters also act as intermediate converters, ie. if a user converter can go to
 * int, double is automatically supported as well as common conversion.
 */
public interface ValueFunction {
	@NonNull Class getFromType();
	@NonNull Class getTargetType();
	@NonNull T convertValue(@NonNull F value);
	
	/**
	 * Helper class to quickly define a {@link ValueFunction} from a {@link Function}.
	 */
	@Getter
	@RequiredArgsConstructor
	@ToString(onlyExplicitlyIncluded = true)
	class ValueFunctionImpl implements ValueFunction {
		@NonNull @ToString.Include protected final Class fromType;
		@NonNull @ToString.Include protected final Class targetType;
		@NonNull private final Function converter;
		@NonNull @Override
		public final T convertValue(@NonNull F value) {
			return converter.apply(value);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy