Advertisement
Guest User

Untitled

a guest
May 21st, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.05 KB | None | 0 0
  1. import java.io.*;
  2. import java.nio.file.Path;
  3. import java.nio.file.Paths;
  4. import java.time.LocalDate;
  5. import java.util.*;
  6. import java.nio.file.FileSystems;
  7.  
  8. import Manager.*;
  9.  
  10. public class Main {
  11. static Vector<Person> nameList = new Vector< >();
  12. static Vector<Task> taskList = new Vector< >();
  13. static Vector<Project> projectList = new Vector< >();
  14.  
  15. public static void main(String[] args) throws IOException {
  16.  
  17. Scanner in = new Scanner(System.in);
  18.  
  19. String[] splitedArray = null;
  20. int indexOfPerson;
  21. int indexOfTask;
  22. int indexOfProject;
  23. String name;
  24. boolean flag;
  25. LocalDate date;
  26.  
  27. while(true){
  28.  
  29. System.out.print(">> ");
  30. String cmd = in.nextLine();
  31. flag = false;
  32.  
  33. try {
  34.  
  35. if (cmd.startsWith("add person")) { //Dodaj osobę :->add person nazwa_osoby
  36. AddPerson(cmd);
  37. }
  38.  
  39. else if (cmd.startsWith("export")) {
  40. splitedArray = cmd.split(" ");
  41. name = "test.txt";
  42. if (splitedArray.length >= 2) {
  43. if (splitedArray[1].length() != 0)
  44. name = splitedArray[1];
  45. else {
  46. System.out.println("Nazwa nieprawidłowa");
  47. continue;
  48. }
  49.  
  50. //Main.Export(name);
  51. Main.Export(name+ ".txt"); // zmienić potem na name ...
  52. } else {
  53. throw new BaseExeption( "noFile");
  54. }
  55.  
  56. }
  57.  
  58. else if (cmd.startsWith("import")) {
  59. splitedArray = cmd.split(" ");
  60. //name = splitedArray[1];
  61. if (splitedArray.length >= 2) {
  62. if (splitedArray[1].length() != 0)
  63. name = splitedArray[1];
  64. else {
  65. System.out.println("Nazwa nieprawidłowa");
  66. continue;
  67. }
  68.  
  69. nameList.clear();
  70. taskList.clear();
  71. projectList.clear();
  72.  
  73. Main.Import(name);
  74. } else {
  75. throw new BaseExeption( "noFile");
  76. }
  77.  
  78. }
  79.  
  80. else if (cmd.startsWith("modify person")) { //Modyfikuj osobę :-> modify person indeks_osoby nazwa
  81. ModifyPerson(cmd, splitedArray);
  82. }
  83.  
  84. else if (cmd.startsWith("delete person")) { //Usuń osobę :-> delete person indeks_osoby
  85. DeletePerson(cmd, splitedArray);
  86. }
  87.  
  88. else if (cmd.startsWith("list person")) { //Wypisz osoby :-> list person
  89. ListPerson();
  90. }
  91.  
  92. else if (cmd.startsWith("add task")) { //Dodaj zadanie :-> add task nazwa indeks_osoby
  93. AddTask(cmd, splitedArray);
  94. }
  95.  
  96. else if (cmd.startsWith("modify task")) { //Modyfikuj zadanie :-> modify task indeks_zadania nazwa
  97. ModifyTask(cmd, splitedArray);
  98. }
  99.  
  100. else if (cmd.startsWith("delete task")) { //Usuń zadanie :-> delete person indeks_zadania
  101. DeleteTask(cmd, splitedArray);
  102. }
  103.  
  104. else if (cmd.startsWith("add tperson")) { //Przypisanie osoby do zadania :-> add tperson indeks_zadania indeks_osoby
  105. AddTperson(cmd, splitedArray);
  106. }
  107.  
  108. else if (cmd.startsWith("list task")) { //Wypisz zadania :-> list task
  109. ListTask();
  110. }
  111.  
  112. else if (cmd.startsWith("add deadline")) { //Dodanie daty do zadania :-> add deadline indeks_zadania RRRR MM DD
  113. AddDeadline(cmd, splitedArray);
  114. }
  115.  
  116. else if (cmd.startsWith("order task asc")) { //Posortwanie według daty rosnąco :-> order task asc
  117. Collections.sort(taskList);
  118. }
  119.  
  120. else if (cmd.startsWith("order task desc")) { //Tu zmienić na komparator
  121. Collections.sort(taskList);
  122. Collections.reverse(taskList);
  123. }
  124.  
  125. else if (cmd.startsWith("late")) { //Wypisanie zadań spóźnionych :-> late
  126. Late();
  127. }
  128.  
  129. else if (cmd.startsWith("add project")) { //Dodanie projektu :-> add project nazwa
  130. AddProject(cmd);
  131. }
  132.  
  133. else if (cmd.startsWith("modify project")) { //Zmiana nazwy projektu
  134. ModifyProject(cmd, splitedArray);
  135. }
  136.  
  137. else if (cmd.startsWith("delete project")) { //Usuwanie projektu
  138. DeleteProject(cmd, splitedArray);
  139. }
  140.  
  141. else if (cmd.startsWith("add pperson")) { //Dodawanie osoby do projektu
  142. AddPperson(cmd, splitedArray);
  143. }
  144.  
  145. else if (cmd.startsWith("delete pperson")) { //Usuwanie osoby z projektu
  146. DeletePperson(cmd, splitedArray);
  147. }
  148.  
  149. else if (cmd.startsWith("add ptask")) { //Dodanie zadania do projektu
  150. AddPtask(cmd, splitedArray);
  151. }
  152.  
  153. else if (cmd.startsWith("delete ptask")) { //Usuwanie zadania z projektu
  154. DeletePtask(cmd, splitedArray);
  155. }
  156.  
  157. else if (cmd.startsWith("list project")) { //Wyświetl wszystkie projekty
  158. ListProject();
  159. }
  160.  
  161. else if (cmd.startsWith("list ptask")) { //Wyświetl task'i danego projektu
  162. ListPtask(cmd, splitedArray);
  163. }
  164.  
  165. else if (cmd.startsWith("list pperson")) { //Wyświetl person'y danego projektu
  166. ListPperson(cmd, splitedArray);
  167. }
  168.  
  169. else if (cmd.startsWith("quit")) break;
  170.  
  171. else {
  172. System.out.println("Niepoprawna komenda. ---");
  173. }
  174. }
  175. catch(BaseExeption e){
  176. if(e.getMessage().equals("noParam"))
  177. e.Parmeters();
  178. else if(e.getMessage().equals("noMember"))
  179. e.Member();
  180. else if(e.getMessage().equals("noTask"))
  181. e.Task();
  182. else if(e.getMessage().equals("noProject"))
  183. e.Project();
  184. else if(e.getMessage().equals("noFile"))
  185. e.File();
  186. else
  187. System.out.println("Błąd. Klasa" + e.toString() + "nie obejmuje błędu.");
  188. }
  189. }
  190. }
  191.  
  192. public static void AddPerson(String cmd){
  193. Person newPerson = new Person(cmd.substring(11));
  194. nameList.add(newPerson);
  195. }
  196.  
  197. public static void ModifyPerson(String cmd, String splitedArray[]) throws BaseExeption{
  198. splitedArray = cmd.split(" ");
  199.  
  200. String name;
  201. int indexOfPerson;
  202. boolean flag = false;
  203.  
  204. if (splitedArray.length >= 4) {
  205. indexOfPerson = Integer.parseInt(splitedArray[2]);
  206. name = splitedArray[3];
  207. }
  208. else {
  209. throw new BaseExeption( "noParam");
  210. }
  211.  
  212. for (Person somePerson : nameList) {
  213. if (somePerson.getID() == indexOfPerson) {
  214. somePerson.setName(name);
  215. flag = true;
  216. break;
  217. }
  218. }
  219. if (!flag) {
  220. throw new BaseExeption( "noMember");
  221. }
  222. }
  223.  
  224. public static void DeletePerson(String cmd, String splitedArray[]) throws BaseExeption{
  225. splitedArray = cmd.split(" ");
  226.  
  227. int indexOfPerson;
  228. boolean flag = false;
  229.  
  230. if (splitedArray.length >= 3) {
  231. indexOfPerson = Integer.parseInt(splitedArray[2]);
  232. }
  233. else {
  234. throw new BaseExeption( "noParam");
  235. }
  236.  
  237. for (Person somePerson : nameList) {
  238. if (somePerson.getID() == indexOfPerson) {
  239. for (Task someTask : taskList) {
  240. if (someTask.getPerson().equals(somePerson)) someTask.setPerson(null);
  241. }
  242.  
  243. for (Project someProject : projectList) {
  244. someProject.deletePerson(somePerson);
  245. }
  246. nameList.remove(somePerson);
  247. flag = true;
  248. break;
  249. }
  250. }
  251. if (!flag) {
  252. throw new BaseExeption( "noMember");
  253. }
  254. }
  255.  
  256. public static void ListPerson(){ //Można dodać żeby więcej info wypisywało
  257. System.out.println("PERSONS\nID | Name");
  258. for (Person somePerson : nameList) {
  259. System.out.println(somePerson.getID() + " | " + somePerson.getName());
  260. }
  261. }
  262.  
  263. public static void AddTask(String cmd, String splitedArray[]) throws BaseExeption{
  264. splitedArray = cmd.split(" ");
  265.  
  266. int indexOfPerson;
  267. boolean flag = false;
  268.  
  269. if (splitedArray.length >= 4) {
  270. Task newTask = new Task(splitedArray[2]);
  271. indexOfPerson = Integer.parseInt(splitedArray[3]);
  272.  
  273. for (Person somePerson : nameList) {
  274. if (somePerson.getID() == indexOfPerson) {
  275. newTask.setPerson(somePerson);
  276. flag = true;
  277. break;
  278. }
  279. }
  280. if (!flag) {
  281. throw new BaseExeption( "noMember");
  282. }
  283. else {
  284. taskList.add(newTask);
  285. }
  286. }
  287. else {
  288. throw new BaseExeption( "noParam");
  289. }
  290. }
  291.  
  292. public static void ModifyTask(String cmd, String splitedArray[]) throws BaseExeption{
  293. splitedArray = cmd.split(" ");
  294.  
  295. int indexOfTask;
  296. String name;
  297. boolean flag = false;
  298.  
  299. if (splitedArray.length >= 4) {
  300. indexOfTask = Integer.parseInt(splitedArray[2]);
  301. name = splitedArray[3];
  302.  
  303. for (Task someTask : taskList) {
  304. if (someTask.getID() == indexOfTask) {
  305. someTask.setName(name);
  306. flag = true;
  307. break;
  308. }
  309. }
  310. if (!flag) {
  311. throw new BaseExeption( "noTask");
  312. }
  313. }
  314. else {
  315. throw new BaseExeption( "noParam");
  316. }
  317. }
  318.  
  319. public static void DeleteTask(String cmd, String splitedArray[]) throws BaseExeption{
  320. splitedArray = cmd.split(" ");
  321.  
  322. int indexOfTask;
  323. String name;
  324. boolean flag = false;
  325.  
  326. if (splitedArray.length >= 3) {
  327. indexOfTask = Integer.parseInt(splitedArray[2]);
  328.  
  329. for (Task someTask : taskList) {
  330. if (someTask.getID() == indexOfTask) {
  331. taskList.remove(someTask);
  332. flag = true;
  333. break;
  334. }
  335. }
  336. if (!flag) {
  337. throw new BaseExeption( "noTask");
  338. }
  339. } else {
  340. throw new BaseExeption( "noParam");
  341. }
  342. }
  343.  
  344. public static void AddTperson(String cmd, String splitedArray[]) throws BaseExeption{
  345. splitedArray = cmd.split(" ");
  346.  
  347. int indexOfTask;
  348. int indexOfPerson;
  349. boolean flag = false;
  350.  
  351. if (splitedArray.length >= 4) {
  352. indexOfPerson = Integer.parseInt(splitedArray[3]);
  353. indexOfTask = Integer.parseInt(splitedArray[2]);
  354.  
  355. for (Person somePerson : nameList) {
  356. if (somePerson.getID() == indexOfPerson) {
  357. indexOfPerson = nameList.indexOf(somePerson);
  358. flag = true;
  359. break;
  360. }
  361. }
  362. if (flag) {
  363. flag = false;
  364. for (Task someTask : taskList) {
  365. if (someTask.getID() == indexOfTask) {
  366. someTask.setPerson(nameList.elementAt(indexOfPerson));
  367. flag = true;
  368. }
  369. }
  370. if (!flag) {
  371. throw new BaseExeption( "noTask");
  372. }
  373. }
  374. else {
  375. throw new BaseExeption( "noMember");
  376. }
  377. }
  378. else {
  379. throw new BaseExeption( "noParam");
  380. }
  381. }
  382.  
  383. public static void AddDeadline(String cmd, String splitedArray[]) throws BaseExeption{
  384. splitedArray = cmd.split(" ");
  385.  
  386. int indexOfTask;
  387. LocalDate date;
  388.  
  389. if (splitedArray.length >= 6) {
  390. indexOfTask = Integer.parseInt(splitedArray[2]);
  391. date = LocalDate.of(Integer.parseInt(splitedArray[3]), Integer.parseInt(splitedArray[4]), Integer.parseInt(splitedArray[5]));
  392. } else {
  393. throw new BaseExeption( "noParam");
  394. }
  395.  
  396. for (Task someTask : taskList) {
  397. if (someTask.getID() == indexOfTask) {
  398. someTask.setDeadline(date);
  399. break;
  400. }
  401. }
  402. }
  403.  
  404. public static void Late(){
  405. String text;
  406. System.out.println("LATE TASKS\nID | Name\t|Person\t|Date");
  407. for (Task someTask : taskList) {
  408. if (LocalDate.now().isAfter(someTask.getDeadLine())) {
  409. text = someTask.getID() + " | " + someTask.getName() + "\t| ";
  410. if (someTask.getPerson() == null) {
  411. text = text + "No person set\t| ";
  412. }
  413. else {
  414. text = text + someTask.getPerson().getName() + "\t| ";
  415. }
  416. if (someTask.getDeadLine() == null) {
  417. text += "non";
  418. }
  419. else {
  420. text = text + someTask.getDeadLine();
  421. }
  422. System.out.println(text);
  423. }
  424. }
  425. }
  426.  
  427. public static void ListTask(){ //Można dodać żeby więcej info wypisywało
  428. String text;
  429. System.out.println("TASKS\nID | Name\t|Person\t|Date");
  430. for (Task someTask : taskList) {
  431. text = someTask.getID() + " | " + someTask.getName() + "\t| ";
  432. if (someTask.getPerson() == null) {
  433. text = text + "No person set\t| ";
  434. }
  435. else {
  436. text = text + someTask.getPerson().getName() + "\t| ";
  437. }
  438. if (someTask.getDeadLine() == null) {
  439. text += "non";
  440. }
  441. else {
  442. text = text + someTask.getDeadLine();
  443. }
  444. System.out.println(text);
  445. }
  446. }
  447.  
  448. public static void AddProject(String cmd){
  449. Project newProject = new Project(cmd.substring(12));
  450. projectList.add(newProject);
  451. }
  452.  
  453. public static void ModifyProject(String cmd, String splitedArray[]) throws BaseExeption{
  454. splitedArray = cmd.split(" ");
  455.  
  456. int indexOfProject;
  457. String name;
  458. boolean flag = false;
  459.  
  460. if (splitedArray.length >= 4) {
  461. indexOfProject = Integer.parseInt(splitedArray[2]);
  462. name = splitedArray[3];
  463. } else {
  464. throw new BaseExeption( "noParam");
  465. }
  466.  
  467. for (Project someProject : projectList) {
  468. if (someProject.getID() == indexOfProject) {
  469. someProject.setName(name);
  470. flag = true;
  471. break;
  472. }
  473. }
  474. if (!flag) {
  475. throw new BaseExeption( "noProject");
  476. }
  477. }
  478.  
  479. public static void DeleteProject(String cmd, String splitedArray[]) throws BaseExeption{
  480. splitedArray = cmd.split(" ");
  481.  
  482. int indexOfProject;
  483. boolean flag = false;
  484.  
  485. if (splitedArray.length >= 3) {
  486. indexOfProject = Integer.parseInt(splitedArray[2]);
  487. } else {
  488. throw new BaseExeption( "noParam");
  489. }
  490.  
  491. for (Project someProject : projectList) {
  492. if (someProject.getID() == indexOfProject) {
  493. projectList.removeElement(someProject);
  494. flag = true;
  495. break;
  496. }
  497. }
  498. if (!flag) {
  499. throw new BaseExeption( "noProject");
  500. }
  501. }
  502.  
  503. public static void AddPperson(String cmd, String splitedArray[]) throws BaseExeption{
  504. splitedArray = cmd.split(" ");
  505.  
  506. int indexOfProject;
  507. int indexOfPerson;
  508. boolean flag = false;
  509.  
  510. if (splitedArray.length >= 4) {
  511. indexOfProject = Integer.parseInt(splitedArray[2]);
  512. indexOfPerson = Integer.parseInt(splitedArray[3]);
  513. }
  514. else {
  515. throw new BaseExeption( "noParam");
  516. }
  517.  
  518. for (Project someProject : projectList) {
  519. if (someProject.getID() == indexOfProject) {
  520. for (Person somePerson : nameList) {
  521. if (somePerson.getID() == indexOfPerson) {
  522. someProject.addPerson(somePerson);
  523. flag = true;
  524. break;
  525. }
  526. }
  527. if (!flag) {
  528. throw new BaseExeption( "noMember");
  529. }
  530. flag = true;
  531. break;
  532. }
  533. }
  534. if (!flag) {
  535. throw new BaseExeption( "noProject");
  536. }
  537. }
  538.  
  539. public static void DeletePperson(String cmd, String splitedArray[]) throws BaseExeption{
  540. splitedArray = cmd.split(" ");
  541.  
  542. int indexOfProject;
  543. int indexOfPerson;
  544. boolean flag = false;
  545.  
  546. if (splitedArray.length >= 4) {
  547. indexOfProject = Integer.parseInt(splitedArray[2]);
  548. indexOfPerson = Integer.parseInt(splitedArray[3]);
  549. } else {
  550. throw new BaseExeption( "noParam");
  551. }
  552.  
  553. for (Project someProject : projectList) {
  554. if (someProject.getID() == indexOfProject) {
  555. for (Person somePerson : nameList) {
  556. if (somePerson.getID() == indexOfPerson) {
  557. someProject.deletePerson(somePerson);
  558. flag = true;
  559. break;
  560. }
  561. }
  562. if (!flag) {
  563. throw new BaseExeption( "noMember");
  564. }
  565. break;
  566. }
  567. }
  568. if (!flag) {
  569. throw new BaseExeption( "noProject");
  570. }
  571. }
  572.  
  573. public static void AddPtask(String cmd, String splitedArray[]) throws BaseExeption{
  574. splitedArray = cmd.split(" ");
  575.  
  576. int indexOfProject;
  577. int indexOfTask;
  578. boolean flag = false;
  579.  
  580. if (splitedArray.length >= 4) {
  581. indexOfProject = Integer.parseInt(splitedArray[2]);
  582. indexOfTask = Integer.parseInt(splitedArray[3]);
  583. } else {
  584. throw new BaseExeption( "noParam");
  585. }
  586.  
  587. for (Project someProject : projectList) {
  588. if (someProject.getID() == indexOfProject) {
  589. for (Task someTask : taskList) {
  590. if (someTask.getID() == indexOfTask) {
  591. someProject.addTask(someTask);
  592. flag = true;
  593. break;
  594. }
  595. }
  596. if (!flag) {
  597. throw new BaseExeption( "noTask");
  598. }
  599. flag = true;
  600. break;
  601. }
  602. }
  603. if (!flag) {
  604. throw new BaseExeption( "noProject");
  605. }
  606. }
  607.  
  608. public static void DeletePtask(String cmd, String splitedArray[]) throws BaseExeption{
  609. splitedArray = cmd.split(" ");
  610.  
  611. int indexOfProject;
  612. int indexOfTask;
  613. boolean flag = false;
  614.  
  615. if (splitedArray.length >= 4) {
  616. indexOfProject = Integer.parseInt(splitedArray[2]);
  617. indexOfTask = Integer.parseInt(splitedArray[3]);
  618. } else {
  619. throw new BaseExeption( "noParam");
  620. }
  621.  
  622. for (Project someProject : projectList) {
  623. if (someProject.getID() == indexOfProject) {
  624. for (Task someTask : taskList) {
  625. if (someTask.getID() == indexOfTask) {
  626. someProject.deleteTask(someTask);
  627. flag = true;
  628. }
  629. }
  630. if (!flag) {
  631. throw new BaseExeption( "noTask");
  632. }
  633. }
  634. }
  635. if (!flag) {
  636. throw new BaseExeption( "noProject");
  637. }
  638. }
  639.  
  640. public static void ListProject(){ //Można dodać żeby więcej info wypisywało
  641. System.out.println("PROJECTS\nID | Name");
  642. for (Project someP : projectList)
  643. System.out.println(someP.getID() + " | " + someP.getName());
  644. }
  645.  
  646. public static void ListPperson(String cmd, String splitedArray[]){ //Można dodać żeby więcej info wypisywało
  647. int indexOfProject;
  648.  
  649. splitedArray = cmd.split(" ");
  650. indexOfProject = 0;
  651. if (splitedArray.length >= 3) indexOfProject = Integer.parseInt(splitedArray[2]);
  652. for (Project someP : projectList)
  653. if (someP.getID() == indexOfProject) someP.showPersons();
  654. }
  655.  
  656. public static void ListPtask(String cmd, String splitedArray[]){ //Można dodać żeby więcej info wypisywało
  657. int indexOfProject;
  658.  
  659. splitedArray = cmd.split(" ");
  660. indexOfProject = 0;
  661. if (splitedArray.length >= 2) indexOfProject = Integer.parseInt(splitedArray[2]);
  662. for (Project someP : projectList)
  663. if (someP.getID() == indexOfProject) someP.showTasks();
  664. }
  665.  
  666. public static void Export(String fileName) throws FileNotFoundException, IOException {
  667.  
  668. try ( FileWriter file= new FileWriter(".//" + fileName)){
  669.  
  670. BufferedWriter buffor = new BufferedWriter(file);
  671.  
  672. if(!nameList.isEmpty()) {
  673. buffor.write("PERSONS: ");
  674. buffor.newLine();
  675. for (Person somePerson : nameList) {
  676. buffor.write(somePerson.getID() + ":" + somePerson.getName());
  677. if (!somePerson.equals(nameList.lastElement())) {
  678. buffor.write(",");
  679. }
  680. }
  681. buffor.newLine();
  682. }
  683. else buffor.newLine();
  684.  
  685. if(!taskList.isEmpty()) {
  686. buffor.write("TASKS: ");
  687. buffor.newLine();
  688. for (Task someTask : taskList) {
  689. buffor.write(someTask.getID() + ":" + someTask.getName() + ":" + someTask.getPerson().getID() + ":" + someTask.getDeadLine());
  690. if (!someTask.equals(taskList.lastElement())) {
  691. buffor.write(",");
  692. }
  693. }
  694. buffor.newLine();
  695. }
  696. else buffor.newLine();
  697.  
  698. if(!projectList.isEmpty()) {
  699. buffor.write("PROJECTS: ");
  700. buffor.newLine();
  701. for (Project someProject : projectList) {
  702. buffor.write(someProject.getID() + ":" + someProject.getName() + ":");
  703. someProject.exportPersons(buffor);
  704. buffor.write(":");
  705. someProject.exportTasks(buffor);
  706. buffor.write(";");
  707. }
  708. }
  709. else buffor.newLine();
  710.  
  711. buffor.close();
  712. System.out.println("Zapisano do pliku");
  713. }
  714. catch (FileNotFoundException a){
  715. System.out.println("Nie ma takiego pliku");
  716. }
  717. }
  718.  
  719. public static void Import(String fileName) throws IOException {
  720.  
  721. BufferedReader fileReader = null;
  722. String filePath = ".//" + fileName;
  723. String[] splitedArray1;
  724. String[] splitedArray2;
  725.  
  726. try {
  727. fileReader = new BufferedReader(new FileReader(filePath));
  728. String text;
  729. text = fileReader.readLine();
  730.  
  731. if(text.equals("PERSONS: ")){
  732. text = fileReader.readLine();
  733. splitedArray1 = text.split(",");
  734.  
  735. for(int i=0; i<splitedArray1.length; i++){
  736.  
  737. splitedArray2 = splitedArray1[i].toString().split(":");
  738. Person newPerson = new Person(splitedArray2[1]);
  739. newPerson.setID(Integer.parseInt(splitedArray2[0]));
  740. nameList.add(newPerson);
  741. }
  742. }
  743.  
  744. text = fileReader.readLine();
  745. if(text.equals("TASKS: ")){
  746. text = fileReader.readLine();
  747. splitedArray1 = text.split(",");
  748.  
  749. for(int i=0; i<splitedArray1.length; i++){
  750.  
  751. splitedArray2 = splitedArray1[i].toString().split(":");
  752. Task newTask = new Task(splitedArray2[1]);
  753. newTask.setID(Integer.parseInt(splitedArray2[0]));
  754. String[] splitedArray3;
  755. splitedArray3 = splitedArray2[3].toString().split("-");
  756. LocalDate date = LocalDate.of(Integer.parseInt(splitedArray3[0]), Integer.parseInt(splitedArray3[1]), Integer.parseInt(splitedArray3[2]));
  757. newTask.setDeadline(date);
  758.  
  759. for(Person somePerson: nameList) {
  760. if (somePerson.getID() == Integer.parseInt(splitedArray2[2])) {
  761. newTask.setPerson(somePerson);
  762. break;
  763. }
  764. }
  765. taskList.add(newTask);
  766. }
  767. }
  768.  
  769. text = fileReader.readLine();
  770. if(text.equals("PROJECTS: ")){
  771. text = fileReader.readLine();
  772. splitedArray1 = text.split(";");
  773.  
  774. for(int i=0; i<splitedArray1.length; i++){
  775.  
  776. splitedArray2 = splitedArray1[i].split(":");
  777. Project newProject = new Project(splitedArray2[1]);
  778. newProject.setID(Integer.parseInt(splitedArray2[0]));
  779. String[] splitedArray3;
  780.  
  781. if(!splitedArray2[2].equals(" ")) {
  782. splitedArray3 = splitedArray2[2].split(",");
  783.  
  784. for (int j = 0; j < splitedArray3.length; j++) {
  785. for (Person somePerson : nameList) {
  786. if (somePerson.getID() == Integer.parseInt(splitedArray3[j])) {
  787. newProject.addPerson(somePerson);
  788. break;
  789. }
  790. }
  791. }
  792. }
  793.  
  794. if(!splitedArray2[3].equals(" ")) {
  795. splitedArray3 = splitedArray2[3].split(",");
  796.  
  797. for (int j = 0; j < splitedArray3.length; j++) {
  798. for (Task someTask : taskList) {
  799. if (someTask.getID() == Integer.parseInt(splitedArray3[j])) {
  800. newProject.addTask(someTask);
  801. break;
  802. }
  803. }
  804. }
  805. }
  806. projectList.add(newProject);
  807. }
  808. }
  809. }
  810. catch (IOException e) {
  811. e.printStackTrace();
  812. }
  813. finally {
  814. if (fileReader != null) {
  815. fileReader.close();
  816. }
  817. }
  818. }
  819. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement