Projects >> blueprints >>5d15f6fd3bf7b05d99f759e8c7cf0b9631bd38ad

Chunk
Conflicting content
 */
public class GMLReader {

<<<<<<< HEAD
    public static final String DEFAULT_LABEL = "undefined";

    private static final int DEFAULT_BUFFER_SIZE = 1000;

    private Map vertexIds = new HashMap();

    private final Graph graph;

    private final String defaultEdgeLabel;

    private boolean directed = false;

    private int edgeCount = 0;

    private String vertexIdKey;

    private String edgeIdKey;

    private String edgeLabelKey = GMLTokens.LABEL;

    /**
     * Create a new GML reader
     * 

* (Uses default edge label DEFAULT_LABEL) * * @param graph the graph to load data into */ public GMLReader(Graph graph) { this(graph, DEFAULT_LABEL); } /** * Create a new GML reader * * @param graph the graph to load data into * @param defaultEdgeLabel the default edge label to be used if the GML edge does not define a label */ public GMLReader(Graph graph, String defaultEdgeLabel) { this.graph = graph; this.defaultEdgeLabel = defaultEdgeLabel; } /** * @param vertexIdKey gml property to use as id for verticies */ public void setVertexIdKey(String vertexIdKey) { this.vertexIdKey = vertexIdKey; } /** * @param edgeIdKey gml property to use as id for edges */ public void setEdgeIdKey(String edgeIdKey) { this.edgeIdKey = edgeIdKey; } /** * @param edgeLabelKey gml property to assign edge Labels to */ public void setEdgeLabelKey(String edgeLabelKey) { this.edgeLabelKey = edgeLabelKey; } /** * Read the GML from from the stream. *

* If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream) throws IOException { inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } /** * Read the GML from from the stream. *

* If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream, int bufferSize) throws IOException { int previousMaxBufferSize = 0; if (graph instanceof TransactionalGraph) { previousMaxBufferSize = ((TransactionalGraph) graph).getMaxBufferSize(); ((TransactionalGraph) graph).setMaxBufferSize(bufferSize); } Reader r = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("ISO-8859-1"))); StreamTokenizer st = new StreamTokenizer(r); try { st.commentChar(GMLTokens.COMMENT_CHAR); st.ordinaryChar('['); st.ordinaryChar(']'); String stringCharacters = "/\\(){}<>!£$%^&*-+=,.?:;@_`|~"; for (int i = 0; i < stringCharacters.length(); i++) { st.wordChars(stringCharacters.charAt(i), stringCharacters.charAt(i)); } parse(st); if (graph instanceof TransactionalGraph) { ((TransactionalGraph) graph).setMaxBufferSize(previousMaxBufferSize); } } catch (IOException e) { throw new IOException(error(st), e); } finally { vertexIds.clear(); } } private boolean hasNext(StreamTokenizer st) throws IOException { return st.nextToken() != StreamTokenizer.TT_EOF; } private String error(StreamTokenizer st) { return "GML malformed line number " + st.lineno() + ": "; } private boolean notLineBreak(int type) { return type != StreamTokenizer.TT_EOL; } private void parse(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { String value = st.sval; if (GMLTokens.GRAPH.equals(value)) { parseGraph(st); if (!hasNext(st)) { return; } } } } throw new IOException("Graph not complete"); } private void parseGraph(StreamTokenizer st) throws IOException { checkValid(st, GMLTokens.GRAPH); while (hasNext(st)) { // st.nextToken(); int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return; } else { String key = st.sval; if (GMLTokens.NODE.equals(key)) { addNode(parseNode(st)); } else if (GMLTokens.EDGE.equals(key)) { addEdge(parseEdge(st)); } else if (GMLTokens.DIRECTED.equals(key)) { directed = parseBoolean(st); } else { // IGNORE parseValue("ignore", st); } } } } throw new IOException("Graph not complete"); } private void addNode(Map map) throws IOException { Object id = map.remove(GMLTokens.ID); if (id != null) { Vertex vertex; vertex = createVertex(map, id); addProperties(vertex, map); } else { throw new IOException("No id found for node"); } } private Vertex createVertex(Map map, Object id) { if (vertexIdKey != null) { * Object vertexId = map.remove(vertexIdKey); if (vertexId != null) { vertexIds.put(id, vertexId); return graph.addVertex(vertexId); } // if no id try to use default id this will fail if not unique vertexIds.put(id, id); } // Use default id system return graph.addVertex(id); } private void addEdge(Map map) throws IOException { Object source = map.remove(GMLTokens.SOURCE); Object target = map.remove(GMLTokens.TARGET); if (source == null) { throw new IOException("Edge has no source"); } if (target == null) { throw new IOException("Edge has no target"); } if (vertexIdKey != null) { source = vertexIds.get(source); target = vertexIds.get(target); } Vertex outVertex = graph.getVertex(source); Vertex inVertex = graph.getVertex(target); if (outVertex == null) { throw new IOException("Edge source " + source + " not found"); } if (inVertex == null) { throw new IOException("Edge target " + target + " not found"); } Object label = map.remove(edgeLabelKey); if (label == null) { // try standard label key label = map.remove(GMLTokens.LABEL); } else { // remove label in case edge label key is not label // label is reserved and cannot be added as a property // if so this data will be lost map.remove(GMLTokens.LABEL); } if (label == null) { label = defaultEdgeLabel; } Object edgeId = edgeCount++; if (edgeIdKey != null) { Object mappedKey = map.remove(edgeIdKey); if (mappedKey != null) { edgeId = mappedKey; } // else use edgecount - could fail if mapped ids overlap with edge count } // remove id as reserved property - can be left is edgeIdKey in not id // This data will be lost map.remove(GMLTokens.ID); Edge edge = graph.addEdge(edgeId, outVertex, inVertex, label.toString()); if (directed) { edge.setProperty(GMLTokens.DIRECTED, directed); } addProperties(edge, map); } private void addProperties(Element element, Map map) { for (Entry entry : map.entrySet()) { element.setProperty(entry.getKey(), entry.getValue()); } } private Object parseValue(String key, StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { Double doubleValue = Double.valueOf(st.nval); if (doubleValue.equals(Double.valueOf(doubleValue.intValue()))) { return doubleValue.intValue(); } else { return doubleValue.floatValue(); } } else { if (type == '[') { return parseMap(key, st); } else if (type == '"') { return st.sval; } } } } * (Uses default edge label DEFAULT_LABEL) throw new IOException("value not found"); } private boolean parseBoolean(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { return st.nval == 1.0; } } } throw new IOException("boolean not found"); } private Map parseNode(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.NODE); } private Map parseEdge(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.EDGE); } private Map parseElement(StreamTokenizer st, String node) throws IOException { checkValid(st, node); return parseMap(node, st); } private Map parseMap(String node, StreamTokenizer st) throws IOException { Map map = new HashMap(); while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return map; } else { String key = st.sval; Object value = parseValue(key, st); map.put(key, value); } } } throw new IOException(node + " incomplete"); } private void checkValid(StreamTokenizer st, String token) throws IOException { if (st.nextToken() != '[') { throw new IOException(token + " not followed by ["); } } /** * Load the GML file into the Graph. * * @param graph to receive the data * @param inputStream GML file * @throws IOException thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream) throws IOException { inputGraph(graph, inputStream, DEFAULT_LABEL); } /** * Load the GML file into the Graph. * * @param graph to receive the data * @param inputStream GML file * @param defaultEdgeLabel default edge label to be used if not defined in the data * @throws IOException thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream, String defaultEdgeLabel) throws IOException { new GMLReader(graph, defaultEdgeLabel).inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } ======= public static final String DEFAULT_LABEL = "undefined"; private static final int DEFAULT_BUFFER_SIZE = 1000; private Map vertexIds = new HashMap(); private final Graph graph; private final String defaultEdgeLabel; private boolean directed = false; private int edgeCount = 0; private String vertexIdKey; private String edgeIdKey; private String edgeLabelKey = GMLTokens.LABEL; /** * Map of the the IDs used in the GML to the IDs used by the underlying graph implementation. */ private Map vertexIdMap = new HashMap(); /** * Create a new GML reader * * @throws IOException * @param graph * the graph to load data into */ public GMLReader(Graph graph) { this(graph, DEFAULT_LABEL); } /** * Create a new GML reader * * @param graph * the graph to load data into * @param defaultEdgeLabel * the default edge label to be used if the GML edge does not define a label */ public GMLReader(Graph graph, String defaultEdgeLabel) { this.graph = graph; this.defaultEdgeLabel = defaultEdgeLabel; } /** * @param vertexIdKey * gml property to use as id for verticies */ public void setVertexIdKey(String vertexIdKey) { this.vertexIdKey = vertexIdKey; } /** * @param edgeIdKey * gml property to use as id for edges */ public void setEdgeIdKey(String edgeIdKey) { this.edgeIdKey = edgeIdKey; } /** * @param edgeLabelKey * gml property to assign edge Labels to */ public void setEdgeLabelKey(String edgeLabelKey) { this.edgeLabelKey = edgeLabelKey; } /** * Read the GML from from the stream. * * If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream) throws IOException { inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } /** * Read the GML from from the stream. * * If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream, int bufferSize) throws IOException { int previousMaxBufferSize = 0; if (graph instanceof TransactionalGraph) { previousMaxBufferSize = ((TransactionalGraph) graph).getMaxBufferSize(); ((TransactionalGraph) graph).setMaxBufferSize(bufferSize); } Reader r = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("ISO-8859-1"))); StreamTokenizer st = new StreamTokenizer(r); try { st.commentChar(GMLTokens.COMMENT_CHAR); st.ordinaryChar('['); st.ordinaryChar(']'); String stringCharacters = "/\\(){}<>!£$%^&*-+=,.?:;@_`|~"; for (int i = 0; i < stringCharacters.length(); i++) { st.wordChars(stringCharacters.charAt(i), stringCharacters.charAt(i)); } parse(st); if (graph instanceof TransactionalGraph) { ((TransactionalGraph) graph).setMaxBufferSize(previousMaxBufferSize); } } catch (IOException e) { throw new IOException(error(st), e); } finally { vertexIds.clear(); } } private boolean hasNext(StreamTokenizer st) throws IOException { return st.nextToken() != StreamTokenizer.TT_EOF; } private String error(StreamTokenizer st) { return "GML malformed line number " + st.lineno() + ": "; } private boolean notLineBreak(int type) { return type != StreamTokenizer.TT_EOL; } private void parse(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { String value = st.sval; if (GMLTokens.GRAPH.equals(value)) { parseGraph(st); if (!hasNext(st)) { return; } } } } throw new IOException("Graph not complete"); } private void parseGraph(StreamTokenizer st) throws IOException { checkValid(st, GMLTokens.GRAPH); while (hasNext(st)) { // st.nextToken(); int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return; } else { String key = st.sval; if (GMLTokens.NODE.equals(key)) { addNode(parseNode(st)); } else if (GMLTokens.EDGE.equals(key)) { addEdge(parseEdge(st)); } else if (GMLTokens.DIRECTED.equals(key)) { directed = parseBoolean(st); } else { // IGNORE parseValue("ignore", st); } } } } throw new IOException("Graph not complete"); } private void addNode(Map map) throws IOException { Object id = map.remove(GMLTokens.ID); if (id != null) { final Vertex vertex = createVertex(map, id); addProperties(vertex, map); // keep track of the identifiers created by the graph. vertexIdMap.put(vertexIds.get(id), vertex.getId()); } else { throw new IOException("No id found for node"); } } private Vertex createVertex(Map map, Object id) { if (vertexIdKey != null) { Object vertexId = map.remove(vertexIdKey); if (vertexId != null) { vertexIds.put(id, vertexId); return graph.addVertex(vertexId); } } // if no id try to use default id this will fail if not unique vertexIds.put(id, id); // Use default id system return graph.addVertex(id); } private void addEdge(Map map) throws IOException { Object source = map.remove(GMLTokens.SOURCE); Object target = map.remove(GMLTokens.TARGET); if (source == null) { throw new IOException("Edge has no source"); } if (target == null) { throw new IOException("Edge has no target"); } if (vertexIdKey != null) { source = vertexIds.get(source); target = vertexIds.get(target); } // grab the identifiers used by the graph itself final Object sourceId = vertexIdMap.get(source); final Object targetId = vertexIdMap.get(target); final Vertex outVertex = graph.getVertex(sourceId); final Vertex inVertex = graph.getVertex(targetId); if (outVertex == null) { throw new IOException("Edge source " + source + " not found"); } if (inVertex == null) { throw new IOException("Edge target " + target + " not found"); } Object label = map.remove(edgeLabelKey); if (label == null) { // try standard label key label = map.remove(GMLTokens.LABEL); } else { // remove label in case edge label key is not label // label is reserved and cannot be added as a property // if so this data will be lost map.remove(GMLTokens.LABEL); } if (label == null) { label = defaultEdgeLabel; } Object edgeId = edgeCount++; if (edgeIdKey != null) { Object mappedKey = map.remove(edgeIdKey); if (mappedKey != null) { edgeId = mappedKey; } // else use edgecount - could fail if mapped ids overlap with edge count } // remove id as reserved property - can be left is edgeIdKey in not id // This data will be lost map.remove(GMLTokens.ID); Edge edge = graph.addEdge(edgeId, outVertex, inVertex, label.toString()); if (directed) { edge.setProperty(GMLTokens.DIRECTED, directed); } addProperties(edge, map); } private void addProperties(Element element, Map map) { for (Entry entry : map.entrySet()) { element.setProperty(entry.getKey(), entry.getValue()); } } private Object parseValue(String key, StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { Double doubleValue = Double.valueOf(st.nval); if (doubleValue.equals(Double.valueOf(doubleValue.intValue()))) { return doubleValue.intValue(); } else { return doubleValue.floatValue(); } } else { if (type == '[') { return parseMap(key, st); } else if (type == '"') { return st.sval; } } } } throw new IOException("value not found"); } private boolean parseBoolean(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { return st.nval == 1.0; } } } throw new IOException("boolean not found"); } private Map parseNode(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.NODE); } private Map parseEdge(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.EDGE); } private Map parseElement(StreamTokenizer st, String node) throws IOException { checkValid(st, node); return parseMap(node, st); } private Map parseMap(String node, StreamTokenizer st) throws IOException { Map map = new HashMap(); while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return map; } else { String key = st.sval; Object value = parseValue(key, st); map.put(key, value); } } } throw new IOException(node + " incomplete"); } private void checkValid(StreamTokenizer st, String token) throws IOException { if (st.nextToken() != '[') { throw new IOException(token + " not followed by ["); } } /** * Load the GML file into the Graph. * * @param graph * to receive the data * @param inputStream * GML file * thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream) throws IOException { inputGraph(graph, inputStream, DEFAULT_LABEL); } /** * Load the GML file into the Graph. * * @param graph * to receive the data * @param inputStream * GML file * @param defaultEdgeLabel * default edge label to be used if not defined in the data * @throws IOException * thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream, String defaultEdgeLabel) throws IOException { new GMLReader(graph, defaultEdgeLabel).inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } >>>>>>> 7ad6fcdca5566066a1f6ff56d5a32686f224f43a }

Solution content
 */
public class GMLReader {

    public static final String DEFAULT_LABEL = "undefined";

    private static final int DEFAULT_BUFFER_SIZE = 1000;

    private Map vertexIds = new HashMap();

    private final Graph graph;

    private final String defaultEdgeLabel;

    private boolean directed = false;

    private int edgeCount = 0;

    private String vertexIdKey;

    private String edgeIdKey;

    private String edgeLabelKey = GMLTokens.LABEL;

    /**
     * Create a new GML reader
     * 

* (Uses default edge label DEFAULT_LABEL) * * @param graph the graph to load data into */ public GMLReader(Graph graph) { this(graph, DEFAULT_LABEL); } /** * Create a new GML reader * * @param graph the graph to load data into * @param defaultEdgeLabel the default edge label to be used if the GML edge does not define a label */ public GMLReader(Graph graph, String defaultEdgeLabel) { this.graph = graph; this.defaultEdgeLabel = defaultEdgeLabel; } /** * @param vertexIdKey gml property to use as id for verticies */ public void setVertexIdKey(String vertexIdKey) { this.vertexIdKey = vertexIdKey; } /** * @param edgeIdKey gml property to use as id for edges */ public void setEdgeIdKey(String edgeIdKey) { this.edgeIdKey = edgeIdKey; } /** * @param edgeLabelKey gml property to assign edge Labels to */ public void setEdgeLabelKey(String edgeLabelKey) { this.edgeLabelKey = edgeLabelKey; } /** * Read the GML from from the stream. *

* If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream) throws IOException { inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } /** * Read the GML from from the stream. *

* If the file is malformed incomplete data can be loaded. * * @param inputStream * @throws IOException */ public void inputGraph(InputStream inputStream, int bufferSize) throws IOException { int previousMaxBufferSize = 0; if (graph instanceof TransactionalGraph) { previousMaxBufferSize = ((TransactionalGraph) graph).getMaxBufferSize(); ((TransactionalGraph) graph).setMaxBufferSize(bufferSize); } finally { } Reader r = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("ISO-8859-1"))); StreamTokenizer st = new StreamTokenizer(r); try { st.commentChar(GMLTokens.COMMENT_CHAR); st.ordinaryChar('['); st.ordinaryChar(']'); String stringCharacters = "/\\(){}<>!£$%^&*-+=,.?:;@_`|~"; for (int i = 0; i < stringCharacters.length(); i++) { st.wordChars(stringCharacters.charAt(i), stringCharacters.charAt(i)); } parse(st); if (graph instanceof TransactionalGraph) { ((TransactionalGraph) graph).setMaxBufferSize(previousMaxBufferSize); } } catch (IOException e) { throw new IOException(error(st), e); vertexIds.clear(); } } private boolean hasNext(StreamTokenizer st) throws IOException { return st.nextToken() != StreamTokenizer.TT_EOF; } private String error(StreamTokenizer st) { return "GML malformed line number " + st.lineno() + ": "; } private boolean notLineBreak(int type) { return type != StreamTokenizer.TT_EOL; } private void parse(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { String value = st.sval; if (GMLTokens.GRAPH.equals(value)) { parseGraph(st); if (!hasNext(st)) { return; } } } } throw new IOException("Graph not complete"); } private void parseGraph(StreamTokenizer st) throws IOException { checkValid(st, GMLTokens.GRAPH); while (hasNext(st)) { // st.nextToken(); int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return; } else { String key = st.sval; if (GMLTokens.NODE.equals(key)) { addNode(parseNode(st)); } else if (GMLTokens.EDGE.equals(key)) { addEdge(parseEdge(st)); } else if (GMLTokens.DIRECTED.equals(key)) { directed = parseBoolean(st); } else { // IGNORE parseValue("ignore", st); } } } } throw new IOException("Graph not complete"); } private void addNode(Map map) throws IOException { Object id = map.remove(GMLTokens.ID); if (id != null) { Vertex vertex; vertex = createVertex(map, id); addProperties(vertex, map); } else { throw new IOException("No id found for node"); } } private Vertex createVertex(Map map, Object id) { if (vertexIdKey != null) { Object vertexId = map.remove(vertexIdKey); if (vertexId != null) { vertexIds.put(id, vertexId); return graph.addVertex(vertexId); } // if no id try to use default id this will fail if not unique vertexIds.put(id, id); } // Use default id system return graph.addVertex(id); } private void addEdge(Map map) throws IOException { Object source = map.remove(GMLTokens.SOURCE); Object target = map.remove(GMLTokens.TARGET); if (source == null) { throw new IOException("Edge has no source"); } if (target == null) { throw new IOException("Edge has no target"); } if (vertexIdKey != null) { source = vertexIds.get(source); target = vertexIds.get(target); } Vertex outVertex = graph.getVertex(source); Vertex inVertex = graph.getVertex(target); if (outVertex == null) { throw new IOException("Edge source " + source + " not found"); } if (inVertex == null) { throw new IOException("Edge target " + target + " not found"); } Object label = map.remove(edgeLabelKey); if (label == null) { // try standard label key label = map.remove(GMLTokens.LABEL); } else { // remove label in case edge label key is not label // label is reserved and cannot be added as a property // if so this data will be lost map.remove(GMLTokens.LABEL); } if (label == null) { label = defaultEdgeLabel; } Object edgeId = edgeCount++; if (edgeIdKey != null) { Object mappedKey = map.remove(edgeIdKey); if (mappedKey != null) { edgeId = mappedKey; } // else use edgecount - could fail if mapped ids overlap with edge count } // remove id as reserved property - can be left is edgeIdKey in not id // This data will be lost map.remove(GMLTokens.ID); Edge edge = graph.addEdge(edgeId, outVertex, inVertex, label.toString()); if (directed) { edge.setProperty(GMLTokens.DIRECTED, directed); } addProperties(edge, map); } private void addProperties(Element element, Map map) { for (Entry entry : map.entrySet()) { element.setProperty(entry.getKey(), entry.getValue()); } } private Object parseValue(String key, StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { Double doubleValue = Double.valueOf(st.nval); if (doubleValue.equals(Double.valueOf(doubleValue.intValue()))) { return doubleValue.intValue(); } else { return doubleValue.floatValue(); } } else { if (type == '[') { return parseMap(key, st); } else if (type == '"') { return st.sval; } } } } throw new IOException("value not found"); } private boolean parseBoolean(StreamTokenizer st) throws IOException { while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == StreamTokenizer.TT_NUMBER) { return st.nval == 1.0; } } } throw new IOException("boolean not found"); } private Map parseNode(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.NODE); } private Map parseEdge(StreamTokenizer st) throws IOException { return parseElement(st, GMLTokens.EDGE); } private Map parseElement(StreamTokenizer st, String node) throws IOException { checkValid(st, node); return parseMap(node, st); } private Map parseMap(String node, StreamTokenizer st) throws IOException { Map map = new HashMap(); while (hasNext(st)) { int type = st.ttype; if (notLineBreak(type)) { if (type == ']') { return map; } else { String key = st.sval; Object value = parseValue(key, st); map.put(key, value); } } } throw new IOException(node + " incomplete"); } private void checkValid(StreamTokenizer st, String token) throws IOException { if (st.nextToken() != '[') { throw new IOException(token + " not followed by ["); } } /** * Load the GML file into the Graph. * * @param graph to receive the data * @param inputStream GML file * @throws IOException thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream) throws IOException { inputGraph(graph, inputStream, DEFAULT_LABEL); } /** * Load the GML file into the Graph. * * @param graph to receive the data * @param inputStream GML file * @param defaultEdgeLabel default edge label to be used if not defined in the data * @throws IOException thrown if the data is not valid */ public static void inputGraph(Graph graph, InputStream inputStream, String defaultEdgeLabel) throws IOException { new GMLReader(graph, defaultEdgeLabel).inputGraph(inputStream, DEFAULT_BUFFER_SIZE); } }

File
GMLReader.java
Developer's decision
Combination
Kind of conflict
Attribute
Comment
Method declaration
Method invocation
Chunk
Conflicting content
 */
public class GMLWriter {

<<<<<<< HEAD
    private static final String DELIMITER = " ";
    private static final String TAB = "\t";
    private static final String NEW_LINE = "\r\n";
    private static final String OPEN_LIST = " [" + NEW_LINE;
    private static final String CLOSE_LIST = "]" + NEW_LINE;
    private final Graph graph;
    private boolean normalize = false;
    private boolean useId = false;
    private String vertexIdKey = GMLTokens.BLUEPRINTS_ID;
    private String edgeIdKey = GMLTokens.BLUEPRINTS_ID;

    /**
     * @param graph the Graph to pull the data from
     */
    public GMLWriter(final Graph graph) {
        this.graph = graph;
    }

    /**
     * @param normalize whether to normalize the output. Normalized output is deterministic with respect to the order of
     *                  elements and properties in the resulting XML document, and is compatible with line diff-based tools
     *                  such as Git. Note: normalized output is memory-intensive and is not appropriate for very large graphs.
     */
    public void setNormalize(final boolean normalize) {
        this.normalize = normalize;
    }

    /**
     * @param useId whether to use the blueprints id directly or substitute with a generated integer. To use this option
     *              the blueprints ids must all be Integers of String representations of integers
     */
    public void setUseId(final boolean useId) {
        this.useId = useId;
    }

    /**
     * @param vertexIdKey gml property to use for the blueprints vertex id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
     */
    public void setVertexIdKey(String vertexIdKey) {
        this.vertexIdKey = vertexIdKey;
    }

    /**
     * @param edgeIdKey gml property to use for the blueprints edges id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
     */
    public void setEdgeIdKey(String edgeIdKey) {
        this.edgeIdKey = edgeIdKey;
    }

    /**
     * Write the data in a Graph to a GML OutputStream.
     *
     * @param gMLOutputStream the GML OutputStream to write the Graph data to
     * @throws IOException thrown if there is an error generating the GML data
     */
    public void outputGraph(final OutputStream gMLOutputStream) throws IOException {

        // ISO 8859-1 as specified in the GML documentation
        Writer writer = new BufferedWriter(new OutputStreamWriter(gMLOutputStream, Charset.forName("ISO-8859-1")));

        List verticies = new ArrayList();
        List edges = new ArrayList();

        populateLists(verticies, edges);

        if (normalize) {
            LexicographicalElementComparator comparator = new LexicographicalElementComparator();
            Collections.sort(verticies, comparator);
            Collections.sort(edges, comparator);
        }

        writeGraph(writer, verticies, edges);

        writer.flush();
        writer.close();
    }

    private void writeGraph(Writer writer, List verticies, List edges) throws IOException {
        Map ids = new HashMap();

        writer.write(GMLTokens.GRAPH);
        writer.write(OPEN_LIST);
        writeVerticies(writer, verticies, ids);
        writeEdges(writer, edges, ids);
        writer.write(CLOSE_LIST);

    }

    private void writeVerticies(Writer writer, List verticies, Map ids) throws IOException {
        int count = 1;
        for (Vertex v : verticies) {
            if (useId) {
                Integer id = Integer.valueOf(v.getId().toString());
                writeVertex(writer, v, id);
                ids.put(v, id);
            } else {
                writeVertex(writer, v, count);
                ids.put(v, count++);
            }

        }
    }

    private void writeVertex(Writer writer, Vertex v, int id) throws IOException {
        writer.write(TAB);
        writer.write(GMLTokens.NODE);
        writer.write(OPEN_LIST);
        writeKey(writer, GMLTokens.ID);
        writeNumberProperty(writer, id);
        writeVertexProperties(writer, v);
        writer.write(TAB);
        writer.write(CLOSE_LIST);
    }

    private void writeEdges(Writer writer, List edges, Map ids) throws IOException {
        for (Edge e : edges) {
            writeEdgeProperties(writer, e, ids.get(e.getOutVertex()), ids.get(e.getInVertex()));
        }
    }

    private void writeEdgeProperties(Writer writer, Edge e, Integer source, Integer target) throws IOException {
        writer.write(TAB);
        writer.write(GMLTokens.EDGE);
        writer.write(OPEN_LIST);
        writeKey(writer, GMLTokens.SOURCE);
        writeNumberProperty(writer, source);
        writeKey(writer, GMLTokens.TARGET);
        writeNumberProperty(writer, target);
        writeKey(writer, GMLTokens.LABEL);
        writeStringProperty(writer, e.getLabel());
        writeEdgeProperties(writer, e);
        writer.write(TAB);
        writer.write(CLOSE_LIST);
    }

    private void writeVertexProperties(Writer writer, Vertex e) throws IOException {
        Object blueprintsId = e.getId();
        if (!useId) {
            writeKey(writer, vertexIdKey);
            if (blueprintsId instanceof Number) {
                writeNumberProperty(writer, (Number) blueprintsId);
            } else {
                writeStringProperty(writer, blueprintsId);
            }
        }
        writeProperties(writer, e);
    }

    private void writeEdgeProperties(Writer writer, Edge e) throws IOException {
        Object blueprintsId = e.getId();
        if (!useId) {
            writeKey(writer, edgeIdKey);
            if (blueprintsId instanceof Number) {
                writeNumberProperty(writer, (Number) blueprintsId);
            } else {
                writeStringProperty(writer, blueprintsId);
            }
        }
        writeProperties(writer, e);
    }

    private void writeProperties(Writer writer, Element e) throws IOException {
        for (String key : e.getPropertyKeys()) {
            Object property = e.getProperty(key);
            writeKey(writer, key);
            writeProperty(writer, property, 0);
        }
    }

    private void writeProperty(Writer writer, Object property, int tab) throws IOException {
        if (property instanceof Number) {
            writeNumberProperty(writer, (Number) property);
        } else if (property instanceof Map) {
            writeMapProperty(writer, (Map) property, tab);
        } else {
            writeStringProperty(writer, property.toString());
        }
    }

    private void writeMapProperty(Writer writer, Map map, int tabs) throws IOException {
        writer.write(OPEN_LIST);
        tabs++;
        for (Entry entry : map.entrySet()) {
            writeTabs(writer, tabs);
            writeKey(writer, entry.getKey().toString());
            writeProperty(writer, entry.getValue(), tabs);
        }
        writeTabs(writer, tabs - 1);
        writer.write(CLOSE_LIST);

    }

    private void writeTabs(Writer writer, int tabs) throws IOException {
        for (int i = 0; i <= tabs; i++) {
            writer.write(TAB);
        }
    }

    private void writeNumberProperty(Writer writer, Number integer) throws IOException {
        writer.write(integer.toString());
        writer.write(NEW_LINE);
    }

    private void writeStringProperty(Writer writer, Object string) throws IOException {
        writer.write("\"");
        writer.write(string.toString());
        writer.write("\"");
        writer.write(NEW_LINE);
    }

    private void writeKey(Writer writer, String command) throws IOException {
        writer.write(TAB);
        writer.write(TAB);
        writer.write(command);
        writer.write(DELIMITER);
    }

    private void populateLists(List verticies, List edges) {
        for (Vertex v : graph.getVertices()) {
            verticies.add(v);
        }
        for (Edge e : graph.getEdges()) {
            edges.add(e);
        }
    }

    /**
     * Write the data in a Graph to a GML OutputStream.
     *
     * @param graph               the Graph to pull the data from
     * @param graphMLOutputStream the GML OutputStream to write the Graph data to
     * @throws IOException thrown if there is an error generating the GML data
     */
    public static void outputGraph(final Graph graph, final OutputStream graphMLOutputStream) throws IOException {
        GMLWriter writer = new GMLWriter(graph);
        writer.outputGraph(graphMLOutputStream);
    }
=======
	private static final String DELIMITER = " ";
	private static final String TAB = "\t";
	private static final String NEW_LINE = System.getProperty("line.separator");
	private static final String OPEN_LIST = " [" + NEW_LINE;
	private static final String CLOSE_LIST = "]" + NEW_LINE;
	private final Graph graph;
	private boolean normalize = false;
	private boolean useId = false;
	private String vertexIdKey = GMLTokens.BLUEPRINTS_ID;
	private String edgeIdKey = GMLTokens.BLUEPRINTS_ID;

	/**
	 * @param graph
	 *            the Graph to pull the data from
	 */
	public GMLWriter(final Graph graph) {
		this.graph = graph;
	}

	/**
	 * @param normalize
	 *            whether to normalize the output. Normalized output is deterministic with respect to the order of
	 *            elements and properties in the resulting XML document, and is compatible with line diff-based tools
	 *            such as Git. Note: normalized output is memory-intensive and is not appropriate for very large graphs.
	 */
	public void setNormalize(final boolean normalize) {
		this.normalize = normalize;
	}

	/**
	 * @param useId
	 *            whether to use the blueprints id directly or substitute with a generated integer. To use this option
	 *            the blueprints ids must all be Integers of String representations of integers
	 */
	public void setUseId(final boolean useId) {
		this.useId = useId;
	}

	/**
	 * @param vertexIdKey
	 *            gml property to use for the blueprints vertex id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
	 */
	public void setVertexIdKey(String vertexIdKey) {
		this.vertexIdKey = vertexIdKey;
	}

	/**
	 * @param edgeIdKey
	 *            gml property to use for the blueprints edges id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
	 */
	public void setEdgeIdKey(String edgeIdKey) {
		this.edgeIdKey = edgeIdKey;
	}

	/**
	 * Write the data in a Graph to a GML OutputStream.
	 * 
	 * @param gMLOutputStream
	 *            the GML OutputStream to write the Graph data to
	 * @throws IOException
	 *             thrown if there is an error generating the GML data
	 */
	public void outputGraph(final OutputStream gMLOutputStream) throws IOException {

		// ISO 8859-1 as specified in the GML documentation
		Writer writer = new BufferedWriter(new OutputStreamWriter(gMLOutputStream, Charset.forName("ISO-8859-1")));

		List verticies = new ArrayList();
		List edges = new ArrayList();

		populateLists(verticies, edges);

		if (normalize) {
			LexicographicalElementComparator comparator = new LexicographicalElementComparator();
			Collections.sort(verticies, comparator);
			Collections.sort(edges, comparator);
		}

		writeGraph(writer, verticies, edges);

		writer.flush();
		writer.close();
	}

	private void writeGraph(Writer writer, List verticies, List edges) throws IOException {
		Map ids = new HashMap();

		writer.write(GMLTokens.GRAPH);
		writer.write(OPEN_LIST);
		writeVerticies(writer, verticies, ids);
		writeEdges(writer, edges, ids);
		writer.write(CLOSE_LIST);

	}

	private void writeVerticies(Writer writer, List verticies, Map ids) throws IOException {
		int count = 1;
		for (Vertex v : verticies) {
			if (useId) {
				Integer id = Integer.valueOf(v.getId().toString());
				writeVertex(writer, v, id);
				ids.put(v, id);
			} else {
				writeVertex(writer, v, count);
				ids.put(v, count++);
			}

		}
	}

	private void writeVertex(Writer writer, Vertex v, int id) throws IOException {
		writer.write(TAB);
		writer.write(GMLTokens.NODE);
		writer.write(OPEN_LIST);
		writeKey(writer, GMLTokens.ID);
		writeNumberProperty(writer, id);
		writeVertexProperties(writer, v);
		writer.write(TAB);
		writer.write(CLOSE_LIST);
	}

	private void writeEdges(Writer writer, List edges, Map ids) throws IOException {
		for (Edge e : edges) {
			writeEdgeProperties(writer, e, ids.get(e.getOutVertex()), ids.get(e.getInVertex()));
		}
	}

	private void writeEdgeProperties(Writer writer, Edge e, Integer source, Integer target) throws IOException {
		writer.write(TAB);
		writer.write(GMLTokens.EDGE);
		writer.write(OPEN_LIST);
		writeKey(writer, GMLTokens.SOURCE);
		writeNumberProperty(writer, source);
		writeKey(writer, GMLTokens.TARGET);
		writeNumberProperty(writer, target);
		writeKey(writer, GMLTokens.LABEL);
		writeStringProperty(writer, e.getLabel());
		writeEdgeProperties(writer, e);
		writer.write(TAB);
		writer.write(CLOSE_LIST);
	}

	private void writeVertexProperties(Writer writer, Vertex e) throws IOException {
		Object blueprintsId = e.getId();
		if (!useId) {
			writeKey(writer, vertexIdKey);
			if (blueprintsId instanceof Number) {
				writeNumberProperty(writer, (Number) blueprintsId);
			} else {
				writeStringProperty(writer, blueprintsId);
			}
		}
		writeProperties(writer, e);
	}

	private void writeEdgeProperties(Writer writer, Edge e) throws IOException {
		Object blueprintsId = e.getId();
		if (!useId) {
			writeKey(writer, edgeIdKey);
			if (blueprintsId instanceof Number) {
				writeNumberProperty(writer, (Number) blueprintsId);
			} else {
				writeStringProperty(writer, blueprintsId);
			}
		}
		writeProperties(writer, e);
	}

	private void writeProperties(Writer writer, Element e) throws IOException {
		for (String key : e.getPropertyKeys()) {
			Object property = e.getProperty(key);
			writeKey(writer, key);
			writeProperty(writer, property, 0);
		}
	}

	private void writeProperty(Writer writer, Object property, int tab) throws IOException {
		if (property instanceof Number) {
			writeNumberProperty(writer, (Number) property);
		} else if (property instanceof Map) {
			writeMapProperty(writer, (Map) property, tab);
		} else {
			writeStringProperty(writer, property.toString());
		}
	}

	private void writeMapProperty(Writer writer, Map map, int tabs) throws IOException {
		writer.write(OPEN_LIST);
		tabs++;
		for (Entry entry : map.entrySet()) {
			writeTabs(writer, tabs);
			writeKey(writer, entry.getKey().toString());
			writeProperty(writer, entry.getValue(), tabs);
		}
		writeTabs(writer, tabs - 1);
		writer.write(CLOSE_LIST);

	}

	private void writeTabs(Writer writer, int tabs) throws IOException {
		for (int i = 0; i <= tabs; i++) {
			writer.write(TAB);
		}
	}

	private void writeNumberProperty(Writer writer, Number integer) throws IOException {
		writer.write(integer.toString());
		writer.write(NEW_LINE);
	}

	private void writeStringProperty(Writer writer, Object string) throws IOException {
		writer.write("\"");
		writer.write(string.toString());
		writer.write("\"");
		writer.write(NEW_LINE);
	}

	private void writeKey(Writer writer, String command) throws IOException {
		writer.write(TAB);
		writer.write(TAB);
		writer.write(command);
		writer.write(DELIMITER);
	}

	private void populateLists(List verticies, List edges) {
		for (Vertex v : graph.getVertices()) {
			verticies.add(v);
		}
		for (Edge e : graph.getEdges()) {
			edges.add(e);
		}
	}

	/**
	 * Write the data in a Graph to a GML OutputStream.
	 * 
	 * @param graph
	 *            the Graph to pull the data from
	 * @param graphMLOutputStream
	 *            the GML OutputStream to write the Graph data to
	 * @throws IOException
	 *             thrown if there is an error generating the GML data
	 */
	public static void outputGraph(final Graph graph, final OutputStream graphMLOutputStream) throws IOException {
		GMLWriter writer = new GMLWriter(graph);
		writer.outputGraph(graphMLOutputStream);
	}
>>>>>>> 7ad6fcdca5566066a1f6ff56d5a32686f224f43a
}
Solution content
 */
public class GMLWriter {

    private static final String DELIMITER = " ";
    private static final String TAB = "\t";
    private static final String NEW_LINE = "\r\n";
    private static final String OPEN_LIST = " [" + NEW_LINE;
    private static final String CLOSE_LIST = "]" + NEW_LINE;
    private final Graph graph;
    private boolean normalize = false;
    private boolean useId = false;
    private String vertexIdKey = GMLTokens.BLUEPRINTS_ID;
    private String edgeIdKey = GMLTokens.BLUEPRINTS_ID;

    /**
     * @param graph the Graph to pull the data from
     */
    public GMLWriter(final Graph graph) {
        this.graph = graph;
    }

    /**
     * @param normalize whether to normalize the output. Normalized output is deterministic with respect to the order of
     *                  elements and properties in the resulting XML document, and is compatible with line diff-based tools
     *                  such as Git. Note: normalized output is memory-intensive and is not appropriate for very large graphs.
     */
    public void setNormalize(final boolean normalize) {
        this.normalize = normalize;
    }

    /**
     * @param useId whether to use the blueprints id directly or substitute with a generated integer. To use this option
     *              the blueprints ids must all be Integers of String representations of integers
     */
    public void setUseId(final boolean useId) {
        this.useId = useId;
    }

    /**
     * @param vertexIdKey gml property to use for the blueprints vertex id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
     */
    public void setVertexIdKey(String vertexIdKey) {
        this.vertexIdKey = vertexIdKey;
    }

    /**
     * @param edgeIdKey gml property to use for the blueprints edges id, defaults to {@link GMLTokens#BLUEPRINTS_ID}
     */
    public void setEdgeIdKey(String edgeIdKey) {
        this.edgeIdKey = edgeIdKey;
    }

    /**
     * Write the data in a Graph to a GML OutputStream.
     *
     * @param gMLOutputStream the GML OutputStream to write the Graph data to
     * @throws IOException thrown if there is an error generating the GML data
     */
    public void outputGraph(final OutputStream gMLOutputStream) throws IOException {

        // ISO 8859-1 as specified in the GML documentation
        Writer writer = new BufferedWriter(new OutputStreamWriter(gMLOutputStream, Charset.forName("ISO-8859-1")));

        List verticies = new ArrayList();
        List edges = new ArrayList();

        populateLists(verticies, edges);

        if (normalize) {
            LexicographicalElementComparator comparator = new LexicographicalElementComparator();
            Collections.sort(verticies, comparator);
            Collections.sort(edges, comparator);
        }

        writeGraph(writer, verticies, edges);

        writer.flush();
        writer.close();
    }

    private void writeGraph(Writer writer, List verticies, List edges) throws IOException {
        Map ids = new HashMap();

        writer.write(GMLTokens.GRAPH);
        writer.write(OPEN_LIST);
        writeVerticies(writer, verticies, ids);
        writeEdges(writer, edges, ids);
        writer.write(CLOSE_LIST);

    }

    private void writeVerticies(Writer writer, List verticies, Map ids) throws IOException {
        int count = 1;
        for (Vertex v : verticies) {
            if (useId) {
                Integer id = Integer.valueOf(v.getId().toString());
                writeVertex(writer, v, id);
                ids.put(v, id);
            } else {
                writeVertex(writer, v, count);
                ids.put(v, count++);
            }

        }
    }

    private void writeVertex(Writer writer, Vertex v, int id) throws IOException {
        writer.write(TAB);
        writer.write(GMLTokens.NODE);
        writer.write(OPEN_LIST);
        writeKey(writer, GMLTokens.ID);
        writeNumberProperty(writer, id);
        writeVertexProperties(writer, v);
        writer.write(TAB);
        writer.write(CLOSE_LIST);
    }

    private void writeEdges(Writer writer, List edges, Map ids) throws IOException {
        for (Edge e : edges) {
            writeEdgeProperties(writer, e, ids.get(e.getOutVertex()), ids.get(e.getInVertex()));
        }
    }

    private void writeEdgeProperties(Writer writer, Edge e, Integer source, Integer target) throws IOException {
        writer.write(TAB);
        writer.write(GMLTokens.EDGE);
        writer.write(OPEN_LIST);
        writeKey(writer, GMLTokens.SOURCE);
    private void writeEdgeProperties(Writer writer, Edge e) throws IOException {
        writeNumberProperty(writer, source);
        writeKey(writer, GMLTokens.TARGET);
        writeNumberProperty(writer, target);
        writeKey(writer, GMLTokens.LABEL);
        writeStringProperty(writer, e.getLabel());
        writeEdgeProperties(writer, e);
        writer.write(TAB);
        writer.write(CLOSE_LIST);
    }

    private void writeVertexProperties(Writer writer, Vertex e) throws IOException {
        Object blueprintsId = e.getId();
        if (!useId) {
            writeKey(writer, vertexIdKey);
            if (blueprintsId instanceof Number) {
                writeNumberProperty(writer, (Number) blueprintsId);
            } else {
                writeStringProperty(writer, blueprintsId);
            }
        }
        writeProperties(writer, e);
    }

        Object blueprintsId = e.getId();
        if (!useId) {
            writeKey(writer, edgeIdKey);
            if (blueprintsId instanceof Number) {
                writeNumberProperty(writer, (Number) blueprintsId);
            } else {
                writeStringProperty(writer, blueprintsId);
            }
        }
        writeProperties(writer, e);
    }

    private void writeProperties(Writer writer, Element e) throws IOException {
        for (String key : e.getPropertyKeys()) {
            Object property = e.getProperty(key);
            writeKey(writer, key);
            writeProperty(writer, property, 0);
        }
    }

    private void writeProperty(Writer writer, Object property, int tab) throws IOException {
        if (property instanceof Number) {
            writeNumberProperty(writer, (Number) property);
        } else if (property instanceof Map) {
            writeMapProperty(writer, (Map) property, tab);
        } else {
            writeStringProperty(writer, property.toString());
        }
    }

    private void writeMapProperty(Writer writer, Map map, int tabs) throws IOException {
        writer.write(OPEN_LIST);
        tabs++;
        for (Entry entry : map.entrySet()) {
            writeTabs(writer, tabs);
            writeKey(writer, entry.getKey().toString());
            writeProperty(writer, entry.getValue(), tabs);
        }
        writeTabs(writer, tabs - 1);
        writer.write(CLOSE_LIST);

    }

    private void writeTabs(Writer writer, int tabs) throws IOException {
        for (int i = 0; i <= tabs; i++) {
            writer.write(TAB);
        }
    }

    private void writeNumberProperty(Writer writer, Number integer) throws IOException {
        writer.write(integer.toString());
        writer.write(NEW_LINE);
    }

    private void writeStringProperty(Writer writer, Object string) throws IOException {
        writer.write("\"");
        writer.write(string.toString());
        writer.write("\"");
        writer.write(NEW_LINE);
    }

    private void writeKey(Writer writer, String command) throws IOException {
        writer.write(TAB);
        writer.write(TAB);
        writer.write(command);
        writer.write(DELIMITER);
    }

    private void populateLists(List verticies, List edges) {
        for (Vertex v : graph.getVertices()) {
            verticies.add(v);
        }
        for (Edge e : graph.getEdges()) {
            edges.add(e);
        }
    }

    /**
     * Write the data in a Graph to a GML OutputStream.
     *
     * @param graph               the Graph to pull the data from
     * @param graphMLOutputStream the GML OutputStream to write the Graph data to
     * @throws IOException thrown if there is an error generating the GML data
     */
    public static void outputGraph(final Graph graph, final OutputStream graphMLOutputStream) throws IOException {
        GMLWriter writer = new GMLWriter(graph);
        writer.outputGraph(graphMLOutputStream);
    }
}
File
GMLWriter.java
Developer's decision
Version 1
Kind of conflict
Attribute
Comment
Method declaration
Method invocation
Chunk
Conflicting content
        String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer.gml"));

        // ignore carriage return character...not really relevant to the test
<<<<<<< HEAD
        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));

    }

    public void testUseIds() throws Exception {
        TinkerGraph g = new TinkerGraph();
        GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g);
        w.setNormalize(true);
        w.setUseId(true);
        w.outputGraph(bos);

        String actual = bos.toString();
        String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer2.gml"));

        // ignore carriage return character...not really relevant to the test
        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));
=======
		assertEquals(expected, actual);
		
	}
	
	public void testUseIds() throws Exception {
		TinkerGraph g = new TinkerGraph();
		GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		GMLWriter w = new GMLWriter(g);
		w.setNormalize(true);
		w.setUseId(true);
		w.outputGraph(bos);
		
		String actual = bos.toString();
		String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer2.gml"));

        // ignore carriage return character...not really relevant to the test
        assertEquals(expected, actual);
		
	}
>>>>>>> 7ad6fcdca5566066a1f6ff56d5a32686f224f43a

    }
Solution content
        String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer.gml"));

        // ignore carriage return character...not really relevant to the test
        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));

    }

    public void testUseIds() throws Exception {
        TinkerGraph g = new TinkerGraph();
        GMLReader.inputGraph(g, GMLReaderTest.class.getResourceAsStream("example.gml"));

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        GMLWriter w = new GMLWriter(g);
        w.setNormalize(true);
        w.setUseId(true);
        w.outputGraph(bos);

        String actual = bos.toString();
        String expected = streamToByteArray(GMLWriterTest.class.getResourceAsStream("writer2.gml"));

        // ignore carriage return character...not really relevant to the test
        assertEquals(expected.replace("\r", ""), actual.replace("\r", ""));

    }
File
GMLWriterTest.java
Developer's decision
Version 1
Kind of conflict
Comment
Method declaration
Method invocation
Method signature
Variable