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

com.github.leeonky.util.Property Maven / Gradle / Ivy

The newest version!
package com.github.leeonky.util;

import java.util.Arrays;
import java.util.List;

import static java.util.stream.Collectors.toList;

public interface Property {
    static List toChainNodes(String chain) {
        return Arrays.stream(chain.split("[\\[\\].]")).filter(s -> !s.isEmpty()).map(s -> {
            try {
                return Integer.valueOf(s);
            } catch (Exception ignore) {
                return s;
            }
        }).collect(toList());
    }

    String getName();

    BeanClass getBeanType();

    PropertyReader getReader();

    PropertyWriter getWriter();

    @SuppressWarnings("unchecked")
    default 

BeanClass

getReaderType() { return (BeanClass

) getReader().getType(); } @SuppressWarnings("unchecked") default

BeanClass

getWriterType() { return (BeanClass

) getWriter().getType(); } default Property setValue(T instance, Object value) { getWriter().setValue(instance, value); return this; } @SuppressWarnings("unchecked") default

P getValue(T instance) { return (P) getReader().getValue(instance); } }