Diamond operators.

This commit is contained in:
akwizgran
2017-11-15 17:28:01 +00:00
committed by Torsten Grote
parent 2d26af1ae2
commit 27328afe3c
83 changed files with 268 additions and 326 deletions

View File

@@ -23,7 +23,7 @@ public class BdfMessageContext {
} }
public BdfMessageContext(BdfDictionary dictionary) { public BdfMessageContext(BdfDictionary dictionary) {
this(dictionary, Collections.<MessageId>emptyList()); this(dictionary, Collections.emptyList());
} }
public BdfDictionary getDictionary() { public BdfDictionary getDictionary() {

View File

@@ -45,7 +45,7 @@ public class Transaction {
* committed. * committed.
*/ */
public void attach(Event e) { public void attach(Event e) {
if (events == null) events = new ArrayList<Event>(); if (events == null) events = new ArrayList<>();
events.add(e); events.add(e);
} }

View File

@@ -22,7 +22,7 @@ public class MessageContext {
} }
public MessageContext(Metadata metadata) { public MessageContext(Metadata metadata) {
this(metadata, Collections.<MessageId>emptyList()); this(metadata, Collections.emptyList());
} }
public Metadata getMetadata() { public Metadata getMetadata() {

View File

@@ -24,7 +24,7 @@ public class PoliteExecutor implements Executor {
private final Object lock = new Object(); private final Object lock = new Object();
@GuardedBy("lock") @GuardedBy("lock")
private final Queue<Runnable> queue = new LinkedList<Runnable>(); private final Queue<Runnable> queue = new LinkedList<>();
private final Executor delegate; private final Executor delegate;
private final int maxConcurrentTasks; private final int maxConcurrentTasks;
private final Logger log; private final Logger log;

View File

@@ -201,8 +201,7 @@ class ClientHelperImpl implements ClientHelper {
public Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary( public Map<MessageId, BdfDictionary> getMessageMetadataAsDictionary(
Transaction txn, GroupId g) throws DbException, FormatException { Transaction txn, GroupId g) throws DbException, FormatException {
Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g); Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g);
Map<MessageId, BdfDictionary> parsed = Map<MessageId, BdfDictionary> parsed = new HashMap<>(raw.size());
new HashMap<MessageId, BdfDictionary>(raw.size());
for (Entry<MessageId, Metadata> e : raw.entrySet()) for (Entry<MessageId, Metadata> e : raw.entrySet())
parsed.put(e.getKey(), metadataParser.parse(e.getValue())); parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
return parsed; return parsed;
@@ -229,8 +228,7 @@ class ClientHelperImpl implements ClientHelper {
FormatException { FormatException {
Metadata metadata = metadataEncoder.encode(query); Metadata metadata = metadataEncoder.encode(query);
Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g, metadata); Map<MessageId, Metadata> raw = db.getMessageMetadata(txn, g, metadata);
Map<MessageId, BdfDictionary> parsed = Map<MessageId, BdfDictionary> parsed = new HashMap<>(raw.size());
new HashMap<MessageId, BdfDictionary>(raw.size());
for (Entry<MessageId, Metadata> e : raw.entrySet()) for (Entry<MessageId, Metadata> e : raw.entrySet())
parsed.put(e.getKey(), metadataParser.parse(e.getValue())); parsed.put(e.getKey(), metadataParser.parse(e.getValue()));
return parsed; return parsed;

View File

@@ -276,8 +276,7 @@ class ContactExchangeTaskImpl extends Thread implements ContactExchangeTask {
private Map<TransportId, TransportProperties> receiveTransportProperties( private Map<TransportId, TransportProperties> receiveTransportProperties(
BdfReader r) throws IOException { BdfReader r) throws IOException {
Map<TransportId, TransportProperties> remote = Map<TransportId, TransportProperties> remote = new HashMap<>();
new HashMap<TransportId, TransportProperties>();
r.readListStart(); r.readListStart();
while (!r.hasListEnd()) { while (!r.hasListEnd()) {
r.readListStart(); r.readListStart();

View File

@@ -34,8 +34,8 @@ class ContactManagerImpl implements ContactManager {
ContactManagerImpl(DatabaseComponent db, KeyManager keyManager) { ContactManagerImpl(DatabaseComponent db, KeyManager keyManager) {
this.db = db; this.db = db;
this.keyManager = keyManager; this.keyManager = keyManager;
addHooks = new CopyOnWriteArrayList<AddContactHook>(); addHooks = new CopyOnWriteArrayList<>();
removeHooks = new CopyOnWriteArrayList<RemoveContactHook>(); removeHooks = new CopyOnWriteArrayList<>();
} }
@Override @Override
@@ -125,7 +125,7 @@ class ContactManagerImpl implements ContactManager {
} finally { } finally {
db.endTransaction(txn); 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); for (Contact c : contacts) if (c.isActive()) active.add(c);
return active; return active;
} }

View File

@@ -602,8 +602,8 @@ class CryptoComponentImpl implements CryptoComponent {
// Package access for testing // Package access for testing
int chooseIterationCount(int targetMillis) { int chooseIterationCount(int targetMillis) {
List<Long> quickSamples = new ArrayList<Long>(PBKDF_SAMPLES); List<Long> quickSamples = new ArrayList<>(PBKDF_SAMPLES);
List<Long> slowSamples = new ArrayList<Long>(PBKDF_SAMPLES); List<Long> slowSamples = new ArrayList<>(PBKDF_SAMPLES);
long iterationNanos = 0, initNanos = 0; long iterationNanos = 0, initNanos = 0;
while (iterationNanos <= 0 || initNanos <= 0) { while (iterationNanos <= 0 || initNanos <= 0) {
// Sample the running time with one iteration and two iterations // Sample the running time with one iteration and two iterations

View File

@@ -48,7 +48,7 @@ public class CryptoModule {
public CryptoModule() { public CryptoModule() {
// Use an unbounded queue // Use an unbounded queue
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(); BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
// Discard tasks that are submitted during shutdown // Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy = RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy(); new ThreadPoolExecutor.DiscardPolicy();

View File

@@ -16,7 +16,7 @@ class PasswordStrengthEstimatorImpl implements PasswordStrengthEstimator {
@Override @Override
public float estimateStrength(String password) { public float estimateStrength(String password) {
HashSet<Character> unique = new HashSet<Character>(); HashSet<Character> unique = new HashSet<>();
int length = password.length(); int length = password.length();
for (int i = 0; i < length; i++) unique.add(password.charAt(i)); for (int i = 0; i < length; i++) unique.add(password.charAt(i));
return Math.min(1, (float) unique.size() / STRONG_UNIQUE_CHARS); return Math.min(1, (float) unique.size() / STRONG_UNIQUE_CHARS);

View File

@@ -331,7 +331,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (!db.containsContact(txn, c)) if (!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
Collection<MessageId> ids = db.getMessagesToSend(txn, c, maxLength); 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) { for (MessageId m : ids) {
messages.add(db.getRawMessage(txn, m)); messages.add(db.getRawMessage(txn, m));
db.updateExpiryTime(txn, c, m, maxLatency); db.updateExpiryTime(txn, c, m, maxLatency);
@@ -381,7 +381,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
throw new NoSuchContactException(); throw new NoSuchContactException();
Collection<MessageId> ids = db.getRequestedMessagesToSend(txn, c, Collection<MessageId> ids = db.getRequestedMessagesToSend(txn, c,
maxLength); maxLength);
List<byte[]> messages = new ArrayList<byte[]>(ids.size()); List<byte[]> messages = new ArrayList<>(ids.size());
for (MessageId m : ids) { for (MessageId m : ids) {
messages.add(db.getRawMessage(txn, m)); messages.add(db.getRawMessage(txn, m));
db.updateExpiryTime(txn, c, m, maxLatency); db.updateExpiryTime(txn, c, m, maxLatency);
@@ -661,7 +661,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsContact(txn, c)) if (!db.containsContact(txn, c))
throw new NoSuchContactException(); throw new NoSuchContactException();
Collection<MessageId> acked = new ArrayList<MessageId>(); Collection<MessageId> acked = new ArrayList<>();
for (MessageId m : a.getMessageIds()) { for (MessageId m : a.getMessageIds()) {
if (db.containsVisibleMessage(txn, c, m)) { if (db.containsVisibleMessage(txn, c, m)) {
db.raiseSeenFlag(txn, c, m); db.raiseSeenFlag(txn, c, m);
@@ -896,8 +896,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
Map<ContactId, TransportKeys> keys) throws DbException { Map<ContactId, TransportKeys> keys) throws DbException {
if (transaction.isReadOnly()) throw new IllegalArgumentException(); if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction); T txn = unbox(transaction);
Map<ContactId, TransportKeys> filtered = Map<ContactId, TransportKeys> filtered = new HashMap<>();
new HashMap<ContactId, TransportKeys>();
for (Entry<ContactId, TransportKeys> e : keys.entrySet()) { for (Entry<ContactId, TransportKeys> e : keys.entrySet()) {
ContactId c = e.getKey(); ContactId c = e.getKey();
TransportKeys k = e.getValue(); TransportKeys k = e.getValue();

View File

@@ -32,7 +32,7 @@ public class DatabaseExecutorModule {
public DatabaseExecutorModule() { public DatabaseExecutorModule() {
// Use an unbounded queue // Use an unbounded queue
BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(); BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>();
// Discard tasks that are submitted during shutdown // Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy = RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy(); new ThreadPoolExecutor.DiscardPolicy();

View File

@@ -26,7 +26,7 @@ public class DatabaseModule {
@Singleton @Singleton
DatabaseComponent provideDatabaseComponent(Database<Connection> db, DatabaseComponent provideDatabaseComponent(Database<Connection> db,
EventBus eventBus, ShutdownManager shutdown) { EventBus eventBus, ShutdownManager shutdown) {
return new DatabaseComponentImpl<Connection>(db, Connection.class, return new DatabaseComponentImpl<>(db, Connection.class, eventBus,
eventBus, shutdown); shutdown);
} }
} }

View File

@@ -263,8 +263,8 @@ abstract class JdbcDatabase implements Database<Connection> {
private final String hashType, binaryType, counterType, secretType; private final String hashType, binaryType, counterType, secretType;
private final Clock clock; private final Clock clock;
private final LinkedList<Connection> connections = // Locking: connectionsLock
new LinkedList<Connection>(); // Locking: connectionsLock private final LinkedList<Connection> connections = new LinkedList<>();
private int openConnections = 0; // Locking: connectionsLock private int openConnections = 0; // Locking: connectionsLock
private boolean closed = false; // Locking: connectionsLock private boolean closed = false; // Locking: connectionsLock
@@ -1035,7 +1035,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " FROM contacts"; + " FROM contacts";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Contact> contacts = new ArrayList<Contact>(); List<Contact> contacts = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
ContactId contactId = new ContactId(rs.getInt(1)); ContactId contactId = new ContactId(rs.getInt(1));
AuthorId authorId = new AuthorId(rs.getBytes(2)); AuthorId authorId = new AuthorId(rs.getBytes(2));
@@ -1069,7 +1069,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, local.getBytes()); ps.setBytes(1, local.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<ContactId> ids = new ArrayList<ContactId>(); List<ContactId> ids = new ArrayList<>();
while (rs.next()) ids.add(new ContactId(rs.getInt(1))); while (rs.next()) ids.add(new ContactId(rs.getInt(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1094,7 +1094,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, remote.getBytes()); ps.setBytes(1, remote.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Contact> contacts = new ArrayList<Contact>(); List<Contact> contacts = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
ContactId c = new ContactId(rs.getInt(1)); ContactId c = new ContactId(rs.getInt(1));
String name = rs.getString(2); String name = rs.getString(2);
@@ -1150,7 +1150,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setString(1, c.getString()); ps.setString(1, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<Group> groups = new ArrayList<Group>(); List<Group> groups = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
GroupId id = new GroupId(rs.getBytes(1)); GroupId id = new GroupId(rs.getBytes(1));
byte[] descriptor = rs.getBytes(2); byte[] descriptor = rs.getBytes(2);
@@ -1203,7 +1203,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getBytes()); ps.setBytes(1, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<ContactId> visible = new ArrayList<ContactId>(); List<ContactId> visible = new ArrayList<>();
while (rs.next()) visible.add(new ContactId(rs.getInt(1))); while (rs.next()) visible.add(new ContactId(rs.getInt(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1255,7 +1255,7 @@ abstract class JdbcDatabase implements Database<Connection> {
+ " FROM localAuthors"; + " FROM localAuthors";
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<LocalAuthor> authors = new ArrayList<LocalAuthor>(); List<LocalAuthor> authors = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
AuthorId authorId = new AuthorId(rs.getBytes(1)); AuthorId authorId = new AuthorId(rs.getBytes(1));
String name = rs.getString(2); String name = rs.getString(2);
@@ -1285,7 +1285,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, g.getBytes()); ps.setBytes(1, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1308,7 +1308,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, state.getValue()); ps.setInt(1, state.getValue());
ps.setBytes(2, g.getBytes()); ps.setBytes(2, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1343,7 +1343,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setString(3, e.getKey()); ps.setString(3, e.getKey());
ps.setBytes(4, e.getValue()); ps.setBytes(4, e.getValue());
rs = ps.executeQuery(); rs = ps.executeQuery();
Set<MessageId> ids = new HashSet<MessageId>(); Set<MessageId> ids = new HashSet<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1377,7 +1377,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, DELIVERED.getValue()); ps.setInt(1, DELIVERED.getValue());
ps.setBytes(2, g.getBytes()); ps.setBytes(2, g.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
Map<MessageId, Metadata> all = new HashMap<MessageId, Metadata>(); Map<MessageId, Metadata> all = new HashMap<>();
Metadata metadata = null; Metadata metadata = null;
MessageId lastMessageId = null; MessageId lastMessageId = null;
while (rs.next()) { while (rs.next()) {
@@ -1406,8 +1406,7 @@ abstract class JdbcDatabase implements Database<Connection> {
Collection<MessageId> matches = getMessageIds(txn, g, query); Collection<MessageId> matches = getMessageIds(txn, g, query);
if (matches.isEmpty()) return Collections.emptyMap(); if (matches.isEmpty()) return Collections.emptyMap();
// Retrieve the metadata for each match // Retrieve the metadata for each match
Map<MessageId, Metadata> all = new HashMap<MessageId, Metadata>( Map<MessageId, Metadata> all = new HashMap<>(matches.size());
matches.size());
for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m)); for (MessageId m : matches) all.put(m, getMessageMetadata(txn, m));
return all; return all;
} }
@@ -1505,7 +1504,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setBytes(1, g.getBytes()); ps.setBytes(1, g.getBytes());
ps.setInt(2, c.getInt()); ps.setInt(2, c.getInt());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageStatus> statuses = new ArrayList<MessageStatus>(); List<MessageStatus> statuses = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
MessageId messageId = new MessageId(rs.getBytes(1)); MessageId messageId = new MessageId(rs.getBytes(1));
boolean sent = rs.getBoolean(2); boolean sent = rs.getBoolean(2);
@@ -1564,7 +1563,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes()); ps.setBytes(1, m.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
Map<MessageId, State> dependencies = new HashMap<MessageId, State>(); Map<MessageId, State> dependencies = new HashMap<>();
while (rs.next()) { while (rs.next()) {
MessageId dependency = new MessageId(rs.getBytes(1)); MessageId dependency = new MessageId(rs.getBytes(1));
State state = State.fromValue(rs.getInt(2)); State state = State.fromValue(rs.getInt(2));
@@ -1602,7 +1601,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setBytes(1, m.getBytes()); ps.setBytes(1, m.getBytes());
rs = ps.executeQuery(); rs = ps.executeQuery();
Map<MessageId, State> dependents = new HashMap<MessageId, State>(); Map<MessageId, State> dependents = new HashMap<>();
while (rs.next()) { while (rs.next()) {
MessageId dependent = new MessageId(rs.getBytes(1)); MessageId dependent = new MessageId(rs.getBytes(1));
State state = State.fromValue(rs.getInt(2)); State state = State.fromValue(rs.getInt(2));
@@ -1654,7 +1653,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setInt(2, maxMessages); ps.setInt(2, maxMessages);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1690,7 +1689,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setLong(3, now); ps.setLong(3, now);
ps.setInt(4, maxMessages); ps.setInt(4, maxMessages);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1715,7 +1714,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, c.getInt()); ps.setInt(1, c.getInt());
ps.setInt(2, maxMessages); ps.setInt(2, maxMessages);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1750,7 +1749,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(2, DELIVERED.getValue()); ps.setInt(2, DELIVERED.getValue());
ps.setLong(3, now); ps.setLong(3, now);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
int total = 0; int total = 0;
while (rs.next()) { while (rs.next()) {
int length = rs.getInt(1); int length = rs.getInt(1);
@@ -1792,7 +1791,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(1, state.getValue()); ps.setInt(1, state.getValue());
ps.setString(2, c.getString()); ps.setString(2, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1822,7 +1821,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setString(1, c.getString()); ps.setString(1, c.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
while (rs.next()) ids.add(new MessageId(rs.getBytes(1))); while (rs.next()) ids.add(new MessageId(rs.getBytes(1)));
rs.close(); rs.close();
ps.close(); ps.close();
@@ -1881,7 +1880,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps.setInt(2, DELIVERED.getValue()); ps.setInt(2, DELIVERED.getValue());
ps.setLong(3, now); ps.setLong(3, now);
rs = ps.executeQuery(); rs = ps.executeQuery();
List<MessageId> ids = new ArrayList<MessageId>(); List<MessageId> ids = new ArrayList<>();
int total = 0; int total = 0;
while (rs.next()) { while (rs.next()) {
int length = rs.getInt(1); int length = rs.getInt(1);
@@ -1935,7 +1934,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setString(1, t.getString()); ps.setString(1, t.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
List<IncomingKeys> inKeys = new ArrayList<IncomingKeys>(); List<IncomingKeys> inKeys = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
long rotationPeriod = rs.getLong(1); long rotationPeriod = rs.getLong(1);
SecretKey tagKey = new SecretKey(rs.getBytes(2)); SecretKey tagKey = new SecretKey(rs.getBytes(2));
@@ -1955,8 +1954,7 @@ abstract class JdbcDatabase implements Database<Connection> {
ps = txn.prepareStatement(sql); ps = txn.prepareStatement(sql);
ps.setString(1, t.getString()); ps.setString(1, t.getString());
rs = ps.executeQuery(); rs = ps.executeQuery();
Map<ContactId, TransportKeys> keys = Map<ContactId, TransportKeys> keys = new HashMap<>();
new HashMap<ContactId, TransportKeys>();
for (int i = 0; rs.next(); i++) { for (int i = 0; rs.next(); i++) {
// There should be three times as many incoming keys // There should be three times as many incoming keys
if (inKeys.size() < (i + 1) * 3) throw new DbStateException(); if (inKeys.size() < (i + 1) * 3) throw new DbStateException();
@@ -2074,8 +2072,8 @@ abstract class JdbcDatabase implements Database<Connection> {
PreparedStatement ps = null; PreparedStatement ps = null;
try { try {
// Determine which keys are being removed // Determine which keys are being removed
List<String> removed = new ArrayList<String>(); List<String> removed = new ArrayList<>();
Map<String, byte[]> retained = new HashMap<String, byte[]>(); Map<String, byte[]> retained = new HashMap<>();
for (Entry<String, byte[]> e : meta.entrySet()) { for (Entry<String, byte[]> e : meta.entrySet()) {
if (e.getValue() == REMOVE) removed.add(e.getKey()); if (e.getValue() == REMOVE) removed.add(e.getKey());
else retained.put(e.getKey(), e.getValue()); else retained.put(e.getKey(), e.getValue());

View File

@@ -15,7 +15,7 @@ import javax.annotation.concurrent.ThreadSafe;
class EventBusImpl implements EventBus { class EventBusImpl implements EventBus {
private final Collection<EventListener> listeners = private final Collection<EventListener> listeners =
new CopyOnWriteArrayList<EventListener>(); new CopyOnWriteArrayList<>();
@Override @Override
public void addListener(EventListener l) { public void addListener(EventListener l) {

View File

@@ -50,10 +50,9 @@ class KeyAgreementConnector {
private final PluginManager pluginManager; private final PluginManager pluginManager;
private final CompletionService<KeyAgreementConnection> connect; private final CompletionService<KeyAgreementConnection> connect;
private final List<KeyAgreementListener> listeners = private final List<KeyAgreementListener> listeners = new ArrayList<>();
new ArrayList<KeyAgreementListener>();
private final List<Future<KeyAgreementConnection>> pending = private final List<Future<KeyAgreementConnection>> pending =
new ArrayList<Future<KeyAgreementConnection>>(); new ArrayList<>();
private volatile boolean connecting = false; private volatile boolean connecting = false;
private volatile boolean alice = false; private volatile boolean alice = false;
@@ -65,8 +64,7 @@ class KeyAgreementConnector {
this.clock = clock; this.clock = clock;
this.crypto = crypto; this.crypto = crypto;
this.pluginManager = pluginManager; this.pluginManager = pluginManager;
connect = new ExecutorCompletionService<KeyAgreementConnection>( connect = new ExecutorCompletionService<>(ioExecutor);
ioExecutor);
} }
public Payload listen(KeyPair localKeyPair) { public Payload listen(KeyPair localKeyPair) {
@@ -75,8 +73,7 @@ class KeyAgreementConnector {
byte[] commitment = crypto.deriveKeyCommitment( byte[] commitment = crypto.deriveKeyCommitment(
localKeyPair.getPublic().getEncoded()); localKeyPair.getPublic().getEncoded());
// Start all listeners and collect their descriptors // Start all listeners and collect their descriptors
List<TransportDescriptor> descriptors = List<TransportDescriptor> descriptors = new ArrayList<>();
new ArrayList<TransportDescriptor>();
for (DuplexPlugin plugin : pluginManager.getKeyAgreementPlugins()) { for (DuplexPlugin plugin : pluginManager.getKeyAgreementPlugins()) {
KeyAgreementListener l = KeyAgreementListener l =
plugin.createKeyAgreementListener(commitment); plugin.createKeyAgreementListener(commitment);

View File

@@ -51,8 +51,7 @@ class PayloadParserImpl implements PayloadParser {
byte[] commitment = payload.getRaw(1); byte[] commitment = payload.getRaw(1);
if (commitment.length != COMMIT_LENGTH) throw new FormatException(); if (commitment.length != COMMIT_LENGTH) throw new FormatException();
// Remaining elements: transport descriptors // Remaining elements: transport descriptors
List<TransportDescriptor> recognised = List<TransportDescriptor> recognised = new ArrayList<>();
new ArrayList<TransportDescriptor>();
for (int i = 2; i < payload.size(); i++) { for (int i = 2; i < payload.size(); i++) {
BdfList descriptor = payload.getList(i); BdfList descriptor = payload.getList(i);
long transportId = descriptor.getLong(0); long transportId = descriptor.getLong(0);

View File

@@ -63,9 +63,9 @@ class LifecycleManagerImpl implements LifecycleManager {
this.crypto = crypto; this.crypto = crypto;
this.authorFactory = authorFactory; this.authorFactory = authorFactory;
this.identityManager = identityManager; this.identityManager = identityManager;
services = new CopyOnWriteArrayList<Service>(); services = new CopyOnWriteArrayList<>();
clients = new CopyOnWriteArrayList<Client>(); clients = new CopyOnWriteArrayList<>();
executors = new CopyOnWriteArrayList<ExecutorService>(); executors = new CopyOnWriteArrayList<>();
} }
@Override @Override

View File

@@ -37,7 +37,7 @@ public class LifecycleModule {
public LifecycleModule() { public LifecycleModule() {
// The thread pool is unbounded, so use direct handoff // 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 // Discard tasks that are submitted during shutdown
RejectedExecutionHandler policy = RejectedExecutionHandler policy =
new ThreadPoolExecutor.DiscardPolicy(); new ThreadPoolExecutor.DiscardPolicy();

View File

@@ -21,7 +21,7 @@ class ShutdownManagerImpl implements ShutdownManager {
private int nextHandle = 0; private int nextHandle = 0;
ShutdownManagerImpl() { ShutdownManagerImpl() {
hooks = new HashMap<Integer, Thread>(); hooks = new HashMap<>();
} }
@Override @Override

View File

@@ -42,8 +42,8 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
@Inject @Inject
ConnectionRegistryImpl(EventBus eventBus) { ConnectionRegistryImpl(EventBus eventBus) {
this.eventBus = eventBus; this.eventBus = eventBus;
connections = new HashMap<TransportId, Map<ContactId, Integer>>(); connections = new HashMap<>();
contactCounts = new HashMap<ContactId, Integer>(); contactCounts = new HashMap<>();
} }
@Override @Override
@@ -58,7 +58,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
try { try {
Map<ContactId, Integer> m = connections.get(t); Map<ContactId, Integer> m = connections.get(t);
if (m == null) { if (m == null) {
m = new HashMap<ContactId, Integer>(); m = new HashMap<>();
connections.put(t, m); connections.put(t, m);
} }
Integer count = m.get(c); Integer count = m.get(c);
@@ -124,7 +124,7 @@ class ConnectionRegistryImpl implements ConnectionRegistry {
try { try {
Map<ContactId, Integer> m = connections.get(t); Map<ContactId, Integer> m = connections.get(t);
if (m == null) return Collections.emptyList(); 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)) if (LOG.isLoggable(INFO))
LOG.info(ids.size() + " contacts connected"); LOG.info(ids.size() + " contacts connected");
return ids; return ids;

View File

@@ -82,10 +82,10 @@ class PluginManagerImpl implements PluginManager, Service {
this.settingsManager = settingsManager; this.settingsManager = settingsManager;
this.transportPropertyManager = transportPropertyManager; this.transportPropertyManager = transportPropertyManager;
this.uiCallback = uiCallback; this.uiCallback = uiCallback;
plugins = new ConcurrentHashMap<TransportId, Plugin>(); plugins = new ConcurrentHashMap<>();
simplexPlugins = new CopyOnWriteArrayList<SimplexPlugin>(); simplexPlugins = new CopyOnWriteArrayList<>();
duplexPlugins = new CopyOnWriteArrayList<DuplexPlugin>(); duplexPlugins = new CopyOnWriteArrayList<>();
startLatches = new ConcurrentHashMap<TransportId, CountDownLatch>(); startLatches = new ConcurrentHashMap<>();
} }
@Override @Override
@@ -156,17 +156,17 @@ class PluginManagerImpl implements PluginManager, Service {
@Override @Override
public Collection<SimplexPlugin> getSimplexPlugins() { public Collection<SimplexPlugin> getSimplexPlugins() {
return new ArrayList<SimplexPlugin>(simplexPlugins); return new ArrayList<>(simplexPlugins);
} }
@Override @Override
public Collection<DuplexPlugin> getDuplexPlugins() { public Collection<DuplexPlugin> getDuplexPlugins() {
return new ArrayList<DuplexPlugin>(duplexPlugins); return new ArrayList<>(duplexPlugins);
} }
@Override @Override
public Collection<DuplexPlugin> getKeyAgreementPlugins() { public Collection<DuplexPlugin> getKeyAgreementPlugins() {
List<DuplexPlugin> supported = new ArrayList<DuplexPlugin>(); List<DuplexPlugin> supported = new ArrayList<>();
for (DuplexPlugin d : duplexPlugins) for (DuplexPlugin d : duplexPlugins)
if (d.supportsKeyAgreement()) supported.add(d); if (d.supportsKeyAgreement()) supported.add(d);
return supported; return supported;

View File

@@ -66,7 +66,7 @@ class Poller implements EventListener {
this.random = random; this.random = random;
this.clock = clock; this.clock = clock;
lock = new ReentrantLock(); lock = new ReentrantLock();
tasks = new HashMap<TransportId, PollTask>(); tasks = new HashMap<>();
} }
@Override @Override

View File

@@ -63,7 +63,7 @@ class LanTcpPlugin extends TcpPlugin {
TransportProperties p = callback.getLocalProperties(); TransportProperties p = callback.getLocalProperties();
String oldIpPorts = p.get(PROP_IP_PORTS); String oldIpPorts = p.get(PROP_IP_PORTS);
List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts); List<InetSocketAddress> olds = parseSocketAddresses(oldIpPorts);
List<InetSocketAddress> locals = new LinkedList<InetSocketAddress>(); List<InetSocketAddress> locals = new LinkedList<>();
for (InetAddress local : getLocalIpAddresses()) { for (InetAddress local : getLocalIpAddresses()) {
if (isAcceptableAddress(local)) { if (isAcceptableAddress(local)) {
// If this is the old address, try to use the same port // 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) { private List<InetSocketAddress> parseSocketAddresses(String ipPorts) {
if (StringUtils.isNullOrEmpty(ipPorts)) return Collections.emptyList(); if (StringUtils.isNullOrEmpty(ipPorts)) return Collections.emptyList();
String[] split = ipPorts.split(SEPARATOR); String[] split = ipPorts.split(SEPARATOR);
List<InetSocketAddress> addresses = new ArrayList<InetSocketAddress>(); List<InetSocketAddress> addresses = new ArrayList<>();
for (String ipPort : split) { for (String ipPort : split) {
InetSocketAddress a = parseSocketAddress(ipPort); InetSocketAddress a = parseSocketAddress(ipPort);
if (a != null) addresses.add(a); if (a != null) addresses.add(a);
@@ -95,7 +95,7 @@ class LanTcpPlugin extends TcpPlugin {
String ipPort = getIpPortString(a); String ipPort = getIpPortString(a);
// Get the list of recently used addresses // Get the list of recently used addresses
String setting = callback.getSettings().get(PREF_LAN_IP_PORTS); String setting = callback.getSettings().get(PREF_LAN_IP_PORTS);
List<String> recent = new ArrayList<String>(); List<String> recent = new ArrayList<>();
if (!StringUtils.isNullOrEmpty(setting)) if (!StringUtils.isNullOrEmpty(setting))
Collections.addAll(recent, setting.split(SEPARATOR)); Collections.addAll(recent, setting.split(SEPARATOR));
// Is the address already in the list? // Is the address already in the list?
@@ -111,7 +111,7 @@ class LanTcpPlugin extends TcpPlugin {
recent = recent.subList(0, MAX_ADDRESSES); recent = recent.subList(0, MAX_ADDRESSES);
setting = StringUtils.join(recent, SEPARATOR); setting = StringUtils.join(recent, SEPARATOR);
// Update the list of addresses shared with contacts // Update the list of addresses shared with contacts
List<String> shared = new ArrayList<String>(recent); List<String> shared = new ArrayList<>(recent);
Collections.sort(shared); Collections.sort(shared);
String property = StringUtils.join(shared, SEPARATOR); String property = StringUtils.join(shared, SEPARATOR);
TransportProperties properties = new TransportProperties(); TransportProperties properties = new TransportProperties();

View File

@@ -317,7 +317,7 @@ abstract class TcpPlugin implements DuplexPlugin {
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
return Collections.emptyList(); return Collections.emptyList();
} }
List<InetAddress> addrs = new ArrayList<InetAddress>(); List<InetAddress> addrs = new ArrayList<>();
for (NetworkInterface iface : ifaces) for (NetworkInterface iface : ifaces)
addrs.addAll(Collections.list(iface.getInetAddresses())); addrs.addAll(Collections.list(iface.getInetAddresses()));
return addrs; return addrs;

View File

@@ -43,7 +43,7 @@ class WanTcpPlugin extends TcpPlugin {
// Use the same address and port as last time if available // Use the same address and port as last time if available
TransportProperties p = callback.getLocalProperties(); TransportProperties p = callback.getLocalProperties();
InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT)); InetSocketAddress old = parseSocketAddress(p.get(PROP_IP_PORT));
List<InetSocketAddress> addrs = new LinkedList<InetSocketAddress>(); List<InetSocketAddress> addrs = new LinkedList<>();
for (InetAddress a : getLocalIpAddresses()) { for (InetAddress a : getLocalIpAddresses()) {
if (isAcceptableAddress(a)) { if (isAcceptableAddress(a)) {
// If this is the old address, try to use the same port // If this is the old address, try to use the same port

View File

@@ -144,8 +144,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
public Map<TransportId, TransportProperties> getLocalProperties( public Map<TransportId, TransportProperties> getLocalProperties(
Transaction txn) throws DbException { Transaction txn) throws DbException {
try { try {
Map<TransportId, TransportProperties> local = Map<TransportId, TransportProperties> local = new HashMap<>();
new HashMap<TransportId, TransportProperties>();
// Find the latest local update for each transport // Find the latest local update for each transport
Map<TransportId, LatestUpdate> latest = findLatestLocal(txn); Map<TransportId, LatestUpdate> latest = findLatestLocal(txn);
// Retrieve and parse the latest local properties // Retrieve and parse the latest local properties
@@ -192,8 +191,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
@Override @Override
public Map<ContactId, TransportProperties> getRemoteProperties( public Map<ContactId, TransportProperties> getRemoteProperties(
TransportId t) throws DbException { TransportId t) throws DbException {
Map<ContactId, TransportProperties> remote = Map<ContactId, TransportProperties> remote = new HashMap<>();
new HashMap<ContactId, TransportProperties>();
// TODO: Transaction can be read-only when code is simplified // TODO: Transaction can be read-only when code is simplified
Transaction txn = db.startTransaction(false); Transaction txn = db.startTransaction(false);
try { try {
@@ -321,8 +319,7 @@ class TransportPropertyManagerImpl implements TransportPropertyManager,
private Map<TransportId, LatestUpdate> findLatestLocal(Transaction txn) private Map<TransportId, LatestUpdate> findLatestLocal(Transaction txn)
throws DbException, FormatException { throws DbException, FormatException {
// TODO: This can be simplified before 1.0 // TODO: This can be simplified before 1.0
Map<TransportId, LatestUpdate> latestUpdates = Map<TransportId, LatestUpdate> latestUpdates = new HashMap<>();
new HashMap<TransportId, LatestUpdate>();
Map<MessageId, BdfDictionary> metadata = clientHelper Map<MessageId, BdfDictionary> metadata = clientHelper
.getMessageMetadataAsDictionary(txn, localGroup.getId()); .getMessageMetadataAsDictionary(txn, localGroup.getId());
for (Entry<MessageId, BdfDictionary> e : metadata.entrySet()) { for (Entry<MessageId, BdfDictionary> e : metadata.entrySet()) {

View File

@@ -41,7 +41,7 @@ class Receiver implements ReadHandler {
Receiver(Clock clock, Sender sender) { Receiver(Clock clock, Sender sender) {
this.sender = sender; this.sender = sender;
this.clock = clock; this.clock = clock;
dataFrames = new TreeSet<Data>(new SequenceNumberComparator()); dataFrames = new TreeSet<>(new SequenceNumberComparator());
} }
Data read() throws IOException, InterruptedException { Data read() throws IOException, InterruptedException {

View File

@@ -42,7 +42,7 @@ class ReliabilityLayerImpl implements ReliabilityLayer, WriteHandler {
this.executor = executor; this.executor = executor;
this.clock = clock; this.clock = clock;
this.writeHandler = writeHandler; this.writeHandler = writeHandler;
writes = new LinkedBlockingQueue<byte[]>(); writes = new LinkedBlockingQueue<>();
} }
@Override @Override

View File

@@ -46,7 +46,7 @@ class Sender {
Sender(Clock clock, WriteHandler writeHandler) { Sender(Clock clock, WriteHandler writeHandler) {
this.clock = clock; this.clock = clock;
this.writeHandler = writeHandler; this.writeHandler = writeHandler;
outstanding = new LinkedList<Outstanding>(); outstanding = new LinkedList<>();
} }
void sendAck(long sequenceNumber, int windowSize) throws IOException { void sendAck(long sequenceNumber, int windowSize) throws IOException {
@@ -136,7 +136,7 @@ class Sender {
if (now - o.lastTransmitted > rto) { if (now - o.lastTransmitted > rto) {
it.remove(); it.remove();
if (retransmit == null) if (retransmit == null)
retransmit = new ArrayList<Outstanding>(); retransmit = new ArrayList<>();
retransmit.add(o); retransmit.add(o);
// Update the retransmission timeout // Update the retransmission timeout
rto <<= 1; rto <<= 1;

View File

@@ -83,7 +83,7 @@ class DuplexOutgoingSession implements SyncSession, EventListener {
this.maxLatency = maxLatency; this.maxLatency = maxLatency;
this.maxIdleTime = maxIdleTime; this.maxIdleTime = maxIdleTime;
this.recordWriter = recordWriter; this.recordWriter = recordWriter;
writerTasks = new LinkedBlockingQueue<ThrowingRunnable<IOException>>(); writerTasks = new LinkedBlockingQueue<>();
} }
@IoExecutor @IoExecutor

View File

@@ -116,7 +116,7 @@ class RecordReaderImpl implements RecordReader {
private List<MessageId> readMessageIds() throws IOException { private List<MessageId> readMessageIds() throws IOException {
if (payloadLength == 0) throw new FormatException(); if (payloadLength == 0) throw new FormatException();
if (payloadLength % UniqueId.LENGTH != 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) { for (int off = 0; off < payloadLength; off += UniqueId.LENGTH) {
byte[] id = new byte[UniqueId.LENGTH]; byte[] id = new byte[UniqueId.LENGTH];
System.arraycopy(payload, off, id, 0, UniqueId.LENGTH); System.arraycopy(payload, off, id, 0, UniqueId.LENGTH);

View File

@@ -71,7 +71,7 @@ class SimplexOutgoingSession implements SyncSession, EventListener {
this.maxLatency = maxLatency; this.maxLatency = maxLatency;
this.recordWriter = recordWriter; this.recordWriter = recordWriter;
outstandingQueries = new AtomicInteger(2); // One per type of record outstandingQueries = new AtomicInteger(2); // One per type of record
writerTasks = new LinkedBlockingQueue<ThrowingRunnable<IOException>>(); writerTasks = new LinkedBlockingQueue<>();
} }
@IoExecutor @IoExecutor

View File

@@ -64,8 +64,8 @@ class ValidationManagerImpl implements ValidationManager, Service,
this.dbExecutor = dbExecutor; this.dbExecutor = dbExecutor;
this.validationExecutor = validationExecutor; this.validationExecutor = validationExecutor;
this.messageFactory = messageFactory; this.messageFactory = messageFactory;
validators = new ConcurrentHashMap<ClientId, MessageValidator>(); validators = new ConcurrentHashMap<>();
hooks = new ConcurrentHashMap<ClientId, IncomingMessageHook>(); hooks = new ConcurrentHashMap<>();
} }
@Override @Override
@@ -105,7 +105,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@DatabaseExecutor @DatabaseExecutor
private void validateOutstandingMessages(ClientId c) { private void validateOutstandingMessages(ClientId c) {
try { try {
Queue<MessageId> unvalidated = new LinkedList<MessageId>(); Queue<MessageId> unvalidated = new LinkedList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
unvalidated.addAll(db.getMessagesToValidate(txn, c)); unvalidated.addAll(db.getMessagesToValidate(txn, c));
@@ -170,7 +170,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@DatabaseExecutor @DatabaseExecutor
private void deliverOutstandingMessages(ClientId c) { private void deliverOutstandingMessages(ClientId c) {
try { try {
Queue<MessageId> pending = new LinkedList<MessageId>(); Queue<MessageId> pending = new LinkedList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
pending.addAll(db.getPendingMessages(txn, c)); pending.addAll(db.getPendingMessages(txn, c));
@@ -229,8 +229,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
pending.addAll(getPendingDependents(txn, id)); pending.addAll(getPendingDependents(txn, id));
if (result.share) { if (result.share) {
db.setMessageShared(txn, id); db.setMessageShared(txn, id);
toShare = new LinkedList<MessageId>( toShare = new LinkedList<>(states.keySet());
states.keySet());
} }
} else { } else {
invalidate = getDependentsToInvalidate(txn, id); invalidate = getDependentsToInvalidate(txn, id);
@@ -277,7 +276,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
} catch (InvalidMessageException e) { } catch (InvalidMessageException e) {
if (LOG.isLoggable(INFO)) if (LOG.isLoggable(INFO))
LOG.log(INFO, e.toString(), e); LOG.log(INFO, e.toString(), e);
Queue<MessageId> invalidate = new LinkedList<MessageId>(); Queue<MessageId> invalidate = new LinkedList<>();
invalidate.add(m.getId()); invalidate.add(m.getId());
invalidateNextMessageAsync(invalidate); invalidateNextMessageAsync(invalidate);
} }
@@ -331,8 +330,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
pending = getPendingDependents(txn, id); pending = getPendingDependents(txn, id);
if (result.share) { if (result.share) {
db.setMessageShared(txn, id); db.setMessageShared(txn, id);
toShare = toShare = new LinkedList<>(dependencies);
new LinkedList<MessageId>(dependencies);
} }
} else { } else {
invalidate = getDependentsToInvalidate(txn, id); invalidate = getDependentsToInvalidate(txn, id);
@@ -378,7 +376,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@DatabaseExecutor @DatabaseExecutor
private Queue<MessageId> getPendingDependents(Transaction txn, MessageId m) private Queue<MessageId> getPendingDependents(Transaction txn, MessageId m)
throws DbException { throws DbException {
Queue<MessageId> pending = new LinkedList<MessageId>(); Queue<MessageId> pending = new LinkedList<>();
Map<MessageId, State> states = db.getMessageDependents(txn, m); Map<MessageId, State> states = db.getMessageDependents(txn, m);
for (Entry<MessageId, State> e : states.entrySet()) { for (Entry<MessageId, State> e : states.entrySet()) {
if (e.getValue() == PENDING) pending.add(e.getKey()); if (e.getValue() == PENDING) pending.add(e.getKey());
@@ -398,7 +396,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@DatabaseExecutor @DatabaseExecutor
private void shareOutstandingMessages(ClientId c) { private void shareOutstandingMessages(ClientId c) {
try { try {
Queue<MessageId> toShare = new LinkedList<MessageId>(); Queue<MessageId> toShare = new LinkedList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
toShare.addAll(db.getMessagesToShare(txn, c)); toShare.addAll(db.getMessagesToShare(txn, c));
@@ -496,7 +494,7 @@ class ValidationManagerImpl implements ValidationManager, Service,
@DatabaseExecutor @DatabaseExecutor
private Queue<MessageId> getDependentsToInvalidate(Transaction txn, private Queue<MessageId> getDependentsToInvalidate(Transaction txn,
MessageId m) throws DbException { MessageId m) throws DbException {
Queue<MessageId> invalidate = new LinkedList<MessageId>(); Queue<MessageId> invalidate = new LinkedList<>();
Map<MessageId, State> states = db.getMessageDependents(txn, m); Map<MessageId, State> states = db.getMessageDependents(txn, m);
for (Entry<MessageId, State> e : states.entrySet()) { for (Entry<MessageId, State> e : states.entrySet()) {
if (e.getValue() != INVALID) invalidate.add(e.getKey()); if (e.getValue() != INVALID) invalidate.add(e.getKey());

View File

@@ -58,15 +58,14 @@ class KeyManagerImpl implements KeyManager, Service, EventListener {
this.pluginConfig = pluginConfig; this.pluginConfig = pluginConfig;
this.transportKeyManagerFactory = transportKeyManagerFactory; this.transportKeyManagerFactory = transportKeyManagerFactory;
// Use a ConcurrentHashMap as a thread-safe set // Use a ConcurrentHashMap as a thread-safe set
activeContacts = new ConcurrentHashMap<ContactId, Boolean>(); activeContacts = new ConcurrentHashMap<>();
managers = new ConcurrentHashMap<TransportId, TransportKeyManager>(); managers = new ConcurrentHashMap<>();
} }
@Override @Override
public void startService() throws ServiceException { public void startService() throws ServiceException {
if (used.getAndSet(true)) throw new IllegalStateException(); if (used.getAndSet(true)) throw new IllegalStateException();
Map<TransportId, Integer> transports = Map<TransportId, Integer> transports = new HashMap<>();
new HashMap<TransportId, Integer>();
for (SimplexPluginFactory f : pluginConfig.getSimplexFactories()) for (SimplexPluginFactory f : pluginConfig.getSimplexFactories())
transports.put(f.getId(), f.getMaxLatency()); transports.put(f.getId(), f.getMaxLatency());
for (DuplexPluginFactory f : pluginConfig.getDuplexFactories()) for (DuplexPluginFactory f : pluginConfig.getDuplexFactories())

View File

@@ -45,7 +45,7 @@ class ReorderingWindow {
} }
List<Long> getUnseen() { 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++) for (int i = 0; i < seen.length; i++)
if (!seen[i]) unseen.add(base + i); if (!seen[i]) unseen.add(base + i);
return unseen; return unseen;
@@ -69,8 +69,8 @@ class ReorderingWindow {
return new Change(added, removed); return new Change(added, removed);
} }
// Record the elements that will be added and removed // Record the elements that will be added and removed
List<Long> added = new ArrayList<Long>(slide); List<Long> added = new ArrayList<>(slide);
List<Long> removed = new ArrayList<Long>(slide); List<Long> removed = new ArrayList<>(slide);
for (int i = 0; i < slide; i++) { for (int i = 0; i < slide; i++) {
if (!seen[i]) removed.add(base + i); if (!seen[i]) removed.add(base + i);
added.add(base + seen.length + i); added.add(base + seen.length + i);

View File

@@ -65,9 +65,9 @@ class TransportKeyManagerImpl implements TransportKeyManager {
this.transportId = transportId; this.transportId = transportId;
rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE; rotationPeriodLength = maxLatency + MAX_CLOCK_DIFFERENCE;
lock = new ReentrantLock(); lock = new ReentrantLock();
inContexts = new HashMap<Bytes, TagContext>(); inContexts = new HashMap<>();
outContexts = new HashMap<ContactId, MutableOutgoingKeys>(); outContexts = new HashMap<>();
keys = new HashMap<ContactId, MutableTransportKeys>(); keys = new HashMap<>();
} }
@Override @Override
@@ -272,8 +272,7 @@ class TransportKeyManagerImpl implements TransportKeyManager {
lock.lock(); lock.lock();
try { try {
// Rotate the keys to the current rotation period // Rotate the keys to the current rotation period
Map<ContactId, TransportKeys> snapshot = Map<ContactId, TransportKeys> snapshot = new HashMap<>();
new HashMap<ContactId, TransportKeys>();
for (Entry<ContactId, MutableTransportKeys> e : keys.entrySet()) for (Entry<ContactId, MutableTransportKeys> e : keys.entrySet())
snapshot.put(e.getKey(), e.getValue().snapshot()); snapshot.put(e.getKey(), e.getValue().snapshot());
RotationResult rotationResult = rotateKeys(snapshot, now); RotationResult rotationResult = rotateKeys(snapshot, now);
@@ -311,8 +310,8 @@ class TransportKeyManagerImpl implements TransportKeyManager {
private final Map<ContactId, TransportKeys> current, rotated; private final Map<ContactId, TransportKeys> current, rotated;
private RotationResult() { private RotationResult() {
current = new HashMap<ContactId, TransportKeys>(); current = new HashMap<>();
rotated = new HashMap<ContactId, TransportKeys>(); rotated = new HashMap<>();
} }
} }
} }

View File

@@ -24,7 +24,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newSingleThreadExecutor(); Executor delegate = Executors.newSingleThreadExecutor();
// Allow all the tasks to be delegated straight away // Allow all the tasks to be delegated straight away
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2); 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); final CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) { for (int i = 0; i < TASKS; i++) {
final int result = i; final int result = i;
@@ -49,7 +49,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newSingleThreadExecutor(); Executor delegate = Executors.newSingleThreadExecutor();
// Allow two tasks to be delegated at a time // Allow two tasks to be delegated at a time
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 2); 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); final CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) { for (int i = 0; i < TASKS; i++) {
final int result = i; final int result = i;
@@ -73,7 +73,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newCachedThreadPool(); Executor delegate = Executors.newCachedThreadPool();
// Allow all the tasks to be delegated straight away // Allow all the tasks to be delegated straight away
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, TASKS * 2); 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]; 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++) latches[i] = new CountDownLatch(1);
for (int i = 0; i < TASKS; i++) { for (int i = 0; i < TASKS; i++) {
@@ -104,7 +104,7 @@ public class PoliteExecutorTest extends BrambleTestCase {
Executor delegate = Executors.newCachedThreadPool(); Executor delegate = Executors.newCachedThreadPool();
// Allow one task to be delegated at a time // Allow one task to be delegated at a time
PoliteExecutor polite = new PoliteExecutor(TAG, delegate, 1); 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); final CountDownLatch latch = new CountDownLatch(TASKS);
for (int i = 0; i < TASKS; i++) { for (int i = 0; i < TASKS; i++) {
final int result = i; final int result = i;

View File

@@ -165,8 +165,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test @Test
public void testGetMessageMetadataAsDictionaryMap() throws Exception { public void testGetMessageMetadataAsDictionaryMap() throws Exception {
final Map<MessageId, BdfDictionary> map = final Map<MessageId, BdfDictionary> map = new HashMap<>();
new HashMap<MessageId, BdfDictionary>();
map.put(messageId, dictionary); map.put(messageId, dictionary);
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
@@ -188,8 +187,7 @@ public class ClientHelperImplTest extends BrambleTestCase {
@Test @Test
public void testGetMessageMetadataAsDictionaryQuery() throws Exception { public void testGetMessageMetadataAsDictionaryQuery() throws Exception {
final Map<MessageId, BdfDictionary> map = final Map<MessageId, BdfDictionary> map = new HashMap<>();
new HashMap<MessageId, BdfDictionary>();
map.put(messageId, dictionary); map.put(messageId, dictionary);
final BdfDictionary query = final BdfDictionary query =
BdfDictionary.of(new BdfEntry("query", "me")); BdfDictionary.of(new BdfEntry("query", "me"));

View File

@@ -132,8 +132,7 @@ public class ContactManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testActiveContacts() throws Exception { public void testActiveContacts() throws Exception {
Collection<Contact> activeContacts = Collections.singletonList(contact); Collection<Contact> activeContacts = Collections.singletonList(contact);
final Collection<Contact> contacts = final Collection<Contact> contacts = new ArrayList<>(activeContacts);
new ArrayList<Contact>(activeContacts);
contacts.add(new Contact(new ContactId(3), remote, local, true, false)); contacts.add(new Contact(new ContactId(3), remote, local, true, false));
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
context.checking(new Expectations() {{ context.checking(new Expectations() {{

View File

@@ -69,7 +69,7 @@ public class EllipticCurvePerformanceTest {
ECPublicKeyParameters public2 = ECPublicKeyParameters public2 =
(ECPublicKeyParameters) keyPair2.getPublic(); (ECPublicKeyParameters) keyPair2.getPublic();
// Time some ECDH key agreements // Time some ECDH key agreements
List<Long> samples = new ArrayList<Long>(); List<Long> samples = new ArrayList<>();
for (int i = 0; i < SAMPLES; i++) { for (int i = 0; i < SAMPLES; i++) {
ECDHCBasicAgreement agreement = new ECDHCBasicAgreement(); ECDHCBasicAgreement agreement = new ECDHCBasicAgreement();
long start = System.nanoTime(); long start = System.nanoTime();
@@ -79,7 +79,7 @@ public class EllipticCurvePerformanceTest {
} }
long agreementMedian = median(samples); long agreementMedian = median(samples);
// Time some signatures // Time some signatures
List<byte[]> signatures = new ArrayList<byte[]>(); List<byte[]> signatures = new ArrayList<>();
samples.clear(); samples.clear();
for (int i = 0; i < SAMPLES; i++) { for (int i = 0; i < SAMPLES; i++) {
Digest digest = new Blake2sDigest(); Digest digest = new Blake2sDigest();

View File

@@ -145,7 +145,7 @@ public class KeyDerivationTest extends BrambleTestCase {
} }
private void assertAllDifferent(TransportKeys... transportKeys) { private void assertAllDifferent(TransportKeys... transportKeys) {
List<SecretKey> secretKeys = new ArrayList<SecretKey>(); List<SecretKey> secretKeys = new ArrayList<>();
for (TransportKeys k : transportKeys) { for (TransportKeys k : transportKeys) {
secretKeys.add(k.getPreviousIncomingKeys().getTagKey()); secretKeys.add(k.getPreviousIncomingKeys().getTagKey());
secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey()); secretKeys.add(k.getPreviousIncomingKeys().getHeaderKey());
@@ -160,7 +160,7 @@ public class KeyDerivationTest extends BrambleTestCase {
} }
private void assertAllDifferent(List<SecretKey> keys) { 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()))); for (SecretKey k : keys) assertTrue(set.add(new Bytes(k.getBytes())));
} }
} }

View File

@@ -28,7 +28,7 @@ public class TagEncodingTest extends BrambleTestCase {
@Test @Test
public void testKeyAffectsTag() throws Exception { public void testKeyAffectsTag() throws Exception {
Set<Bytes> set = new HashSet<Bytes>(); Set<Bytes> set = new HashSet<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
byte[] tag = new byte[TAG_LENGTH]; byte[] tag = new byte[TAG_LENGTH];
SecretKey tagKey = TestUtils.getSecretKey(); SecretKey tagKey = TestUtils.getSecretKey();
@@ -39,7 +39,7 @@ public class TagEncodingTest extends BrambleTestCase {
@Test @Test
public void testProtocolVersionAffectsTag() throws Exception { public void testProtocolVersionAffectsTag() throws Exception {
Set<Bytes> set = new HashSet<Bytes>(); Set<Bytes> set = new HashSet<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
byte[] tag = new byte[TAG_LENGTH]; byte[] tag = new byte[TAG_LENGTH];
crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION + i, streamNumber); crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION + i, streamNumber);
@@ -49,7 +49,7 @@ public class TagEncodingTest extends BrambleTestCase {
@Test @Test
public void testStreamNumberAffectsTag() throws Exception { public void testStreamNumberAffectsTag() throws Exception {
Set<Bytes> set = new HashSet<Bytes>(); Set<Bytes> set = new HashSet<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
byte[] tag = new byte[TAG_LENGTH]; byte[] tag = new byte[TAG_LENGTH];
crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION, streamNumber + i); crypto.encodeTag(tag, tagKey, PROTOCOL_VERSION, streamNumber + i);

View File

@@ -1,7 +1,6 @@
package org.briarproject.bramble.data; package org.briarproject.bramble.data;
import org.briarproject.bramble.test.BrambleTestCase; import org.briarproject.bramble.test.BrambleTestCase;
import org.briarproject.bramble.test.TestUtils;
import org.briarproject.bramble.util.StringUtils; import org.briarproject.bramble.util.StringUtils;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@@ -155,7 +154,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
@Test @Test
public void testWriteList() throws IOException { 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); for (int i = 0; i < 3; i++) l.add(i);
w.writeList(l); w.writeList(l);
// LIST tag, elements as integers, END tag // LIST tag, elements as integers, END tag
@@ -164,7 +163,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
@Test @Test
public void testListCanContainNull() throws IOException { public void testListCanContainNull() throws IOException {
List<Object> l = new ArrayList<Object>(); List<Object> l = new ArrayList<>();
l.add(1); l.add(1);
l.add(null); l.add(null);
l.add(NULL_VALUE); l.add(NULL_VALUE);
@@ -177,7 +176,7 @@ public class BdfWriterImplTest extends BrambleTestCase {
@Test @Test
public void testWriteDictionary() throws IOException { public void testWriteDictionary() throws IOException {
// Use LinkedHashMap to get predictable iteration order // 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); for (int i = 0; i < 4; i++) m.put(String.valueOf(i), i);
w.writeDictionary(m); w.writeDictionary(m);
// DICTIONARY tag, keys as strings and values as integers, END tag // DICTIONARY tag, keys as strings and values as integers, END tag
@@ -216,12 +215,12 @@ public class BdfWriterImplTest extends BrambleTestCase {
@Test @Test
public void testWriteNestedDictionariesAndLists() throws IOException { 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]); inner.put("bar", new byte[0]);
List<Object> list = new ArrayList<Object>(); List<Object> list = new ArrayList<>();
list.add(1); list.add(1);
list.add(inner); list.add(inner);
Map<String, Object> outer = new LinkedHashMap<String, Object>(); Map<String, Object> outer = new LinkedHashMap<>();
outer.put("foo", list); outer.put("foo", list);
w.writeDictionary(outer); w.writeDictionary(outer);
// DICTIONARY tag, "foo" as string, LIST tag, 1 as integer, // DICTIONARY tag, "foo" as string, LIST tag, 1 as integer,

View File

@@ -99,7 +99,7 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
@Test @Test
public void testList() throws FormatException { public void testList() throws FormatException {
List<Long> l = new ArrayList<Long>(4); List<Long> l = new ArrayList<>(4);
l.add(42L); l.add(42L);
l.add(1337L); l.add(1337L);
l.add(Long.MIN_VALUE); l.add(Long.MIN_VALUE);
@@ -114,7 +114,7 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
@Test @Test
public void testDictionary() throws FormatException { 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("1", true);
m.put("2", false); m.put("2", false);
@@ -130,19 +130,19 @@ public class MetadataEncoderParserIntegrationTest extends BrambleTestCase {
@Test @Test
public void testComplexDictionary() throws FormatException { public void testComplexDictionary() throws FormatException {
Map<String, List> m = new HashMap<String, List>(); Map<String, List> m = new HashMap<>();
List<String> one = new ArrayList<String>(3); List<String> one = new ArrayList<>(3);
one.add("\uFDD0"); one.add("\uFDD0");
one.add("\uFDD1"); one.add("\uFDD1");
one.add("\uFDD2"); one.add("\uFDD2");
m.put("One", one); m.put("One", one);
List<String> two = new ArrayList<String>(2); List<String> two = new ArrayList<>(2);
two.add("\u0080"); two.add("\u0080");
two.add("\uD800\uDC00"); two.add("\uD800\uDC00");
m.put("Two", two); m.put("Two", two);
d.put("test", m); d.put("test", m);
Map<String, Boolean> m2 = new HashMap<String, Boolean>(); Map<String, Boolean> m2 = new HashMap<>();
m2.put("should be true", true); m2.put("should be true", true);
d.put("another test", m2); d.put("another test", m2);

View File

@@ -323,7 +323,7 @@ public class BasicH2Test extends BrambleTestCase {
private List<String> getNames() throws SQLException { private List<String> getNames() throws SQLException {
String sql = "SELECT name FROM foo ORDER BY uniqueId"; String sql = "SELECT name FROM foo ORDER BY uniqueId";
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<>();
try { try {
PreparedStatement ps = connection.prepareStatement(sql); PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = ps.executeQuery(); ResultSet rs = ps.executeQuery();

View File

@@ -120,8 +120,8 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
private DatabaseComponent createDatabaseComponent(Database<Object> database, private DatabaseComponent createDatabaseComponent(Database<Object> database,
EventBus eventBus, ShutdownManager shutdown) { EventBus eventBus, ShutdownManager shutdown) {
return new DatabaseComponentImpl<Object>(database, Object.class, return new DatabaseComponentImpl<>(database, Object.class, eventBus,
eventBus, shutdown); shutdown);
} }
@Test @Test
@@ -1703,7 +1703,7 @@ public class DatabaseComponentImplTest extends BrambleTestCase {
Transaction transaction = db.startTransaction(false); Transaction transaction = db.startTransaction(false);
try { try {
db.addLocalMessage(transaction, message, metadata, true); db.addLocalMessage(transaction, message, metadata, true);
Collection<MessageId> dependencies = new ArrayList<MessageId>(2); Collection<MessageId> dependencies = new ArrayList<>(2);
dependencies.add(messageId1); dependencies.add(messageId1);
dependencies.add(messageId2); dependencies.add(messageId2);
db.addMessageDependencies(transaction, message, dependencies); db.addMessageDependencies(transaction, message, dependencies);

View File

@@ -870,7 +870,7 @@ public class H2DatabaseTest extends BrambleTestCase {
assertEquals(0, db.countOfferedMessages(txn, contactId)); assertEquals(0, db.countOfferedMessages(txn, contactId));
// Add some offered messages and count them // 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++) { for (int i = 0; i < 10; i++) {
MessageId m = new MessageId(TestUtils.getRandomId()); MessageId m = new MessageId(TestUtils.getRandomId());
db.addOfferedMessage(txn, contactId, m); db.addOfferedMessage(txn, contactId, m);

View File

@@ -81,7 +81,7 @@ public class IdentityManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testGetAuthorStatus() throws DbException { public void testGetAuthorStatus() throws DbException {
final AuthorId authorId = new AuthorId(TestUtils.getRandomId()); final AuthorId authorId = new AuthorId(TestUtils.getRandomId());
final Collection<Contact> contacts = new ArrayList<Contact>(); final Collection<Contact> contacts = new ArrayList<>();
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(db).startTransaction(true); oneOf(db).startTransaction(true);

View File

@@ -15,7 +15,7 @@ public class ShutdownManagerImplTest extends BrambleTestCase {
@Test @Test
public void testAddAndRemove() { public void testAddAndRemove() {
ShutdownManager s = createShutdownManager(); ShutdownManager s = createShutdownManager();
Set<Integer> handles = new HashSet<Integer>(); Set<Integer> handles = new HashSet<>();
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
int handle = s.addShutdownHook(new Runnable() { int handle = s.addShutdownHook(new Runnable() {
@Override @Override

View File

@@ -194,8 +194,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
plugin.createKeyAgreementListener(new byte[COMMIT_LENGTH]); plugin.createKeyAgreementListener(new byte[COMMIT_LENGTH]);
assertNotNull(kal); assertNotNull(kal);
Callable<KeyAgreementConnection> c = kal.listen(); Callable<KeyAgreementConnection> c = kal.listen();
FutureTask<KeyAgreementConnection> f = FutureTask<KeyAgreementConnection> f = new FutureTask<>(c);
new FutureTask<KeyAgreementConnection>(c);
new Thread(f).start(); new Thread(f).start();
// The plugin should have bound a socket and stored the port number // The plugin should have bound a socket and stored the port number
BdfList descriptor = kal.getDescriptor(); BdfList descriptor = kal.getDescriptor();
@@ -291,7 +290,7 @@ public class LanTcpPluginTest extends BrambleTestCase {
private static class Callback implements DuplexPluginCallback { private static class Callback implements DuplexPluginCallback {
private final Map<ContactId, TransportProperties> remote = private final Map<ContactId, TransportProperties> remote =
new Hashtable<ContactId, TransportProperties>(); new Hashtable<>();
private final CountDownLatch propertiesLatch = new CountDownLatch(1); private final CountDownLatch propertiesLatch = new CountDownLatch(1);
private final CountDownLatch connectionsLatch = new CountDownLatch(1); private final CountDownLatch connectionsLatch = new CountDownLatch(1);
private final TransportProperties local = new TransportProperties(); private final TransportProperties local = new TransportProperties();

View File

@@ -179,7 +179,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
new BdfEntry("local", false) new BdfEntry("local", false)
); );
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// A remote update for another transport should be ignored // A remote update for another transport should be ignored
MessageId barUpdateId = new MessageId(getRandomId()); MessageId barUpdateId = new MessageId(getRandomId());
messageMetadata.put(barUpdateId, BdfDictionary.of( messageMetadata.put(barUpdateId, BdfDictionary.of(
@@ -221,7 +221,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
new BdfEntry("local", false) new BdfEntry("local", false)
); );
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// Old remote updates for the same transport should be deleted // Old remote updates for the same transport should be deleted
final MessageId fooVersion2 = new MessageId(getRandomId()); final MessageId fooVersion2 = new MessageId(getRandomId());
messageMetadata.put(fooVersion2, BdfDictionary.of( messageMetadata.put(fooVersion2, BdfDictionary.of(
@@ -274,7 +274,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
new BdfEntry("local", false) new BdfEntry("local", false)
); );
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// Old remote updates for the same transport should be deleted // Old remote updates for the same transport should be deleted
final MessageId fooVersion2 = new MessageId(getRandomId()); final MessageId fooVersion2 = new MessageId(getRandomId());
messageMetadata.put(fooVersion2, BdfDictionary.of( messageMetadata.put(fooVersion2, BdfDictionary.of(
@@ -322,7 +322,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
final Group contactGroup = getGroup(); final Group contactGroup = getGroup();
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
Map<TransportId, TransportProperties> properties = Map<TransportId, TransportProperties> properties =
new LinkedHashMap<TransportId, TransportProperties>(); new LinkedHashMap<>();
properties.put(new TransportId("foo"), fooProperties); properties.put(new TransportId("foo"), fooProperties);
properties.put(new TransportId("bar"), barProperties); properties.put(new TransportId("bar"), barProperties);
@@ -359,7 +359,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
throws Exception { throws Exception {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// A local update for another transport should be ignored // A local update for another transport should be ignored
MessageId barUpdateId = new MessageId(getRandomId()); MessageId barUpdateId = new MessageId(getRandomId());
messageMetadata.put(barUpdateId, BdfDictionary.of( messageMetadata.put(barUpdateId, BdfDictionary.of(
@@ -386,7 +386,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
public void testReturnsLocalProperties() throws Exception { public void testReturnsLocalProperties() throws Exception {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// A local update for another transport should be ignored // A local update for another transport should be ignored
MessageId barUpdateId = new MessageId(getRandomId()); MessageId barUpdateId = new MessageId(getRandomId());
messageMetadata.put(barUpdateId, BdfDictionary.of( messageMetadata.put(barUpdateId, BdfDictionary.of(
@@ -432,7 +432,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
final Group contactGroup2 = getGroup(); final Group contactGroup2 = getGroup();
final Group contactGroup3 = getGroup(); final Group contactGroup3 = getGroup();
final Map<MessageId, BdfDictionary> messageMetadata3 = final Map<MessageId, BdfDictionary> messageMetadata3 =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// A remote update for another transport should be ignored // A remote update for another transport should be ignored
MessageId barUpdateId = new MessageId(getRandomId()); MessageId barUpdateId = new MessageId(getRandomId());
messageMetadata3.put(barUpdateId, BdfDictionary.of( messageMetadata3.put(barUpdateId, BdfDictionary.of(
@@ -641,7 +641,7 @@ public class TransportPropertyManagerImplTest extends BrambleMockTestCase {
private void expectGetLocalProperties(final Transaction txn) private void expectGetLocalProperties(final Transaction txn)
throws Exception { throws Exception {
final Map<MessageId, BdfDictionary> messageMetadata = final Map<MessageId, BdfDictionary> messageMetadata =
new LinkedHashMap<MessageId, BdfDictionary>(); new LinkedHashMap<>();
// The only update for transport "foo" should be returned // The only update for transport "foo" should be returned
final MessageId fooVersion999 = new MessageId(getRandomId()); final MessageId fooVersion999 = new MessageId(getRandomId());
messageMetadata.put(fooVersion999, BdfDictionary.of( messageMetadata.put(fooVersion999, BdfDictionary.of(

View File

@@ -718,8 +718,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
public void testRecursiveInvalidation() throws Exception { public void testRecursiveInvalidation() throws Exception {
final MessageId messageId3 = new MessageId(TestUtils.getRandomId()); final MessageId messageId3 = new MessageId(TestUtils.getRandomId());
final MessageId messageId4 = new MessageId(TestUtils.getRandomId()); final MessageId messageId4 = new MessageId(TestUtils.getRandomId());
final Map<MessageId, State> twoDependents = final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
new LinkedHashMap<MessageId, State>();
twoDependents.put(messageId1, PENDING); twoDependents.put(messageId1, PENDING);
twoDependents.put(messageId2, PENDING); twoDependents.put(messageId2, PENDING);
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
@@ -826,12 +825,10 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
raw); raw);
final Message message4 = new Message(messageId4, groupId, timestamp, final Message message4 = new Message(messageId4, groupId, timestamp,
raw); raw);
final Map<MessageId, State> twoDependents = final Map<MessageId, State> twoDependents = new LinkedHashMap<>();
new LinkedHashMap<MessageId, State>();
twoDependents.put(messageId1, PENDING); twoDependents.put(messageId1, PENDING);
twoDependents.put(messageId2, PENDING); twoDependents.put(messageId2, PENDING);
final Map<MessageId, State> twoDependencies = final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
new LinkedHashMap<MessageId, State>();
twoDependencies.put(messageId1, DELIVERED); twoDependencies.put(messageId1, DELIVERED);
twoDependencies.put(messageId2, DELIVERED); twoDependencies.put(messageId2, DELIVERED);
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);
@@ -979,8 +976,7 @@ public class ValidationManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testOnlyReadyPendingDependentsGetDelivered() throws Exception { public void testOnlyReadyPendingDependentsGetDelivered() throws Exception {
final Map<MessageId, State> twoDependencies = final Map<MessageId, State> twoDependencies = new LinkedHashMap<>();
new LinkedHashMap<MessageId, State>();
twoDependencies.put(messageId, DELIVERED); twoDependencies.put(messageId, DELIVERED);
twoDependencies.put(messageId2, UNKNOWN); twoDependencies.put(messageId2, UNKNOWN);
final Transaction txn = new Transaction(null, true); final Transaction txn = new Transaction(null, true);

View File

@@ -38,7 +38,7 @@ public class LinuxSecureRandomSpiTest extends BrambleTestCase {
System.err.println("WARNING: Skipping test, can't run on this OS"); System.err.println("WARNING: Skipping test, can't run on this OS");
return; return;
} }
Set<Bytes> seeds = new HashSet<Bytes>(); Set<Bytes> seeds = new HashSet<>();
LinuxSecureRandomSpi engine = new LinuxSecureRandomSpi(); LinuxSecureRandomSpi engine = new LinuxSecureRandomSpi();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
byte[] seed = engine.engineGenerateSeed(SEED_BYTES); byte[] seed = engine.engineGenerateSeed(SEED_BYTES);

View File

@@ -63,7 +63,7 @@ public class KeyManagerImplTest extends BrambleTestCase {
Author remoteAuthor = new Author(remoteAuthorId, "author", Author remoteAuthor = new Author(remoteAuthorId, "author",
getRandomBytes(42)); getRandomBytes(42));
AuthorId localAuthorId = new AuthorId(getRandomId()); 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, contacts.add(new Contact(contactId, remoteAuthor, localAuthorId, true,
true)); true));
contacts.add(new Contact(inactiveContactId, remoteAuthor, localAuthorId, contacts.add(new Contact(inactiveContactId, remoteAuthor, localAuthorId,

View File

@@ -63,8 +63,7 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
context.mock(ScheduledExecutorService.class); context.mock(ScheduledExecutorService.class);
final Clock clock = context.mock(Clock.class); final Clock clock = context.mock(Clock.class);
final Map<ContactId, TransportKeys> loaded = final Map<ContactId, TransportKeys> loaded = new LinkedHashMap<>();
new LinkedHashMap<ContactId, TransportKeys>();
final TransportKeys shouldRotate = createTransportKeys(900, 0); final TransportKeys shouldRotate = createTransportKeys(900, 0);
final TransportKeys shouldNotRotate = createTransportKeys(1000, 0); final TransportKeys shouldNotRotate = createTransportKeys(1000, 0);
loaded.put(contactId, shouldRotate); loaded.put(contactId, shouldRotate);
@@ -343,7 +342,7 @@ public class TransportKeyManagerImplTest extends BrambleTestCase {
final boolean alice = true; final boolean alice = true;
final TransportKeys transportKeys = createTransportKeys(1000, 0); final TransportKeys transportKeys = createTransportKeys(1000, 0);
// Keep a copy of the tags // 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); final Transaction txn = new Transaction(null, false);
context.checking(new Expectations() {{ context.checking(new Expectations() {{

View File

@@ -10,7 +10,7 @@ import java.util.List;
class EmojiPages { class EmojiPages {
static List<EmojiPageModel> getPages(Context ctx) { static List<EmojiPageModel> getPages(Context ctx) {
return Arrays.<EmojiPageModel>asList( return Arrays.asList(
new StaticEmojiPageModel(ctx, R.drawable.ic_emoji_smiley_people, new StaticEmojiPageModel(ctx, R.drawable.ic_emoji_smiley_people,
R.array.emoji_smiley_people, R.array.emoji_smiley_people,
"emoji_smiley_people.png"), "emoji_smiley_people.png"),

View File

@@ -86,7 +86,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
this.identityManager = identityManager; this.identityManager = identityManager;
this.blogFactory = blogFactory; this.blogFactory = blogFactory;
this.blogPostFactory = blogPostFactory; this.blogPostFactory = blogPostFactory;
removeHooks = new CopyOnWriteArrayList<RemoveBlogHook>(); removeHooks = new CopyOnWriteArrayList<>();
} }
@Override @Override
@@ -404,7 +404,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
throws DbException { throws DbException {
Collection<Blog> allBlogs = getBlogs(); Collection<Blog> allBlogs = getBlogs();
List<Blog> blogs = new ArrayList<Blog>(); List<Blog> blogs = new ArrayList<>();
for (Blog b : allBlogs) { for (Blog b : allBlogs) {
if (b.getAuthor().equals(localAuthor)) { if (b.getAuthor().equals(localAuthor)) {
blogs.add(b); blogs.add(b);
@@ -421,7 +421,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
@Override @Override
public Collection<Blog> getBlogs() throws DbException { public Collection<Blog> getBlogs() throws DbException {
try { try {
List<Blog> blogs = new ArrayList<Blog>(); List<Blog> blogs = new ArrayList<>();
Collection<Group> groups; Collection<Group> groups;
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
@@ -492,7 +492,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
new BdfEntry(KEY_TYPE, COMMENT.getInt()) new BdfEntry(KEY_TYPE, COMMENT.getInt())
); );
Collection<BlogPostHeader> headers = new ArrayList<BlogPostHeader>(); Collection<BlogPostHeader> headers = new ArrayList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
Map<MessageId, BdfDictionary> metadata1 = Map<MessageId, BdfDictionary> metadata1 =
@@ -500,20 +500,18 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
Map<MessageId, BdfDictionary> metadata2 = Map<MessageId, BdfDictionary> metadata2 =
clientHelper.getMessageMetadataAsDictionary(txn, g, query2); clientHelper.getMessageMetadataAsDictionary(txn, g, query2);
Map<MessageId, BdfDictionary> metadata = Map<MessageId, BdfDictionary> metadata =
new HashMap<MessageId, BdfDictionary>( new HashMap<>(metadata1.size() + metadata2.size());
metadata1.size() + metadata2.size());
metadata.putAll(metadata1); metadata.putAll(metadata1);
metadata.putAll(metadata2); metadata.putAll(metadata2);
// get all authors we need to get the status for // 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()) { for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
authors.add(new AuthorId( authors.add(new AuthorId(
entry.getValue().getDictionary(KEY_AUTHOR) entry.getValue().getDictionary(KEY_AUTHOR)
.getRaw(KEY_AUTHOR_ID))); .getRaw(KEY_AUTHOR_ID)));
} }
// get statuses for all authors // get statuses for all authors
Map<AuthorId, Status> authorStatuses = Map<AuthorId, Status> authorStatuses = new HashMap<>();
new HashMap<AuthorId, Status>();
for (AuthorId authorId : authors) { for (AuthorId authorId : authors) {
authorStatuses.put(authorId, authorStatuses.put(authorId,
identityManager.getAuthorStatus(txn, authorId)); identityManager.getAuthorStatus(txn, authorId));
@@ -562,7 +560,7 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
GroupId groupId, MessageId id, BdfDictionary meta) GroupId groupId, MessageId id, BdfDictionary meta)
throws DbException, FormatException { throws DbException, FormatException {
return getPostHeaderFromMetadata(txn, groupId, id, meta, return getPostHeaderFromMetadata(txn, groupId, id, meta,
Collections.<AuthorId, Status>emptyMap()); Collections.emptyMap());
} }
private BlogPostHeader getPostHeaderFromMetadata(Transaction txn, private BlogPostHeader getPostHeaderFromMetadata(Transaction txn,

View File

@@ -96,7 +96,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
private QueueState loadQueueState(Transaction txn, GroupId g) private QueueState loadQueueState(Transaction txn, GroupId g)
throws DbException { throws DbException {
try { try {
TreeMap<Long, MessageId> pending = new TreeMap<Long, MessageId>(); TreeMap<Long, MessageId> pending = new TreeMap<>();
Metadata groupMeta = db.getGroupMetadata(txn, g); Metadata groupMeta = db.getGroupMetadata(txn, g);
byte[] raw = groupMeta.get(QUEUE_STATE_KEY); byte[] raw = groupMeta.get(QUEUE_STATE_KEY);
if (raw == null) return new QueueState(0, 0, pending); if (raw == null) return new QueueState(0, 0, pending);
@@ -231,7 +231,7 @@ class MessageQueueManagerImpl implements MessageQueueManager {
m.getTimestamp(), queuePosition, m.getRaw()); m.getTimestamp(), queuePosition, m.getRaw());
queueState.incomingPosition++; queueState.incomingPosition++;
// Collect any consecutive messages // Collect any consecutive messages
List<MessageId> consecutive = new ArrayList<MessageId>(); List<MessageId> consecutive = new ArrayList<>();
MessageId next; MessageId next;
while ((next = queueState.popIncomingMessageId()) != null) while ((next = queueState.popIncomingMessageId()) != null)
consecutive.add(next); consecutive.add(next);

View File

@@ -19,10 +19,9 @@ import javax.annotation.concurrent.ThreadSafe;
public class MessageTreeImpl<T extends MessageTree.MessageNode> public class MessageTreeImpl<T extends MessageTree.MessageNode>
implements MessageTree<T> { implements MessageTree<T> {
private final Map<MessageId, List<T>> nodeMap = private final Map<MessageId, List<T>> nodeMap = new HashMap<>();
new HashMap<MessageId, List<T>>(); private final List<T> roots = new ArrayList<>();
private final List<T> roots = new ArrayList<T>(); private final List<List<T>> unsortedLists = new ArrayList<>();
private final List<List<T>> unsortedLists = new ArrayList<List<T>>();
private Comparator<T> comparator = new Comparator<T>() { private Comparator<T> comparator = new Comparator<T>() {
@Override @Override
@@ -41,7 +40,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
public synchronized void add(Collection<T> nodes) { public synchronized void add(Collection<T> nodes) {
// add all nodes to the node map // add all nodes to the node map
for (T node : nodes) { for (T node : nodes) {
nodeMap.put(node.getId(), new ArrayList<T>()); nodeMap.put(node.getId(), new ArrayList<>());
} }
// parse the nodes for dependencies // parse the nodes for dependencies
for (T node : nodes) { for (T node : nodes) {
@@ -100,7 +99,7 @@ public class MessageTreeImpl<T extends MessageTree.MessageNode>
@Override @Override
public synchronized Collection<T> depthFirstOrder() { public synchronized Collection<T> depthFirstOrder() {
List<T> orderedList = new ArrayList<T>(); List<T> orderedList = new ArrayList<>();
for (T root : roots) { for (T root : roots) {
traverse(orderedList, root, 0); traverse(orderedList, root, 0);
} }

View File

@@ -154,7 +154,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
db.addGroup(txn, g); db.addGroup(txn, g);
// Add initial metadata // Add initial metadata
List<Feed> feeds = new ArrayList<Feed>(0); List<Feed> feeds = new ArrayList<>(0);
storeFeeds(txn, feeds); storeFeeds(txn, feeds);
} }
@@ -237,7 +237,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
} }
private List<Feed> getFeeds(Transaction txn) throws DbException { private List<Feed> getFeeds(Transaction txn) throws DbException {
List<Feed> feeds = new ArrayList<Feed>(); List<Feed> feeds = new ArrayList<>();
Group g = getLocalGroup(); Group g = getLocalGroup();
try { try {
BdfDictionary d = BdfDictionary d =
@@ -300,7 +300,7 @@ class FeedManagerImpl implements FeedManager, Client, EventListener,
} }
// Fetch and update all feeds // Fetch and update all feeds
List<Feed> newFeeds = new ArrayList<Feed>(feeds.size()); List<Feed> newFeeds = new ArrayList<>(feeds.size());
for (Feed feed : feeds) { for (Feed feed : feeds) {
try { try {
newFeeds.add(fetchFeed(feed)); newFeeds.add(fetchFeed(feed));

View File

@@ -75,7 +75,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
this.forumFactory = forumFactory; this.forumFactory = forumFactory;
this.forumPostFactory = forumPostFactory; this.forumPostFactory = forumPostFactory;
this.messageTracker = messageTracker; this.messageTracker = messageTracker;
removeHooks = new CopyOnWriteArrayList<RemoveForumHook>(); removeHooks = new CopyOnWriteArrayList<>();
} }
@Override @Override
@@ -203,7 +203,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
} }
List<Forum> forums = new ArrayList<Forum>(); List<Forum> forums = new ArrayList<>();
for (Group g : groups) forums.add(parseForum(g)); for (Group g : groups) forums.add(parseForum(g));
return forums; return forums;
} catch (FormatException e) { } catch (FormatException e) {
@@ -232,13 +232,13 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
public Collection<ForumPostHeader> getPostHeaders(GroupId g) public Collection<ForumPostHeader> getPostHeaders(GroupId g)
throws DbException { throws DbException {
Collection<ForumPostHeader> headers = new ArrayList<ForumPostHeader>(); Collection<ForumPostHeader> headers = new ArrayList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
Map<MessageId, BdfDictionary> metadata = Map<MessageId, BdfDictionary> metadata =
clientHelper.getMessageMetadataAsDictionary(txn, g); clientHelper.getMessageMetadataAsDictionary(txn, g);
// get all authors we need to get the status for // 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()) { for (Entry<MessageId, BdfDictionary> entry : metadata.entrySet()) {
BdfDictionary d = BdfDictionary d =
entry.getValue().getDictionary(KEY_AUTHOR, null); entry.getValue().getDictionary(KEY_AUTHOR, null);
@@ -246,7 +246,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
authors.add(new AuthorId(d.getRaw(KEY_ID))); authors.add(new AuthorId(d.getRaw(KEY_ID)));
} }
// get statuses for all authors // get statuses for all authors
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>(); Map<AuthorId, Status> statuses = new HashMap<>();
for (AuthorId id : authors) { for (AuthorId id : authors) {
statuses.put(id, identityManager.getAuthorStatus(txn, id)); statuses.put(id, identityManager.getAuthorStatus(txn, id));
} }
@@ -290,8 +290,7 @@ class ForumManagerImpl extends BdfIncomingMessageHook implements ForumManager {
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id, private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,
BdfDictionary meta) throws DbException, FormatException { BdfDictionary meta) throws DbException, FormatException {
return getForumPostHeader(txn, id, meta, return getForumPostHeader(txn, id, meta, Collections.emptyMap());
Collections.<AuthorId, Status>emptyMap());
} }
private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id, private ForumPostHeader getForumPostHeader(Transaction txn, MessageId id,

View File

@@ -106,7 +106,7 @@ class IntroduceeEngine
else return abortSession(currentState, localState); 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) { if (action == LOCAL_ACCEPT || action == LOCAL_DECLINE) {
localState.put(STATE, nextState.getValue()); localState.put(STATE, nextState.getValue());
localState.put(ANSWERED, true); localState.put(ANSWERED, true);
@@ -136,8 +136,7 @@ class IntroduceeEngine
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
List<Event> events = Collections.emptyList(); List<Event> events = Collections.emptyList();
return new StateUpdate<BdfDictionary, BdfDictionary>(false, return new StateUpdate<>(false, false,
false,
localState, messages, events); localState, messages, events);
} catch (FormatException e) { } catch (FormatException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
@@ -204,16 +203,15 @@ class IntroduceeEngine
} }
// we are done (probably declined response), ignore & delete message // we are done (probably declined response), ignore & delete message
else if (currentState == FINISHED) { else if (currentState == FINISHED) {
return new StateUpdate<BdfDictionary, BdfDictionary>(true, return new StateUpdate<>(true, false, localState,
false, localState,
Collections.<BdfDictionary>emptyList(), Collections.<BdfDictionary>emptyList(),
Collections.<Event>emptyList()); Collections.emptyList());
} }
// this should not happen // this should not happen
else { else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false,
localState, messages, events); localState, messages, events);
} catch (FormatException e) { } catch (FormatException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
@@ -361,15 +359,14 @@ class IntroduceeEngine
Event event = new IntroductionAbortedEvent(contactId, sessionId); Event event = new IntroductionAbortedEvent(contactId, sessionId);
List<Event> events = Collections.singletonList(event); List<Event> events = Collections.singletonList(event);
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false, localState, messages, events);
localState, messages, events);
} }
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate( private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
BdfDictionary localState) throws FormatException { BdfDictionary localState) throws FormatException {
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false, localState,
localState, Collections.<BdfDictionary>emptyList(), Collections.<BdfDictionary>emptyList(),
Collections.<Event>emptyList()); Collections.emptyList());
} }
} }

View File

@@ -539,8 +539,7 @@ class IntroduceeManager {
private Map<TransportId, TransportProperties> parseTransportProperties( private Map<TransportId, TransportProperties> parseTransportProperties(
BdfDictionary d) throws FormatException { BdfDictionary d) throws FormatException {
Map<TransportId, TransportProperties> tpMap = Map<TransportId, TransportProperties> tpMap = new HashMap<>();
new HashMap<TransportId, TransportProperties>();
BdfDictionary tpMapDict = d.getDictionary(TRANSPORT); BdfDictionary tpMapDict = d.getDictionary(TRANSPORT);
for (String key : tpMapDict.keySet()) { for (String key : tpMapDict.keySet()) {
TransportId transportId = new TransportId(key); TransportId transportId = new TransportId(key);

View File

@@ -102,7 +102,7 @@ class IntroducerEngine
localState.put(STATE, nextState.getValue()); localState.put(STATE, nextState.getValue());
if (action == LOCAL_REQUEST) { if (action == LOCAL_REQUEST) {
// create the introduction requests for both contacts // create the introduction requests for both contacts
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2); List<BdfDictionary> messages = new ArrayList<>(2);
BdfDictionary msg1 = new BdfDictionary(); BdfDictionary msg1 = new BdfDictionary();
msg1.put(TYPE, TYPE_REQUEST); msg1.put(TYPE, TYPE_REQUEST);
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID)); msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
@@ -129,8 +129,7 @@ class IntroducerEngine
logLocalAction(currentState, localState); logLocalAction(currentState, localState);
List<Event> events = Collections.emptyList(); List<Event> events = Collections.emptyList();
return new StateUpdate<BdfDictionary, BdfDictionary>(false, return new StateUpdate<>(false, false,
false,
localState, messages, events); localState, messages, events);
} else { } else {
throw new IllegalArgumentException("Unknown Local Action"); throw new IllegalArgumentException("Unknown Local Action");
@@ -206,7 +205,7 @@ class IntroducerEngine
} else { } else {
throw new IllegalArgumentException("Bad state"); throw new IllegalArgumentException("Bad state");
} }
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false,
localState, messages, events); localState, messages, events);
} catch (FormatException e) { } catch (FormatException e) {
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
@@ -334,7 +333,7 @@ class IntroducerEngine
currentState.name()); currentState.name());
localState.put(STATE, ERROR.getValue()); localState.put(STATE, ERROR.getValue());
List<BdfDictionary> messages = new ArrayList<BdfDictionary>(2); List<BdfDictionary> messages = new ArrayList<>(2);
BdfDictionary msg1 = new BdfDictionary(); BdfDictionary msg1 = new BdfDictionary();
msg1.put(TYPE, TYPE_ABORT); msg1.put(TYPE, TYPE_ABORT);
msg1.put(SESSION_ID, localState.getRaw(SESSION_ID)); msg1.put(SESSION_ID, localState.getRaw(SESSION_ID));
@@ -347,7 +346,7 @@ class IntroducerEngine
messages.add(msg2); messages.add(msg2);
// send one abort event per contact // 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)); SessionId sessionId = new SessionId(localState.getRaw(SESSION_ID));
ContactId contactId1 = ContactId contactId1 =
new ContactId(localState.getLong(CONTACT_ID_1).intValue()); new ContactId(localState.getLong(CONTACT_ID_1).intValue());
@@ -358,15 +357,14 @@ class IntroducerEngine
Event event2 = new IntroductionAbortedEvent(contactId2, sessionId); Event event2 = new IntroductionAbortedEvent(contactId2, sessionId);
events.add(event2); events.add(event2);
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false, localState, messages, events);
localState, messages, events);
} }
private StateUpdate<BdfDictionary, BdfDictionary> noUpdate( private StateUpdate<BdfDictionary, BdfDictionary> noUpdate(
BdfDictionary localState) throws FormatException { BdfDictionary localState) throws FormatException {
return new StateUpdate<BdfDictionary, BdfDictionary>(false, false, return new StateUpdate<>(false, false, localState,
localState, Collections.<BdfDictionary>emptyList(), Collections.<BdfDictionary>emptyList(),
Collections.<Event>emptyList()); Collections.emptyList());
} }
} }

View File

@@ -336,8 +336,7 @@ class IntroductionManagerImpl extends ConversationClientImpl
public Collection<IntroductionMessage> getIntroductionMessages( public Collection<IntroductionMessage> getIntroductionMessages(
ContactId contactId) throws DbException { ContactId contactId) throws DbException {
Collection<IntroductionMessage> list = Collection<IntroductionMessage> list = new ArrayList<>();
new ArrayList<IntroductionMessage>();
Map<MessageId, BdfDictionary> metadata; Map<MessageId, BdfDictionary> metadata;
Collection<MessageStatus> statuses; Collection<MessageStatus> statuses;

View File

@@ -24,7 +24,7 @@ class ConversationManagerImpl implements ConversationManager {
@Inject @Inject
ConversationManagerImpl(DatabaseComponent db) { ConversationManagerImpl(DatabaseComponent db) {
this.db = db; this.db = db;
clients = new CopyOnWriteArraySet<ConversationClient>(); clients = new CopyOnWriteArraySet<>();
} }
@Override @Override

View File

@@ -176,8 +176,7 @@ class MessagingManagerImpl extends ConversationClientImpl
} finally { } finally {
db.endTransaction(txn); db.endTransaction(txn);
} }
Collection<PrivateMessageHeader> headers = Collection<PrivateMessageHeader> headers = new ArrayList<>();
new ArrayList<PrivateMessageHeader>();
for (MessageStatus s : statuses) { for (MessageStatus s : statuses) {
MessageId id = s.getMessageId(); MessageId id = s.getMessageId();
BdfDictionary meta = metadata.get(id); BdfDictionary meta = metadata.get(id);

View File

@@ -202,7 +202,7 @@ class GroupMessageValidator extends BdfMessageValidator {
// The parent post, if any, // The parent post, if any,
// and the member's previous message are dependencies // 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)); if (parentId != null) dependencies.add(new MessageId(parentId));
dependencies.add(new MessageId(previousMessageId)); dependencies.add(new MessageId(previousMessageId));

View File

@@ -100,7 +100,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
this.contactManager = contactManager; this.contactManager = contactManager;
this.identityManager = identityManager; this.identityManager = identityManager;
this.messageTracker = messageTracker; this.messageTracker = messageTracker;
hooks = new CopyOnWriteArrayList<PrivateGroupHook>(); hooks = new CopyOnWriteArrayList<>();
} }
@Override @Override
@@ -284,7 +284,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
} }
try { try {
Collection<PrivateGroup> privateGroups = Collection<PrivateGroup> privateGroups =
new ArrayList<PrivateGroup>(groups.size()); new ArrayList<>(groups.size());
for (Group g : groups) { for (Group g : groups) {
privateGroups.add(privateGroupFactory.parsePrivateGroup(g)); privateGroups.add(privateGroupFactory.parsePrivateGroup(g));
} }
@@ -324,20 +324,19 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
@Override @Override
public Collection<GroupMessageHeader> getHeaders(GroupId g) public Collection<GroupMessageHeader> getHeaders(GroupId g)
throws DbException { throws DbException {
Collection<GroupMessageHeader> headers = Collection<GroupMessageHeader> headers = new ArrayList<>();
new ArrayList<GroupMessageHeader>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
Map<MessageId, BdfDictionary> metadata = Map<MessageId, BdfDictionary> metadata =
clientHelper.getMessageMetadataAsDictionary(txn, g); clientHelper.getMessageMetadataAsDictionary(txn, g);
// get all authors we need to get the status for // 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()) { for (BdfDictionary meta : metadata.values()) {
byte[] idBytes = meta.getRaw(KEY_MEMBER_ID); byte[] idBytes = meta.getRaw(KEY_MEMBER_ID);
authors.add(new AuthorId(idBytes)); authors.add(new AuthorId(idBytes));
} }
// get statuses for all authors // get statuses for all authors
Map<AuthorId, Status> statuses = new HashMap<AuthorId, Status>(); Map<AuthorId, Status> statuses = new HashMap<>();
for (AuthorId id : authors) { for (AuthorId id : authors) {
statuses.put(id, identityManager.getAuthorStatus(txn, id)); statuses.put(id, identityManager.getAuthorStatus(txn, id));
} }
@@ -404,7 +403,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
public Collection<GroupMember> getMembers(GroupId g) throws DbException { public Collection<GroupMember> getMembers(GroupId g) throws DbException {
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
Collection<GroupMember> members = new ArrayList<GroupMember>(); Collection<GroupMember> members = new ArrayList<>();
Map<Author, Visibility> authors = getMembers(txn, g); Map<Author, Visibility> authors = getMembers(txn, g);
LocalAuthor la = identityManager.getLocalAuthor(txn); LocalAuthor la = identityManager.getLocalAuthor(txn);
PrivateGroup privateGroup = getPrivateGroup(txn, g); PrivateGroup privateGroup = getPrivateGroup(txn, g);
@@ -434,8 +433,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta = BdfDictionary meta =
clientHelper.getGroupMetadataAsDictionary(txn, g); clientHelper.getGroupMetadataAsDictionary(txn, g);
BdfList list = meta.getList(GROUP_KEY_MEMBERS); BdfList list = meta.getList(GROUP_KEY_MEMBERS);
Map<Author, Visibility> members = Map<Author, Visibility> members = new HashMap<>(list.size());
new HashMap<Author, Visibility>(list.size());
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
BdfDictionary d = list.getDictionary(i); BdfDictionary d = list.getDictionary(i);
Author member = getAuthor(d); Author member = getAuthor(d);
@@ -584,7 +582,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta, boolean local) BdfDictionary meta, boolean local)
throws DbException, FormatException { throws DbException, FormatException {
GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(), GroupMessageHeader header = getGroupMessageHeader(txn, m.getGroupId(),
m.getId(), meta, Collections.<AuthorId, Status>emptyMap()); m.getId(), meta, Collections.emptyMap());
String body = getMessageBody(clientHelper.toList(m)); String body = getMessageBody(clientHelper.toList(m));
txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body, txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, body,
local)); local));
@@ -594,7 +592,7 @@ class PrivateGroupManagerImpl extends BdfIncomingMessageHook
BdfDictionary meta, boolean local, Visibility v) BdfDictionary meta, boolean local, Visibility v)
throws DbException, FormatException { throws DbException, FormatException {
JoinMessageHeader header = getJoinMessageHeader(txn, m.getGroupId(), 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, "", txn.attach(new GroupMessageAddedEvent(m.getGroupId(), header, "",
local)); local));
} }

View File

@@ -366,7 +366,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
Map<MessageId, BdfDictionary> results = clientHelper Map<MessageId, BdfDictionary> results = clientHelper
.getMessageMetadataAsDictionary(txn, contactGroupId, query); .getMessageMetadataAsDictionary(txn, contactGroupId, query);
messages = new ArrayList<InvitationMessage>(results.size()); messages = new ArrayList<>(results.size());
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey(); MessageId m = e.getKey();
MessageMetadata meta = MessageMetadata meta =
@@ -427,7 +427,7 @@ class GroupInvitationManagerImpl extends ConversationClientImpl
@Override @Override
public Collection<GroupInvitationItem> getInvitations() throws DbException { public Collection<GroupInvitationItem> getInvitations() throws DbException {
List<GroupInvitationItem> items = new ArrayList<GroupInvitationItem>(); List<GroupInvitationItem> items = new ArrayList<>();
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {

View File

@@ -17,10 +17,10 @@ import javax.annotation.concurrent.Immutable;
import static org.briarproject.briar.sharing.MessageType.INVITE; 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_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_LOCAL;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE; 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_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_SHAREABLE_ID;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP; import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI; 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); BdfList descriptor = body.getList(2);
S shareable = createShareable(descriptor); S shareable = createShareable(descriptor);
String message = body.getOptionalString(3); String message = body.getOptionalString(3);
return new InviteMessage<S>(m.getId(), previousMessageId, return new InviteMessage<>(m.getId(), previousMessageId,
m.getGroupId(), shareable, message, m.getTimestamp()); m.getGroupId(), shareable, message, m.getTimestamp());
} }

View File

@@ -311,7 +311,7 @@ abstract class SharingManagerImpl<S extends Shareable>
BdfDictionary query = messageParser.getMessagesVisibleInUiQuery(); BdfDictionary query = messageParser.getMessagesVisibleInUiQuery();
Map<MessageId, BdfDictionary> results = clientHelper Map<MessageId, BdfDictionary> results = clientHelper
.getMessageMetadataAsDictionary(txn, contactGroupId, query); .getMessageMetadataAsDictionary(txn, contactGroupId, query);
messages = new ArrayList<InvitationMessage>(results.size()); messages = new ArrayList<>(results.size());
for (Entry<MessageId, BdfDictionary> e : results.entrySet()) { for (Entry<MessageId, BdfDictionary> e : results.entrySet()) {
MessageId m = e.getKey(); MessageId m = e.getKey();
MessageMetadata meta = MessageMetadata meta =
@@ -367,11 +367,9 @@ abstract class SharingManagerImpl<S extends Shareable>
@Override @Override
public Collection<SharingInvitationItem> getInvitations() public Collection<SharingInvitationItem> getInvitations()
throws DbException { throws DbException {
List<SharingInvitationItem> items = List<SharingInvitationItem> items = new ArrayList<>();
new ArrayList<SharingInvitationItem>();
BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery(); BdfDictionary query = messageParser.getInvitesAvailableToAnswerQuery();
Map<S, Collection<Contact>> sharers = Map<S, Collection<Contact>> sharers = new HashMap<>();
new HashMap<S, Collection<Contact>>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
// get invitations from each contact // get invitations from each contact
@@ -387,7 +385,7 @@ abstract class SharingManagerImpl<S extends Shareable>
if (sharers.containsKey(s)) { if (sharers.containsKey(s)) {
sharers.get(s).add(c); sharers.get(s).add(c);
} else { } else {
Collection<Contact> contacts = new ArrayList<Contact>(); Collection<Contact> contacts = new ArrayList<>();
contacts.add(c); contacts.add(c);
sharers.put(s, contacts); sharers.put(s, contacts);
} }
@@ -414,7 +412,7 @@ abstract class SharingManagerImpl<S extends Shareable>
@Override @Override
public Collection<Contact> getSharedWith(GroupId g) throws DbException { public Collection<Contact> getSharedWith(GroupId g) throws DbException {
// TODO report also pending invitations // TODO report also pending invitations
Collection<Contact> contacts = new ArrayList<Contact>(); Collection<Contact> contacts = new ArrayList<>();
Transaction txn = db.startTransaction(true); Transaction txn = db.startTransaction(true);
try { try {
for (Contact c : db.getContacts(txn)) { for (Contact c : db.getContacts(txn)) {

View File

@@ -88,8 +88,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
private final Executor ioExecutor; private final Executor ioExecutor;
private final Random random = new Random(); private final Random random = new Random();
private final Map<Contact, LocalAuthor> localAuthors = private final Map<Contact, LocalAuthor> localAuthors = new HashMap<>();
new HashMap<Contact, LocalAuthor>();
@Inject @Inject
TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock, TestDataCreatorImpl(AuthorFactory authorFactory, Clock clock,
@@ -146,7 +145,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
private List<Contact> createContacts() throws DbException { 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(); LocalAuthor localAuthor = identityManager.getLocalAuthor();
for (int i = 0; i < NUM_CONTACTS; i++) { for (int i = 0; i < NUM_CONTACTS; i++) {
Contact contact = addRandomContact(localAuthor); Contact contact = addRandomContact(localAuthor);
@@ -206,8 +205,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
} }
private Map<TransportId, TransportProperties> getRandomTransportProperties() { private Map<TransportId, TransportProperties> getRandomTransportProperties() {
Map<TransportId, TransportProperties> props = Map<TransportId, TransportProperties> props = new HashMap<>();
new HashMap<TransportId, TransportProperties>();
// Bluetooth // Bluetooth
TransportProperties bt = new TransportProperties(); TransportProperties bt = new TransportProperties();
@@ -339,7 +337,7 @@ public class TestDataCreatorImpl implements TestDataCreator {
private List<Forum> createForums(List<Contact> contacts) private List<Forum> createForums(List<Contact> contacts)
throws DbException { 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++) { for (int i = 0; i < NUM_FORUMS; i++) {
// create forum // create forum
String name = GROUP_NAMES[random.nextInt(GROUP_NAMES.length)]; 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) private void createRandomForumPosts(Forum forum, List<Contact> contacts)
throws DbException { throws DbException {
List<ForumPost> posts = new ArrayList<ForumPost>(); List<ForumPost> posts = new ArrayList<>();
for (int i = 0; i < NUM_FORUM_POSTS; i++) { for (int i = 0; i < NUM_FORUM_POSTS; i++) {
Contact contact = contacts.get(random.nextInt(contacts.size())); Contact contact = contacts.get(random.nextInt(contacts.size()));
LocalAuthor author = localAuthors.get(contact); LocalAuthor author = localAuthors.get(contact);

View File

@@ -131,7 +131,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<MessageValidator> captured = final AtomicReference<MessageValidator> captured =
new AtomicReference<MessageValidator>(); new AtomicReference<>();
final QueueMessageValidator queueMessageValidator = final QueueMessageValidator queueMessageValidator =
context.mock(QueueMessageValidator.class); context.mock(QueueMessageValidator.class);
// The message is too short to be a valid queue message // The message is too short to be a valid queue message
@@ -142,7 +142,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerMessageValidator(with(clientId), oneOf(validationManager).registerMessageValidator(with(clientId),
with(any(MessageValidator.class))); with(any(MessageValidator.class)));
will(new CaptureArgumentAction<MessageValidator>(captured, will(new CaptureArgumentAction<>(captured,
MessageValidator.class, 1)); MessageValidator.class, 1));
}}); }});
@@ -175,7 +175,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<MessageValidator> captured = final AtomicReference<MessageValidator> captured =
new AtomicReference<MessageValidator>(); new AtomicReference<>();
final QueueMessageValidator queueMessageValidator = final QueueMessageValidator queueMessageValidator =
context.mock(QueueMessageValidator.class); context.mock(QueueMessageValidator.class);
// The message has a negative queue position // The message has a negative queue position
@@ -188,7 +188,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerMessageValidator(with(clientId), oneOf(validationManager).registerMessageValidator(with(clientId),
with(any(MessageValidator.class))); with(any(MessageValidator.class)));
will(new CaptureArgumentAction<MessageValidator>(captured, will(new CaptureArgumentAction<>(captured,
MessageValidator.class, 1)); MessageValidator.class, 1));
}}); }});
@@ -221,7 +221,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<MessageValidator> captured = final AtomicReference<MessageValidator> captured =
new AtomicReference<MessageValidator>(); new AtomicReference<>();
final QueueMessageValidator queueMessageValidator = final QueueMessageValidator queueMessageValidator =
context.mock(QueueMessageValidator.class); context.mock(QueueMessageValidator.class);
final Metadata metadata = new Metadata(); final Metadata metadata = new Metadata();
@@ -235,7 +235,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerMessageValidator(with(clientId), oneOf(validationManager).registerMessageValidator(with(clientId),
with(any(MessageValidator.class))); with(any(MessageValidator.class)));
will(new CaptureArgumentAction<MessageValidator>(captured, will(new CaptureArgumentAction<>(captured,
MessageValidator.class, 1)); MessageValidator.class, 1));
// The message should be delegated // The message should be delegated
oneOf(queueMessageValidator).validateMessage( oneOf(queueMessageValidator).validateMessage(
@@ -268,7 +268,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
final ValidationManager validationManager = final ValidationManager validationManager =
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<IncomingMessageHook> captured = final AtomicReference<IncomingMessageHook> captured =
new AtomicReference<IncomingMessageHook>(); new AtomicReference<>();
final IncomingQueueMessageHook incomingQueueMessageHook = final IncomingQueueMessageHook incomingQueueMessageHook =
context.mock(IncomingQueueMessageHook.class); context.mock(IncomingQueueMessageHook.class);
@@ -284,7 +284,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerIncomingMessageHook(with(clientId), oneOf(validationManager).registerIncomingMessageHook(with(clientId),
with(any(IncomingMessageHook.class))); with(any(IncomingMessageHook.class)));
will(new CaptureArgumentAction<IncomingMessageHook>(captured, will(new CaptureArgumentAction<>(captured,
IncomingMessageHook.class, 1)); IncomingMessageHook.class, 1));
oneOf(db).getGroupMetadata(txn, groupId); oneOf(db).getGroupMetadata(txn, groupId);
will(returnValue(groupMetadata)); will(returnValue(groupMetadata));
@@ -320,7 +320,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
final ValidationManager validationManager = final ValidationManager validationManager =
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<IncomingMessageHook> captured = final AtomicReference<IncomingMessageHook> captured =
new AtomicReference<IncomingMessageHook>(); new AtomicReference<>();
final IncomingQueueMessageHook incomingQueueMessageHook = final IncomingQueueMessageHook incomingQueueMessageHook =
context.mock(IncomingQueueMessageHook.class); context.mock(IncomingQueueMessageHook.class);
@@ -338,7 +338,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerIncomingMessageHook(with(clientId), oneOf(validationManager).registerIncomingMessageHook(with(clientId),
with(any(IncomingMessageHook.class))); with(any(IncomingMessageHook.class)));
will(new CaptureArgumentAction<IncomingMessageHook>(captured, will(new CaptureArgumentAction<>(captured,
IncomingMessageHook.class, 1)); IncomingMessageHook.class, 1));
oneOf(db).getGroupMetadata(txn, groupId); oneOf(db).getGroupMetadata(txn, groupId);
will(returnValue(groupMetadata)); will(returnValue(groupMetadata));
@@ -376,7 +376,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
final ValidationManager validationManager = final ValidationManager validationManager =
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<IncomingMessageHook> captured = final AtomicReference<IncomingMessageHook> captured =
new AtomicReference<IncomingMessageHook>(); new AtomicReference<>();
final IncomingQueueMessageHook incomingQueueMessageHook = final IncomingQueueMessageHook incomingQueueMessageHook =
context.mock(IncomingQueueMessageHook.class); context.mock(IncomingQueueMessageHook.class);
@@ -393,7 +393,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerIncomingMessageHook(with(clientId), oneOf(validationManager).registerIncomingMessageHook(with(clientId),
with(any(IncomingMessageHook.class))); with(any(IncomingMessageHook.class)));
will(new CaptureArgumentAction<IncomingMessageHook>(captured, will(new CaptureArgumentAction<>(captured,
IncomingMessageHook.class, 1)); IncomingMessageHook.class, 1));
oneOf(db).getGroupMetadata(txn, groupId); oneOf(db).getGroupMetadata(txn, groupId);
will(returnValue(groupMetadata)); will(returnValue(groupMetadata));
@@ -434,7 +434,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
final ValidationManager validationManager = final ValidationManager validationManager =
context.mock(ValidationManager.class); context.mock(ValidationManager.class);
final AtomicReference<IncomingMessageHook> captured = final AtomicReference<IncomingMessageHook> captured =
new AtomicReference<IncomingMessageHook>(); new AtomicReference<>();
final IncomingQueueMessageHook incomingQueueMessageHook = final IncomingQueueMessageHook incomingQueueMessageHook =
context.mock(IncomingQueueMessageHook.class); context.mock(IncomingQueueMessageHook.class);
@@ -458,7 +458,7 @@ public class MessageQueueManagerImplTest extends BriarTestCase {
context.checking(new Expectations() {{ context.checking(new Expectations() {{
oneOf(validationManager).registerIncomingMessageHook(with(clientId), oneOf(validationManager).registerIncomingMessageHook(with(clientId),
with(any(IncomingMessageHook.class))); with(any(IncomingMessageHook.class)));
will(new CaptureArgumentAction<IncomingMessageHook>(captured, will(new CaptureArgumentAction<>(captured,
IncomingMessageHook.class, 1)); IncomingMessageHook.class, 1));
oneOf(db).getGroupMetadata(txn, groupId); oneOf(db).getGroupMetadata(txn, groupId);
will(returnValue(groupMetadata)); will(returnValue(groupMetadata));

View File

@@ -19,7 +19,7 @@ public class MessageTreeImplTest {
@Test @Test
public void testMessageTree() { public void testMessageTree() {
tree = new MessageTreeImpl<TestNode>(); tree = new MessageTreeImpl<>();
testSimpleTree(); testSimpleTree();
tree.clear(); tree.clear();
testSimpleTree(); testSimpleTree();

View File

@@ -105,7 +105,7 @@ public class FeedManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testPostFeedEntriesEmptyDate() throws Exception { public void testPostFeedEntriesEmptyDate() throws Exception {
final Transaction txn = new Transaction(null, false); final Transaction txn = new Transaction(null, false);
List<SyndEntry> entries = new ArrayList<SyndEntry>(); List<SyndEntry> entries = new ArrayList<>();
entries.add(new SyndEntryImpl()); entries.add(new SyndEntryImpl());
final SyndEntry entry = new SyndEntryImpl(); final SyndEntry entry = new SyndEntryImpl();
entry.setUpdatedDate(new Date()); entry.setUpdatedDate(new Date());

View File

@@ -464,7 +464,7 @@ public class IntroductionIntegrationTest
assertTrue(listener1.requestReceived); assertTrue(listener1.requestReceived);
// get SessionId // get SessionId
List<IntroductionMessage> list = new ArrayList<IntroductionMessage>( List<IntroductionMessage> list = new ArrayList<>(
introductionManager1.getIntroductionMessages(contactId0From1)); introductionManager1.getIntroductionMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
assertTrue(list.get(0) instanceof IntroductionRequest); assertTrue(list.get(0) instanceof IntroductionRequest);

View File

@@ -172,7 +172,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext = BdfMessageContext messageContext =
validator.validateMessage(message, group, body); validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, creator, assertExpectedMessageContext(messageContext, JOIN, creator,
Collections.<MessageId>emptyList()); Collections.emptyList());
assertTrue(messageContext.getDictionary() assertTrue(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG)); .getBoolean(KEY_INITIAL_JOIN_MSG));
} }
@@ -325,7 +325,7 @@ public class GroupMessageValidatorTest extends ValidatorTestCase {
BdfMessageContext messageContext = BdfMessageContext messageContext =
validator.validateMessage(message, group, body); validator.validateMessage(message, group, body);
assertExpectedMessageContext(messageContext, JOIN, member, assertExpectedMessageContext(messageContext, JOIN, member,
Collections.<MessageId>emptyList()); Collections.emptyList());
assertFalse(messageContext.getDictionary() assertFalse(messageContext.getDictionary()
.getBoolean(KEY_INITIAL_JOIN_MSG)); .getBoolean(KEY_INITIAL_JOIN_MSG));
} }

View File

@@ -631,8 +631,7 @@ public class GroupInvitationManagerImplTest extends BrambleMockTestCase {
final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u")); final BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
final MessageId messageId2 = new MessageId(TestUtils.getRandomId()); final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e")); final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
final Map<MessageId, BdfDictionary> results = final Map<MessageId, BdfDictionary> results = new HashMap<>();
new HashMap<MessageId, BdfDictionary>();
results.put(message.getId(), meta); results.put(message.getId(), meta);
results.put(messageId2, meta2); results.put(messageId2, meta2);
final long time1 = 1L, time2 = 2L; 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 BdfDictionary query = BdfDictionary.of(new BdfEntry("q", "u"));
final MessageId messageId2 = new MessageId(TestUtils.getRandomId()); final MessageId messageId2 = new MessageId(TestUtils.getRandomId());
final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e")); final BdfDictionary meta2 = BdfDictionary.of(new BdfEntry("m2", "e"));
final Map<MessageId, BdfDictionary> results = final Map<MessageId, BdfDictionary> results = new HashMap<>();
new HashMap<MessageId, BdfDictionary>();
results.put(message.getId(), meta); results.put(message.getId(), meta);
results.put(messageId2, meta2); results.put(messageId2, meta2);
final Message message2 = new Message(messageId2, contactGroup.getId(), final Message message2 = new Message(messageId2, contactGroup.getId(),

View File

@@ -146,9 +146,8 @@ public class BlogSharingIntegrationTest
assertTrue(blogManager1.getBlogs().contains(blog2)); assertTrue(blogManager1.getBlogs().contains(blog2));
// invitee has one invitation message from sharer // invitee has one invitation message from sharer
List<InvitationMessage> list = List<InvitationMessage> list = new ArrayList<>(
new ArrayList<InvitationMessage>(blogSharingManager1 blogSharingManager1.getInvitationMessages(contactId0From1));
.getInvitationMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
// check other things are alright with the message // check other things are alright with the message
for (InvitationMessage m : list) { for (InvitationMessage m : list) {
@@ -222,9 +221,8 @@ public class BlogSharingIntegrationTest
assertTrue(blogManager1.getBlogs().contains(rssBlog)); assertTrue(blogManager1.getBlogs().contains(rssBlog));
// invitee has one invitation message from sharer // invitee has one invitation message from sharer
List<InvitationMessage> list = List<InvitationMessage> list = new ArrayList<>(
new ArrayList<InvitationMessage>(blogSharingManager1 blogSharingManager1.getInvitationMessages(contactId0From1));
.getInvitationMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
// check other things are alright with the message // check other things are alright with the message
for (InvitationMessage m : list) { for (InvitationMessage m : list) {
@@ -286,9 +284,8 @@ public class BlogSharingIntegrationTest
assertEquals(0, blogSharingManager1.getInvitations().size()); assertEquals(0, blogSharingManager1.getInvitations().size());
// invitee has one invitation message from sharer and one response // invitee has one invitation message from sharer and one response
List<InvitationMessage> list = List<InvitationMessage> list = new ArrayList<>(
new ArrayList<InvitationMessage>(blogSharingManager1 blogSharingManager1.getInvitationMessages(contactId0From1));
.getInvitationMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
// check things are alright with the message // check things are alright with the message
for (InvitationMessage m : list) { for (InvitationMessage m : list) {

View File

@@ -94,23 +94,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testAddingContactFreshState() throws Exception { public void testAddingContactFreshState() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
new HashMap<MessageId, BdfDictionary>(0);
testAddingContact(sessions); testAddingContact(sessions);
} }
@Test @Test
public void testAddingContactExistingState() throws Exception { public void testAddingContactExistingState() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
new HashMap<MessageId, BdfDictionary>(1);
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
testAddingContact(sessions); testAddingContact(sessions);
} }
@Test(expected = DbException.class) @Test(expected = DbException.class)
public void testAddingContactMultipleSessions() throws Exception { public void testAddingContactMultipleSessions() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
new HashMap<MessageId, BdfDictionary>(2);
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
testAddingContact(sessions); testAddingContact(sessions);
@@ -118,23 +115,20 @@ public class BlogSharingManagerImplTest extends BrambleMockTestCase {
@Test @Test
public void testRemovingBlogFreshState() throws Exception { public void testRemovingBlogFreshState() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(0);
new HashMap<MessageId, BdfDictionary>(0);
testRemovingBlog(sessions); testRemovingBlog(sessions);
} }
@Test @Test
public void testRemovingBlogExistingState() throws Exception { public void testRemovingBlogExistingState() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(1);
new HashMap<MessageId, BdfDictionary>(1);
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
testRemovingBlog(sessions); testRemovingBlog(sessions);
} }
@Test(expected = DbException.class) @Test(expected = DbException.class)
public void testRemovingBlogMultipleSessions() throws Exception { public void testRemovingBlogMultipleSessions() throws Exception {
Map<MessageId, BdfDictionary> sessions = Map<MessageId, BdfDictionary> sessions = new HashMap<>(2);
new HashMap<MessageId, BdfDictionary>(2);
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
sessions.put(new MessageId(getRandomId()), new BdfDictionary()); sessions.put(new MessageId(getRandomId()), new BdfDictionary());
testRemovingBlog(sessions); testRemovingBlog(sessions);

View File

@@ -129,9 +129,8 @@ public class ForumSharingIntegrationTest
assertEquals(1, forumManager1.getForums().size()); assertEquals(1, forumManager1.getForums().size());
// invitee has one invitation message from sharer // invitee has one invitation message from sharer
List<InvitationMessage> list = List<InvitationMessage> list = new ArrayList<>(
new ArrayList<InvitationMessage>(forumSharingManager1 forumSharingManager1.getInvitationMessages(contactId0From1));
.getInvitationMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
// check other things are alright with the forum message // check other things are alright with the forum message
for (InvitationMessage m : list) { for (InvitationMessage m : list) {
@@ -189,9 +188,8 @@ public class ForumSharingIntegrationTest
assertEquals(0, forumSharingManager1.getInvitations().size()); assertEquals(0, forumSharingManager1.getInvitations().size());
// invitee has one invitation message from sharer and one response // invitee has one invitation message from sharer and one response
List<InvitationMessage> list = List<InvitationMessage> list = new ArrayList<>(
new ArrayList<InvitationMessage>(forumSharingManager1 forumSharingManager1.getInvitationMessages(contactId0From1));
.getInvitationMessages(contactId0From1));
assertEquals(2, list.size()); assertEquals(2, list.size());
// check things are alright with the forum message // check things are alright with the forum message
for (InvitationMessage m : list) { for (InvitationMessage m : list) {