com.ibm.wala.util.graph.GXL Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.ibm.wala.util Show documentation
Show all versions of com.ibm.wala.util Show documentation
T. J. Watson Libraries for Analysis
/*
* Copyright (c) 2013 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*/
package com.ibm.wala.util.graph;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Function;
public class GXL {
public interface EntityTypes {
String type(T entity);
String type(Graph entity);
String type(T from, T to);
}
public static String toGXL(
Graph G,
EntityTypes types,
String graphId,
Function nodeIds,
Function> nodeProperties) {
StringBuilder sb = new StringBuilder();
sb.append("\n");
sb.append("\n");
sb.append("\n");
sb.append(" \n");
sb.append(" \n");
for (T n : G) {
sb.append(" \n");
sb.append(" \n");
Map props = nodeProperties.apply(n);
if (props != null) {
for (Map.Entry e : props.entrySet()) {
sb.append(" \n");
if (e.getValue() != null) {
sb.append(" ").append(e.getValue()).append(" \n");
} else {
sb.append(" \n");
}
sb.append(" \n");
}
}
sb.append(" \n");
}
for (T n : G) {
Iterator ss = G.getSuccNodes(n);
while (ss.hasNext()) {
T s = ss.next();
sb.append(" \n");
sb.append(" \n");
sb.append(" \n");
}
}
sb.append(" \n");
sb.append(" \n");
return sb.toString();
}
}