mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Introduce UUIDMap for storing objects that are keyed by a UUID
This patch introduces the new ``UUIDMap`` type, reducing code duplication and making UUID lookups faster. We currently already use UUIDs as the identifier for the ``DatabaseEntry`` and ``Slot`` types, but the way lookups by UUID work are kind of ugly, as we simply iterate over the list until we find a match. As we're probably going to have more types like this soon (groups and icons, for example), I figured it'd be good to abstract this away into a separate type and make it a map instead of a list. The only thing that has gotten slower is the ``swap`` method. The internal ``LinkedHashMap`` retains insertion order with a linked list, but does not know about the position of the values, so we basically have to copy the entire map to simply swap two values. I don't think it's too big of a deal, because swap operations still take less than a millisecond even with large vaults, but suggestions for improving this are welcome. I had to update gradle and JUnit to be able to use the new ``assertThrows`` assertion method, so this patch includes that as well.
This commit is contained in:
parent
6769fefd00
commit
2323d89938
21 changed files with 375 additions and 243 deletions
|
@ -40,12 +40,9 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||
import com.bumptech.glide.request.target.CustomTarget;
|
||||
import com.bumptech.glide.request.transition.Transition;
|
||||
import com.beemdevelopment.aegis.util.Cloner;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -391,6 +388,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, final int resultCode, Intent data) {
|
||||
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
|
||||
|
@ -492,7 +490,7 @@ public class EditEntryActivity extends AegisActivity {
|
|||
if (_origEntry == null) {
|
||||
entry = new DatabaseEntry(info);
|
||||
} else {
|
||||
entry = cloneEntry(_origEntry);
|
||||
entry = Cloner.clone(_origEntry);
|
||||
entry.setInfo(info);
|
||||
}
|
||||
entry.setIssuer(_textIssuer.getText().toString());
|
||||
|
@ -570,20 +568,6 @@ public class EditEntryActivity extends AegisActivity {
|
|||
return -1;
|
||||
}
|
||||
|
||||
private static DatabaseEntry cloneEntry(DatabaseEntry entry) {
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(entry);
|
||||
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||
return (DatabaseEntry) ois.readObject();
|
||||
} catch (ClassNotFoundException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ParseException extends Exception {
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue