@Test public void mergeNotes () { int notesNumber = 3; List<Note> notes = new ArrayList<>(); for (int i = 0; i < notesNumber; i++) { Note note = new Note(); note.setTitle("Merged note " + i + " title"); note.setContent("Merged note " + i + " content"); notes.add(note); } Note mergeNote = NotesHelper.mergeNotes(notes, false); assertNotNull(mergeNote); Assert.assertEquals("Merged note 0 title", mergeNote.getTitle()); Assert.assertTrue(mergeNote.getContent().contains("Merged note 0 content")); Assert.assertTrue(mergeNote.getContent().contains("Merged note 1 content")); Assert.assertTrue(mergeNote.getContent().contains("Merged note 2 content")); assertEquals(StringUtils.countMatches(mergeNote.getContent(), Constants.MERGED_NOTES_SEPARATOR), 2); }
public static Note mergeNotes (List<Note> notes, boolean keepMergedNotes) { boolean locked = false; ArrayList<Attachment> attachments = new ArrayList<>(); String reminder = null; String reminderRecurrenceRule = null; Double latitude = null; Double longitude = null; Note mergedNote = new Note(); mergedNote.setTitle(notes.get(0).getTitle()); mergedNote.setArchived(notes.get(0).isArchived()); mergedNote.setCategory(notes.get(0).getCategory()); StringBuilder content = new StringBuilder(); boolean includeTitle = false; for (Note note : notes) { appendContent(note, content, includeTitle); locked = locked || note.isLocked(); String currentReminder = note.getAlarm(); if (!StringUtils.isEmpty(currentReminder) && reminder == null) { reminder = currentReminder; reminderRecurrenceRule = note.getRecurrenceRule(); } latitude = ObjectUtils.defaultIfNull(latitude, note.getLatitude()); longitude = ObjectUtils.defaultIfNull(longitude, note.getLongitude()); addAttachments(keepMergedNotes, note, attachments); includeTitle = true; } mergedNote.setContent(content.toString()); mergedNote.setLocked(locked); mergedNote.setAlarm(reminder); mergedNote.setRecurrenceRule(reminderRecurrenceRule); mergedNote.setLatitude(latitude); mergedNote.setLongitude(longitude); mergedNote.setAttachmentsList(attachments); return mergedNote; }
NotesHelper { public static Note mergeNotes (List<Note> notes, boolean keepMergedNotes) { boolean locked = false; ArrayList<Attachment> attachments = new ArrayList<>(); String reminder = null; String reminderRecurrenceRule = null; Double latitude = null; Double longitude = null; Note mergedNote = new Note(); mergedNote.setTitle(notes.get(0).getTitle()); mergedNote.setArchived(notes.get(0).isArchived()); mergedNote.setCategory(notes.get(0).getCategory()); StringBuilder content = new StringBuilder(); boolean includeTitle = false; for (Note note : notes) { appendContent(note, content, includeTitle); locked = locked || note.isLocked(); String currentReminder = note.getAlarm(); if (!StringUtils.isEmpty(currentReminder) && reminder == null) { reminder = currentReminder; reminderRecurrenceRule = note.getRecurrenceRule(); } latitude = ObjectUtils.defaultIfNull(latitude, note.getLatitude()); longitude = ObjectUtils.defaultIfNull(longitude, note.getLongitude()); addAttachments(keepMergedNotes, note, attachments); includeTitle = true; } mergedNote.setContent(content.toString()); mergedNote.setLocked(locked); mergedNote.setAlarm(reminder); mergedNote.setRecurrenceRule(reminderRecurrenceRule); mergedNote.setLatitude(latitude); mergedNote.setLongitude(longitude); mergedNote.setAttachmentsList(attachments); return mergedNote; } }
NotesHelper { public static Note mergeNotes (List<Note> notes, boolean keepMergedNotes) { boolean locked = false; ArrayList<Attachment> attachments = new ArrayList<>(); String reminder = null; String reminderRecurrenceRule = null; Double latitude = null; Double longitude = null; Note mergedNote = new Note(); mergedNote.setTitle(notes.get(0).getTitle()); mergedNote.setArchived(notes.get(0).isArchived()); mergedNote.setCategory(notes.get(0).getCategory()); StringBuilder content = new StringBuilder(); boolean includeTitle = false; for (Note note : notes) { appendContent(note, content, includeTitle); locked = locked || note.isLocked(); String currentReminder = note.getAlarm(); if (!StringUtils.isEmpty(currentReminder) && reminder == null) { reminder = currentReminder; reminderRecurrenceRule = note.getRecurrenceRule(); } latitude = ObjectUtils.defaultIfNull(latitude, note.getLatitude()); longitude = ObjectUtils.defaultIfNull(longitude, note.getLongitude()); addAttachments(keepMergedNotes, note, attachments); includeTitle = true; } mergedNote.setContent(content.toString()); mergedNote.setLocked(locked); mergedNote.setAlarm(reminder); mergedNote.setRecurrenceRule(reminderRecurrenceRule); mergedNote.setLatitude(latitude); mergedNote.setLongitude(longitude); mergedNote.setAttachmentsList(attachments); return mergedNote; }  }
NotesHelper { public static Note mergeNotes (List<Note> notes, boolean keepMergedNotes) { boolean locked = false; ArrayList<Attachment> attachments = new ArrayList<>(); String reminder = null; String reminderRecurrenceRule = null; Double latitude = null; Double longitude = null; Note mergedNote = new Note(); mergedNote.setTitle(notes.get(0).getTitle()); mergedNote.setArchived(notes.get(0).isArchived()); mergedNote.setCategory(notes.get(0).getCategory()); StringBuilder content = new StringBuilder(); boolean includeTitle = false; for (Note note : notes) { appendContent(note, content, includeTitle); locked = locked || note.isLocked(); String currentReminder = note.getAlarm(); if (!StringUtils.isEmpty(currentReminder) && reminder == null) { reminder = currentReminder; reminderRecurrenceRule = note.getRecurrenceRule(); } latitude = ObjectUtils.defaultIfNull(latitude, note.getLatitude()); longitude = ObjectUtils.defaultIfNull(longitude, note.getLongitude()); addAttachments(keepMergedNotes, note, attachments); includeTitle = true; } mergedNote.setContent(content.toString()); mergedNote.setLocked(locked); mergedNote.setAlarm(reminder); mergedNote.setRecurrenceRule(reminderRecurrenceRule); mergedNote.setLatitude(latitude); mergedNote.setLongitude(longitude); mergedNote.setAttachmentsList(attachments); return mergedNote; }  static boolean haveSameId(Note note, Note currentNote); static StringBuilder appendContent(Note note, StringBuilder content, boolean includeTitle); static void addAttachments(boolean keepMergedNotes, Note note, ArrayList<Attachment> attachments); static Note mergeNotes(List<Note> notes, boolean keepMergedNotes); static StatsSingleNote getNoteInfos(Note note); static int getWords(Note note); static int getChars(Note note); }
NotesHelper { public static Note mergeNotes (List<Note> notes, boolean keepMergedNotes) { boolean locked = false; ArrayList<Attachment> attachments = new ArrayList<>(); String reminder = null; String reminderRecurrenceRule = null; Double latitude = null; Double longitude = null; Note mergedNote = new Note(); mergedNote.setTitle(notes.get(0).getTitle()); mergedNote.setArchived(notes.get(0).isArchived()); mergedNote.setCategory(notes.get(0).getCategory()); StringBuilder content = new StringBuilder(); boolean includeTitle = false; for (Note note : notes) { appendContent(note, content, includeTitle); locked = locked || note.isLocked(); String currentReminder = note.getAlarm(); if (!StringUtils.isEmpty(currentReminder) && reminder == null) { reminder = currentReminder; reminderRecurrenceRule = note.getRecurrenceRule(); } latitude = ObjectUtils.defaultIfNull(latitude, note.getLatitude()); longitude = ObjectUtils.defaultIfNull(longitude, note.getLongitude()); addAttachments(keepMergedNotes, note, attachments); includeTitle = true; } mergedNote.setContent(content.toString()); mergedNote.setLocked(locked); mergedNote.setAlarm(reminder); mergedNote.setRecurrenceRule(reminderRecurrenceRule); mergedNote.setLatitude(latitude); mergedNote.setLongitude(longitude); mergedNote.setAttachmentsList(attachments); return mergedNote; }  static boolean haveSameId(Note note, Note currentNote); static StringBuilder appendContent(Note note, StringBuilder content, boolean includeTitle); static void addAttachments(boolean keepMergedNotes, Note note, ArrayList<Attachment> attachments); static Note mergeNotes(List<Note> notes, boolean keepMergedNotes); static StatsSingleNote getNoteInfos(Note note); static int getWords(Note note); static int getChars(Note note);  }