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

gr.james.simplegraph.DirectedEdgeImpl Maven / Gradle / Ivy

Go to download

Simple Graph is a graph interface for Java 6 that is designed to expose a very simple API to support working with graphs

The newest version!
package gr.james.simplegraph;

import java.util.Arrays;

final class DirectedEdgeImpl implements DirectedEdge {
    private final int source;
    private final int target;

    DirectedEdgeImpl(int source, int target) {
        this.source = source;
        this.target = target;
    }

    @Override
    public int source() {
        return source;
    }

    @Override
    public int target() {
        return target;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null || !(obj instanceof DirectedEdge)) {
            return false;
        }
        final DirectedEdge that = (DirectedEdge) obj;
        return source() == that.source() &&
                target() == that.target();
    }

    @Override
    public int hashCode() {
        return Arrays.hashCode(new Object[]{source(), target()});
    }

    @Override
    public String toString() {
        return String.format("%d -> %d", source(), target());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy