Skip to content

Commit

Permalink
JAMES-1669 refactor for loop to foreach
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/james/project/trunk@1726771 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mbaechler committed Jan 26, 2016
1 parent e4583d4 commit 7671fa6
Show file tree
Hide file tree
Showing 77 changed files with 537 additions and 643 deletions.
Expand Up @@ -21,7 +21,6 @@
package org.apache.james.mailbox.acl; package org.apache.james.mailbox.acl;


import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
Expand Down Expand Up @@ -251,8 +250,7 @@ public boolean hasRight(String requestUser, GroupMembershipResolver groupMembers
boolean result = false; boolean result = false;
Map<MailboxACLEntryKey, MailboxACLRights> entries = resourceOwnerIsGroup ? groupGlobalACL.getEntries() : userGlobalACL.getEntries(); Map<MailboxACLEntryKey, MailboxACLRights> entries = resourceOwnerIsGroup ? groupGlobalACL.getEntries() : userGlobalACL.getEntries();
if (entries != null) { if (entries != null) {
for (Iterator<Map.Entry<MailboxACLEntryKey, MailboxACLRights>> it = entries.entrySet().iterator(); it.hasNext();) { for (Entry<MailboxACLEntryKey, MailboxACLRights> entry : entries.entrySet()) {
final Entry<MailboxACLEntryKey, MailboxACLRights> entry = it.next();
final MailboxACLEntryKey key = entry.getKey(); final MailboxACLEntryKey key = entry.getKey();
if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) { if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) {
if (key.isNegative()) { if (key.isNegative()) {
Expand All @@ -267,8 +265,7 @@ public boolean hasRight(String requestUser, GroupMembershipResolver groupMembers
if (resourceACL != null) { if (resourceACL != null) {
entries = resourceACL.getEntries(); entries = resourceACL.getEntries();
if (entries != null) { if (entries != null) {
for (Iterator<Map.Entry<MailboxACLEntryKey, MailboxACLRights>> it = entries.entrySet().iterator(); it.hasNext();) { for (Entry<MailboxACLEntryKey, MailboxACLRights> entry : entries.entrySet()) {
final Entry<MailboxACLEntryKey, MailboxACLRights> entry = it.next();
final MailboxACLEntryKey key = entry.getKey(); final MailboxACLEntryKey key = entry.getKey();
if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) { if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup) && entry.getValue().contains(right)) {
if (key.isNegative()) { if (key.isNegative()) {
Expand Down Expand Up @@ -425,8 +422,7 @@ public MailboxACL.MailboxACLRights resolveRights(String requestUser, GroupMember
private void resolveRights(MailboxACLEntryKey queryKey, GroupMembershipResolver groupMembershipResolver, final Map<MailboxACLEntryKey, MailboxACLRights> entries, String resourceOwner, boolean resourceOwnerIsGroup, MailboxACL.MailboxACLRights[] positiveNegativePair) private void resolveRights(MailboxACLEntryKey queryKey, GroupMembershipResolver groupMembershipResolver, final Map<MailboxACLEntryKey, MailboxACLRights> entries, String resourceOwner, boolean resourceOwnerIsGroup, MailboxACL.MailboxACLRights[] positiveNegativePair)
throws UnsupportedRightException { throws UnsupportedRightException {
if (entries != null) { if (entries != null) {
for (Iterator<Map.Entry<MailboxACLEntryKey, MailboxACLRights>> it = entries.entrySet().iterator(); it.hasNext();) { for (Entry<MailboxACLEntryKey, MailboxACLRights> entry : entries.entrySet()) {
final Entry<MailboxACLEntryKey, MailboxACLRights> entry = it.next();
final MailboxACLEntryKey key = entry.getKey(); final MailboxACLEntryKey key = entry.getKey();
if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup)) { if (applies(key, queryKey, groupMembershipResolver, resourceOwner, resourceOwnerIsGroup)) {
if (key.isNegative()) { if (key.isNegative()) {
Expand Down
Expand Up @@ -20,7 +20,6 @@
package org.apache.james.mailbox.model; package org.apache.james.mailbox.model;


import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.Set; import java.util.Set;


import org.apache.james.mailbox.model.MessageResult.MimePath; import org.apache.james.mailbox.model.MessageResult.MimePath;
Expand Down Expand Up @@ -92,8 +91,7 @@ public void addPartContent(MimePath path, int content) {
partContentDescriptors = new HashSet<PartContentDescriptor>(); partContentDescriptors = new HashSet<PartContentDescriptor>();
} }
PartContentDescriptorImpl currentDescriptor = null; PartContentDescriptorImpl currentDescriptor = null;
for (Iterator<PartContentDescriptor> it = partContentDescriptors.iterator(); it.hasNext();) { for (PartContentDescriptor descriptor : partContentDescriptors) {
PartContentDescriptor descriptor = (PartContentDescriptor) it.next();
if (path.equals(descriptor.path())) { if (path.equals(descriptor.path())) {
currentDescriptor = (PartContentDescriptorImpl) descriptor; currentDescriptor = (PartContentDescriptorImpl) descriptor;
break; break;
Expand Down
Expand Up @@ -76,11 +76,9 @@ private static void addModifiedUserFlags(Flags oldFlags, Flags newFlags, Flags m




private static void addModifiedUserFlags(Flags oldFlags, Flags newFlags, String[] userflags, Flags modifiedFlags) { private static void addModifiedUserFlags(Flags oldFlags, Flags newFlags, String[] userflags, Flags modifiedFlags) {
for (int i = 0; i < userflags.length; i++) { for (String userFlag : userflags) {
String userFlag = userflags[i];
if (isChanged(oldFlags, newFlags, userFlag)) { if (isChanged(oldFlags, newFlags, userFlag)) {
modifiedFlags.add(userFlag); modifiedFlags.add(userFlag);

} }
} }
} }
Expand Down
Expand Up @@ -121,12 +121,11 @@ public void run() {


// check if the uids were higher on each append. See MAILBOX-131 // check if the uids were higher on each append. See MAILBOX-131
long last = 0; long last = 0;
for (int i = 0; i < uList.size(); i++) { for (Long uid : uList) {
long l = uList.get(i); if (uid <= last) {
if (l <= last) { fail(uid + "->" + last);
fail(l + "->" + last);
} else { } else {
last = l; last = uid;
} }


} }
Expand Down
Expand Up @@ -758,8 +758,7 @@ private void deleteDeletedMessagesInMailbox(Mailbox<HBaseId> mailbox) throws IOE


private Map<Long, MessageMetaData> createMetaData(List<MailboxMessage<HBaseId>> uids) { private Map<Long, MessageMetaData> createMetaData(List<MailboxMessage<HBaseId>> uids) {
final Map<Long, MessageMetaData> data = new HashMap<Long, MessageMetaData>(); final Map<Long, MessageMetaData> data = new HashMap<Long, MessageMetaData>();
for (int i = 0; i < uids.size(); i++) { for (MailboxMessage<HBaseId> m : uids) {
MailboxMessage<HBaseId> m = uids.get(i);
data.put(m.getUid(), new SimpleMessageMetaData(m)); data.put(m.getUid(), new SimpleMessageMetaData(m));
} }
return data; return data;
Expand Down
Expand Up @@ -18,29 +18,6 @@
****************************************************************/ ****************************************************************/
package org.apache.james.mailbox.hbase.mail; package org.apache.james.mailbox.hbase.mail;


import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES;
import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOX_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_META_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_BODY_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_HEADERS_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTION_CF;
import static org.junit.Assert.assertEquals;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.mail.Flags;
import javax.mail.internet.SharedInputStream;
import javax.mail.util.SharedByteArrayInputStream;

import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Bytes;
import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MailboxSession;
Expand All @@ -58,6 +35,28 @@
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;


import javax.mail.Flags;
import javax.mail.internet.SharedInputStream;
import javax.mail.util.SharedByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES;
import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOXES_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.MAILBOX_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_META_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGES_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_BODY_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.MESSAGE_DATA_HEADERS_CF;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTIONS_TABLE;
import static org.apache.james.mailbox.hbase.HBaseNames.SUBSCRIPTION_CF;
import static org.junit.Assert.assertEquals;

/** /**
* Unit tests for HBaseMessageMapper. * Unit tests for HBaseMessageMapper.
* *
Expand Down Expand Up @@ -100,8 +99,8 @@ public void setUp() throws Exception {
generateTestData(); generateTestData();
final MailboxSession session = new MockMailboxSession("ieugen"); final MailboxSession session = new MockMailboxSession("ieugen");
messageMapper = new HBaseMessageMapper(session, uidProvider, modSeqProvider, conf); messageMapper = new HBaseMessageMapper(session, uidProvider, modSeqProvider, conf);
for (int i = 0; i < MESSAGE_NO.size(); i++) { for (MailboxMessage<HBaseId> message : MESSAGE_NO) {
messageMapper.add(MBOXES.get(1), MESSAGE_NO.get(i)); messageMapper.add(MBOXES.get(1), message);
} }
} }


Expand Down
Expand Up @@ -409,8 +409,7 @@ public Map<Long, MessageMetaData> expungeMarkedForDeletionInMailbox(Mailbox<JCRI
break; break;
} }
Map<Long, MessageMetaData> uids = new HashMap<Long, MessageMetaData>(); Map<Long, MessageMetaData> uids = new HashMap<Long, MessageMetaData>();
for (int i = 0; i < results.size(); i++) { for (MailboxMessage<JCRId> m : results) {
MailboxMessage<JCRId> m = results.get(i);
long uid = m.getUid(); long uid = m.getUid();
uids.put(uid, new SimpleMessageMetaData(m)); uids.put(uid, new SimpleMessageMetaData(m));
delete(mailbox, m); delete(mailbox, m);
Expand Down
Expand Up @@ -298,10 +298,9 @@ public void merge(Node node) throws RepositoryException, IOException {




List<Property> currentProperties = getProperties(); List<Property> currentProperties = getProperties();
List<Property> newProperites = new ArrayList<Property>(); List<Property> newProperties = new ArrayList<Property>();
for (int i = 0; i < currentProperties.size(); i++) { for (Property prop : currentProperties) {
Property prop = currentProperties.get(i); newProperties.add(new JCRProperty(prop, logger));
newProperites.add(new JCRProperty(prop, logger));
} }
// remove old properties, we will add a bunch of new ones // remove old properties, we will add a bunch of new ones
NodeIterator iterator = node.getNodes("messageProperty"); NodeIterator iterator = node.getNodes("messageProperty");
Expand All @@ -310,8 +309,8 @@ public void merge(Node node) throws RepositoryException, IOException {
} }


// store new properties // store new properties
for (int i = 0; i < newProperites.size(); i++) { for (Property newProperty : newProperties) {
JCRProperty prop = (JCRProperty) newProperites.get(i); JCRProperty prop = (JCRProperty) newProperty;
Node propNode = node.addNode("messageProperty", "nt:unstructured"); Node propNode = node.addNode("messageProperty", "nt:unstructured");
propNode.addMixin(PROPERTY_NODE_TYPE); propNode.addMixin(PROPERTY_NODE_TYPE);
prop.merge(propNode); prop.merge(propNode);
Expand Down
Expand Up @@ -72,8 +72,8 @@ public void delete(Subscription subscription) throws SubscriptionException {
Property prop = node.getProperty(JCRSubscription.MAILBOXES_PROPERTY); Property prop = node.getProperty(JCRSubscription.MAILBOXES_PROPERTY);
Value[] values = prop.getValues(); Value[] values = prop.getValues();
List<String> newValues = new ArrayList<String>(); List<String> newValues = new ArrayList<String>();
for (int i = 0; i < values.length; i++) { for (Value value : values) {
String m = values[i].getString(); String m = value.getString();
if (m.equals(sub.getMailbox()) == false) { if (m.equals(sub.getMailbox()) == false) {
newValues.add(m); newValues.add(m);
} }
Expand Down Expand Up @@ -139,8 +139,8 @@ public List<Subscription> findSubscriptionsForUser(String user) throws Subscript
Node node = nodeIt.nextNode(); Node node = nodeIt.nextNode();
if (node.hasProperty(JCRSubscription.MAILBOXES_PROPERTY)) { if (node.hasProperty(JCRSubscription.MAILBOXES_PROPERTY)) {
Value[] values = node.getProperty(JCRSubscription.MAILBOXES_PROPERTY).getValues(); Value[] values = node.getProperty(JCRSubscription.MAILBOXES_PROPERTY).getValues();
for (int i = 0; i < values.length; i++) { for (Value value : values) {
subList.add(new JCRSubscription(node, values[i].getString(), getLogger())); subList.add(new JCRSubscription(node, value.getString(), getLogger()));
} }
} }
} }
Expand Down
Expand Up @@ -112,8 +112,8 @@ public void merge(Node node) throws RepositoryException{
if (node.hasProperty(MAILBOXES_PROPERTY)) { if (node.hasProperty(MAILBOXES_PROPERTY)) {
Value[] mailboxes = node.getProperty(MAILBOXES_PROPERTY).getValues(); Value[] mailboxes = node.getProperty(MAILBOXES_PROPERTY).getValues();
List<String>newMailboxes = new ArrayList<String>(); List<String>newMailboxes = new ArrayList<String>();
for (int i = 0; i< mailboxes.length; i++) { for (Value mailbox : mailboxes) {
String m = mailboxes[i].getString(); String m = mailbox.getString();
newMailboxes.add(m); newMailboxes.add(m);
} }
if (newMailboxes.contains(getMailbox()) == false) { if (newMailboxes.contains(getMailbox()) == false) {
Expand Down
Expand Up @@ -358,8 +358,7 @@ private List<MailboxMessage<JPAId>> findMessagesInMailbox(Mailbox<JPAId> mailbox


private Map<Long, MessageMetaData> createMetaData(List<MailboxMessage<JPAId>> uids) { private Map<Long, MessageMetaData> createMetaData(List<MailboxMessage<JPAId>> uids) {
final Map<Long, MessageMetaData> data = new HashMap<Long, MessageMetaData>(); final Map<Long, MessageMetaData> data = new HashMap<Long, MessageMetaData>();
for (int i = 0; i < uids.size(); i++) { for (MailboxMessage<JPAId> m : uids) {
MailboxMessage<JPAId> m = uids.get(i);
data.put(m.getUid(), new SimpleMessageMetaData(m)); data.put(m.getUid(), new SimpleMessageMetaData(m));
} }
return data; return data;
Expand Down
Expand Up @@ -507,8 +507,8 @@ public void setFlags(Flags flags) {
*/ */
String[] userflags = flags.getUserFlags(); String[] userflags = flags.getUserFlags();
userFlags.clear(); userFlags.clear();
for (int i = 0 ; i< userflags.length; i++) { for (String userflag : userflags) {
userFlags.add(new JPAUserFlag(userflags[i])); userFlags.add(new JPAUserFlag(userflag));
} }
} }


Expand Down

0 comments on commit 7671fa6

Please sign in to comment.