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

io.github.icodegarden.nutrient.lang.IdObject Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package io.github.icodegarden.nutrient.lang;

import java.util.List;

import io.github.icodegarden.nutrient.lang.util.ClassUtils;

/**
 * 
 * @author Fangfang.Xu
 *
 */
public interface IdObject {

	ID getId();

	void setId(ID id);

	@SuppressWarnings("all")
	public static void setIdIfNecessary(Object id, Object target) {
		if (target instanceof IdObject && ((IdObject) target).getId() == null) {
			List> types = ClassUtils.getGenericInterfaceTypes(target, IdObject.class);
			if (!types.isEmpty() && types.get(0).equals(id.getClass())) {
				/**
				 * 要求参数类型相同
				 */
				((IdObject) target).setId(id);
			}
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy