Skip to content

Commit 9742ff5

Browse files
authored
Merge pull request #125 from Flashky/feature/56-add-labelededge-class-for-jgrapht-graphs
feat: add LabeledEdge class #56
2 parents 21c6fb4 + 0aa61da commit 9742ff5

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.adventofcode.flashk.common.jgrapht;
2+
3+
import org.jgrapht.graph.DefaultEdge;
4+
import org.jgrapht.nio.Attribute;
5+
import org.jgrapht.nio.AttributeType;
6+
7+
/// Labeled edge class based on [JGraphT LabeledEdges](https://jgrapht.org/guide/LabeledEdges)
8+
///
9+
/// Allows creating an edge with label.
10+
///
11+
/// It also implements the JGraphT Attribute interface to allow exporting the labels in DOT representation
12+
public class LabeledEdge extends DefaultEdge implements Attribute {
13+
14+
private final String label;
15+
16+
public LabeledEdge(String label) {
17+
this.label = label;
18+
}
19+
20+
@Override
21+
public String getValue() {
22+
return label;
23+
}
24+
25+
@Override
26+
public AttributeType getType() {
27+
return AttributeType.STRING;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return "(" + getSource() + " : " + getTarget() + " : " + label + ")";
33+
}
34+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.adventofcode.flashk.common.jgrapht;
2+
3+
import org.jgrapht.nio.AttributeType;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
class LabeledEdgeTest {
9+
10+
@Test
11+
void getValue() {
12+
LabeledEdge labeledEdge = new LabeledEdge("expected");
13+
assertEquals("expected", labeledEdge.getValue());
14+
}
15+
16+
@Test
17+
void getType() {
18+
LabeledEdge labeledEdge = new LabeledEdge("expected");
19+
assertEquals(AttributeType.STRING, labeledEdge.getType());
20+
}
21+
}

0 commit comments

Comments
 (0)