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

tk.hongkailiu.test.app.graph.NonDirectedGraph Maven / Gradle / Ivy

The newest version!
package tk.hongkailiu.test.app.graph;

import org.apache.commons.lang3.builder.ToStringBuilder;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class NonDirectedGraph extends Graph {

    public NonDirectedGraph(Set vertices, Map> adjacentList) {
        super(vertices, adjacentList);
    }

    @Override public void addEdge(String v1Str, String v2Str) {
        GraphUtil.addNonDirectedEdge(v1Str, v2Str, vertices, adjacentList);
    }

    @Override public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    /**
     * a minimum spanning tree of the graph
     * P Lefore 643
     *
     * @return a minimal spanning tree
     */
    public Map getAMinimumSpanningTree() {
        throw new RuntimeException("motheod not implemented yet");
    }


    public final static class Builder {
        private Set vertices = new HashSet();
        private Map> adjacentList = new HashMap>();

        public Builder addVertex(String label) {
            GraphUtil.addVertex(label, vertices);
            return this;
        }

        public Builder addEdge(String l1, String l2) {
            GraphUtil.addNonDirectedEdge(l1, l2, vertices, adjacentList);
            return this;
        }

        public NonDirectedGraph build() {
            return new NonDirectedGraph(vertices, adjacentList);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy