Skip to content

Commit b039326

Browse files
committed
make Attributes iterable
Signed-off-by: Stefan Niederhauser <[email protected]>
1 parent ed139d2 commit b039326

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

graphviz-java/src/main/java/guru/nidi/graphviz/attribute/Attributes.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
package guru.nidi.graphviz.attribute;
1717

1818
import javax.annotation.Nullable;
19+
import java.util.Iterator;
1920
import java.util.List;
21+
import java.util.Map.Entry;
2022

2123
import static java.util.Arrays.asList;
2224

23-
public interface Attributes<F extends For> {
25+
public interface Attributes<F extends For> extends Iterable<Entry<String, Object>> {
2426
Attributes<? super F> applyTo(MapAttributes<? super F> attrs);
2527

2628
default Attributes<? super F> applyTo(Attributes<? super F> attrs) {
@@ -62,6 +64,11 @@ default Object get(String key) {
6264
return applyTo(new MapAttributes<>()).get(key);
6365
}
6466

67+
@Override
68+
default Iterator<Entry<String, Object>> iterator() {
69+
return applyTo(new MapAttributes<>()).iterator();
70+
}
71+
6572
default boolean isEmpty() {
6673
return applyTo(new MapAttributes<>()).isEmpty();
6774
}

graphviz-java/src/main/java/guru/nidi/graphviz/model/MutableAttributed.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static guru.nidi.graphviz.attribute.Attributes.attr;
2525
import static guru.nidi.graphviz.attribute.Attributes.attrs;
2626

27-
public interface MutableAttributed<T, F extends For> extends Attributes<F>, Iterable<Entry<String, Object>> {
27+
public interface MutableAttributed<T, F extends For> extends Attributes<F> {
2828
default T add(String name, @Nullable Object value) {
2929
return add(attr(name, value));
3030
}

graphviz-java/src/main/java/guru/nidi/graphviz/model/SimpleMutableAttributed.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public Attributes<? super F> applyTo(MapAttributes<? super F> attrs) {
4242
return attrs.add(attributes);
4343
}
4444

45-
@Override
46-
public Iterator<Entry<String, Object>> iterator() {
47-
return attributes.iterator();
48-
}
49-
5045
@Override
5146
public Object get(String key) {
5247
return attributes.get(key);

0 commit comments

Comments
 (0)