Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public int InitLocalTaskData() {
- if (!synchronising) {
- //Try to load it from file, if it is not found reinitialize it as new
- //The pattern is hardcoded, I cannot allow randomness or customisation for this one
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-D");
- ArrayList< Task> TempTaskDataLoadList = new ArrayList<>(); //temporary add it into this list
- Task TempTask; //use this temporary variable too
- //and those below
- int TempTID = 0;
- int TempTLID = 0;
- ArrayList< Integer> TempAUIDs = new ArrayList< Integer>();
- String TempTT;
- String TempTD;
- boolean TempCV = false; //default value initialization. Meh!!!
- LocalDate TempDOTC;
- int TempTCID = 0;
- LocalDate TempLTCD;
- int TempLTCID = 0;
- SystemLogs.info(LocalDataDirectoryPath + LocalTaskDataFileName);
- ReadFromFile(LocalDataDirectoryPath, LocalTaskDataFileName);
- if ((TempFileContent != null && !TempFileContent.equalsIgnoreCase(""))) {
- String items[] = TempFileContent.split("\n"); //makes an array of lines
- System.out.println(TempFileContent);
- String values[]; //an array of string values from lines, will be initialized later
- for (String item : items) {
- values = item.split(" ");
- //temporary values again
- for (String val : values) {
- if (values != null && !val.equalsIgnoreCase("")) {
- TempTID = Integer.parseInt(values[0]);
- TempTLID = Integer.parseInt(values[1]);
- String[] InputIDs = values[2].split("|");
- int finalIDArray[] = new int[InputIDs.length];
- for (int i = 0; i < InputIDs.length; i++) {
- finalIDArray[i] = Integer.parseInt(InputIDs[i]);
- }
- ArrayList< Integer> finalIDList = new ArrayList<>();
- for (int i = 0; i < finalIDArray.length; i++) {
- finalIDList.add(finalIDArray[i]);
- }
- TempAUIDs = finalIDList;
- TempTT = values[3];
- TempTD = values[4];
- TempCV = Boolean.getBoolean(values[5]);
- TempDOTC = LocalDate.parse(values[6],formatter);
- TempTCID = Integer.parseInt(values[7]);
- TempLTCD = LocalDate.parse(values[8],formatter);
- TempLTCID = Integer.parseInt(values[9]);
- TempTask = new Task(TempTLID, TempAUIDs, TempTT, TempTD, TempTCID, TempLTCID);
- TempTask.setID(TempTID);
- TempTask.setisComplete(TempCV);
- TempTask.setDateOfTaskCreation(TempDOTC);
- TempTask.setTaskCreatorID(TempTCID);
- TempTask.setLastTaskChangeDate(TempLTCD);
- TempTask.setLastTaskCommitterID(TempLTCID);
- //after all is set add it to the temporary user list
- TempTaskDataLoadList.add(TempTask);
- }
- } //no, it is not Mower, it is Slower
- } //and finally, set the user data to the loaded data list
- TaskData = TempTaskDataLoadList;
- System.out.println("Task Data loaded successfully. \n");
- return 31;
- } else if (TempFileContent != null && TempFileContent.equalsIgnoreCase("")) {
- System.err.println("Error: Task data is empty. Initializing built-in task data intead... \n");
- //Initialize the local user data, requires at least one administrator and one guest account
- TaskData = new ArrayList<>(); //initializes an empty task list
- return 30;
- } else if (TempFileContent == null) {
- System.err.println("Error: Task data cannot be loaded. Initializing built-in task data instead... \n");
- TaskData = new ArrayList<>();
- return 29;
- } else {
- System.err.println("Error: Task data cannot be initialized. Cannot proceed...\n");
- return 28;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement