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

com.github.mikesafonov.specification.builder.starter.FieldWithValue Maven / Gradle / Ivy

There is a newer version: 1.10.0
Show newest version
package com.github.mikesafonov.specification.builder.starter;

import com.github.mikesafonov.specification.builder.starter.annotations.Name;
import com.github.mikesafonov.specification.builder.starter.type.SegmentFilter;
import lombok.Value;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Collection;

/**
 * @author Mike Safonov
 */
@Value
public class FieldWithValue {

    private Field field;
    private Object value;


    public String getFieldName() {
        return field.isAnnotationPresent(Name.class)
            ? field.getAnnotation(Name.class).value()
            : field.getName();
    }

    public boolean isAnnotatedBy(Class annotationClass){
        return field.isAnnotationPresent(annotationClass);
    }

    public  T getAnnotation(Class annotationClass) {
        return field.getAnnotation(annotationClass);
    }

    public boolean isValueCollection(){
        return Collection.class.isAssignableFrom(value.getClass());
    }

    public Collection getValueAsCollection(){
        return (Collection) value;
    }

    public boolean isValueSegmentFilter(){
        return SegmentFilter.class.isAssignableFrom(value.getClass());
    }

    public SegmentFilter getValueAsSegmentFilter(){
        return (SegmentFilter) value;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy