mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Diamond operators.
This commit is contained in:
@@ -23,7 +23,7 @@ public class BdfMessageContext {
|
||||
}
|
||||
|
||||
public BdfMessageContext(BdfDictionary dictionary) {
|
||||
this(dictionary, Collections.<MessageId>emptyList());
|
||||
this(dictionary, Collections.emptyList());
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class Transaction {
|
||||
* committed.
|
||||
*/
|
||||
public void attach(Event e) {
|
||||
if (events == null) events = new ArrayList<Event>();
|
||||
if (events == null) events = new ArrayList<>();
|
||||
events.add(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class MessageContext {
|
||||
}
|
||||
|
||||
public MessageContext(Metadata metadata) {
|
||||
this(metadata, Collections.<MessageId>emptyList());
|
||||
this(metadata, Collections.emptyList());
|
||||
}
|
||||
|
||||
public Metadata getMetadata() {
|
||||
|
||||
@@ -24,7 +24,7 @@ public class PoliteExecutor implements Executor {
|
||||
|
||||
private final Object lock = new Object();
|
||||
@GuardedBy("lock")
|
||||
private final Queue<Runnable> queue = new LinkedList<Runnable>();
|
||||
private final Queue<Runnable> queue = new LinkedList<>();
|
||||
private final Executor delegate;
|
||||
private final int maxConcurrentTasks;
|
||||
private final Logger log;
|
||||
|
||||
@@ -201,8 +201,7 @@ class ClientHelperImpl implements ClientHelper {
|
||||
public Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
|
||||
Transaction txn, GroupId g) throws DbException, FormatException {
|
||||
Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g);
|
||||
Map<MessageId, BdfDictionary> parsed =
|
||||
new HashMap<MessageId, BdfDictionary>(raw.size());
|
||||
Map<MessageId, BdfDictionary> parsed = new HashMap<>(raw.size());
|
||||
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
||||
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
||||
return parsed;
|
||||
@@ -229,8 +228,7 @@ class ClientHelperImpl implements ClientHelper {
|
||||
FormatException {
|
||||
Metadata metadata = metadataEncoder.encode(query);
|
||||
Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g, metadata);
|
||||
Map<MessageId, BdfDictionary> parsed =
|
||||
new HashMap<MessageId, BdfDictionary>(raw.size());
|
||||
Map<MessageId, BdfDictionary> parsed = new HashMap<>(raw.size());
|
||||
for (Entry<MessageId, Metadata> e : raw.entrySet())
|
||||
parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
|
||||
return parsed;
|
||||
|
||||
@@ -276,8 +276,7 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
|
||||
|
||||
private Map<TransportId, TransportProperties> receiveTransportProperties(
|
||||
BdfReader r) throws IOException {
|
||||
Map<TransportId, TransportProperties> remote =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> remote = new HashMap<>();
|
||||
r.readListStart();
|
||||
while (!r.hasListEnd()) {
|
||||
r.readListStart();
|
||||
|
||||
@@ -34,8 +34,8 @@ class ContactManagerImpl implements ContactManager {
|
||||
ContactManagerImpl(DatabaseComponent db, KeyManager keyManager) {
|
||||
this.db = db;
|
||||
this.keyManager = keyManager;
|
||||
addHooks = new CopyOnWriteArrayList<AddContactHook>();
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveContactHook>();
|
||||
addHooks = new CopyOnWriteArrayList<>();
|
||||
removeHooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +125,7 @@ class ContactManagerImpl implements ContactManager {
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
List<Contact> active = new ArrayList<Contact>(contacts.size());
|
||||
List<Contact> active = new ArrayList<>(contacts.size());
|
||||
for (Contact c : contacts) if (c.isActive()) active.add(c);
|
||||
return active;
|
||||
}
|
||||
|
||||
@@ -602,8 +602,8 @@ class CryptoComponentImpl implements CryptoComponent {
|
||||
|
||||
// Package access for testing
|
||||
int chooseIterationCount(int targetMillis) {
|
||||
List<Long> quickSamples = new ArrayList<Long>(PBKDF_SAMPLES);
|
||||
List<Long> slowSamples = new ArrayList<Long>(PBKDF_SAMPLES);
|
||||
List<Long> quickSamples = new ArrayList<>(PBKDF_SAMPLES);
|
||||
List<Long> slowSamples = new ArrayList<>(PBKDF_SAMPLES);
|
||||
long iterationNanos = 0, initNanos = 0;
|
||||
while (iterationNanos <= 0 || initNanos <= 0) {
|
||||
// Sample the running time with one iteration and two iterations
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CryptoModule {
|
||||
|
||||
public CryptoModule() {
|
||||
// Use an unbounded queue
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
|
||||
@@ -16,7 +16,7 @@ class PasswordStrengthEstimatorImpl implements PasswordStrengthEstimator {
|
||||
|
||||
@Override
|
||||
public float estimateStrength(String password) {
|
||||
HashSet<Character> unique = new HashSet<Character>();
|
||||
HashSet<Character> unique = new HashSet<>();
|
||||
int length = password.length();
|
||||
for (int i = 0; i < length; i++) unique.add(password.charAt(i));
|
||||
return Math.min(1, (float) unique.size() / STRONG_UNIQUE_CHARS);
|
||||
|
||||
@@ -331,7 +331,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
if (!db.containsContact(txn, c))
|
||||
throw new NoSuchContactException();
|
||||
Collection<MessageId> ids = db.getMessagesToSend(txn, c, maxLength);
|
||||
List<byte[]> messages = new ArrayList<byte[]>(ids.size());
|
||||
List<byte[]> messages = new ArrayList<>(ids.size());
|
||||
for (MessageId m : ids) {
|
||||
messages.add(db.getRawMessage(txn, m));
|
||||
db.updateExpiryTime(txn, c, m, maxLatency);
|
||||
@@ -381,7 +381,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
throw new NoSuchContactException();
|
||||
Collection<MessageId> ids = db.getRequestedMessagesToSend(txn, c,
|
||||
maxLength);
|
||||
List<byte[]> messages = new ArrayList<byte[]>(ids.size());
|
||||
List<byte[]> messages = new ArrayList<>(ids.size());
|
||||
for (MessageId m : ids) {
|
||||
messages.add(db.getRawMessage(txn, m));
|
||||
db.updateExpiryTime(txn, c, m, maxLatency);
|
||||
@@ -661,7 +661,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsContact(txn, c))
|
||||
throw new NoSuchContactException();
|
||||
Collection<MessageId> acked = new ArrayList<MessageId>();
|
||||
Collection<MessageId> acked = new ArrayList<>();
|
||||
for (MessageId m : a.getMessageIds()) {
|
||||
if (db.containsVisibleMessage(txn, c, m)) {
|
||||
db.raiseSeenFlag(txn, c, m);
|
||||
@@ -896,8 +896,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
Map<ContactId, TransportKeys> keys) throws DbException {
|
||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||
T txn = unbox(transaction);
|
||||
Map<ContactId, TransportKeys> filtered =
|
||||
new HashMap<ContactId, TransportKeys>();
|
||||
Map<ContactId, TransportKeys> filtered = new HashMap<>();
|
||||
for (Entry<ContactId, TransportKeys> e : keys.entrySet()) {
|
||||
ContactId c = e.getKey();
|
||||
TransportKeys k = e.getValue();
|
||||
|
||||
@@ -32,7 +32,7 @@ public class DatabaseExecutorModule {
|
||||
|
||||
public DatabaseExecutorModule() {
|
||||
// Use an unbounded queue
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
|
||||
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
|
||||
@@ -26,7 +26,7 @@ public class DatabaseModule {
|
||||
@Singleton
|
||||
DatabaseComponent provideDatabaseComponent(Database<Connection> db,
|
||||
EventBus eventBus, ShutdownManager shutdown) {
|
||||
return new DatabaseComponentImpl<Connection>(db, Connection.class,
|
||||
eventBus, shutdown);
|
||||
return new DatabaseComponentImpl<>(db, Connection.class, eventBus,
|
||||
shutdown);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,8 +263,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
private final String hashType, binaryType, counterType, secretType;
|
||||
private final Clock clock;
|
||||
|
||||
private final LinkedList<Connection> connections =
|
||||
new LinkedList<Connection>(); // Locking: connectionsLock
|
||||
// Locking: connectionsLock
|
||||
private final LinkedList<Connection> connections = new LinkedList<>();
|
||||
|
||||
private int openConnections = 0; // Locking: connectionsLock
|
||||
private boolean closed = false; // Locking: connectionsLock
|
||||
@@ -1035,7 +1035,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " FROM contacts";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
List<Contact> contacts = new ArrayList<Contact>();
|
||||
List<Contact> contacts = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
ContactId contactId = new ContactId(rs.getInt(1));
|
||||
AuthorId authorId = new AuthorId(rs.getBytes(2));
|
||||
@@ -1069,7 +1069,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, local.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<ContactId> ids = new ArrayList<ContactId>();
|
||||
List<ContactId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new ContactId(rs.getInt(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1094,7 +1094,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, remote.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<Contact> contacts = new ArrayList<Contact>();
|
||||
List<Contact> contacts = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
ContactId c = new ContactId(rs.getInt(1));
|
||||
String name = rs.getString(2);
|
||||
@@ -1150,7 +1150,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, c.getString());
|
||||
rs = ps.executeQuery();
|
||||
List<Group> groups = new ArrayList<Group>();
|
||||
List<Group> groups = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
GroupId id = new GroupId(rs.getBytes(1));
|
||||
byte[] descriptor = rs.getBytes(2);
|
||||
@@ -1203,7 +1203,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, g.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<ContactId> visible = new ArrayList<ContactId>();
|
||||
List<ContactId> visible = new ArrayList<>();
|
||||
while (rs.next()) visible.add(new ContactId(rs.getInt(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1255,7 +1255,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
+ " FROM localAuthors";
|
||||
ps = txn.prepareStatement(sql);
|
||||
rs = ps.executeQuery();
|
||||
List<LocalAuthor> authors = new ArrayList<LocalAuthor>();
|
||||
List<LocalAuthor> authors = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
AuthorId authorId = new AuthorId(rs.getBytes(1));
|
||||
String name = rs.getString(2);
|
||||
@@ -1285,7 +1285,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, g.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1308,7 +1308,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, state.getValue());
|
||||
ps.setBytes(2, g.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1343,7 +1343,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setString(3, e.getKey());
|
||||
ps.setBytes(4, e.getValue());
|
||||
rs = ps.executeQuery();
|
||||
Set<MessageId> ids = new HashSet<MessageId>();
|
||||
Set<MessageId> ids = new HashSet<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1377,7 +1377,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, DELIVERED.getValue());
|
||||
ps.setBytes(2, g.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
Map<MessageId, Metadata> all = new HashMap<MessageId, Metadata>();
|
||||
Map<MessageId, Metadata> all = new HashMap<>();
|
||||
Metadata metadata = null;
|
||||
MessageId lastMessageId = null;
|
||||
while (rs.next()) {
|
||||
@@ -1406,8 +1406,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
Collection<MessageId> matches = getMessageIds(txn, g, query);
|
||||
if (matches.isEmpty()) return Collections.emptyMap();
|
||||
// Retrieve the metadata for each match
|
||||
Map<MessageId, Metadata> all = new HashMap<MessageId, Metadata>(
|
||||
matches.size());
|
||||
Map<MessageId, Metadata> all = new HashMap<>(matches.size());
|
||||
for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m));
|
||||
return all;
|
||||
}
|
||||
@@ -1505,7 +1504,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setBytes(1, g.getBytes());
|
||||
ps.setInt(2, c.getInt());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageStatus> statuses = new ArrayList<MessageStatus>();
|
||||
List<MessageStatus> statuses = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
MessageId messageId = new MessageId(rs.getBytes(1));
|
||||
boolean sent = rs.getBoolean(2);
|
||||
@@ -1564,7 +1563,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, m.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
Map<MessageId, State> dependencies = new HashMap<MessageId, State>();
|
||||
Map<MessageId, State> dependencies = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
MessageId dependency = new MessageId(rs.getBytes(1));
|
||||
State state = State.fromValue(rs.getInt(2));
|
||||
@@ -1602,7 +1601,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setBytes(1, m.getBytes());
|
||||
rs = ps.executeQuery();
|
||||
Map<MessageId, State> dependents = new HashMap<MessageId, State>();
|
||||
Map<MessageId, State> dependents = new HashMap<>();
|
||||
while (rs.next()) {
|
||||
MessageId dependent = new MessageId(rs.getBytes(1));
|
||||
State state = State.fromValue(rs.getInt(2));
|
||||
@@ -1654,7 +1653,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setInt(2, maxMessages);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1690,7 +1689,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setLong(3, now);
|
||||
ps.setInt(4, maxMessages);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1715,7 +1714,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, c.getInt());
|
||||
ps.setInt(2, maxMessages);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1750,7 +1749,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(2, DELIVERED.getValue());
|
||||
ps.setLong(3, now);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
int total = 0;
|
||||
while (rs.next()) {
|
||||
int length = rs.getInt(1);
|
||||
@@ -1792,7 +1791,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(1, state.getValue());
|
||||
ps.setString(2, c.getString());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1822,7 +1821,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, c.getString());
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
|
||||
rs.close();
|
||||
ps.close();
|
||||
@@ -1881,7 +1880,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps.setInt(2, DELIVERED.getValue());
|
||||
ps.setLong(3, now);
|
||||
rs = ps.executeQuery();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
int total = 0;
|
||||
while (rs.next()) {
|
||||
int length = rs.getInt(1);
|
||||
@@ -1935,7 +1934,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, t.getString());
|
||||
rs = ps.executeQuery();
|
||||
List<IncomingKeys> inKeys = new ArrayList<IncomingKeys>();
|
||||
List<IncomingKeys> inKeys = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
long rotationPeriod = rs.getLong(1);
|
||||
SecretKey tagKey = new SecretKey(rs.getBytes(2));
|
||||
@@ -1955,8 +1954,7 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
ps = txn.prepareStatement(sql);
|
||||
ps.setString(1, t.getString());
|
||||
rs = ps.executeQuery();
|
||||
Map<ContactId, TransportKeys> keys =
|
||||
new HashMap<ContactId, TransportKeys>();
|
||||
Map<ContactId, TransportKeys> keys = new HashMap<>();
|
||||
for (int i = 0; rs.next(); i++) {
|
||||
// There should be three times as many incoming keys
|
||||
if (inKeys.size() < (i + 1) * 3) throw new DbStateException();
|
||||
@@ -2074,8 +2072,8 @@ abstract class JdbcDatabase implements Database<Connection> {
|
||||
PreparedStatement ps = null;
|
||||
try {
|
||||
// Determine which keys are being removed
|
||||
List<String> removed = new ArrayList<String>();
|
||||
Map<String, byte[]> retained = new HashMap<String, byte[]>();
|
||||
List<String> removed = new ArrayList<>();
|
||||
Map<String, byte[]> retained = new HashMap<>();
|
||||
for (Entry<String, byte[]> e : meta.entrySet()) {
|
||||
if (e.getValue() == REMOVE) removed.add(e.getKey());
|
||||
else retained.put(e.getKey(), e.getValue());
|
||||
|
||||
@@ -15,7 +15,7 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||
class EventBusImpl implements EventBus {
|
||||
|
||||
private final Collection<EventListener> listeners =
|
||||
new CopyOnWriteArrayList<EventListener>();
|
||||
new CopyOnWriteArrayList<>();
|
||||
|
||||
@Override
|
||||
public void addListener(EventListener l) {
|
||||
|
||||
@@ -50,10 +50,9 @@ class KeyAgreementConnector {
|
||||
private final PluginManager pluginManager;
|
||||
private final CompletionService<KeyAgreementConnection> connect;
|
||||
|
||||
private final List<KeyAgreementListener> listeners =
|
||||
new ArrayList<KeyAgreementListener>();
|
||||
private final List<KeyAgreementListener> listeners = new ArrayList<>();
|
||||
private final List<Future<KeyAgreementConnection>> pending =
|
||||
new ArrayList<Future<KeyAgreementConnection>>();
|
||||
new ArrayList<>();
|
||||
|
||||
private volatile boolean connecting = false;
|
||||
private volatile boolean alice = false;
|
||||
@@ -65,8 +64,7 @@ class KeyAgreementConnector {
|
||||
this.clock = clock;
|
||||
this.crypto = crypto;
|
||||
this.pluginManager = pluginManager;
|
||||
connect = new ExecutorCompletionService<KeyAgreementConnection>(
|
||||
ioExecutor);
|
||||
connect = new ExecutorCompletionService<>(ioExecutor);
|
||||
}
|
||||
|
||||
public Payload listen(KeyPair localKeyPair) {
|
||||
@@ -75,8 +73,7 @@ class KeyAgreementConnector {
|
||||
byte[] commitment = crypto.deriveKeyCommitment(
|
||||
localKeyPair.getPublic().getEncoded());
|
||||
// Start all listeners and collect their descriptors
|
||||
List<TransportDescriptor> descriptors =
|
||||
new ArrayList<TransportDescriptor>();
|
||||
List<TransportDescriptor> descriptors = new ArrayList<>();
|
||||
for (DuplexPlugin plugin : pluginManager.getKeyAgreementPlugins()) {
|
||||
KeyAgreementListener l =
|
||||
plugin.createKeyAgreementListener(commitment);
|
||||
|
||||
@@ -51,8 +51,7 @@ class PayloadParserImpl implements PayloadParser {
|
||||
byte[] commitment = payload.getRaw(1);
|
||||
if (commitment.length != COMMIT_LENGTH) throw new FormatException();
|
||||
// Remaining elements: transport descriptors
|
||||
List<TransportDescriptor> recognised =
|
||||
new ArrayList<TransportDescriptor>();
|
||||
List<TransportDescriptor> recognised = new ArrayList<>();
|
||||
for (int i = 2; i < payload.size(); i++) {
|
||||
BdfList descriptor = payload.getList(i);
|
||||
long transportId = descriptor.getLong(0);
|
||||
|
||||
@@ -63,9 +63,9 @@ class LifecycleManagerImpl implements LifecycleManager {
|
||||
this.crypto = crypto;
|
||||
this.authorFactory = authorFactory;
|
||||
this.identityManager = identityManager;
|
||||
services = new CopyOnWriteArrayList<Service>();
|
||||
clients = new CopyOnWriteArrayList<Client>();
|
||||
executors = new CopyOnWriteArrayList<ExecutorService>();
|
||||
services = new CopyOnWriteArrayList<>();
|
||||
clients = new CopyOnWriteArrayList<>();
|
||||
executors = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -37,7 +37,7 @@ public class LifecycleModule {
|
||||
|
||||
public LifecycleModule() {
|
||||
// The thread pool is unbounded, so use direct handoff
|
||||
BlockingQueue<Runnable> queue = new SynchronousQueue<Runnable>();
|
||||
BlockingQueue<Runnable> queue = new SynchronousQueue<>();
|
||||
// Discard tasks that are submitted during shutdown
|
||||
RejectedExecutionHandler policy =
|
||||
new ThreadPoolExecutor.DiscardPolicy();
|
||||
|
||||
@@ -21,7 +21,7 @@ class ShutdownManagerImpl implements ShutdownManager {
|
||||
private int nextHandle = 0;
|
||||
|
||||
ShutdownManagerImpl() {
|
||||
hooks = new HashMap<Integer, Thread>();
|
||||
hooks = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,8 +42,8 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
@Inject
|
||||
ConnectionRegistryImpl(EventBus eventBus) {
|
||||
this.eventBus = eventBus;
|
||||
connections = new HashMap<TransportId, Map<ContactId, Integer>>();
|
||||
contactCounts = new HashMap<ContactId, Integer>();
|
||||
connections = new HashMap<>();
|
||||
contactCounts = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -58,7 +58,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
try {
|
||||
Map<ContactId, Integer> m = connections.get(t);
|
||||
if (m == null) {
|
||||
m = new HashMap<ContactId, Integer>();
|
||||
m = new HashMap<>();
|
||||
connections.put(t, m);
|
||||
}
|
||||
Integer count = m.get(c);
|
||||
@@ -124,7 +124,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
|
||||
try {
|
||||
Map<ContactId, Integer> m = connections.get(t);
|
||||
if (m == null) return Collections.emptyList();
|
||||
List<ContactId> ids = new ArrayList<ContactId>(m.keySet());
|
||||
List<ContactId> ids = new ArrayList<>(m.keySet());
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info(ids.size() + " contacts connected");
|
||||
return ids;
|
||||
|
||||
@@ -82,10 +82,10 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
this.settingsManager = settingsManager;
|
||||
this.transportPropertyManager = transportPropertyManager;
|
||||
this.uiCallback = uiCallback;
|
||||
plugins = new ConcurrentHashMap<TransportId, Plugin>();
|
||||
simplexPlugins = new CopyOnWriteArrayList<SimplexPlugin>();
|
||||
duplexPlugins = new CopyOnWriteArrayList<DuplexPlugin>();
|
||||
startLatches = new ConcurrentHashMap<TransportId, CountDownLatch>();
|
||||
plugins = new ConcurrentHashMap<>();
|
||||
simplexPlugins = new CopyOnWriteArrayList<>();
|
||||
duplexPlugins = new CopyOnWriteArrayList<>();
|
||||
startLatches = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,17 +156,17 @@ class PluginManagerImpl implements PluginManager, Service {
|
||||
|
||||
@Override
|
||||
public Collection<SimplexPlugin> getSimplexPlugins() {
|
||||
return new ArrayList<SimplexPlugin>(simplexPlugins);
|
||||
return new ArrayList<>(simplexPlugins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getDuplexPlugins() {
|
||||
return new ArrayList<DuplexPlugin>(duplexPlugins);
|
||||
return new ArrayList<>(duplexPlugins);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<DuplexPlugin> getKeyAgreementPlugins() {
|
||||
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>();
|
||||
List<DuplexPlugin> supported = new ArrayList<>();
|
||||
for (DuplexPlugin d : duplexPlugins)
|
||||
if (d.supportsKeyAgreement()) supported.add(d);
|
||||
return supported;
|
||||
|
||||
@@ -66,7 +66,7 @@ class Poller implements EventListener {
|
||||
this.random = random;
|
||||
this.clock = clock;
|
||||
lock = new ReentrantLock();
|
||||
tasks = new HashMap<TransportId, PollTask>();
|
||||
tasks = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -63,7 +63,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
String oldIpPorts = p.get(PROP_IP_PORTS);
|
||||
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
|
||||
List<InetSocketAddress> locals = new LinkedList<InetSocketAddress>();
|
||||
List<InetSocketAddress> locals = new LinkedList<>();
|
||||
for (InetAddress local : getLocalIpAddresses()) {
|
||||
if (isAcceptableAddress(local)) {
|
||||
// If this is the old address, try to use the same port
|
||||
@@ -82,7 +82,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
private List<InetSocketAddress> parseSocketAddresses(String ipPorts) {
|
||||
if (StringUtils.isNullOrEmpty(ipPorts)) return Collections.emptyList();
|
||||
String[] split = ipPorts.split(SEPARATOR);
|
||||
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>();
|
||||
List<InetSocketAddress> addresses = new ArrayList<>();
|
||||
for (String ipPort : split) {
|
||||
InetSocketAddress a = parseSocketAddress(ipPort);
|
||||
if (a != null) addresses.add(a);
|
||||
@@ -95,7 +95,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
String ipPort = getIpPortString(a);
|
||||
// Get the list of recently used addresses
|
||||
String setting = callback.getSettings().get(PREF_LAN_IP_PORTS);
|
||||
List<String> recent = new ArrayList<String>();
|
||||
List<String> recent = new ArrayList<>();
|
||||
if (!StringUtils.isNullOrEmpty(setting))
|
||||
Collections.addAll(recent, setting.split(SEPARATOR));
|
||||
// Is the address already in the list?
|
||||
@@ -111,7 +111,7 @@ class LanTcpPlugin extends TcpPlugin {
|
||||
recent = recent.subList(0, MAX_ADDRESSES);
|
||||
setting = StringUtils.join(recent, SEPARATOR);
|
||||
// Update the list of addresses shared with contacts
|
||||
List<String> shared = new ArrayList<String>(recent);
|
||||
List<String> shared = new ArrayList<>(recent);
|
||||
Collections.sort(shared);
|
||||
String property = StringUtils.join(shared, SEPARATOR);
|
||||
TransportProperties properties = new TransportProperties();
|
||||
|
||||
@@ -317,7 +317,7 @@ abstract class TcpPlugin implements DuplexPlugin {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<InetAddress> addrs = new ArrayList<InetAddress>();
|
||||
List<InetAddress> addrs = new ArrayList<>();
|
||||
for (NetworkInterface iface : ifaces)
|
||||
addrs.addAll(Collections.list(iface.getInetAddresses()));
|
||||
return addrs;
|
||||
|
||||
@@ -43,7 +43,7 @@ class WanTcpPlugin extends TcpPlugin {
|
||||
// Use the same address and port as last time if available
|
||||
TransportProperties p = callback.getLocalProperties();
|
||||
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
|
||||
List<InetSocketAddress> addrs = new LinkedList<InetSocketAddress>();
|
||||
List<InetSocketAddress> addrs = new LinkedList<>();
|
||||
for (InetAddress a : getLocalIpAddresses()) {
|
||||
if (isAcceptableAddress(a)) {
|
||||
// If this is the old address, try to use the same port
|
||||
|
||||
@@ -144,8 +144,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
public Map<TransportId, TransportProperties> getLocalProperties(
|
||||
Transaction txn) throws DbException {
|
||||
try {
|
||||
Map<TransportId, TransportProperties> local =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> local = new HashMap<>();
|
||||
// Find the latest local update for each transport
|
||||
Map<TransportId, LatestUpdate> latest = findLatestLocal(txn);
|
||||
// Retrieve and parse the latest local properties
|
||||
@@ -192,8 +191,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
@Override
|
||||
public Map<ContactId, TransportProperties> getRemoteProperties(
|
||||
TransportId t) throws DbException {
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
new HashMap<ContactId, TransportProperties>();
|
||||
Map<ContactId, TransportProperties> remote = new HashMap<>();
|
||||
// TODO: Transaction can be read-only when code is simplified
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
@@ -321,8 +319,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
|
||||
private Map<TransportId, LatestUpdate> findLatestLocal(Transaction txn)
|
||||
throws DbException, FormatException {
|
||||
// TODO: This can be simplified before 1.0
|
||||
Map<TransportId, LatestUpdate> latestUpdates =
|
||||
new HashMap<TransportId, LatestUpdate>();
|
||||
Map<TransportId, LatestUpdate> latestUpdates = new HashMap<>();
|
||||
Map<MessageId, BdfDictionary> metadata = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, localGroup.getId());
|
||||
for (Entry<MessageId, BdfDictionary> e : metadata.entrySet()) {
|
||||
|
||||
@@ -41,7 +41,7 @@ class Receiver implements ReadHandler {
|
||||
Receiver(Clock clock, Sender sender) {
|
||||
this.sender = sender;
|
||||
this.clock = clock;
|
||||
dataFrames = new TreeSet<Data>(new SequenceNumberComparator());
|
||||
dataFrames = new TreeSet<>(new SequenceNumberComparator());
|
||||
}
|
||||
|
||||
Data read() throws IOException, InterruptedException {
|
||||
|
||||
@@ -42,7 +42,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
|
||||
this.executor = executor;
|
||||
this.clock = clock;
|
||||
this.writeHandler = writeHandler;
|
||||
writes = new LinkedBlockingQueue<byte[]>();
|
||||
writes = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -46,7 +46,7 @@ class Sender {
|
||||
Sender(Clock clock, WriteHandler writeHandler) {
|
||||
this.clock = clock;
|
||||
this.writeHandler = writeHandler;
|
||||
outstanding = new LinkedList<Outstanding>();
|
||||
outstanding = new LinkedList<>();
|
||||
}
|
||||
|
||||
void sendAck(long sequenceNumber, int windowSize) throws IOException {
|
||||
@@ -136,7 +136,7 @@ class Sender {
|
||||
if (now - o.lastTransmitted > rto) {
|
||||
it.remove();
|
||||
if (retransmit == null)
|
||||
retransmit = new ArrayList<Outstanding>();
|
||||
retransmit = new ArrayList<>();
|
||||
retransmit.add(o);
|
||||
// Update the retransmission timeout
|
||||
rto <<= 1;
|
||||
|
||||
@@ -83,7 +83,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.recordWriter = recordWriter;
|
||||
writerTasks = new LinkedBlockingQueue<ThrowingRunnable<IOException>>();
|
||||
writerTasks = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
|
||||
@@ -116,7 +116,7 @@ class RecordReaderImpl implements RecordReader {
|
||||
private List<MessageId> readMessageIds() throws IOException {
|
||||
if (payloadLength == 0) throw new FormatException();
|
||||
if (payloadLength % UniqueId.LENGTH != 0) throw new FormatException();
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
for (int off = 0; off < payloadLength; off += UniqueId.LENGTH) {
|
||||
byte[] id = new byte[UniqueId.LENGTH];
|
||||
System.arraycopy(payload, off, id, 0, UniqueId.LENGTH);
|
||||
|
||||
@@ -71,7 +71,7 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
|
||||
this.maxLatency = maxLatency;
|
||||
this.recordWriter = recordWriter;
|
||||
outstandingQueries = new AtomicInteger(2); // One per type of record
|
||||
writerTasks = new LinkedBlockingQueue<ThrowingRunnable<IOException>>();
|
||||
writerTasks = new LinkedBlockingQueue<>();
|
||||
}
|
||||
|
||||
@IoExecutor
|
||||
|
||||
@@ -64,8 +64,8 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
this.dbExecutor = dbExecutor;
|
||||
this.validationExecutor = validationExecutor;
|
||||
this.messageFactory = messageFactory;
|
||||
validators = new ConcurrentHashMap<ClientId, MessageValidator>();
|
||||
hooks = new ConcurrentHashMap<ClientId, IncomingMessageHook>();
|
||||
validators = new ConcurrentHashMap<>();
|
||||
hooks = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,7 +105,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@DatabaseExecutor
|
||||
private void validateOutstandingMessages(ClientId c) {
|
||||
try {
|
||||
Queue<MessageId> unvalidated = new LinkedList<MessageId>();
|
||||
Queue<MessageId> unvalidated = new LinkedList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
unvalidated.addAll(db.getMessagesToValidate(txn, c));
|
||||
@@ -170,7 +170,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@DatabaseExecutor
|
||||
private void deliverOutstandingMessages(ClientId c) {
|
||||
try {
|
||||
Queue<MessageId> pending = new LinkedList<MessageId>();
|
||||
Queue<MessageId> pending = new LinkedList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
pending.addAll(db.getPendingMessages(txn, c));
|
||||
@@ -229,8 +229,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
pending.addAll(getPendingDependents(txn, id));
|
||||
if (result.share) {
|
||||
db.setMessageShared(txn, id);
|
||||
toShare = new LinkedList<MessageId>(
|
||||
states.keySet());
|
||||
toShare = new LinkedList<>(states.keySet());
|
||||
}
|
||||
} else {
|
||||
invalidate = getDependentsToInvalidate(txn, id);
|
||||
@@ -277,7 +276,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
} catch (InvalidMessageException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.log(INFO, e.toString(), e);
|
||||
Queue<MessageId> invalidate = new LinkedList<MessageId>();
|
||||
Queue<MessageId> invalidate = new LinkedList<>();
|
||||
invalidate.add(m.getId());
|
||||
invalidateNextMessageAsync(invalidate);
|
||||
}
|
||||
@@ -331,8 +330,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
pending = getPendingDependents(txn, id);
|
||||
if (result.share) {
|
||||
db.setMessageShared(txn, id);
|
||||
toShare =
|
||||
new LinkedList<MessageId>(dependencies);
|
||||
toShare = new LinkedList<>(dependencies);
|
||||
}
|
||||
} else {
|
||||
invalidate = getDependentsToInvalidate(txn, id);
|
||||
@@ -378,7 +376,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@DatabaseExecutor
|
||||
private Queue<MessageId> getPendingDependents(Transaction txn, MessageId m)
|
||||
throws DbException {
|
||||
Queue<MessageId> pending = new LinkedList<MessageId>();
|
||||
Queue<MessageId> pending = new LinkedList<>();
|
||||
Map<MessageId, State> states = db.getMessageDependents(txn, m);
|
||||
for (Entry<MessageId, State> e : states.entrySet()) {
|
||||
if (e.getValue() == PENDING) pending.add(e.getKey());
|
||||
@@ -398,7 +396,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@DatabaseExecutor
|
||||
private void shareOutstandingMessages(ClientId c) {
|
||||
try {
|
||||
Queue<MessageId> toShare = new LinkedList<MessageId>();
|
||||
Queue<MessageId> toShare = new LinkedList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
toShare.addAll(db.getMessagesToShare(txn, c));
|
||||
@@ -496,7 +494,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
|
||||
@DatabaseExecutor
|
||||
private Queue<MessageId> getDependentsToInvalidate(Transaction txn,
|
||||
MessageId m) throws DbException {
|
||||
Queue<MessageId> invalidate = new LinkedList<MessageId>();
|
||||
Queue<MessageId> invalidate = new LinkedList<>();
|
||||
Map<MessageId, State> states = db.getMessageDependents(txn, m);
|
||||
for (Entry<MessageId, State> e : states.entrySet()) {
|
||||
if (e.getValue() != INVALID) invalidate.add(e.getKey());
|
||||
|
||||
@@ -58,15 +58,14 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
|
||||
this.pluginConfig = pluginConfig;
|
||||
this.transportKeyManagerFactory = transportKeyManagerFactory;
|
||||
// Use a ConcurrentHashMap as a thread-safe set
|
||||
activeContacts = new ConcurrentHashMap<ContactId, Boolean>();
|
||||
managers = new ConcurrentHashMap<TransportId, TransportKeyManager>();
|
||||
activeContacts = new ConcurrentHashMap<>();
|
||||
managers = new ConcurrentHashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startService() throws ServiceException {
|
||||
if (used.getAndSet(true)) throw new IllegalStateException();
|
||||
Map<TransportId, Integer> transports =
|
||||
new HashMap<TransportId, Integer>();
|
||||
Map<TransportId, Integer> transports = new HashMap<>();
|
||||
for (SimplexPluginFactory f : pluginConfig.getSimplexFactories())
|
||||
transports.put(f.getId(), f.getMaxLatency());
|
||||
for (DuplexPluginFactory f : pluginConfig.getDuplexFactories())
|
||||
|
||||
@@ -45,7 +45,7 @@ class ReorderingWindow {
|
||||
}
|
||||
|
||||
List<Long> getUnseen() {
|
||||
List<Long> unseen = new ArrayList<Long>(seen.length);
|
||||
List<Long> unseen = new ArrayList<>(seen.length);
|
||||
for (int i = 0; i < seen.length; i++)
|
||||
if (!seen[i]) unseen.add(base + i);
|
||||
return unseen;
|
||||
@@ -69,8 +69,8 @@ class ReorderingWindow {
|
||||
return new Change(added, removed);
|
||||
}
|
||||
// Record the elements that will be added and removed
|
||||
List<Long> added = new ArrayList<Long>(slide);
|
||||
List<Long> removed = new ArrayList<Long>(slide);
|
||||
List<Long> added = new ArrayList<>(slide);
|
||||
List<Long> removed = new ArrayList<>(slide);
|
||||
for (int i = 0; i < slide; i++) {
|
||||
if (!seen[i]) removed.add(base + i);
|
||||
added.add(base + seen.length + i);
|
||||
|
||||
@@ -65,9 +65,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
this.transportId = transportId;
|
||||
rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
|
||||
lock = new ReentrantLock();
|
||||
inContexts = new HashMap<Bytes, TagContext>();
|
||||
outContexts = new HashMap<ContactId, MutableOutgoingKeys>();
|
||||
keys = new HashMap<ContactId, MutableTransportKeys>();
|
||||
inContexts = new HashMap<>();
|
||||
outContexts = new HashMap<>();
|
||||
keys = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -272,8 +272,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
lock.lock();
|
||||
try {
|
||||
// Rotate the keys to the current rotation period
|
||||
Map<ContactId, TransportKeys> snapshot =
|
||||
new HashMap<ContactId, TransportKeys>();
|
||||
Map<ContactId, TransportKeys> snapshot = new HashMap<>();
|
||||
for (Entry<ContactId, MutableTransportKeys> e : keys.entrySet())
|
||||
snapshot.put(e.getKey(), e.getValue().snapshot());
|
||||
RotationResult rotationResult = rotateKeys(snapshot, now);
|
||||
@@ -311,8 +310,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
|
||||
private final Map<ContactId, TransportKeys> current, rotated;
|
||||
|
||||
private RotationResult() {
|
||||
current = new HashMap<ContactId, TransportKeys>();
|
||||
rotated = new HashMap<ContactId, TransportKeys>();
|
||||
current = new HashMap<>();
|
||||
rotated = new HashMap<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newSingleThreadExecutor();
|
||||
// Allow all the tasks to be delegated straight away
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
|
||||
final List<Integer> list = new Vector<Integer>();
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
@@ -49,7 +49,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newSingleThreadExecutor();
|
||||
// Allow two tasks to be delegated at a time
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 2);
|
||||
final List<Integer> list = new Vector<Integer>();
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
@@ -73,7 +73,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newCachedThreadPool();
|
||||
// Allow all the tasks to be delegated straight away
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2);
|
||||
final List<Integer> list = new Vector<Integer>();
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch[] latches = new CountDownLatch[TASKS];
|
||||
for (int i = 0; i < TASKS; i++) latches[i] = new CountDownLatch(1);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
@@ -104,7 +104,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
|
||||
Executor delegate = Executors.newCachedThreadPool();
|
||||
// Allow one task to be delegated at a time
|
||||
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 1);
|
||||
final List<Integer> list = new Vector<Integer>();
|
||||
final List<Integer> list = new Vector<>();
|
||||
final CountDownLatch latch = new CountDownLatch(TASKS);
|
||||
for (int i = 0; i < TASKS; i++) {
|
||||
final int result = i;
|
||||
|
||||
@@ -165,8 +165,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageMetadataAsDictionaryMap() throws Exception {
|
||||
final Map<MessageId, BdfDictionary> map =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
final Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
map.put(messageId, dictionary);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
|
||||
@@ -188,8 +187,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testGetMessageMetadataAsDictionaryQuery() throws Exception {
|
||||
final Map<MessageId, BdfDictionary> map =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
final Map<MessageId, BdfDictionary> map = new HashMap<>();
|
||||
map.put(messageId, dictionary);
|
||||
final BdfDictionary query =
|
||||
BdfDictionary.of(new BdfEntry("query", "me"));
|
||||
|
||||
@@ -132,8 +132,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testActiveContacts() throws Exception {
|
||||
Collection<Contact> activeContacts = Collections.singletonList(contact);
|
||||
final Collection<Contact> contacts =
|
||||
new ArrayList<Contact>(activeContacts);
|
||||
final Collection<Contact> contacts = new ArrayList<>(activeContacts);
|
||||
contacts.add(new Contact(new ContactId(3), remote, local, true, false));
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -69,7 +69,7 @@ public class EllipticCurvePerformanceTest {
|
||||
ECPublicKeyParameters public2 =
|
||||
(ECPublicKeyParameters) keyPair2.getPublic();
|
||||
// Time some ECDH key agreements
|
||||
List<Long> samples = new ArrayList<Long>();
|
||||
List<Long> samples = new ArrayList<>();
|
||||
for (int i = 0; i < SAMPLES; i++) {
|
||||
ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
|
||||
long start = System.nanoTime();
|
||||
@@ -79,7 +79,7 @@ public class EllipticCurvePerformanceTest {
|
||||
}
|
||||
long agreementMedian = median(samples);
|
||||
// Time some signatures
|
||||
List<byte[]> signatures = new ArrayList<byte[]>();
|
||||
List<byte[]> signatures = new ArrayList<>();
|
||||
samples.clear();
|
||||
for (int i = 0; i < SAMPLES; i++) {
|
||||
Digest digest = new Blake2sDigest();
|
||||
|
||||
@@ -145,7 +145,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
private void assertAllDifferent(TransportKeys... transportKeys) {
|
||||
List<SecretKey> secretKeys = new ArrayList<SecretKey>();
|
||||
List<SecretKey> secretKeys = new ArrayList<>();
|
||||
for (TransportKeys k : transportKeys) {
|
||||
secretKeys.add(k.getPreviousIncomingKeys().getTagKey());
|
||||
secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey());
|
||||
@@ -160,7 +160,7 @@ public class KeyDerivationTest extends BrambleTestCase {
|
||||
}
|
||||
|
||||
private void assertAllDifferent(List<SecretKey> keys) {
|
||||
Set<Bytes> set = new HashSet<Bytes>();
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (SecretKey k : keys) assertTrue(set.add(new Bytes(k.getBytes())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TagEncodingTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testKeyAffectsTag() throws Exception {
|
||||
Set<Bytes> set = new HashSet<Bytes>();
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
SecretKey tagKey = TestUtils.getSecretKey();
|
||||
@@ -39,7 +39,7 @@ public class TagEncodingTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testProtocolVersionAffectsTag() throws Exception {
|
||||
Set<Bytes> set = new HashSet<Bytes>();
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION + i, streamNumber);
|
||||
@@ -49,7 +49,7 @@ public class TagEncodingTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testStreamNumberAffectsTag() throws Exception {
|
||||
Set<Bytes> set = new HashSet<Bytes>();
|
||||
Set<Bytes> set = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
byte[] tag = new byte[TAG_LENGTH];
|
||||
crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION, streamNumber + i);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package org.briarproject.bramble.data;
|
||||
|
||||
import org.briarproject.bramble.test.BrambleTestCase;
|
||||
import org.briarproject.bramble.test.TestUtils;
|
||||
import org.briarproject.bramble.util.StringUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -155,7 +154,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriteList() throws IOException {
|
||||
List<Object> l = new ArrayList<Object>();
|
||||
List<Object> l = new ArrayList<>();
|
||||
for (int i = 0; i < 3; i++) l.add(i);
|
||||
w.writeList(l);
|
||||
// LIST tag, elements as integers, END tag
|
||||
@@ -164,7 +163,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testListCanContainNull() throws IOException {
|
||||
List<Object> l = new ArrayList<Object>();
|
||||
List<Object> l = new ArrayList<>();
|
||||
l.add(1);
|
||||
l.add(null);
|
||||
l.add(NULL_VALUE);
|
||||
@@ -177,7 +176,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testWriteDictionary() throws IOException {
|
||||
// Use LinkedHashMap to get predictable iteration order
|
||||
Map<String, Object> m = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> m = new LinkedHashMap<>();
|
||||
for (int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
|
||||
w.writeDictionary(m);
|
||||
// DICTIONARY tag, keys as strings and values as integers, END tag
|
||||
@@ -216,12 +215,12 @@ public class BdfWriterImplTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testWriteNestedDictionariesAndLists() throws IOException {
|
||||
Map<String, Object> inner = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> inner = new LinkedHashMap<>();
|
||||
inner.put("bar", new byte[0]);
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
List<Object> list = new ArrayList<>();
|
||||
list.add(1);
|
||||
list.add(inner);
|
||||
Map<String, Object> outer = new LinkedHashMap<String, Object>();
|
||||
Map<String, Object> outer = new LinkedHashMap<>();
|
||||
outer.put("foo", list);
|
||||
w.writeDictionary(outer);
|
||||
// DICTIONARY tag, "foo" as string, LIST tag, 1 as integer,
|
||||
|
||||
@@ -99,7 +99,7 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testList() throws FormatException {
|
||||
List<Long> l = new ArrayList<Long>(4);
|
||||
List<Long> l = new ArrayList<>(4);
|
||||
l.add(42L);
|
||||
l.add(1337L);
|
||||
l.add(Long.MIN_VALUE);
|
||||
@@ -114,7 +114,7 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testDictionary() throws FormatException {
|
||||
Map<String, Boolean> m = new HashMap<String, Boolean>();
|
||||
Map<String, Boolean> m = new HashMap<>();
|
||||
m.put("1", true);
|
||||
m.put("2", false);
|
||||
|
||||
@@ -130,19 +130,19 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
|
||||
|
||||
@Test
|
||||
public void testComplexDictionary() throws FormatException {
|
||||
Map<String, List> m = new HashMap<String, List>();
|
||||
List<String> one = new ArrayList<String>(3);
|
||||
Map<String, List> m = new HashMap<>();
|
||||
List<String> one = new ArrayList<>(3);
|
||||
one.add("\uFDD0");
|
||||
one.add("\uFDD1");
|
||||
one.add("\uFDD2");
|
||||
m.put("One", one);
|
||||
List<String> two = new ArrayList<String>(2);
|
||||
List<String> two = new ArrayList<>(2);
|
||||
two.add("\u0080");
|
||||
two.add("\uD800\uDC00");
|
||||
m.put("Two", two);
|
||||
d.put("test", m);
|
||||
|
||||
Map<String, Boolean> m2 = new HashMap<String, Boolean>();
|
||||
Map<String, Boolean> m2 = new HashMap<>();
|
||||
m2.put("should be true", true);
|
||||
d.put("another test", m2);
|
||||
|
||||
|
||||
@@ -323,7 +323,7 @@ public class BasicH2Test extends BrambleTestCase {
|
||||
|
||||
private List<String> getNames() throws SQLException {
|
||||
String sql = "SELECT name FROM foo ORDER BY uniqueId";
|
||||
List<String> names = new ArrayList<String>();
|
||||
List<String> names = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = connection.prepareStatement(sql);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
||||
@@ -120,8 +120,8 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
|
||||
private DatabaseComponent createDatabaseComponent(Database<Object> database,
|
||||
EventBus eventBus, ShutdownManager shutdown) {
|
||||
return new DatabaseComponentImpl<Object>(database, Object.class,
|
||||
eventBus, shutdown);
|
||||
return new DatabaseComponentImpl<>(database, Object.class, eventBus,
|
||||
shutdown);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1703,7 +1703,7 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
|
||||
Transaction transaction = db.startTransaction(false);
|
||||
try {
|
||||
db.addLocalMessage(transaction, message, metadata, true);
|
||||
Collection<MessageId> dependencies = new ArrayList<MessageId>(2);
|
||||
Collection<MessageId> dependencies = new ArrayList<>(2);
|
||||
dependencies.add(messageId1);
|
||||
dependencies.add(messageId2);
|
||||
db.addMessageDependencies(transaction, message, dependencies);
|
||||
|
||||
@@ -870,7 +870,7 @@ public class H2DatabaseTest extends BrambleTestCase {
|
||||
assertEquals(0, db.countOfferedMessages(txn, contactId));
|
||||
|
||||
// Add some offered messages and count them
|
||||
List<MessageId> ids = new ArrayList<MessageId>();
|
||||
List<MessageId> ids = new ArrayList<>();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
MessageId m = new MessageId(TestUtils.getRandomId());
|
||||
db.addOfferedMessage(txn, contactId, m);
|
||||
|
||||
@@ -81,7 +81,7 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testGetAuthorStatus() throws DbException {
|
||||
final AuthorId authorId = new AuthorId(TestUtils.getRandomId());
|
||||
final Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
final Collection<Contact> contacts = new ArrayList<>();
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(db).startTransaction(true);
|
||||
|
||||
@@ -15,7 +15,7 @@ public class ShutdownManagerImplTest extends BrambleTestCase {
|
||||
@Test
|
||||
public void testAddAndRemove() {
|
||||
ShutdownManager s = createShutdownManager();
|
||||
Set<Integer> handles = new HashSet<Integer>();
|
||||
Set<Integer> handles = new HashSet<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
int handle = s.addShutdownHook(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -194,8 +194,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
plugin.createKeyAgreementListener(new byte[COMMIT_LENGTH]);
|
||||
assertNotNull(kal);
|
||||
Callable<KeyAgreementConnection> c = kal.listen();
|
||||
FutureTask<KeyAgreementConnection> f =
|
||||
new FutureTask<KeyAgreementConnection>(c);
|
||||
FutureTask<KeyAgreementConnection> f = new FutureTask<>(c);
|
||||
new Thread(f).start();
|
||||
// The plugin should have bound a socket and stored the port number
|
||||
BdfList descriptor = kal.getDescriptor();
|
||||
@@ -291,7 +290,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
|
||||
private static class Callback implements DuplexPluginCallback {
|
||||
|
||||
private final Map<ContactId, TransportProperties> remote =
|
||||
new Hashtable<ContactId, TransportProperties>();
|
||||
new Hashtable<>();
|
||||
private final CountDownLatch propertiesLatch = new CountDownLatch(1);
|
||||
private final CountDownLatch connectionsLatch = new CountDownLatch(1);
|
||||
private final TransportProperties local = new TransportProperties();
|
||||
|
||||
@@ -179,7 +179,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata.put(barUpdateId, BdfDictionary.of(
|
||||
@@ -221,7 +221,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// Old remote updates for the same transport should be deleted
|
||||
final MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion2, BdfDictionary.of(
|
||||
@@ -274,7 +274,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
new BdfEntry("local", false)
|
||||
);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// Old remote updates for the same transport should be deleted
|
||||
final MessageId fooVersion2 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion2, BdfDictionary.of(
|
||||
@@ -322,7 +322,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
final Group contactGroup = getGroup();
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
Map<TransportId, TransportProperties> properties =
|
||||
new LinkedHashMap<TransportId, TransportProperties>();
|
||||
new LinkedHashMap<>();
|
||||
properties.put(new TransportId("foo"), fooProperties);
|
||||
properties.put(new TransportId("bar"), barProperties);
|
||||
|
||||
@@ -359,7 +359,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// A local update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata.put(barUpdateId, BdfDictionary.of(
|
||||
@@ -386,7 +386,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
public void testReturnsLocalProperties() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// A local update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata.put(barUpdateId, BdfDictionary.of(
|
||||
@@ -432,7 +432,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
final Group contactGroup2 = getGroup();
|
||||
final Group contactGroup3 = getGroup();
|
||||
final Map<MessageId, BdfDictionary> messageMetadata3 =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// A remote update for another transport should be ignored
|
||||
MessageId barUpdateId = new MessageId(getRandomId());
|
||||
messageMetadata3.put(barUpdateId, BdfDictionary.of(
|
||||
@@ -641,7 +641,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
|
||||
private void expectGetLocalProperties(final Transaction txn)
|
||||
throws Exception {
|
||||
final Map<MessageId, BdfDictionary> messageMetadata =
|
||||
new LinkedHashMap<MessageId, BdfDictionary>();
|
||||
new LinkedHashMap<>();
|
||||
// The only update for transport "foo" should be returned
|
||||
final MessageId fooVersion999 = new MessageId(getRandomId());
|
||||
messageMetadata.put(fooVersion999, BdfDictionary.of(
|
||||
|
||||
@@ -718,8 +718,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
public void testRecursiveInvalidation() throws Exception {
|
||||
final MessageId messageId3 = new MessageId(TestUtils.getRandomId());
|
||||
final MessageId messageId4 = new MessageId(TestUtils.getRandomId());
|
||||
final Map<MessageId, State> twoDependents =
|
||||
new LinkedHashMap<MessageId, State>();
|
||||
final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
twoDependents.put(messageId1, PENDING);
|
||||
twoDependents.put(messageId2, PENDING);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
@@ -826,12 +825,10 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
raw);
|
||||
final Message message4 = new Message(messageId4, groupId, timestamp,
|
||||
raw);
|
||||
final Map<MessageId, State> twoDependents =
|
||||
new LinkedHashMap<MessageId, State>();
|
||||
final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
|
||||
twoDependents.put(messageId1, PENDING);
|
||||
twoDependents.put(messageId2, PENDING);
|
||||
final Map<MessageId, State> twoDependencies =
|
||||
new LinkedHashMap<MessageId, State>();
|
||||
final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
twoDependencies.put(messageId1, DELIVERED);
|
||||
twoDependencies.put(messageId2, DELIVERED);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
@@ -979,8 +976,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testOnlyReadyPendingDependentsGetDelivered() throws Exception {
|
||||
final Map<MessageId, State> twoDependencies =
|
||||
new LinkedHashMap<MessageId, State>();
|
||||
final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
|
||||
twoDependencies.put(messageId, DELIVERED);
|
||||
twoDependencies.put(messageId2, UNKNOWN);
|
||||
final Transaction txn = new Transaction(null, true);
|
||||
|
||||
@@ -38,7 +38,7 @@ public class LinuxSecureRandomSpiTest extends BrambleTestCase {
|
||||
System.err.println("WARNING: Skipping test, can't run on this OS");
|
||||
return;
|
||||
}
|
||||
Set<Bytes> seeds = new HashSet<Bytes>();
|
||||
Set<Bytes> seeds = new HashSet<>();
|
||||
LinuxSecureRandomSpi engine = new LinuxSecureRandomSpi();
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
byte[] seed = engine.engineGenerateSeed(SEED_BYTES);
|
||||
|
||||
@@ -63,7 +63,7 @@ public class KeyManagerImplTest extends BrambleTestCase {
|
||||
Author remoteAuthor = new Author(remoteAuthorId, "author",
|
||||
getRandomBytes(42));
|
||||
AuthorId localAuthorId = new AuthorId(getRandomId());
|
||||
final Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
final Collection<Contact> contacts = new ArrayList<>();
|
||||
contacts.add(new Contact(contactId, remoteAuthor, localAuthorId, true,
|
||||
true));
|
||||
contacts.add(new Contact(inactiveContactId, remoteAuthor, localAuthorId,
|
||||
|
||||
@@ -63,8 +63,7 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
context.mock(ScheduledExecutorService.class);
|
||||
final Clock clock = context.mock(Clock.class);
|
||||
|
||||
final Map<ContactId, TransportKeys> loaded =
|
||||
new LinkedHashMap<ContactId, TransportKeys>();
|
||||
final Map<ContactId, TransportKeys> loaded = new LinkedHashMap<>();
|
||||
final TransportKeys shouldRotate = createTransportKeys(900, 0);
|
||||
final TransportKeys shouldNotRotate = createTransportKeys(1000, 0);
|
||||
loaded.put(contactId, shouldRotate);
|
||||
@@ -343,7 +342,7 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
|
||||
final boolean alice = true;
|
||||
final TransportKeys transportKeys = createTransportKeys(1000, 0);
|
||||
// Keep a copy of the tags
|
||||
final List<byte[]> tags = new ArrayList<byte[]>();
|
||||
final List<byte[]> tags = new ArrayList<>();
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
|
||||
context.checking(new Expectations() {{
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.List;
|
||||
class EmojiPages {
|
||||
|
||||
static List<EmojiPageModel> getPages(Context ctx) {
|
||||
return Arrays.<EmojiPageModel>asList(
|
||||
return Arrays.asList(
|
||||
new StaticEmojiPageModel(ctx, R.drawable.ic_emoji_smiley_people,
|
||||
R.array.emoji_smiley_people,
|
||||
"emoji_smiley_people.png"),
|
||||
|
||||
@@ -86,7 +86,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
this.identityManager = identityManager;
|
||||
this.blogFactory = blogFactory;
|
||||
this.blogPostFactory = blogPostFactory;
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveBlogHook>();
|
||||
removeHooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -404,7 +404,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
throws DbException {
|
||||
|
||||
Collection<Blog> allBlogs = getBlogs();
|
||||
List<Blog> blogs = new ArrayList<Blog>();
|
||||
List<Blog> blogs = new ArrayList<>();
|
||||
for (Blog b : allBlogs) {
|
||||
if (b.getAuthor().equals(localAuthor)) {
|
||||
blogs.add(b);
|
||||
@@ -421,7 +421,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
@Override
|
||||
public Collection<Blog> getBlogs() throws DbException {
|
||||
try {
|
||||
List<Blog> blogs = new ArrayList<Blog>();
|
||||
List<Blog> blogs = new ArrayList<>();
|
||||
Collection<Group> groups;
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
@@ -492,7 +492,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
new BdfEntry(KEY_TYPE, COMMENT.getInt())
|
||||
);
|
||||
|
||||
Collection<BlogPostHeader> headers = new ArrayList<BlogPostHeader>();
|
||||
Collection<BlogPostHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata1 =
|
||||
@@ -500,20 +500,18 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
Map<MessageId, BdfDictionary> metadata2 =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g, query2);
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
new HashMap<MessageId, BdfDictionary>(
|
||||
metadata1.size() + metadata2.size());
|
||||
new HashMap<>(metadata1.size() + metadata2.size());
|
||||
metadata.putAll(metadata1);
|
||||
metadata.putAll(metadata2);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
authors.add(new AuthorId(
|
||||
entry.getValue().getDictionary(KEY_AUTHOR)
|
||||
.getRaw(KEY_AUTHOR_ID)));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> authorStatuses =
|
||||
new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> authorStatuses = new HashMap<>();
|
||||
for (AuthorId authorId : authors) {
|
||||
authorStatuses.put(authorId,
|
||||
identityManager.getAuthorStatus(txn, authorId));
|
||||
@@ -562,7 +560,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
GroupId groupId, MessageId id, BdfDictionary meta)
|
||||
throws DbException, FormatException {
|
||||
return getPostHeaderFromMetadata(txn, groupId, id, meta,
|
||||
Collections.<AuthorId, Status>emptyMap());
|
||||
Collections.emptyMap());
|
||||
}
|
||||
|
||||
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,
|
||||
|
||||
@@ -96,7 +96,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
|
||||
private QueueState loadQueueState(Transaction txn, GroupId g)
|
||||
throws DbException {
|
||||
try {
|
||||
TreeMap<Long, MessageId> pending = new TreeMap<Long, MessageId>();
|
||||
TreeMap<Long, MessageId> pending = new TreeMap<>();
|
||||
Metadata groupMeta = db.getGroupMetadata(txn, g);
|
||||
byte[] raw = groupMeta.get(QUEUE_STATE_KEY);
|
||||
if (raw == null) return new QueueState(0, 0, pending);
|
||||
@@ -231,7 +231,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
|
||||
m.getTimestamp(), queuePosition, m.getRaw());
|
||||
queueState.incomingPosition++;
|
||||
// Collect any consecutive messages
|
||||
List<MessageId> consecutive = new ArrayList<MessageId>();
|
||||
List<MessageId> consecutive = new ArrayList<>();
|
||||
MessageId next;
|
||||
while ((next = queueState.popIncomingMessageId()) != null)
|
||||
consecutive.add(next);
|
||||
|
||||
@@ -19,10 +19,9 @@ import javax.annotation.concurrent.ThreadSafe;
|
||||
public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
implements MessageTree<T> {
|
||||
|
||||
private final Map<MessageId, List<T>> nodeMap =
|
||||
new HashMap<MessageId, List<T>>();
|
||||
private final List<T> roots = new ArrayList<T>();
|
||||
private final List<List<T>> unsortedLists = new ArrayList<List<T>>();
|
||||
private final Map<MessageId, List<T>> nodeMap = new HashMap<>();
|
||||
private final List<T> roots = new ArrayList<>();
|
||||
private final List<List<T>> unsortedLists = new ArrayList<>();
|
||||
|
||||
private Comparator<T> comparator = new Comparator<T>() {
|
||||
@Override
|
||||
@@ -41,7 +40,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
public synchronized void add(Collection<T> nodes) {
|
||||
// add all nodes to the node map
|
||||
for (T node : nodes) {
|
||||
nodeMap.put(node.getId(), new ArrayList<T>());
|
||||
nodeMap.put(node.getId(), new ArrayList<>());
|
||||
}
|
||||
// parse the nodes for dependencies
|
||||
for (T node : nodes) {
|
||||
@@ -100,7 +99,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
|
||||
|
||||
@Override
|
||||
public synchronized Collection<T> depthFirstOrder() {
|
||||
List<T> orderedList = new ArrayList<T>();
|
||||
List<T> orderedList = new ArrayList<>();
|
||||
for (T root : roots) {
|
||||
traverse(orderedList, root, 0);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
db.addGroup(txn, g);
|
||||
|
||||
// Add initial metadata
|
||||
List<Feed> feeds = new ArrayList<Feed>(0);
|
||||
List<Feed> feeds = new ArrayList<>(0);
|
||||
storeFeeds(txn, feeds);
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
}
|
||||
|
||||
private List<Feed> getFeeds(Transaction txn) throws DbException {
|
||||
List<Feed> feeds = new ArrayList<Feed>();
|
||||
List<Feed> feeds = new ArrayList<>();
|
||||
Group g = getLocalGroup();
|
||||
try {
|
||||
BdfDictionary d =
|
||||
@@ -300,7 +300,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
|
||||
}
|
||||
|
||||
// Fetch and update all feeds
|
||||
List<Feed> newFeeds = new ArrayList<Feed>(feeds.size());
|
||||
List<Feed> newFeeds = new ArrayList<>(feeds.size());
|
||||
for (Feed feed : feeds) {
|
||||
try {
|
||||
newFeeds.add(fetchFeed(feed));
|
||||
|
||||
@@ -75,7 +75,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
this.forumFactory = forumFactory;
|
||||
this.forumPostFactory = forumPostFactory;
|
||||
this.messageTracker = messageTracker;
|
||||
removeHooks = new CopyOnWriteArrayList<RemoveForumHook>();
|
||||
removeHooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -203,7 +203,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
List<Forum> forums = new ArrayList<Forum>();
|
||||
List<Forum> forums = new ArrayList<>();
|
||||
for (Group g : groups) forums.add(parseForum(g));
|
||||
return forums;
|
||||
} catch (FormatException e) {
|
||||
@@ -232,13 +232,13 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
public Collection<ForumPostHeader> getPostHeaders(GroupId g)
|
||||
throws DbException {
|
||||
|
||||
Collection<ForumPostHeader> headers = new ArrayList<ForumPostHeader>();
|
||||
Collection<ForumPostHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
|
||||
BdfDictionary d =
|
||||
entry.getValue().getDictionary(KEY_AUTHOR, null);
|
||||
@@ -246,7 +246,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
authors.add(new AuthorId(d.getRaw(KEY_ID)));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||
for (AuthorId id : authors) {
|
||||
statuses.put(id, identityManager.getAuthorStatus(txn, id));
|
||||
}
|
||||
@@ -290,8 +290,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
|
||||
|
||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||
BdfDictionary meta) throws DbException, FormatException {
|
||||
return getForumPostHeader(txn, id, meta,
|
||||
Collections.<AuthorId, Status>emptyMap());
|
||||
return getForumPostHeader(txn, id, meta, Collections.emptyMap());
|
||||
}
|
||||
|
||||
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
|
||||
|
||||
@@ -106,7 +106,7 @@ class IntroduceeEngine
|
||||
else return abortSession(currentState, localState);
|
||||
}
|
||||
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(1);
|
||||
List<BdfDictionary> messages = new ArrayList<>(1);
|
||||
if (action == LOCAL_ACCEPT || action == LOCAL_DECLINE) {
|
||||
localState.put(STATE, nextState.getValue());
|
||||
localState.put(ANSWERED, true);
|
||||
@@ -136,8 +136,7 @@ class IntroduceeEngine
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
List<Event> events = Collections.emptyList();
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false,
|
||||
false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -204,16 +203,15 @@ class IntroduceeEngine
|
||||
}
|
||||
// we are done (probably declined response), ignore & delete message
|
||||
else if (currentState == FINISHED) {
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(true,
|
||||
false, localState,
|
||||
return new StateUpdate<>(true, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
Collections.emptyList());
|
||||
}
|
||||
// this should not happen
|
||||
else {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -361,15 +359,14 @@ class IntroduceeEngine
|
||||
Event event = new IntroductionAbortedEvent(contactId, sessionId);
|
||||
List<Event> events = Collections.singletonList(event);
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, messages, events);
|
||||
return new StateUpdate<>(false, false, localState, messages, events);
|
||||
}
|
||||
|
||||
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
|
||||
BdfDictionary localState) throws FormatException {
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
return new StateUpdate<>(false, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -539,8 +539,7 @@ class IntroduceeManager {
|
||||
private Map<TransportId, TransportProperties> parseTransportProperties(
|
||||
BdfDictionary d) throws FormatException {
|
||||
|
||||
Map<TransportId, TransportProperties> tpMap =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> tpMap = new HashMap<>();
|
||||
BdfDictionary tpMapDict = d.getDictionary(TRANSPORT);
|
||||
for (String key : tpMapDict.keySet()) {
|
||||
TransportId transportId = new TransportId(key);
|
||||
|
||||
@@ -102,7 +102,7 @@ class IntroducerEngine
|
||||
localState.put(STATE, nextState.getValue());
|
||||
if (action == LOCAL_REQUEST) {
|
||||
// create the introduction requests for both contacts
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2);
|
||||
List<BdfDictionary> messages = new ArrayList<>(2);
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_REQUEST);
|
||||
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
|
||||
@@ -129,8 +129,7 @@ class IntroducerEngine
|
||||
logLocalAction(currentState, localState);
|
||||
|
||||
List<Event> events = Collections.emptyList();
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false,
|
||||
false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unknown Local Action");
|
||||
@@ -206,7 +205,7 @@ class IntroducerEngine
|
||||
} else {
|
||||
throw new IllegalArgumentException("Bad state");
|
||||
}
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
return new StateUpdate<>(false, false,
|
||||
localState, messages, events);
|
||||
} catch (FormatException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
@@ -334,7 +333,7 @@ class IntroducerEngine
|
||||
currentState.name());
|
||||
|
||||
localState.put(STATE, ERROR.getValue());
|
||||
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2);
|
||||
List<BdfDictionary> messages = new ArrayList<>(2);
|
||||
BdfDictionary msg1 = new BdfDictionary();
|
||||
msg1.put(TYPE, TYPE_ABORT);
|
||||
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
|
||||
@@ -347,7 +346,7 @@ class IntroducerEngine
|
||||
messages.add(msg2);
|
||||
|
||||
// send one abort event per contact
|
||||
List<Event> events = new ArrayList<Event>(2);
|
||||
List<Event> events = new ArrayList<>(2);
|
||||
SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
|
||||
ContactId contactId1 =
|
||||
new ContactId(localState.getLong(CONTACT_ID_1).intValue());
|
||||
@@ -358,15 +357,14 @@ class IntroducerEngine
|
||||
Event event2 = new IntroductionAbortedEvent(contactId2, sessionId);
|
||||
events.add(event2);
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, messages, events);
|
||||
return new StateUpdate<>(false, false, localState, messages, events);
|
||||
}
|
||||
|
||||
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
|
||||
BdfDictionary localState) throws FormatException {
|
||||
|
||||
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false,
|
||||
localState, Collections.<BdfDictionary>emptyList(),
|
||||
Collections.<Event>emptyList());
|
||||
return new StateUpdate<>(false, false, localState,
|
||||
Collections.<BdfDictionary>emptyList(),
|
||||
Collections.emptyList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,8 +336,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
|
||||
public Collection<IntroductionMessage> getIntroductionMessages(
|
||||
ContactId contactId) throws DbException {
|
||||
|
||||
Collection<IntroductionMessage> list =
|
||||
new ArrayList<IntroductionMessage>();
|
||||
Collection<IntroductionMessage> list = new ArrayList<>();
|
||||
|
||||
Map<MessageId, BdfDictionary> metadata;
|
||||
Collection<MessageStatus> statuses;
|
||||
|
||||
@@ -24,7 +24,7 @@ class ConversationManagerImpl implements ConversationManager {
|
||||
@Inject
|
||||
ConversationManagerImpl(DatabaseComponent db) {
|
||||
this.db = db;
|
||||
clients = new CopyOnWriteArraySet<ConversationClient>();
|
||||
clients = new CopyOnWriteArraySet<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -176,8 +176,7 @@ class MessagingManagerImpl extends ConversationClientImpl
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
}
|
||||
Collection<PrivateMessageHeader> headers =
|
||||
new ArrayList<PrivateMessageHeader>();
|
||||
Collection<PrivateMessageHeader> headers = new ArrayList<>();
|
||||
for (MessageStatus s : statuses) {
|
||||
MessageId id = s.getMessageId();
|
||||
BdfDictionary meta = metadata.get(id);
|
||||
|
||||
@@ -202,7 +202,7 @@ class GroupMessageValidator extends BdfMessageValidator {
|
||||
|
||||
// The parent post, if any,
|
||||
// and the member's previous message are dependencies
|
||||
Collection<MessageId> dependencies = new ArrayList<MessageId>();
|
||||
Collection<MessageId> dependencies = new ArrayList<>();
|
||||
if (parentId != null) dependencies.add(new MessageId(parentId));
|
||||
dependencies.add(new MessageId(previousMessageId));
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
this.contactManager = contactManager;
|
||||
this.identityManager = identityManager;
|
||||
this.messageTracker = messageTracker;
|
||||
hooks = new CopyOnWriteArrayList<PrivateGroupHook>();
|
||||
hooks = new CopyOnWriteArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,7 +284,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
}
|
||||
try {
|
||||
Collection<PrivateGroup> privateGroups =
|
||||
new ArrayList<PrivateGroup>(groups.size());
|
||||
new ArrayList<>(groups.size());
|
||||
for (Group g : groups) {
|
||||
privateGroups.add(privateGroupFactory.parsePrivateGroup(g));
|
||||
}
|
||||
@@ -324,20 +324,19 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
@Override
|
||||
public Collection<GroupMessageHeader> getHeaders(GroupId g)
|
||||
throws DbException {
|
||||
Collection<GroupMessageHeader> headers =
|
||||
new ArrayList<GroupMessageHeader>();
|
||||
Collection<GroupMessageHeader> headers = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Map<MessageId, BdfDictionary> metadata =
|
||||
clientHelper.getMessageMetadataAsDictionary(txn, g);
|
||||
// get all authors we need to get the status for
|
||||
Set<AuthorId> authors = new HashSet<AuthorId>();
|
||||
Set<AuthorId> authors = new HashSet<>();
|
||||
for (BdfDictionary meta : metadata.values()) {
|
||||
byte[] idBytes = meta.getRaw(KEY_MEMBER_ID);
|
||||
authors.add(new AuthorId(idBytes));
|
||||
}
|
||||
// get statuses for all authors
|
||||
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>();
|
||||
Map<AuthorId, Status> statuses = new HashMap<>();
|
||||
for (AuthorId id : authors) {
|
||||
statuses.put(id, identityManager.getAuthorStatus(txn, id));
|
||||
}
|
||||
@@ -404,7 +403,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
public Collection<GroupMember> getMembers(GroupId g) throws DbException {
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
Collection<GroupMember> members = new ArrayList<GroupMember>();
|
||||
Collection<GroupMember> members = new ArrayList<>();
|
||||
Map<Author, Visibility> authors = getMembers(txn, g);
|
||||
LocalAuthor la = identityManager.getLocalAuthor(txn);
|
||||
PrivateGroup privateGroup = getPrivateGroup(txn, g);
|
||||
@@ -434,8 +433,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta =
|
||||
clientHelper.getGroupMetadataAsDictionary(txn, g);
|
||||
BdfList list = meta.getList(GROUP_KEY_MEMBERS);
|
||||
Map<Author, Visibility> members =
|
||||
new HashMap<Author, Visibility>(list.size());
|
||||
Map<Author, Visibility> members = new HashMap<>(list.size());
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
BdfDictionary d = list.getDictionary(i);
|
||||
Author member = getAuthor(d);
|
||||
@@ -584,7 +582,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta, boolean local)
|
||||
throws DbException, FormatException {
|
||||
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap());
|
||||
m.getId(), meta, Collections.emptyMap());
|
||||
String body = getMessageBody(clientHelper.toList(m));
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
|
||||
local));
|
||||
@@ -594,7 +592,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
|
||||
BdfDictionary meta, boolean local, Visibility v)
|
||||
throws DbException, FormatException {
|
||||
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(),
|
||||
m.getId(), meta, Collections.<AuthorId, Status>emptyMap(), v);
|
||||
m.getId(), meta, Collections.emptyMap(), v);
|
||||
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
|
||||
local));
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
messages = new ArrayList<InvitationMessage>(results.size());
|
||||
messages = new ArrayList<>(results.size());
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
@@ -427,7 +427,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
|
||||
|
||||
@Override
|
||||
public Collection<GroupInvitationItem> getInvitations() throws DbException {
|
||||
List<GroupInvitationItem> items = new ArrayList<GroupInvitationItem>();
|
||||
List<GroupInvitationItem> items = new ArrayList<>();
|
||||
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
|
||||
@@ -17,10 +17,10 @@ import javax.annotation.concurrent.Immutable;
|
||||
|
||||
import static org.briarproject.briar.sharing.MessageType.INVITE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_LOCAL;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_READ;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
|
||||
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI;
|
||||
@@ -91,7 +91,7 @@ abstract class MessageParserImpl<S extends Shareable>
|
||||
BdfList descriptor = body.getList(2);
|
||||
S shareable = createShareable(descriptor);
|
||||
String message = body.getOptionalString(3);
|
||||
return new InviteMessage<S>(m.getId(), previousMessageId,
|
||||
return new InviteMessage<>(m.getId(), previousMessageId,
|
||||
m.getGroupId(), shareable, message, m.getTimestamp());
|
||||
}
|
||||
|
||||
|
||||
@@ -311,7 +311,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
|
||||
Map<MessageId, BdfDictionary> results = clientHelper
|
||||
.getMessageMetadataAsDictionary(txn, contactGroupId, query);
|
||||
messages = new ArrayList<InvitationMessage>(results.size());
|
||||
messages = new ArrayList<>(results.size());
|
||||
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
|
||||
MessageId m = e.getKey();
|
||||
MessageMetadata meta =
|
||||
@@ -367,11 +367,9 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public Collection<SharingInvitationItem> getInvitations()
|
||||
throws DbException {
|
||||
List<SharingInvitationItem> items =
|
||||
new ArrayList<SharingInvitationItem>();
|
||||
List<SharingInvitationItem> items = new ArrayList<>();
|
||||
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
|
||||
Map<S, Collection<Contact>> sharers =
|
||||
new HashMap<S, Collection<Contact>>();
|
||||
Map<S, Collection<Contact>> sharers = new HashMap<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
// get invitations from each contact
|
||||
@@ -387,7 +385,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
if (sharers.containsKey(s)) {
|
||||
sharers.get(s).add(c);
|
||||
} else {
|
||||
Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
contacts.add(c);
|
||||
sharers.put(s, contacts);
|
||||
}
|
||||
@@ -414,7 +412,7 @@ abstract class SharingManagerImpl<S extends Shareable>
|
||||
@Override
|
||||
public Collection<Contact> getSharedWith(GroupId g) throws DbException {
|
||||
// TODO report also pending invitations
|
||||
Collection<Contact> contacts = new ArrayList<Contact>();
|
||||
Collection<Contact> contacts = new ArrayList<>();
|
||||
Transaction txn = db.startTransaction(true);
|
||||
try {
|
||||
for (Contact c : db.getContacts(txn)) {
|
||||
|
||||
@@ -88,8 +88,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
private final Executor ioExecutor;
|
||||
|
||||
private final Random random = new Random();
|
||||
private final Map<Contact, LocalAuthor> localAuthors =
|
||||
new HashMap<Contact, LocalAuthor>();
|
||||
private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
|
||||
@@ -146,7 +145,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
private List<Contact> createContacts() throws DbException {
|
||||
List<Contact> contacts = new ArrayList<Contact>(NUM_CONTACTS);
|
||||
List<Contact> contacts = new ArrayList<>(NUM_CONTACTS);
|
||||
LocalAuthor localAuthor = identityManager.getLocalAuthor();
|
||||
for (int i = 0; i < NUM_CONTACTS; i++) {
|
||||
Contact contact = addRandomContact(localAuthor);
|
||||
@@ -206,8 +205,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
}
|
||||
|
||||
private Map<TransportId, TransportProperties> getRandomTransportProperties() {
|
||||
Map<TransportId, TransportProperties> props =
|
||||
new HashMap<TransportId, TransportProperties>();
|
||||
Map<TransportId, TransportProperties> props = new HashMap<>();
|
||||
|
||||
// Bluetooth
|
||||
TransportProperties bt = new TransportProperties();
|
||||
@@ -339,7 +337,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private List<Forum> createForums(List<Contact> contacts)
|
||||
throws DbException {
|
||||
List<Forum> forums = new ArrayList<Forum>(NUM_FORUMS);
|
||||
List<Forum> forums = new ArrayList<>(NUM_FORUMS);
|
||||
for (int i = 0; i < NUM_FORUMS; i++) {
|
||||
// create forum
|
||||
String name = GROUP_NAMES[random.nextInt(GROUP_NAMES.length)];
|
||||
@@ -367,7 +365,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
|
||||
|
||||
private void createRandomForumPosts(Forum forum, List<Contact> contacts)
|
||||
throws DbException {
|
||||
List<ForumPost> posts = new ArrayList<ForumPost>();
|
||||
List<ForumPost> posts = new ArrayList<>();
|
||||
for (int i = 0; i < NUM_FORUM_POSTS; i++) {
|
||||
Contact contact = contacts.get(random.nextInt(contacts.size()));
|
||||
LocalAuthor author = localAuthors.get(contact);
|
||||
|
||||
@@ -131,7 +131,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message is too short to be a valid queue message
|
||||
@@ -142,7 +142,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
}});
|
||||
|
||||
@@ -175,7 +175,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
// The message has a negative queue position
|
||||
@@ -188,7 +188,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
}});
|
||||
|
||||
@@ -221,7 +221,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.mock(ValidationManager.class);
|
||||
|
||||
final AtomicReference<MessageValidator> captured =
|
||||
new AtomicReference<MessageValidator>();
|
||||
new AtomicReference<>();
|
||||
final QueueMessageValidator queueMessageValidator =
|
||||
context.mock(QueueMessageValidator.class);
|
||||
final Metadata metadata = new Metadata();
|
||||
@@ -235,7 +235,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerMessageValidator(with(clientId),
|
||||
with(any(MessageValidator.class)));
|
||||
will(new CaptureArgumentAction<MessageValidator>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
MessageValidator.class, 1));
|
||||
// The message should be delegated
|
||||
oneOf(queueMessageValidator).validateMessage(
|
||||
@@ -268,7 +268,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
final ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
@@ -284,7 +284,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -320,7 +320,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
final ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
@@ -338,7 +338,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -376,7 +376,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
final ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
@@ -393,7 +393,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
@@ -434,7 +434,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
final ValidationManager validationManager =
|
||||
context.mock(ValidationManager.class);
|
||||
final AtomicReference<IncomingMessageHook> captured =
|
||||
new AtomicReference<IncomingMessageHook>();
|
||||
new AtomicReference<>();
|
||||
final IncomingQueueMessageHook incomingQueueMessageHook =
|
||||
context.mock(IncomingQueueMessageHook.class);
|
||||
|
||||
@@ -458,7 +458,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
|
||||
context.checking(new Expectations() {{
|
||||
oneOf(validationManager).registerIncomingMessageHook(with(clientId),
|
||||
with(any(IncomingMessageHook.class)));
|
||||
will(new CaptureArgumentAction<IncomingMessageHook>(captured,
|
||||
will(new CaptureArgumentAction<>(captured,
|
||||
IncomingMessageHook.class, 1));
|
||||
oneOf(db).getGroupMetadata(txn, groupId);
|
||||
will(returnValue(groupMetadata));
|
||||
|
||||
@@ -19,7 +19,7 @@ public class MessageTreeImplTest {
|
||||
|
||||
@Test
|
||||
public void testMessageTree() {
|
||||
tree = new MessageTreeImpl<TestNode>();
|
||||
tree = new MessageTreeImpl<>();
|
||||
testSimpleTree();
|
||||
tree.clear();
|
||||
testSimpleTree();
|
||||
|
||||
@@ -105,7 +105,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
|
||||
@Test
|
||||
public void testPostFeedEntriesEmptyDate() throws Exception {
|
||||
final Transaction txn = new Transaction(null, false);
|
||||
List<SyndEntry> entries = new ArrayList<SyndEntry>();
|
||||
List<SyndEntry> entries = new ArrayList<>();
|
||||
entries.add(new SyndEntryImpl());
|
||||
final SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setUpdatedDate(new Date());
|
||||
|
||||
@@ -464,7 +464,7 @@ public class IntroductionIntegrationTest
|
||||
assertTrue(listener1.requestReceived);
|
||||
|
||||
// get SessionId
|
||||
List<IntroductionMessage> list = new ArrayList<IntroductionMessage>(
|
||||
List<IntroductionMessage> list = new ArrayList<>(
|
||||
introductionManager1.getIntroductionMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
assertTrue(list.get(0) instanceof IntroductionRequest);
|
||||
|
||||
@@ -172,7 +172,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, creator,
|
||||
Collections.<MessageId>emptyList());
|
||||
Collections.emptyList());
|
||||
assertTrue(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
}
|
||||
@@ -325,7 +325,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
|
||||
BdfMessageContext messageContext =
|
||||
validator.validateMessage(message, group, body);
|
||||
assertExpectedMessageContext(messageContext, JOIN, member,
|
||||
Collections.<MessageId>emptyList());
|
||||
Collections.emptyList());
|
||||
assertFalse(messageContext.getDictionary()
|
||||
.getBoolean(KEY_INITIAL_JOIN_MSG));
|
||||
}
|
||||
|
||||
@@ -631,8 +631,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
final Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final long time1 = 1L, time2 = 2L;
|
||||
@@ -705,8 +704,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
|
||||
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
|
||||
final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
|
||||
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
|
||||
final Map<MessageId, BdfDictionary> results =
|
||||
new HashMap<MessageId, BdfDictionary>();
|
||||
final Map<MessageId, BdfDictionary> results = new HashMap<>();
|
||||
results.put(message.getId(), meta);
|
||||
results.put(messageId2, meta2);
|
||||
final Message message2 = new Message(messageId2, contactGroup.getId(),
|
||||
|
||||
@@ -146,9 +146,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(blog2));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -222,9 +221,8 @@ public class BlogSharingIntegrationTest
|
||||
assertTrue(blogManager1.getBlogs().contains(rssBlog));
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -286,9 +284,8 @@ public class BlogSharingIntegrationTest
|
||||
assertEquals(0, blogSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(blogSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
blogSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the message
|
||||
for (InvitationMessage m : list) {
|
||||
|
||||
@@ -94,23 +94,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testAddingContactFreshState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(0);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
|
||||
testAddingContact(sessions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddingContactExistingState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(1);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testAddingContact(sessions);
|
||||
}
|
||||
|
||||
@Test(expected = DbException.class)
|
||||
public void testAddingContactMultipleSessions() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(2);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testAddingContact(sessions);
|
||||
@@ -118,23 +115,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
|
||||
|
||||
@Test
|
||||
public void testRemovingBlogFreshState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(0);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemovingBlogExistingState() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(1);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testRemovingBlog(sessions);
|
||||
}
|
||||
|
||||
@Test(expected = DbException.class)
|
||||
public void testRemovingBlogMultipleSessions() throws Exception {
|
||||
Map<MessageId, BdfDictionary> sessions =
|
||||
new HashMap<MessageId, BdfDictionary>(2);
|
||||
Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
sessions.put(new MessageId(getRandomId()), new BdfDictionary());
|
||||
testRemovingBlog(sessions);
|
||||
|
||||
@@ -129,9 +129,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(1, forumManager1.getForums().size());
|
||||
|
||||
// invitee has one invitation message from sharer
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check other things are alright with the forum message
|
||||
for (InvitationMessage m : list) {
|
||||
@@ -189,9 +188,8 @@ public class ForumSharingIntegrationTest
|
||||
assertEquals(0, forumSharingManager1.getInvitations().size());
|
||||
|
||||
// invitee has one invitation message from sharer and one response
|
||||
List<InvitationMessage> list =
|
||||
new ArrayList<InvitationMessage>(forumSharingManager1
|
||||
.getInvitationMessages(contactId0From1));
|
||||
List<InvitationMessage> list = new ArrayList<>(
|
||||
forumSharingManager1.getInvitationMessages(contactId0From1));
|
||||
assertEquals(2, list.size());
|
||||
// check things are alright with the forum message
|
||||
for (InvitationMessage m : list) {
|
||||
|
||||
Reference in New Issue
Block a user