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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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.SharingConstants.MSG_KEY_AVAILABLE_TO_ANSWER;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_LOCAL;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_MESSAGE_TYPE;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_READ;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_INVITATION_ACCEPTED;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_SHAREABLE_ID;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_TIMESTAMP;
import static org.briarproject.briar.sharing.SharingConstants.MSG_KEY_VISIBLE_IN_UI;
@@ -91,7 +91,7 @@ abstract class MessageParserImpl<S extends Shareable>
BdfList descriptor = body.getList(2);
S shareable = createShareable(descriptor);
String message = body.getOptionalString(3);
return new InviteMessage<S>(m.getId(), previousMessageId,
return new InviteMessage<>(m.getId(), previousMessageId,
m.getGroupId(), shareable, message, m.getTimestamp());
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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