Advertisement
Guest User

Untitled

a guest
Jul 25th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. //package com.javarush.test.level19.lesson10.bonus01;
  2. //
  3. //import java.io.BufferedReader;
  4. //import java.io.FileReader;
  5. //import java.io.IOException;
  6. //import java.io.InputStreamReader;
  7. //import java.util.ArrayList;
  8. //import java.util.List;
  9. //
  10. ///* Отслеживаем изменения
  11. //Считать в консоли 2 имени файла - file1, file2.
  12. //Файлы содержат строки, file2 является обновленной версией file1, часть строк совпадают.
  13. //Нужно создать объединенную версию строк, записать их в список lines
  14. //Операции ADDED и REMOVED не могут идти подряд, они всегда разделены SAME
  15. //Пример:
  16. //оригинальный   редактированный    общий
  17. //file1:         file2:             результат:(lines)
  18. //
  19. //строка1        строка1            SAME строка1
  20. //строка2                           REMOVED строка2
  21. //строка3        строка3            SAME строка3
  22. //строка4                           REMOVED строка4
  23. //строка5        строка5            SAME строка5
  24. //               строка0            ADDED строка0
  25. //строка1        строка1            SAME строка1
  26. //строка2                           REMOVED строка2
  27. //строка3        строка3            SAME строка3
  28. //               строка5            ADDED строка5
  29. //строка4        строка4            SAME строка4
  30. //строка5                           REMOVED строка5
  31. //*/
  32. //
  33. //public class SolutionYuliia
  34. //{
  35. //    public static List<LineItem> lines = new ArrayList<LineItem>();
  36. //
  37. //    public static void main(String[] args) throws IOException
  38. //    {
  39. //        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  40. //        BufferedReader fileReader = new BufferedReader(new FileReader(reader.readLine()));
  41. //        ArrayList<String> list1 = new ArrayList<>();
  42. //        while (fileReader.ready()) {
  43. //            list1.add(fileReader.readLine());
  44. //        }
  45. //        fileReader.close();
  46. //        fileReader = new BufferedReader(new FileReader(reader.readLine()));
  47. //        ArrayList<String> list2 = new ArrayList<>();
  48. //        while (fileReader.ready()) {
  49. //            list2.add(fileReader.readLine());
  50. //        }
  51. //        for (int i = 0; i < list1.size(); i++) {
  52. //            String line1 = list1.get(i);
  53. //            System.out.println("Line1 = " + line1);
  54. //            if (i < list2.size() - 1) {
  55. //                String line2 = list2.get(i);
  56. //                System.out.println("Line2 = " + line2);
  57. //                if (line1.equals(line2))
  58. //                    lines.add(new LineItem(Type.SAME, line1));
  59. //                else {
  60. //                    if (i + 1 < list1.size() - 1)
  61. //                    {
  62. //                        String line12 = list1.get(i + 1);
  63. //                        if (line2.equals(line12)){
  64. //                            lines.add(new LineItem(Type.REMOVED, line1));
  65. //                            lines.add(new LineItem(Type.SAME, line2));
  66. //                        } else if (i + 1 < list2.size() - 1) {
  67. //                            String line22 = list2.get(i + 1);
  68. //                            if (line22.equals(line1))
  69. //                            {
  70. //                                lines.add(new LineItem(Type.ADDED, line2));
  71. //                                lines.add(new LineItem(Type.SAME, line1));
  72. //                            }
  73. //                        }
  74. //                    }
  75. //
  76. //                }
  77. //            } else
  78. //                lines.add(new LineItem(Type.REMOVED, line1));
  79. //        }
  80. //        System.out.println(lines.size());
  81. //        for (LineItem li : lines)
  82. //            System.out.println(li.type + " " + li.line);
  83. //    }
  84. //
  85. //
  86. //    public static enum Type {
  87. //        ADDED,        //добавлена новая строка
  88. //        REMOVED,      //удалена строка
  89. //        SAME          //без изменений
  90. //    }
  91. //
  92. //    public static class LineItem {
  93. //        public Type type;
  94. //        public String line;
  95. //
  96. //        public LineItem(Type type, String line) {
  97. //            this.type = type;
  98. //            this.line = line;
  99. //        }
  100. //    }
  101. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement