1
2
3
4
5
6
7
8
9
10
11 package edu.uci.ics.jung.io.graphml;
12
13 import java.util.HashMap;
14 import java.util.Map;
15
16
17
18
19
20
21
22
23 public class GraphMetadata extends AbstractMetadata {
24
25 public enum EdgeDefault {
26 DIRECTED, UNDIRECTED
27 }
28
29 private String id;
30 private EdgeDefault edgeDefault;
31 private String description;
32 private Object graph;
33 final private Map<Object, NodeMetadata> nodes = new HashMap<Object, NodeMetadata>();
34 final private Map<Object, EdgeMetadata> edges = new HashMap<Object, EdgeMetadata>();
35 final private Map<Object, HyperEdgeMetadata> hyperEdges = new HashMap<Object, HyperEdgeMetadata>();
36
37 public String getId() {
38 return id;
39 }
40
41 public void setId(String id) {
42 this.id = id;
43 }
44
45 public EdgeDefault getEdgeDefault() {
46 return edgeDefault;
47 }
48
49 public void setEdgeDefault(EdgeDefault edgeDefault) {
50 this.edgeDefault = edgeDefault;
51 }
52
53 public String getDescription() {
54 return description;
55 }
56
57 public void setDescription(String desc) {
58 this.description = desc;
59 }
60
61 public void addNodeMetadata(Object vertex, NodeMetadata metadata) {
62 nodes.put(vertex, metadata);
63 }
64
65 public NodeMetadata getNodeMetadata(Object vertex) {
66 return nodes.get(vertex);
67 }
68
69 public Map<Object, NodeMetadata> getNodeMap() {
70 return nodes;
71 }
72
73 public void addEdgeMetadata(Object edge, EdgeMetadata metadata) {
74 edges.put(edge, metadata);
75 }
76
77 public EdgeMetadata getEdgeMetadata(Object edge) {
78 return edges.get(edge);
79 }
80
81 public Map<Object, EdgeMetadata> getEdgeMap() {
82 return edges;
83 }
84
85 public void addHyperEdgeMetadata(Object edge, HyperEdgeMetadata metadata) {
86 hyperEdges.put(edge, metadata);
87 }
88
89 public HyperEdgeMetadata getHyperEdgeMetadata(Object edge) {
90 return hyperEdges.get(edge);
91 }
92
93 public Map<Object, HyperEdgeMetadata> getHyperEdgeMap() {
94 return hyperEdges;
95 }
96
97 public Object getGraph() {
98 return graph;
99 }
100
101 public void setGraph(Object graph) {
102 this.graph = graph;
103 }
104
105 public MetadataType getMetadataType() {
106 return MetadataType.GRAPH;
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121 public String getVertexProperty(Object vertex, String key)
122 throws IllegalArgumentException {
123 NodeMetadata metadata = getNodeMetadata(vertex);
124 if (metadata == null) {
125 throw new IllegalArgumentException(
126 "Metadata does not exist for provided vertex");
127 }
128
129 return metadata.getProperty(key);
130 }
131
132
133
134
135
136
137
138
139
140
141
142
143
144 public String getEdgeProperty(Object edge, String key)
145 throws IllegalArgumentException {
146
147
148 EdgeMetadata em = getEdgeMetadata(edge);
149 if (em != null) {
150 return em.getProperty(key);
151 }
152
153
154 HyperEdgeMetadata hem = getHyperEdgeMetadata(edge);
155 if (hem != null) {
156 return hem.getProperty(key);
157 }
158
159
160 throw new IllegalArgumentException(
161 "Metadata does not exist for provided edge");
162 }
163
164 }