FileObject

public class FileObject

Author

Tebin Raouf

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

    1. Create TaskNode for each task
    2. Create Successors for each task
    3. 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 function

    Declaration

    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]?)