001/*
002 * (C) Copyright 2017 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     bdelbosc
018 */
019package org.nuxeo.lib.stream.computation;
020
021import java.util.stream.Collectors;
022import java.util.stream.IntStream;
023
024/**
025 * An abstract {@link Computation} that manages the metadata init. The inputs streams are named i1, i2 ... The output
026 * streams are named o1, o2 ...
027 *
028 * @since 9.3
029 */
030public abstract class AbstractComputation implements Computation {
031    protected final ComputationMetadata metadata;
032
033    public AbstractComputation(String name, int nbInputStreams, int nbOutputStreams) {
034        this.metadata = new ComputationMetadata(name,
035                IntStream.range(1, nbInputStreams + 1).boxed().map(i -> "i" + i).collect(Collectors.toSet()),
036                IntStream.range(1, nbOutputStreams + 1).boxed().map(i -> "o" + i).collect(Collectors.toSet()));
037    }
038
039    @Override
040    public void init(ComputationContext context) {
041
042    }
043
044    @Override
045    public void processTimer(ComputationContext context, String key, long timestamp) {
046
047    }
048
049    @Override
050    public ComputationMetadata metadata() {
051        return metadata;
052    }
053}