All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ibm.wala.util.graph.GXL Maven / Gradle / Ivy

There is a newer version: 1.6.7
Show newest version
/*
 * 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();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy