Advertisement
CaptainManiac999

Faulty integer array parsing

Aug 1st, 2021
1,105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.65 KB | None | 0 0
  1.   public int InitLocalTaskData() {
  2.         if (!synchronising) {
  3.            
  4.             //Try to load it from file, if it is not found reinitialize it as new
  5.             //The pattern is hardcoded, I cannot allow randomness or customisation for this one
  6.             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-M-D");
  7.             ArrayList< Task> TempTaskDataLoadList = new ArrayList<>(); //temporary add it into this list
  8.             Task TempTask; //use this temporary variable too
  9.             //and those below
  10.             int TempTID = 0;
  11.             int TempTLID = 0;
  12.             ArrayList< Integer> TempAUIDs = new ArrayList< Integer>();
  13.             String TempTT;
  14.             String TempTD;
  15.             boolean TempCV = false; //default value initialization. Meh!!!
  16.             LocalDate TempDOTC;
  17.             int TempTCID = 0;
  18.             LocalDate TempLTCD;
  19.             int TempLTCID = 0;
  20.  
  21.             SystemLogs.info(LocalDataDirectoryPath + LocalTaskDataFileName);
  22.             ReadFromFile(LocalDataDirectoryPath, LocalTaskDataFileName);
  23.  
  24.             if ((TempFileContent != null && !TempFileContent.equalsIgnoreCase(""))) {
  25.                 String items[] = TempFileContent.split("\n"); //makes an array of lines
  26.                 System.out.println(TempFileContent);
  27.                 String values[]; //an array of string values from lines, will be initialized later
  28.                 for (String item : items) {
  29.                     values = item.split(" ");
  30.                     //temporary values again
  31.                     for (String val : values) {
  32.                         if (values != null && !val.equalsIgnoreCase("")) {
  33.                             TempTID = Integer.parseInt(values[0]);
  34.                             TempTLID = Integer.parseInt(values[1]);
  35.                             String[] InputIDs = values[2].split("|");
  36.                             int finalIDArray[] = new int[InputIDs.length];
  37.                             for (int i = 0; i < InputIDs.length; i++) {
  38.                                 finalIDArray[i] = Integer.parseInt(InputIDs[i]);
  39.                             }
  40.                             ArrayList< Integer> finalIDList = new ArrayList<>();
  41.                             for (int i = 0; i < finalIDArray.length; i++) {
  42.                                 finalIDList.add(finalIDArray[i]);
  43.                             }
  44.                             TempAUIDs = finalIDList;
  45.                             TempTT = values[3];
  46.                             TempTD = values[4];
  47.                             TempCV = Boolean.getBoolean(values[5]);
  48.                             TempDOTC = LocalDate.parse(values[6],formatter);
  49.                             TempTCID = Integer.parseInt(values[7]);
  50.                             TempLTCD = LocalDate.parse(values[8],formatter);
  51.                             TempLTCID = Integer.parseInt(values[9]);
  52.                             TempTask = new Task(TempTLID, TempAUIDs, TempTT, TempTD, TempTCID, TempLTCID);
  53.                             TempTask.setID(TempTID);
  54.                             TempTask.setisComplete(TempCV);
  55.                             TempTask.setDateOfTaskCreation(TempDOTC);
  56.                             TempTask.setTaskCreatorID(TempTCID);
  57.                             TempTask.setLastTaskChangeDate(TempLTCD);
  58.                             TempTask.setLastTaskCommitterID(TempLTCID);
  59.                             //after all is set add it to the temporary user list
  60.                             TempTaskDataLoadList.add(TempTask);
  61.                         }
  62.                     } //no, it is not Mower, it is Slower
  63.                 } //and finally, set the user data to the loaded data list
  64.                 TaskData = TempTaskDataLoadList;
  65.                 System.out.println("Task Data loaded successfully. \n");
  66.                 return 31;
  67.             } else if (TempFileContent != null && TempFileContent.equalsIgnoreCase("")) {
  68.                 System.err.println("Error: Task data is empty. Initializing built-in task data intead... \n");
  69.                 //Initialize the local user data, requires at least one administrator and one guest account
  70.                 TaskData = new ArrayList<>(); //initializes an empty task list
  71.                 return 30;
  72.             } else if (TempFileContent == null) {
  73.                 System.err.println("Error: Task data cannot be loaded. Initializing built-in task data instead... \n");
  74.                 TaskData = new ArrayList<>();
  75.                 return 29;
  76.             } else {
  77.                 System.err.println("Error: Task data cannot be initialized. Cannot proceed...\n");
  78.                 return 28;
  79.             }
  80.         }
  81.         return 0;
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement