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

com.happy3w.toolkits.sort.GraphNode Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.happy3w.toolkits.sort;

import lombok.Getter;
import lombok.Setter;

import java.util.HashSet;
import java.util.Set;

@Getter
@Setter
public class GraphNode {
    private V value;
    private Set needs;
    private Set provides;

    private Set> upstreamNodes = new HashSet<>();
    private Set> downstreamNodes = new HashSet<>();
    private int depth;

    public GraphNode(V value, Set needs, Set provides) {
        this.value = value;
        this.needs = needs;
        this.provides = provides;
        ensureNoSelfCircle();
    }

    private void ensureNoSelfCircle() {
        Set retains = new HashSet<>(needs);
        retains.retainAll(provides);
        if (!retains.isEmpty()) {
            throw new IllegalArgumentException("There must be a circle with node:" + value);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy