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

com.gitee.feizns.bean.Property Maven / Gradle / Ivy

There is a newer version: 5.5-RELEASE
Show newest version
package com.gitee.feizns.bean;

import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/**
 * 属性.
 * @author feizns
 * @since 2019/6/5
 */
public interface Property extends AnnotatedElement {

    /**
     * 获取属性值
     * @return value
     */
    default T val() {
        return null;
    }

    /**
     * 获取属性值
     * @return value
     */
    default  R val(Class targetType) {
        return null;
    }

    /**
     * 为属性赋值
     * @param newVal
     * @return oldVal
     */
    default T getAndSet(T newVal) {
        return val();
    }

    /**
     * 设置属性
     * @param newVal
     * @return
     */
    default Property set(Object newVal) {
        return this;
    }

    /**
     * 获取属性
     * @return
     */
    default Property get(String name) {
        return of(val(), name);
    }

    /**
     * 获取属性
     * @param name
     * @param targetType
     * @param 

* @return */ default

Property

get(String name, Class

targetType) { return of(val(), name, targetType); } /** * 属性名 * @return */ default String name() { return null; } /** * 是否可读 * @return */ default boolean isReadable() { return false; } /** * 是否可写 * @return */ default boolean isWritable() { return false; } /** * 获取属性所属的对象 * @return */ default Object getTarget() { return null; } /** * 获取字段 * @return */ default Field getField() { return null; } /** * 读方法 * @return */ default Method readMethod() { return null; } /** * 写方法 * @return */ default Method writeMethod() { return null; } @Override default T getAnnotation(Class annotationClass) { return null; } @Override default Annotation[] getAnnotations() { return new Annotation[0]; } @Override default Annotation[] getDeclaredAnnotations() { return new Annotation[0]; } /** * 构建 * @param target * @param name * @param * @return */ static Property of(Object target, String name) { return new DefaultPropertyImpl<>(target, name); } /** * 构建 * @param target * @param name * @param * @return */ static Property of(Object target, String name, Class propertyClass) { return new DefaultPropertyImpl<>(target, name, propertyClass); } }