Files
FairEmail/app/src/main/java/eu/faircode/email/TupleOperationEx.java

121 lines
3.5 KiB
Java
Raw Normal View History

package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2021-01-01 08:56:36 +01:00
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
2020-01-25 18:26:44 +01:00
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
2020-01-27 13:13:29 +01:00
import org.json.JSONArray;
2019-02-26 11:05:21 +01:00
import java.util.Objects;
public class TupleOperationEx extends EntityOperation {
2020-01-25 10:49:59 +01:00
public int priority;
public String accountName;
public String folderName;
2019-01-29 11:06:53 +00:00
public boolean synchronize;
@Override
public boolean equals(Object obj) {
if (obj instanceof TupleOperationEx) {
TupleOperationEx other = (TupleOperationEx) obj;
return (super.equals(obj) &&
2020-01-25 10:49:59 +01:00
this.priority == other.priority &&
Objects.equals(this.accountName, other.accountName) &&
2019-02-26 11:05:21 +01:00
Objects.equals(this.folderName, other.folderName) &&
2019-01-29 11:06:53 +00:00
this.synchronize == other.synchronize);
} else
return false;
}
2020-01-25 18:26:44 +01:00
PartitionKey getPartitionKey(boolean offline) {
2020-01-25 18:26:44 +01:00
PartitionKey key = new PartitionKey();
2020-01-27 13:13:29 +01:00
2020-10-07 07:38:22 +02:00
key.folder = this.folder;
key.order = this.id;
2020-01-27 14:14:08 +01:00
if (offline) {
// open/close folder is expensive
key.priority = this.priority + 10;
return key;
}
2020-01-27 14:14:08 +01:00
key.priority = this.priority;
2020-02-20 14:08:13 +01:00
if (ADD.equals(name) || DELETE.equals(name)) {
key.id = "msg:" + message;
} else if (FETCH.equals(name))
2020-01-27 13:13:29 +01:00
try {
JSONArray jargs = new JSONArray(args);
long uid = jargs.getLong(0);
key.id = "uid:" + uid;
} catch (Throwable ex) {
Log.e(ex);
}
else if (!MOVE.equals(name))
key.id = "id:" + id;
key.operation = this.name;
2020-01-25 18:26:44 +01:00
return key;
}
class PartitionKey {
2020-10-07 07:38:22 +02:00
private long folder;
private long order;
2020-01-25 18:26:44 +01:00
private int priority;
2020-01-27 14:14:08 +01:00
private String id;
2020-01-25 18:26:44 +01:00
private String operation;
long getOrder() {
return this.order;
2020-01-27 14:14:08 +01:00
}
2020-01-25 18:26:44 +01:00
int getPriority() {
return this.priority;
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public boolean equals(@Nullable Object obj) {
if (obj instanceof PartitionKey) {
PartitionKey other = (PartitionKey) obj;
2020-10-07 07:38:22 +02:00
return (this.folder == other.folder &&
this.priority == other.priority &&
2020-01-27 14:14:08 +01:00
Objects.equals(this.id, other.id) &&
Objects.equals(this.operation, other.operation));
2020-01-25 18:26:44 +01:00
} else
return false;
}
@NonNull
@Override
public String toString() {
2020-01-27 14:14:08 +01:00
return (priority + ":" +
(id == null ? "" : id) + ":" +
(operation == null ? "" : operation));
2020-01-25 18:26:44 +01:00
}
}
}