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

org.jetlinks.rule.engine.api.RuleDataCodec Maven / Gradle / Ivy

The newest version!
package org.jetlinks.rule.engine.api;

import reactor.core.publisher.Flux;

import java.util.Arrays;
import java.util.Optional;

public interface RuleDataCodec {

    Object encode(T data, Feature... features);

    Flux decode(RuleData data, Feature... features);

    interface Feature {
        default String getId() {
            return this.getClass().getSimpleName();
        }

        default String getName() {
            return getId();
        }

        default boolean has(Feature... features) {
            return Arrays.stream(features)
                    .anyMatch(feature -> feature.getId().equals(this.getId()));
        }

        static  Optional find(Class type, Feature... features) {
            return Arrays.stream(features)
                    .filter(type::isInstance)
                    .map(type::cast)
                    .findFirst();
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy