- java.lang.Object
-
- org.jgrapht.nio.BaseEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
-
- org.jgrapht.nio.csv.CSVEventDrivenImporter
-
- All Implemented Interfaces:
EventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
public class CSVEventDrivenImporter extends BaseEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>> implements EventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>
Imports a graph from a CSV Format or any other Delimiter-separated value format.The importer supports various different formats which can be adjusted using the
setFormatmethod. The supported formats are the same CSV formats used by Gephi. For some of the formats, the behavior of the importer can be adjusted using thesetParametermethod. SeeCSVFormatfor a description of the formats.The importer respects rfc4180. The caller can also adjust the separator to something like semicolon or pipe instead of comma. In such a case, all fields are unescaped using the new separator. See Delimiter-separated values for more information.
This importer does not distinguish between
CSVFormat.EDGE_LISTandCSVFormat.ADJACENCY_LIST. In both cases it assumes the format isCSVFormat.ADJACENCY_LIST.- See Also:
CSVFormat
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classCSVEventDrivenImporter.AdjacencyListCSVListenerprivate classCSVEventDrivenImporter.MatrixCSVListenerprivate classCSVEventDrivenImporter.RowCSVListenerprivate classCSVEventDrivenImporter.ThrowingErrorListener
-
Field Summary
Fields Modifier and Type Field Description private static charDEFAULT_DELIMITERprivate chardelimiterprivate CSVFormatformatprivate java.util.Set<CSVFormat.Parameter>parameters
-
Constructor Summary
Constructors Constructor Description CSVEventDrivenImporter()Constructs a new importer using theCSVFormat.ADJACENCY_LISTformat as default.CSVEventDrivenImporter(CSVFormat format)Constructs a new importer.CSVEventDrivenImporter(CSVFormat format, char delimiter)Constructs a new importer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description chargetDelimiter()Get the delimiter (comma, semicolon, pipe, etc).CSVFormatgetFormat()Get the format that the importer is using.voidimportInput(java.io.Reader input)Import a graphbooleanisParameter(CSVFormat.Parameter p)Return if a particular parameter of the exporter is enabledprivate voidread(java.io.Reader input, CSVBaseListener listener)voidsetDelimiter(char delimiter)Set the delimiter (comma, semicolon, pipe, etc).voidsetFormat(CSVFormat format)Set the format of the importervoidsetParameter(CSVFormat.Parameter p, boolean value)Set the value of a parameter of the exporter-
Methods inherited from class org.jgrapht.nio.BaseEventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addEdgeWithAttributesConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, addVertexWithAttributesConsumer, notifyEdge, notifyEdgeAttribute, notifyEdgeCount, notifyEdgeWithAttributes, notifyGraphAttribute, notifyImportEvent, notifyVertex, notifyVertexAttribute, notifyVertexCount, notifyVertexWithAttributes, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeEdgeWithAttributesConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer, removeVertexWithAttributesConsumer
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jgrapht.nio.EventDrivenImporter
addEdgeAttributeConsumer, addEdgeConsumer, addEdgeCountConsumer, addEdgeWithAttributesConsumer, addGraphAttributeConsumer, addImportEventConsumer, addVertexAttributeConsumer, addVertexConsumer, addVertexCountConsumer, addVertexWithAttributesConsumer, importInput, importInput, removeEdgeAttributeConsumer, removeEdgeConsumer, removeEdgeCountConsumer, removeEdgeWithAttributesConsumer, removeGraphAttributeConsumer, removeImportEventConsumer, removeVertexAttributeConsumer, removeVertexConsumer, removeVertexCountConsumer, removeVertexWithAttributesConsumer
-
-
-
-
Field Detail
-
DEFAULT_DELIMITER
private static final char DEFAULT_DELIMITER
- See Also:
- Constant Field Values
-
format
private CSVFormat format
-
delimiter
private char delimiter
-
parameters
private final java.util.Set<CSVFormat.Parameter> parameters
-
-
Constructor Detail
-
CSVEventDrivenImporter
public CSVEventDrivenImporter()
Constructs a new importer using theCSVFormat.ADJACENCY_LISTformat as default.
-
CSVEventDrivenImporter
public CSVEventDrivenImporter(CSVFormat format)
Constructs a new importer.- Parameters:
format- format to use out of the supported ones
-
CSVEventDrivenImporter
public CSVEventDrivenImporter(CSVFormat format, char delimiter)
Constructs a new importer.- Parameters:
format- format to use out of the supported onesdelimiter- delimiter to use (comma, semicolon, pipe, etc.)
-
-
Method Detail
-
getFormat
public CSVFormat getFormat()
Get the format that the importer is using.- Returns:
- the input format
-
setFormat
public void setFormat(CSVFormat format)
Set the format of the importer- Parameters:
format- the format to use
-
getDelimiter
public char getDelimiter()
Get the delimiter (comma, semicolon, pipe, etc).- Returns:
- the delimiter
-
setDelimiter
public void setDelimiter(char delimiter)
Set the delimiter (comma, semicolon, pipe, etc).- Parameters:
delimiter- the delimiter to use
-
isParameter
public boolean isParameter(CSVFormat.Parameter p)
Return if a particular parameter of the exporter is enabled- Parameters:
p- the parameter- Returns:
trueif the parameter is set,falseotherwise
-
setParameter
public void setParameter(CSVFormat.Parameter p, boolean value)
Set the value of a parameter of the exporter- Parameters:
p- the parametervalue- the value to set
-
importInput
public void importInput(java.io.Reader input) throws ImportExceptionDescription copied from interface:EventDrivenImporterImport a graph- Specified by:
importInputin interfaceEventDrivenImporter<java.lang.String,Triple<java.lang.String,java.lang.String,java.lang.Double>>- Parameters:
input- the input reader- Throws:
ImportException- in case any error occurs, such as I/O or parse error
-
read
private void read(java.io.Reader input, CSVBaseListener listener) throws ImportException- Throws:
ImportException
-
-