List of usage examples for com.google.common.collect Sets newHashSetWithExpectedSize
public static <E> HashSet<E> newHashSetWithExpectedSize(int expectedSize)
From source file:com.android.mail.browse.ConversationCursor.java
/** * If a destructive notification action was triggered, but has not yet been processed because an * "Undo" action is available, we do not want to show the conversation in the list. *///from ww w.ja v a 2s .c o m public void handleNotificationActions() { // Needs to be on the UI thread because it updates the ConversationCursor's internal // state which violates assumptions about how the ListView works and how // the ConversationViewPager works if performed off of the UI thread. // Also, prevents ConcurrentModificationExceptions on mNotificationTempDeleted. mMainThreadHandler.post(new Runnable() { @Override public void run() { final SparseArrayCompat<NotificationAction> undoNotifications = NotificationActionUtils.sUndoNotifications; final Set<Conversation> undoneConversations = NotificationActionUtils.sUndoneConversations; final Set<Conversation> undoConversations = Sets .newHashSetWithExpectedSize(undoNotifications.size()); boolean changed = false; for (int i = 0; i < undoNotifications.size(); i++) { final NotificationAction notificationAction = undoNotifications.get(undoNotifications.keyAt(i)); // We only care about notifications that were for this folder // or if the action was delete final Folder folder = notificationAction.getFolder(); final boolean deleteAction = notificationAction .getNotificationActionType() == NotificationActionType.DELETE; if (folder.conversationListUri.equals(qUri) || deleteAction) { // We only care about destructive actions if (notificationAction.getNotificationActionType().getIsDestructive()) { final Conversation conversation = notificationAction.getConversation(); undoConversations.add(conversation); if (!mNotificationTempDeleted.contains(conversation)) { sProvider.deleteLocal(conversation.uri, ConversationCursor.this, null); mNotificationTempDeleted.add(conversation); changed = true; } } } } // Remove any conversations from the temporary deleted state // if they no longer have an undo notification final Iterator<Conversation> iterator = mNotificationTempDeleted.iterator(); while (iterator.hasNext()) { final Conversation conversation = iterator.next(); if (!undoConversations.contains(conversation)) { // We should only be un-deleting local cursor edits // if the notification was undone rather than just // disappearing because the internal cursor // gets updated when the undo goes away via timeout which // will update everything properly. if (undoneConversations.contains(conversation)) { sProvider.undeleteLocal(conversation.uri, ConversationCursor.this); undoneConversations.remove(conversation); } iterator.remove(); changed = true; } } if (changed) { notifyDataChanged(); } } }); }
From source file:com.zimbra.cs.db.DbMailItem.java
public static List<UnderlyingData> getByHashes(Mailbox mbox, List<String> hashes) throws ServiceException { if (ListUtil.isEmpty(hashes)) { return null; }/*from ww w.jav a2s.c o m*/ DbConnection conn = mbox.getOperationConnection(); PreparedStatement stmt = null; ResultSet rs = null; try { stmt = conn.prepareStatement("SELECT " + DB_FIELDS + " FROM " + getMailItemTableName(mbox, "mi") + ", " + getConversationTableName(mbox, "oc") + " WHERE mi.id = oc.conv_id AND " + DbUtil.whereIn("oc.hash", hashes.size()) + (DebugConfig.disableMailboxGroups ? "" : " AND oc.mailbox_id = ? AND mi.mailbox_id = oc.mailbox_id")); int pos = 1; for (String hash : hashes) { stmt.setString(pos++, hash); } pos = setMailboxId(stmt, mbox, pos); rs = stmt.executeQuery(); List<UnderlyingData> dlist = new ArrayList<UnderlyingData>(3); Set<Integer> convIds = Sets.newHashSetWithExpectedSize(3); while (rs.next()) { int id = rs.getInt(CI_ID); if (convIds.contains(id)) { continue; } UnderlyingData data = constructItem(rs); if (data.type == MailItem.Type.CONVERSATION.toByte()) { completeConversation(mbox, conn, data); } dlist.add(data); convIds.add(data.id); } return dlist.isEmpty() ? null : dlist; } catch (SQLException e) { throw ServiceException.FAILURE("fetching conversation for hash " + hashes, e); } finally { DbPool.closeResults(rs); DbPool.closeStatement(stmt); } }