/** * Splice - add a group from one database to a parent from another (or copy from the same db) */ public void splice(G newParent, Group<?, ?, ?, ?> groupToSplice) { G addedGroup = newParent.addGroup(newParent.getDatabase().newGroup(groupToSplice)); addedGroup.copy(groupToSplice); }
private E entryFactory(D database, String g, int e) { E result = database.newEntry(); result.setTitle(g + "-" + e); result.setUsername(g + " - un - " + e); result.setPassword(g + "- p -" + e); result.setUrl(g + "- url - " + e); result.setNotes(g + "- n - " + e); return result; }
@Override public boolean deleteEntry(final UUID uuid) { E e = findEntry(uuid); if (e == null) { return false; } e.getParent().removeEntry(e); if (isRecycleBinEnabled()) { getRecycleBin().addEntry(e); } return true; }
private D createNewDatabase() throws IOException { D database = getDatabase(); for (Integer g = 0; g < 5; g++){ G group = database.getRootGroup().addGroup(database.newGroup(g.toString())); for (int e = 0; e <= g; e++) { group.addEntry(entryFactory(database, g.toString(), e)); } } return database; }
@Override public void copy(Group<? extends Database, ? extends Group, ? extends Entry, ? extends Icon> parent) { for (Group<?,?,?,?> child : parent.getGroups()) { G addedGroup = addGroup(this.getDatabase().newGroup(child)); addedGroup.copy(child); } for (Entry entry : parent.getEntries()) { addEntry(this.getDatabase().newEntry(entry)); } }
/** * Group by title */ public G groupByTitle(D database) { List<? extends E> entries = database.findEntries(new Entry.Matcher() { @Override public boolean matches(Entry entry) { return entry.getProperty(Entry.STANDARD_PROPERTY_NAME_TITLE).toLowerCase().contains("findme!"); } }); // create a new group using DB factory method G newParent = database.newGroup("Found entries"); // iterate over the found entries for (E entry : entries) { // copy the entry using DB factory so it remains where it was found as well as being in new group E copy = database.newEntry(entry); // add new entry to new group newParent.addEntry(copy); } return newParent; }
@Override public boolean deleteGroup(final UUID uuid) { G g = findGroup(uuid); if (g==null) { return false; } g.getParent().removeGroup(g); if (isRecycleBinEnabled()) { getRecycleBin().addGroup(g); } return true; }
@Override public String getId() { return database.getName() + " (" + database.getRootGroup().getUuid().toString() + ")"; }
/** * Doesn't do anything other than output the database using default PrintVisitor * @throws IOException when naughty */ @Test public void inspectNewDatabase () throws IOException { Database database = createNewDatabase(); database.visit(new Visitor.Print()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || !(o instanceof Icon)) return false; Icon icon = (Icon) o; return index == icon.getIndex(); } }
@Override public void visit(Visitor visitor) { visitor.startVisit(getRootGroup()); visit(getRootGroup(), visitor); visitor.endVisit(getRootGroup()); }
@Override public boolean matches(Entry entry) { return entry.getUuid().equals(uuid); } });
@Override public boolean matches(Entry entry) { return entry.getProperty(Entry.STANDARD_PROPERTY_NAME_TITLE).toLowerCase().contains("findme!"); } });
@Override public List<? extends E> findEntries(String find) { return getRootGroup().findEntries(find, true); }
@Override public boolean match(Entry.Matcher matcher) { return matcher.matches(this); }
@Override public void endVisit(Group group) { if (group.isRecycleBin()) { recycle = false; } } });