io.datakernel.datastream.processor.StreamReducer Maven / Gradle / Ivy
/*
* Copyright (C) 2015 SoftIndex LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datakernel.datastream.processor;
import io.datakernel.datastream.StreamConsumer;
import io.datakernel.datastream.processor.StreamReducers.Reducer;
import java.util.Comparator;
import java.util.function.Function;
/**
* Perform aggregative functions on the elements sorted by keys from input streams. Searches key of item
* with key function, selects elements with some key, reductions it and streams result sorted by key.
* It is {@link AbstractStreamReducer}.
*
* @param type of key of element
* @param type of output data
* @param type of accumulator
*/
public final class StreamReducer extends AbstractStreamReducer {
// region creators
private StreamReducer(Comparator keyComparator) {
super(keyComparator);
}
/**
* Creates a new instance of StreamReducer
*
* @param keyComparator comparator for compare keys
*/
public static StreamReducer create(Comparator keyComparator) {
return new StreamReducer<>(keyComparator);
}
@Override
public StreamReducer withBufferSize(int bufferSize) {
return (StreamReducer) super.withBufferSize(bufferSize);
}
// endregion
/**
* Creates a new input stream for this reducer
*
* @param keyFunction function for counting key
* @param reducer reducer witch will performs actions with its stream
* @param type of input data
* @return new consumer
*/
@Override
public StreamConsumer newInput(Function keyFunction, Reducer reducer) {
return super.newInput(keyFunction, reducer);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy