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

com.fluxtion.ext.streaming.api.window.WindowBuildOperations Maven / Gradle / Ivy

There is a newer version: 2.10.50
Show newest version
/*
 * Copyright (c) 2020, V12 Technology Ltd.
 * All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the Server Side Public License, version 1,
 * as published by MongoDB, Inc.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Server Side Public License for more details.
 *
 * You should have received a copy of the Server Side Public License
 * along with this program.  If not, see 
 * .
 */
package com.fluxtion.ext.streaming.api.window;

import com.fluxtion.api.partition.LambdaReflection.SerializableFunction;
import com.fluxtion.ext.streaming.api.Duration;
import com.fluxtion.ext.streaming.api.WrappedCollection;
import com.fluxtion.ext.streaming.api.WrappedList;
import com.fluxtion.ext.streaming.api.Wrapper;
import com.fluxtion.ext.streaming.api.group.GroupBy;
import java.util.ServiceLoader;

/**
 * Window building functions for sliding and tumbling windows.
 *
 * @author Greg Higgins [email protected]
 */
public interface WindowBuildOperations {
    
    //sliding collections
    default > WrappedList sliding(T source, int itemsPerBucket, int numberOfBuckets){
        return service().sliding(source, itemsPerBucket, numberOfBuckets);
    }
    
    default > GroupBy sliding(T source, int itemsPerBucket, int numberOfBuckets){
        return service().sliding(source, itemsPerBucket, numberOfBuckets);
    }
    
    default > GroupBy sliding(T source, Duration time, int numberOfBuckets){
        return service().sliding(source, time, numberOfBuckets);
    }
    
    default > WrappedList sliding(T source, Duration time, int numberOfBuckets){
        return service().sliding(source, time, numberOfBuckets);
    }
    
    //tumbling collections
    default > WrappedList tumbling(T source, int itemsPerBucket){
        return service().tumbling(source, itemsPerBucket);
    }
    
    default > GroupBy tumbling(T source, int itemsPerBucket){
        return service().tumbling(source, itemsPerBucket);
    }
    
    default > GroupBy tumbling(T source, Duration time){
        return service().tumbling(source, time);
    }
    
    default > WrappedList tumbling(T source, Duration time){
        return service().tumbling(source, time);
    }
    
    //sliding scalar
    default > Wrapper sliding(T source, SerializableFunction mapper, int itemsPerBucket, int numberOfBuckets){
        return service().sliding(source, mapper, itemsPerBucket, numberOfBuckets);
    }
    
    default > Wrapper sliding(T source, SerializableFunction mapper, Duration time, int numberOfBuckets){
        return service().sliding(source, mapper, time, numberOfBuckets);
    }
    
    //tumbling scalar
    default > Wrapper tumbling(T source, SerializableFunction mapper, int itemsPerBucket){
        return service().tumbling(source, mapper, itemsPerBucket);
    }
    
    default > Wrapper tumbling(T source, SerializableFunction mapper, Duration time){
        return service().tumbling(source, mapper, time);
    }
    
    static WindowBuildOperations service() {
        ServiceLoader load = ServiceLoader.load(WindowBuildOperations.class);
        if (load.iterator().hasNext()) {
            return load.iterator().next();
        } else {
            load = ServiceLoader.load(WindowBuildOperations.class, WindowBuildOperations.class.getClassLoader());
            if (load.iterator().hasNext()) {
                return load.iterator().next();
            } else {
                return new WindowBuildOperations() {
                    @Override
                    public > GroupBy sliding(T source, int itemsPerBucket, int numberOfBuckets) {
                        return null;
                    }

                    @Override
                    public > WrappedList sliding(T source, int itemsPerBucket, int numberOfBuckets) {
                        return null;
                    }
                    
                };
            }
        }
    }


}