@Test public void testHypergraphFile() throws Exception { Transformer<GraphMetadata, Hypergraph<Number, Number>> graphFactory = new Transformer<GraphMetadata, Hypergraph<Number, Number>>() { public Hypergraph<Number, Number> transform(GraphMetadata md) { return new SetHypergraph<Number, Number>(); } }; Transformer<NodeMetadata, Number> vertexFactory = new Transformer<NodeMetadata, Number>() { int n = 0; public Number transform(NodeMetadata md) { return n++; } }; Transformer<EdgeMetadata, Number> edgeFactory = new Transformer<EdgeMetadata, Number>() { int n = 100; public Number transform(EdgeMetadata md) { return n++; } }; Transformer<HyperEdgeMetadata, Number> hyperEdgeFactory = new Transformer<HyperEdgeMetadata, Number>() { int n = 0; public Number transform(HyperEdgeMetadata md) { return n++; } }; Reader fileReader = new InputStreamReader(getClass().getResourceAsStream("hyper.graphml")); GraphMLReader2<Hypergraph<Number, Number>, Number, Number> hyperreader = new GraphMLReader2<Hypergraph<Number, Number>, Number, Number>(fileReader, graphFactory, vertexFactory, edgeFactory, hyperEdgeFactory); Hypergraph<Number, Number> graph = hyperreader.readGraph(); Assert.assertEquals(graph.getVertexCount(), 7); Assert.assertEquals(graph.getEdgeCount(), 4); Set<Number> incident = new HashSet<Number>(); incident.add(0); incident.add(100); Assert.assertEquals(incident, graph.getIncidentEdges(0)); incident.clear(); incident.add(0); incident.add(2); Assert.assertEquals(incident, graph.getIncidentEdges(1)); incident.clear(); incident.add(0); Assert.assertEquals(incident, graph.getIncidentEdges(2)); incident.clear(); incident.add(1); incident.add(2); Assert.assertEquals(incident, graph.getIncidentEdges(3)); incident.clear(); incident.add(1); incident.add(100); Assert.assertEquals(incident, graph.getIncidentEdges(4)); incident.clear(); incident.add(1); Assert.assertEquals(incident, graph.getIncidentEdges(5)); incident.clear(); incident.add(1); Assert.assertEquals(incident, graph.getIncidentEdges(6)); }
@SuppressWarnings("unchecked") public G readGraph() throws GraphIOException { try { init(); while (xmlEventReader.hasNext()) { XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; String name = element.getName().getLocalPart(); if (GraphMLConstants.KEY_NAME.equals(name)) { Key key = (Key) parserRegistry.getParser(name).parse( xmlEventReader, element); document.getKeyMap().addKey(key); } else if (GraphMLConstants.GRAPH_NAME.equals(name)) { GraphMetadata graph = (GraphMetadata) parserRegistry .getParser(name).parse(xmlEventReader, element); document.getGraphMetadata().add(graph); return (G)graph.getGraph(); } else if (GraphMLConstants.GRAPHML_NAME.equals(name)) { } else { parserRegistry.getUnknownElementParser().parse( xmlEventReader, element); } } else if (event.isEndDocument()) { break; } } } catch (Exception e) { ExceptionConverter.convert(e); } throw new GraphIOException("Unable to read Graph from document - the document could be empty"); }
GraphMLReader2 implements
        GraphReader<G, V, E> { @SuppressWarnings("unchecked") public G readGraph() throws GraphIOException { try { init(); while (xmlEventReader.hasNext()) { XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; String name = element.getName().getLocalPart(); if (GraphMLConstants.KEY_NAME.equals(name)) { Key key = (Key) parserRegistry.getParser(name).parse( xmlEventReader, element); document.getKeyMap().addKey(key); } else if (GraphMLConstants.GRAPH_NAME.equals(name)) { GraphMetadata graph = (GraphMetadata) parserRegistry .getParser(name).parse(xmlEventReader, element); document.getGraphMetadata().add(graph); return (G)graph.getGraph(); } else if (GraphMLConstants.GRAPHML_NAME.equals(name)) { } else { parserRegistry.getUnknownElementParser().parse( xmlEventReader, element); } } else if (event.isEndDocument()) { break; } } } catch (Exception e) { ExceptionConverter.convert(e); } throw new GraphIOException("Unable to read Graph from document - the document could be empty"); } }
GraphMLReader2 implements
        GraphReader<G, V, E> { @SuppressWarnings("unchecked") public G readGraph() throws GraphIOException { try { init(); while (xmlEventReader.hasNext()) { XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; String name = element.getName().getLocalPart(); if (GraphMLConstants.KEY_NAME.equals(name)) { Key key = (Key) parserRegistry.getParser(name).parse( xmlEventReader, element); document.getKeyMap().addKey(key); } else if (GraphMLConstants.GRAPH_NAME.equals(name)) { GraphMetadata graph = (GraphMetadata) parserRegistry .getParser(name).parse(xmlEventReader, element); document.getGraphMetadata().add(graph); return (G)graph.getGraph(); } else if (GraphMLConstants.GRAPHML_NAME.equals(name)) { } else { parserRegistry.getUnknownElementParser().parse( xmlEventReader, element); } } else if (event.isEndDocument()) { break; } } } catch (Exception e) { ExceptionConverter.convert(e); } throw new GraphIOException("Unable to read Graph from document - the document could be empty"); } GraphMLReader2(Reader fileReader,
                          Transformer<GraphMetadata, G> graphTransformer,
                          Transformer<NodeMetadata, V> vertexTransformer,
                          Transformer<EdgeMetadata, E> edgeTransformer,
                          Transformer<HyperEdgeMetadata, E> hyperEdgeTransformer); }
GraphMLReader2 implements
        GraphReader<G, V, E> { @SuppressWarnings("unchecked") public G readGraph() throws GraphIOException { try { init(); while (xmlEventReader.hasNext()) { XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; String name = element.getName().getLocalPart(); if (GraphMLConstants.KEY_NAME.equals(name)) { Key key = (Key) parserRegistry.getParser(name).parse( xmlEventReader, element); document.getKeyMap().addKey(key); } else if (GraphMLConstants.GRAPH_NAME.equals(name)) { GraphMetadata graph = (GraphMetadata) parserRegistry .getParser(name).parse(xmlEventReader, element); document.getGraphMetadata().add(graph); return (G)graph.getGraph(); } else if (GraphMLConstants.GRAPHML_NAME.equals(name)) { } else { parserRegistry.getUnknownElementParser().parse( xmlEventReader, element); } } else if (event.isEndDocument()) { break; } } } catch (Exception e) { ExceptionConverter.convert(e); } throw new GraphIOException("Unable to read Graph from document - the document could be empty"); } GraphMLReader2(Reader fileReader,
                          Transformer<GraphMetadata, G> graphTransformer,
                          Transformer<NodeMetadata, V> vertexTransformer,
                          Transformer<EdgeMetadata, E> edgeTransformer,
                          Transformer<HyperEdgeMetadata, E> hyperEdgeTransformer); Transformer<GraphMetadata, G> getGraphTransformer(); Transformer<NodeMetadata, V> getVertexTransformer(); Transformer<EdgeMetadata, E> getEdgeTransformer(); Transformer<HyperEdgeMetadata, E> getHyperEdgeTransformer(); void init(); void close(); GraphMLDocument getGraphMLDocument(); @SuppressWarnings("unchecked") G readGraph(); }
GraphMLReader2 implements
        GraphReader<G, V, E> { @SuppressWarnings("unchecked") public G readGraph() throws GraphIOException { try { init(); while (xmlEventReader.hasNext()) { XMLEvent event = xmlEventReader.nextEvent(); if (event.isStartElement()) { StartElement element = (StartElement) event; String name = element.getName().getLocalPart(); if (GraphMLConstants.KEY_NAME.equals(name)) { Key key = (Key) parserRegistry.getParser(name).parse( xmlEventReader, element); document.getKeyMap().addKey(key); } else if (GraphMLConstants.GRAPH_NAME.equals(name)) { GraphMetadata graph = (GraphMetadata) parserRegistry .getParser(name).parse(xmlEventReader, element); document.getGraphMetadata().add(graph); return (G)graph.getGraph(); } else if (GraphMLConstants.GRAPHML_NAME.equals(name)) { } else { parserRegistry.getUnknownElementParser().parse( xmlEventReader, element); } } else if (event.isEndDocument()) { break; } } } catch (Exception e) { ExceptionConverter.convert(e); } throw new GraphIOException("Unable to read Graph from document - the document could be empty"); } GraphMLReader2(Reader fileReader,
                          Transformer<GraphMetadata, G> graphTransformer,
                          Transformer<NodeMetadata, V> vertexTransformer,
                          Transformer<EdgeMetadata, E> edgeTransformer,
                          Transformer<HyperEdgeMetadata, E> hyperEdgeTransformer); Transformer<GraphMetadata, G> getGraphTransformer(); Transformer<NodeMetadata, V> getVertexTransformer(); Transformer<EdgeMetadata, E> getEdgeTransformer(); Transformer<HyperEdgeMetadata, E> getHyperEdgeTransformer(); void init(); void close(); GraphMLDocument getGraphMLDocument(); @SuppressWarnings("unchecked") G readGraph();  }