TamaGolem/src/ElementGraph.java
2025-05-10 13:12:46 +02:00

44 lines
1.1 KiB
Java

package it.arnaldo.unibs.tamagolem;
import java.util.*;
public class ElementGraph {
private final Set<GraphElement> elements;
public ElementGraph() {
this.elements = new HashSet<>();
}
public void addElement(GraphElement element) {
elements.add(element);
}
public int getValue(Element fromElement, Element toElement) {
for (GraphElement graphElement : elements) {
if (graphElement.getElement().equals(fromElement)) {
return graphElement.getLinkValue(toElement);
}
}
return 0;
}
public Set<GraphElement> getElements() {
return elements;
}
public void printGraph() {
for (GraphElement from : elements) {
Element fromElement = from.getElement();
System.out.println("[" + fromElement + "] →");
for (ElementLink link : from.getLinks()) {
Element toElement = link.getElement();
int value = link.getValue();
System.out.printf(" -> %s : %d\n", toElement, value);
}
System.out.println();
}
}
}