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

org.apache.edgent.graph.spi.AbstractGraph Maven / Gradle / Ivy

The newest version!
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you 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 org.apache.edgent.graph.spi;

import java.util.ArrayList;
import java.util.List;

import org.apache.edgent.function.Predicate;
import org.apache.edgent.function.Supplier;
import org.apache.edgent.graph.Connector;
import org.apache.edgent.graph.Graph;
import org.apache.edgent.graph.Vertex;
import org.apache.edgent.oplet.Oplet;
import org.apache.edgent.oplet.core.Peek;
import org.apache.edgent.oplet.core.Source;

/**
 * A skeletal implementation of the {@link Graph} interface,
 * to minimize the effort required to implement the interface.
 * 
 * @param  unnecessary?
 */
public abstract class AbstractGraph implements Graph {
 
    @Override
    public , P> Connector

source(N oplet) { return insert(oplet, 0, 1).getConnectors().get(0); } @Override public , C, P> Connector

pipe(Connector output, N oplet) { Vertex pipeVertex = insert(oplet, 1, 1); output.connect(pipeVertex, 0); return pipeVertex.getConnectors().get(0); } @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void peekAll(Supplier> supplier, Predicate> select) { // Select vertices which satisfy the specified predicate List> vertices = new ArrayList<>(); for (Vertex v : getVertices()) { if (select.test(v)) { vertices.add(v); } } // Insert peek oplets on isConnected() output ports for (Vertex v : vertices) { List> connectors = v.getConnectors(); for (Connector c : connectors) { if (c.isConnected()) { Peek oplet = supplier.get(); c.peek((Peek) oplet); } } } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy