mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-06-10 00:27:49 +00:00
Make replaceKey and removeKey functions rely on id's instead of instances
This commit is contained in:
parent
7bc4f19cf0
commit
e3024eda47
3 changed files with 36 additions and 30 deletions
|
@ -66,17 +66,13 @@ public class Database {
|
|||
}
|
||||
|
||||
public void removeKey(DatabaseEntry entry) {
|
||||
entry = getKeyByID(entry.getID());
|
||||
_entries.remove(entry);
|
||||
}
|
||||
|
||||
public void replaceKey(DatabaseEntry newEntry) {
|
||||
for (DatabaseEntry oldEntry : _entries) {
|
||||
if (oldEntry.getID() == newEntry.getID()) {
|
||||
_entries.set(_entries.indexOf(oldEntry), newEntry);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("no entry found with the same id");
|
||||
DatabaseEntry oldEntry = getKeyByID(newEntry.getID());
|
||||
_entries.set(_entries.indexOf(oldEntry), newEntry);
|
||||
}
|
||||
|
||||
public void swapKeys(DatabaseEntry entry1, DatabaseEntry entry2) {
|
||||
|
@ -86,4 +82,13 @@ public class Database {
|
|||
public List<DatabaseEntry> getKeys() {
|
||||
return Collections.unmodifiableList(_entries);
|
||||
}
|
||||
|
||||
private DatabaseEntry getKeyByID(long id) {
|
||||
for (DatabaseEntry entry : _entries) {
|
||||
if (entry.getID() == id) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("no entry found with the same id");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue