com.link_intersystems.graph.CycleDetector Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of lis-commons-graph Show documentation
Show all versions of lis-commons-graph Show documentation
Link Intersystems Commons Graph (lis-commons-graph) is a collection of reusable software components
that provide support for graph and tree related programming tasks, such as models and search algorithms.
package com.link_intersystems.graph;
import java.util.Collection;
import java.util.HashSet;
import java.util.Objects;
import java.util.function.Consumer;
/**
* @author René Link {@literal }
*/
public class CycleDetector implements Consumer {
protected static class ElementIdentity {
private int identityHashCode;
private Object element;
ElementIdentity(Object element) {
identityHashCode = System.identityHashCode(element);
this.element = element;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ElementIdentity that = (ElementIdentity) o;
return identityHashCode == that.identityHashCode && Objects.equals(element, that.element);
}
@Override
public int hashCode() {
return Objects.hash(identityHashCode, element);
}
}
private Collection