es.usc.citius.hipster.graph.HashBasedHipsterDirectedGraph Maven / Gradle / Ivy
/*
* 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.graph;
import es.usc.citius.hipster.util.Function;
import es.usc.citius.hipster.util.F;
import java.util.*;
/**
* Implementation of a HipsterDirectedGraph using a Guava Hash Table.
*
* @author Pablo Rodríguez Mier <[email protected]>
*/
public class HashBasedHipsterDirectedGraph extends HashBasedHipsterGraph implements HipsterMutableGraph, HipsterDirectedGraph {
@Override
public GraphEdge buildEdge(V v1, V v2, E value) {
return new DirectedEdge(v1, v2, value);
}
@Override
public Iterable> outgoingEdgesOf(final V vertex) {
return F.filter(edgesOf(vertex), new Function, Boolean>() {
@Override
public Boolean apply(GraphEdge edge) {
return edge.getVertex1().equals(vertex);
}
});
}
@Override
public Iterable> incomingEdgesOf(final V vertex) {
return F.filter(edgesOf(vertex), new Function, Boolean>() {
@Override
public Boolean apply(GraphEdge edge) {
return edge.getVertex2().equals(vertex);
}
});
}
@Override
public Iterable> edges() {
// TODO: [java-8-migration] use stream filter
return F.map(
F.filter(HashBasedHipsterDirectedGraph.super.vedges(),
new Function>, Boolean>() {
@Override
public Boolean apply(Map.Entry> input) {
return input.getKey().equals(input.getValue().getVertex1());
}
}),
new Function>, GraphEdge>() {
@Override
public GraphEdge apply(Map.Entry> input) {
return input.getValue();
}
});
}
public static HashBasedHipsterDirectedGraph create() {
return new HashBasedHipsterDirectedGraph();
}
}