FileObject
public class FileObject
The class to parse a text file into objects and graph
-
A holder for the input header
Declaration
Swift
private var header: [String]
-
All rows of the input without the header
Declaration
Swift
private var rows: [[String]]
-
The absolute path of the file
Declaration
Swift
private var filePath: String
-
FileObject Initializer
Declaration
Swift
public init(_ filePath: String)
Parameters
filePath
the path of the text file
-
getGraph: get the populated graph
Declaration
Swift
public func getGraph() -> Graph
Return Value
Graph
-
Populate the graph in three steps
- Create TaskNode for each task
- Create Successors for each task
- Create Predecessors for each task
Declaration
Swift
private func populateGraph() -> Graph
-
Create dictionary for the tasks from
rows
. Key: is the task name, Value: is an array of task name For example: [A
,2
,na
] ->A
: [na
] [B
,3
,A
] ->B
: [A
] This is a helper functionDeclaration
Swift
private func convertRowToDictionary() -> Dictionary<String, [String]>
-
Read the given file and parse
Declaration
Swift
private func read(file path: String)
-
Utility Function to parse the input separator is comma
,
Declaration
Swift
private func convertToObject(_ rows: [Substring]?)