|
| 1 | +package dataStructures.graphs; |
| 2 | + |
| 3 | +import java.util.HashMap; |
| 4 | +import java.util.List; |
| 5 | +import java.util.Map; |
| 6 | +import java.util.Objects; |
| 7 | + |
| 8 | +public class CustomGraph { |
| 9 | + |
| 10 | + public static void main(String[] args) { |
| 11 | + CustomGraph customGraph = new CustomGraph(); |
| 12 | + Map<Vertex, List<Vertex>> map = new HashMap<>(); |
| 13 | + map.put(new Vertex("name"), List.of()); |
| 14 | + map.put(new Vertex("name2"), List.of(new Vertex("name"))); |
| 15 | + customGraph.setAdjVertices(map); |
| 16 | + System.out.println(customGraph); |
| 17 | + } |
| 18 | + |
| 19 | + // |
| 20 | + private Map<Vertex, List<Vertex>> adjVertices; |
| 21 | + |
| 22 | + public CustomGraph() { |
| 23 | + } |
| 24 | + |
| 25 | + public CustomGraph(Map<Vertex, List<Vertex>> adjVertices) { |
| 26 | + this.adjVertices = adjVertices; |
| 27 | + } |
| 28 | + |
| 29 | + public Map<Vertex, List<Vertex>> getAdjVertices() { |
| 30 | + return adjVertices; |
| 31 | + } |
| 32 | + |
| 33 | + public void setAdjVertices(Map<Vertex, List<Vertex>> adjVertices) { |
| 34 | + this.adjVertices = adjVertices; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public String toString() { |
| 39 | + return "Graph {" + |
| 40 | + "vertices=" + adjVertices + |
| 41 | + '}'; |
| 42 | + } |
| 43 | + |
| 44 | + public static class Vertex { |
| 45 | + String label; |
| 46 | + Vertex(String label) { |
| 47 | + this.label = label; |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public boolean equals(Object o) { |
| 52 | + if (o == null || getClass() != o.getClass()) |
| 53 | + return false; |
| 54 | + Vertex vertex = (Vertex) o; |
| 55 | + return Objects.equals(label, vertex.label); |
| 56 | + } |
| 57 | + |
| 58 | + @Override |
| 59 | + public int hashCode() { |
| 60 | + return Objects.hashCode(label); |
| 61 | + } |
| 62 | + |
| 63 | + @Override |
| 64 | + public String toString() { |
| 65 | + return "Vertex {" + |
| 66 | + "label='" + label + '\'' + |
| 67 | + '}'; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments