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

devutility.internal.lang.reflect.FieldUtils Maven / Gradle / Ivy

There is a newer version: 1.3.8.1
Show newest version
package devutility.internal.lang.reflect;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

import devutility.internal.annotations.Order;
import devutility.internal.util.CollectionUtils;

public class FieldUtils {
	/**
	 * Field whether contains annotations?
	 * @param field: Field object
	 * @param annotations: Annotations want to check.
	 * @return boolean
	 */
	public static boolean contain(Field field, List annotations) {
		if (field == null || CollectionUtils.isNullOrEmpty(annotations)) {
			return false;
		}

		List fieldAnnotations = Arrays.asList(field.getAnnotations());
		return CollectionUtils.exist(annotations, i -> fieldAnnotations.contains(i));
	}

	/**
	 * Return Order value by provided Field object. 0 if no Order setting.
	 * @param field Field object.
	 * @return int
	 */
	public static int getOrder(Field field) {
		Order order = field.getAnnotation(Order.class);

		if (order == null) {
			return 0;
		}

		return order.value();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy