Class DrawflowGraphFormat

  • All Implemented Interfaces:
    GraphFormat

    public class DrawflowGraphFormat
    extends java.lang.Object
    implements GraphFormat
    Writes a graph in the "drawflow" format.
    Author:
    Holger Eichelberger, SSE
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String NAME  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      IvmlGraphMapper.IvmlGraph fromString​(java.lang.String graph, GraphFactory factory, DecisionVariableProvider varProvider)
      Parses graph from this format into an IVML graph structure.
      java.lang.String getFormatKind()
      Returns the kind of format produced.
      private static int getInteger​(org.json.simple.JSONObject object, java.lang.String field, int dflt)
      Obtains an int from object.
      private static <T> T getJson​(org.json.simple.JSONObject object, java.lang.String field, java.lang.Class<T> cls, java.util.function.Supplier<T> dflt, java.util.function.Function<java.lang.Object,​T> converter)
      Obtains a JSON object from object.
      private static org.json.simple.JSONArray getJsonArray​(org.json.simple.JSONObject object, java.lang.String field)
      Obtains a JSON array from object.
      private static org.json.simple.JSONObject getJsonObject​(org.json.simple.JSONObject object, java.lang.String field)
      Obtains a JSON object from object.
      java.lang.String getName()
      Returns the name to address/access this format.
      private static java.lang.String getString​(org.json.simple.JSONObject object, java.lang.String field, java.lang.String dflt)
      Obtains a string from object.
      java.lang.String toString​(IvmlGraphMapper.IvmlGraph graph)
      Turns graph into this format.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DrawflowGraphFormat

        public DrawflowGraphFormat()
    • Method Detail

      • getName

        public java.lang.String getName()
        Description copied from interface: GraphFormat
        Returns the name to address/access this format.
        Specified by:
        getName in interface GraphFormat
        Returns:
        the unique name
      • getFormatKind

        public java.lang.String getFormatKind()
        Description copied from interface: GraphFormat
        Returns the kind of format produced.
        Specified by:
        getFormatKind in interface GraphFormat
        Returns:
        the format kind, e.g., XML, JSON, ...
      • toString

        public java.lang.String toString​(IvmlGraphMapper.IvmlGraph graph)
                                  throws java.util.concurrent.ExecutionException
        Description copied from interface: GraphFormat
        Turns graph into this format.
        Specified by:
        toString in interface GraphFormat
        Parameters:
        graph - the graph, may be null
        Returns:
        the formatted graph, an empty graph if graph is null
        Throws:
        java.util.concurrent.ExecutionException - if the translation fails
      • fromString

        public IvmlGraphMapper.IvmlGraph fromString​(java.lang.String graph,
                                                    GraphFactory factory,
                                                    DecisionVariableProvider varProvider)
                                             throws java.util.concurrent.ExecutionException
        Description copied from interface: GraphFormat
        Parses graph from this format into an IVML graph structure.
        Specified by:
        fromString in interface GraphFormat
        Parameters:
        graph - the graph, may be null
        factory - a factory to be used to create graph instances
        varProvider - the provider allowing to access variables
        Returns:
        the IVML graph structure, an empty graph if graph is null
        Throws:
        java.util.concurrent.ExecutionException - if the translation fails
      • getJson

        private static <T> T getJson​(org.json.simple.JSONObject object,
                                     java.lang.String field,
                                     java.lang.Class<T> cls,
                                     java.util.function.Supplier<T> dflt,
                                     java.util.function.Function<java.lang.Object,​T> converter)
        Obtains a JSON object from object.
        Type Parameters:
        T - the type to be returned
        Parameters:
        object - the object to read from
        field - the field name to read from within object
        cls - the type as class
        dflt - the default value if field does not exist
        converter - optional converter if the found value is not compliant with cls, may be null
        Returns:
        returns the JSON object or, if not found, an empty JSON object
      • getJsonObject

        private static org.json.simple.JSONObject getJsonObject​(org.json.simple.JSONObject object,
                                                                java.lang.String field)
        Obtains a JSON object from object.
        Parameters:
        object - the object to read from
        field - the field name
        Returns:
        returns the JSON object or, if not found, an empty JSON object
      • getJsonArray

        private static org.json.simple.JSONArray getJsonArray​(org.json.simple.JSONObject object,
                                                              java.lang.String field)
        Obtains a JSON array from object.
        Parameters:
        object - the object to read from
        field - the field name
        Returns:
        returns the JSON array, or, if not found, an empty JSON array
      • getString

        private static java.lang.String getString​(org.json.simple.JSONObject object,
                                                  java.lang.String field,
                                                  java.lang.String dflt)
        Obtains a string from object.
        Parameters:
        object - the object to read from
        field - the field name
        dflt - the default value
        Returns:
        returns the string or, if not found, dflt
      • getInteger

        private static int getInteger​(org.json.simple.JSONObject object,
                                      java.lang.String field,
                                      int dflt)
        Obtains an int from object.
        Parameters:
        object - the object to read from
        field - the field name
        dflt - the default value
        Returns:
        returns the int value or, if not found, dflt