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

es.usc.citius.hipster.thirdparty.graphs.jung.JUNGHipsterDirectedGraphAdapter Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 CITIUS , University of Santiago de Compostela.
 *
 *    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 es.usc.citius.hipster.thirdparty.graphs.jung;


import edu.uci.ics.jung.graph.Graph;
import es.usc.citius.hipster.graph.GraphEdge;
import es.usc.citius.hipster.graph.HipsterDirectedGraph;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

/**
 * An adapter class to adapt a JUNG graph to the Hipster Graph interface.
 * @param  vertex type.
 * @param  edge type.
 */
public class JUNGHipsterDirectedGraphAdapter extends JUNGHipsterGraphAdapter implements HipsterDirectedGraph {

    public JUNGHipsterDirectedGraphAdapter(Graph graph) {
        super(graph);
    }

    @Override
    public Iterable> outgoingEdgesOf(V vertex) {
        try {
            // getOutEdges blueprints impl throws null pointer exception
            final Collection outEdges = graph.getOutEdges(vertex);
            if (outEdges == null || outEdges.isEmpty()) {
                return Collections.emptyList();
            }
            return adapt(outEdges);
        } catch (NullPointerException e){
            return Collections.emptyList();
        }
    }

    @Override
    public Iterable> incomingEdgesOf(V vertex) {
        try {
            // getInEdges blueprints impl throws null pointer exception
            final Collection inEdges = graph.getInEdges(vertex);
            if (inEdges == null || inEdges.isEmpty()) {
                return Collections.emptyList();
            }
            return adapt(inEdges);
        }catch(NullPointerException e){
            return Collections.emptyList();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy