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

io.polaris.core.converter.Converter Maven / Gradle / Ivy

There is a newer version: 3.2.1
Show newest version
package io.polaris.core.converter;

import java.lang.reflect.Type;

/**
 * @author Qt
 * @since 1.8
 */
@FunctionalInterface
public interface Converter {

	 T convert(Type valueType, S value);

	default  T convert(S value) {
		return convert(value.getClass(), value);
	}

	default  T convertOrDefault(Type valueType, S value, T defaultValue) {
		T t = convert(valueType, value);
		if (t == null) {
			t = defaultValue;
		}
		return t;
	}

	default  T convertOrDefault(S value, T defaultValue) {
		return convertOrDefault(value.getClass(), value, defaultValue);
	}

}