@Test public void renameTest() { folder.rename("renamed/folder"); assertEquals("renamed/folder", note1.getFolderId()); assertEquals("renamed/folder", note2.getFolderId()); assertEquals("renamed/folder", note3.getFolderId()); assertEquals("renamed/folder/note1", note1.getName()); assertEquals("renamed/folder/note2", note2.getName()); assertEquals("renamed/folder/note3", note3.getName()); folder.rename("a"); assertEquals("a", note1.getFolderId()); assertEquals("a", note2.getFolderId()); assertEquals("a", note3.getFolderId()); assertEquals("a/note1", note1.getName()); assertEquals("a/note2", note2.getName()); assertEquals("a/note3", note3.getName()); }
public void rename(String newId) { if (isRoot()) return; String oldId = getId(); id = normalizeFolderId(newId); logger.info("Rename {} to {}", oldId, getId()); synchronized (notes) { for (Note note : notes.values()) { String noteName = note.getNameWithoutPath(); String newNotePath; if (newId.equals(ROOT_FOLDER_ID)) { newNotePath = noteName; } else { newNotePath = newId + "/" + noteName; } note.setName(newNotePath); } } for (Folder child : children.values()) { child.rename(getId() + "/" + child.getName()); } notifyRenamed(oldId); }
Folder { public void rename(String newId) { if (isRoot()) return; String oldId = getId(); id = normalizeFolderId(newId); logger.info("Rename {} to {}", oldId, getId()); synchronized (notes) { for (Note note : notes.values()) { String noteName = note.getNameWithoutPath(); String newNotePath; if (newId.equals(ROOT_FOLDER_ID)) { newNotePath = noteName; } else { newNotePath = newId + "/" + noteName; } note.setName(newNotePath); } } for (Folder child : children.values()) { child.rename(getId() + "/" + child.getName()); } notifyRenamed(oldId); } }
Folder { public void rename(String newId) { if (isRoot()) return; String oldId = getId(); id = normalizeFolderId(newId); logger.info("Rename {} to {}", oldId, getId()); synchronized (notes) { for (Note note : notes.values()) { String noteName = note.getNameWithoutPath(); String newNotePath; if (newId.equals(ROOT_FOLDER_ID)) { newNotePath = noteName; } else { newNotePath = newId + "/" + noteName; } note.setName(newNotePath); } } for (Folder child : children.values()) { child.rename(getId() + "/" + child.getName()); } notifyRenamed(oldId); } Folder(String id); }
Folder { public void rename(String newId) { if (isRoot()) return; String oldId = getId(); id = normalizeFolderId(newId); logger.info("Rename {} to {}", oldId, getId()); synchronized (notes) { for (Note note : notes.values()) { String noteName = note.getNameWithoutPath(); String newNotePath; if (newId.equals(ROOT_FOLDER_ID)) { newNotePath = noteName; } else { newNotePath = newId + "/" + noteName; } note.setName(newNotePath); } } for (Folder child : children.values()) { child.rename(getId() + "/" + child.getName()); } notifyRenamed(oldId); } Folder(String id); String getId(); String getName(); String getParentFolderId(); static String normalizeFolderId(String id); void rename(String newId); void merge(Folder folder); void addFolderListener(FolderListener listener); void notifyRenamed(String oldFolderId); Folder getParent(); Map<String, Folder> getChildren(); void setParent(Folder parent); void addChild(Folder child); void removeChild(String folderId); void addNote(Note note); void addNotes(List<Note> newNotes); void removeNote(Note note); List<Note> getNotes(); List<Note> getNotesRecursively(); int countNotes(); boolean hasChild(); boolean isTrash(); }
Folder { public void rename(String newId) { if (isRoot()) return; String oldId = getId(); id = normalizeFolderId(newId); logger.info("Rename {} to {}", oldId, getId()); synchronized (notes) { for (Note note : notes.values()) { String noteName = note.getNameWithoutPath(); String newNotePath; if (newId.equals(ROOT_FOLDER_ID)) { newNotePath = noteName; } else { newNotePath = newId + "/" + noteName; } note.setName(newNotePath); } } for (Folder child : children.values()) { child.rename(getId() + "/" + child.getName()); } notifyRenamed(oldId); } Folder(String id); String getId(); String getName(); String getParentFolderId(); static String normalizeFolderId(String id); void rename(String newId); void merge(Folder folder); void addFolderListener(FolderListener listener); void notifyRenamed(String oldFolderId); Folder getParent(); Map<String, Folder> getChildren(); void setParent(Folder parent); void addChild(Folder child); void removeChild(String folderId); void addNote(Note note); void addNotes(List<Note> newNotes); void removeNote(Note note); List<Note> getNotes(); List<Note> getNotesRecursively(); int countNotes(); boolean hasChild(); boolean isTrash(); static final String ROOT_FOLDER_ID; static final String TRASH_FOLDER_ID; static final String TRASH_FOLDER_CONFLICT_INFIX; }