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

cdc.graphs.impl.BasicGraphEdge Maven / Gradle / Ivy

There is a newer version: 0.71.2
Show newest version
package cdc.graphs.impl;

import java.util.Objects;

import cdc.graphs.GraphEdge;

/**
 * Base and naive implementation of graph edge.
 *
 * @author Damien Carbonne
 *
 * @param  Node type.
 */
public class BasicGraphEdge implements GraphEdge {
    private final N source;
    private final N target;

    public BasicGraphEdge(N source,
                          N target) {
        this.source = source;
        this.target = target;
    }

    @Override
    public N getSource() {
        return source;
    }

    @Override
    public N getTarget() {
        return target;
    }

    @Override
    public int hashCode() {
        return Objects.hash(source,
                            target);
    }

    @Override
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof BasicGraphEdge)) {
            return false;
        }
        final BasicGraphEdge other = (BasicGraphEdge) object;
        return Objects.equals(source, other.source)
                && Objects.equals(target, other.target);
    }

    @Override
    public String toString() {
        return "[" + getSource() + " -> " + getTarget() + "]";
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy