Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package com.javarush.test.level19.lesson10.bonus01;
- //
- //import java.io.BufferedReader;
- //import java.io.FileReader;
- //import java.io.IOException;
- //import java.io.InputStreamReader;
- //import java.util.ArrayList;
- //import java.util.List;
- //
- ///* Отслеживаем изменения
- //Считать в консоли 2 имени файла - file1, file2.
- //Файлы содержат строки, file2 является обновленной версией file1, часть строк совпадают.
- //Нужно создать объединенную версию строк, записать их в список lines
- //Операции ADDED и REMOVED не могут идти подряд, они всегда разделены SAME
- //Пример:
- //оригинальный редактированный общий
- //file1: file2: результат:(lines)
- //
- //строка1 строка1 SAME строка1
- //строка2 REMOVED строка2
- //строка3 строка3 SAME строка3
- //строка4 REMOVED строка4
- //строка5 строка5 SAME строка5
- // строка0 ADDED строка0
- //строка1 строка1 SAME строка1
- //строка2 REMOVED строка2
- //строка3 строка3 SAME строка3
- // строка5 ADDED строка5
- //строка4 строка4 SAME строка4
- //строка5 REMOVED строка5
- //*/
- //
- //public class SolutionYuliia
- //{
- // public static List<LineItem> lines = new ArrayList<LineItem>();
- //
- // public static void main(String[] args) throws IOException
- // {
- // BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- // BufferedReader fileReader = new BufferedReader(new FileReader(reader.readLine()));
- // ArrayList<String> list1 = new ArrayList<>();
- // while (fileReader.ready()) {
- // list1.add(fileReader.readLine());
- // }
- // fileReader.close();
- // fileReader = new BufferedReader(new FileReader(reader.readLine()));
- // ArrayList<String> list2 = new ArrayList<>();
- // while (fileReader.ready()) {
- // list2.add(fileReader.readLine());
- // }
- // for (int i = 0; i < list1.size(); i++) {
- // String line1 = list1.get(i);
- // System.out.println("Line1 = " + line1);
- // if (i < list2.size() - 1) {
- // String line2 = list2.get(i);
- // System.out.println("Line2 = " + line2);
- // if (line1.equals(line2))
- // lines.add(new LineItem(Type.SAME, line1));
- // else {
- // if (i + 1 < list1.size() - 1)
- // {
- // String line12 = list1.get(i + 1);
- // if (line2.equals(line12)){
- // lines.add(new LineItem(Type.REMOVED, line1));
- // lines.add(new LineItem(Type.SAME, line2));
- // } else if (i + 1 < list2.size() - 1) {
- // String line22 = list2.get(i + 1);
- // if (line22.equals(line1))
- // {
- // lines.add(new LineItem(Type.ADDED, line2));
- // lines.add(new LineItem(Type.SAME, line1));
- // }
- // }
- // }
- //
- // }
- // } else
- // lines.add(new LineItem(Type.REMOVED, line1));
- // }
- // System.out.println(lines.size());
- // for (LineItem li : lines)
- // System.out.println(li.type + " " + li.line);
- // }
- //
- //
- // public static enum Type {
- // ADDED, //добавлена новая строка
- // REMOVED, //удалена строка
- // SAME //без изменений
- // }
- //
- // public static class LineItem {
- // public Type type;
- // public String line;
- //
- // public LineItem(Type type, String line) {
- // this.type = type;
- // this.line = line;
- // }
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement