Enum CSVFormat

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<CSVFormat>

    public enum CSVFormat
    extends java.lang.Enum<CSVFormat>
    Supported CSV formats.
    • Format EDGE_LIST contains one edge per line. The following example

       a,b
       b,c
       
      represents a graph with two edges: a->b and b->c.
    • Format ADJACENCY_LIST contains the adjacency list of each vertex per line. The first field on a line is a vertex while the remaining fields are its neighbors.

       a,b
       b,c,d
       c,a,c,d
       
      represents a graph with edges: a->b, b->c, b->d, c->a, c->c, c->d.

      Mixed variants of EDGE_LIST and ADJACENCY_LIST are also considered valid. As an example consider the following input

       a,b
       b,a
       d,a
       c,a,b
       b,d,a
       
      which represents a graph with edges: a->b, b->a, d->a, c->a, c->b, b->d, b->a. Multiple occurrences of the same edge result into a multi-graph.

      Weighted variants are also valid if CSVFormat.Parameter.EDGE_WEIGHTS is set. In this case the target vertex must be followed by the edge weight. The following example illustrates the weighted variant:

       a,b,2.0
       b,a,3.0
       d,a,2.0
       c,a,1.5,b,2.5
       b,d,3.3,a,5.5
       
    • Format MATRIX outputs an adjacency matrix representation of the graph. Each line represents a vertex. The following

       0,1,0,1,0
       1,0,0,0,0
       0,0,1,0,0
       0,1,0,1,0
       0,0,0,0,0
       
      represents a graph with five vertices 1,2,3,4,5 which contains edges: 1->2, 1->4, 2->1, 3->3, 4->2, 4->4.

      In case CSVFormat.Parameter.MATRIX_FORMAT_ZERO_WHEN_NO_EDGE is not set the equivalent format would be:

       ,1,,1,
       1,,,,
       ,,1,,
       ,1,,1,
       ,,,,
       

      Weighted variants are also valid if CSVFormat.Parameter.EDGE_WEIGHTS is set. The above example would then be:

       ,1.0,,1.0,
       1.0,,,,
       ,,1.0,,
       ,1.0,,1.0,
       ,,,,
       
      If additionally CSVFormat.Parameter.MATRIX_FORMAT_ZERO_WHEN_NO_EDGE is set then a zero as an integer means that the corresponding edge is missing, while a zero as a double means than the edge exists and has zero weight.

      If parameter CSVFormat.Parameter.MATRIX_FORMAT_NODEID is set then node identifiers are also included as in the following example:

       ,a,b,c,d,e
       a,,1,,1,
       b,1,,,,
       c,,,1,,
       d,,1,,1,
       e,,,,,
       
      In the above example the first line contains the node identifiers and the first field of each line contain the vertex it corresponds to. In case node identifiers are present line-shuffled input is also valid such as:
       ,a,b,c,d,e
       c,,,1,,
       b,1,,,,
       e,,,,,
       d,,1,,1,
       a,,1,,1,
       
      The last example represents the graph with edges: a->b, a->d, b->a, c->c, d->b, d->d.
    Author:
    Dimitrios Michail
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CSVFormat.Parameter
      Parameters that affect the behavior of CVS importers/exporters.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static CSVFormat valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static CSVFormat[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • EDGE_LIST

        public static final CSVFormat EDGE_LIST
        Edge list
      • ADJACENCY_LIST

        public static final CSVFormat ADJACENCY_LIST
        Adjacency list
      • MATRIX

        public static final CSVFormat MATRIX
        Matrix
    • Method Detail

      • values

        public static CSVFormat[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (CSVFormat c : CSVFormat.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static CSVFormat valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null