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

main.io.github.moonlightsuite.moonlight.TemporalMonitorProducer Maven / Gradle / Ivy

Go to download

MoonLight is a light-weight Java-tool for monitoring temporal, spatial and spatio-temporal properties of distributed complex systems, such as Cyber-Physical Systems and Collective Adaptive Systems.

The newest version!
package io.github.moonlightsuite.moonlight;

import io.github.moonlightsuite.moonlight.core.formula.Interval;
import io.github.moonlightsuite.moonlight.core.io.SerializableData;
import io.github.moonlightsuite.moonlight.core.signal.SignalDomain;
import io.github.moonlightsuite.moonlight.offline.monitoring.temporal.TemporalMonitor;
import io.github.moonlightsuite.moonlight.core.base.MoonLightRecord;
import io.github.moonlightsuite.moonlight.offline.signal.RecordHandler;

import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Function;

@FunctionalInterface
public interface TemporalMonitorProducer {

     TemporalMonitor apply(SignalDomain domain, MoonLightRecord args);

    static TemporalMonitorProducer produceImplication(TemporalMonitorProducer left, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.impliesMonitor(left.apply(domain,args),domain,right.apply(domain,args));
            }
        };
    }

    static TemporalMonitorProducer produceAtomic(BiFunction atomic) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.atomicMonitor(s -> domain.valueOf(atomic.apply(args,s)));
            }
        };
    }

    static TemporalMonitorProducer produceAtomic(BiFunction left, String op, BiFunction right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.atomicMonitor(s -> SerializableData.getOperator(domain,op).apply(left.apply(args,s), right.apply(args,s)));
            }
        };
    }

    static TemporalMonitorProducer produceAnd(TemporalMonitorProducer left, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.andMonitor(left.apply(domain,args),domain,right.apply(domain,args));
            }
        };
    }

    static TemporalMonitorProducer produceOr(TemporalMonitorProducer left, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.orMonitor(left.apply(domain,args),domain,right.apply(domain,args));
            }
        };
    }

    static TemporalMonitorProducer produceNegation(TemporalMonitorProducer arg) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.notMonitor(arg.apply(domain,args),domain);
            }
        };
    }

    static TemporalMonitorProducer produceFalse() {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.atomicMonitor(v -> domain.min());
            }
        };
    }

    static TemporalMonitorProducer produceTrue() {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.atomicMonitor(v -> domain.max());
            }
        };
    }

    static TemporalMonitorProducer produceOnce(TemporalMonitorProducer arg) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.onceMonitor(arg.apply(domain,args),domain);
            }
        };
    }

    static TemporalMonitorProducer produceHistorically(TemporalMonitorProducer arg) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.historicallyMonitor(arg.apply(domain,args),domain);
            }
        };
    }

    static TemporalMonitorProducer produceEventually(TemporalMonitorProducer arg) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.eventuallyMonitor(arg.apply(domain,args),domain);
            }
        };
    }

    static TemporalMonitorProducer produceGlobally(TemporalMonitorProducer arg) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.globallyMonitor(arg.apply(domain,args),domain);
            }
        };
    }

    static TemporalMonitorProducer produceOnce(TemporalMonitorProducer arg, Function interval) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.onceMonitor(arg.apply(domain,args),domain,interval.apply(args));
            }
        };
    }

    static TemporalMonitorProducer produceHistorically(TemporalMonitorProducer arg, Function interval) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.historicallyMonitor(arg.apply(domain,args),domain,interval.apply(args));
            }
        };
    }

    static TemporalMonitorProducer produceEventually(TemporalMonitorProducer arg, Function interval) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.eventuallyMonitor(arg.apply(domain,args),domain,interval.apply(args));
            }
        };
    }

    static TemporalMonitorProducer produceGlobally(TemporalMonitorProducer arg, Function interval) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.globallyMonitor(arg.apply(domain,args),domain,interval.apply(args));
            }
        };
    }

    static TemporalMonitorProducer produceUntil(TemporalMonitorProducer left, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.untilMonitor(left.apply(domain,args), right.apply(domain,args), domain);
            }
        };
    }

    static TemporalMonitorProducer produceUntil(TemporalMonitorProducer left, Function interval, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.untilMonitor(left.apply(domain,args), interval.apply(args), right.apply(domain,args), domain);
            }
        };
    }

    static TemporalMonitorProducer produceSince(TemporalMonitorProducer left, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.sinceMonitor(left.apply(domain,args), right.apply(domain,args), domain);
            }
        };
    }

    static TemporalMonitorProducer produceSince(TemporalMonitorProducer left, Function interval, TemporalMonitorProducer right) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return TemporalMonitor.sinceMonitor(left.apply(domain,args), interval.apply(args), right.apply(domain,args), domain);
            }
        };
    }

    static TemporalMonitorProducer produceCall(TemporalMonitorProducer temporalMonitorProducer, RecordHandler callee, List> functionArgument) {
        return new TemporalMonitorProducer() {
            @Override
            public  TemporalMonitor apply(SignalDomain domain, MoonLightRecord args) {
                return temporalMonitorProducer.apply(domain,callee.fromDoubleArray(functionArgument.stream().mapToDouble(f -> f.apply(args)).toArray()));
            }
        };
    }


}