提交 22b27200 编写于 作者: J Josh Soref

Java 5: foreach

上级 893e5c08
......@@ -245,8 +245,7 @@ public class ExtensionList<T> extends AbstractList<T> implements OnMaster {
}
private <T> boolean removeComponent(Collection<ExtensionComponent<T>> collection, Object t) {
for (Iterator<ExtensionComponent<T>> itr = collection.iterator(); itr.hasNext();) {
ExtensionComponent<T> c = itr.next();
for (ExtensionComponent<T> c : collection) {
if (c.getInstance().equals(t)) {
return collection.remove(c);
}
......
......@@ -1463,9 +1463,9 @@ public class Util {
public static int permissionsToMode(Set<PosixFilePermission> permissions) {
PosixFilePermission[] allPermissions = PosixFilePermission.values();
int result = 0;
for (int i = 0; i < allPermissions.length; i++) {
for (PosixFilePermission allPermission : allPermissions) {
result <<= 1;
result |= permissions.contains(allPermissions[i]) ? 1 : 0;
result |= permissions.contains(allPermission) ? 1 : 0;
}
return result;
}
......
......@@ -339,10 +339,9 @@ public class DependencyGraph implements Comparator<AbstractProject> {
set = new ArrayList<DependencyGroup>();
map.put(key,set);
}
for (ListIterator<DependencyGroup> it = set.listIterator(); it.hasNext();) {
DependencyGroup d = it.next();
for (DependencyGroup d : set) {
// Check for existing edge that connects the same two projects:
if (d.getUpstreamProject()==dep.getUpstreamProject() && d.getDownstreamProject()==dep.getDownstreamProject()) {
if (d.getUpstreamProject() == dep.getUpstreamProject() && d.getDownstreamProject() == dep.getDownstreamProject()) {
d.add(dep);
return;
}
......
......@@ -189,9 +189,9 @@ public class TokenBasedRememberMeServices2 extends TokenBasedRememberMeServices
return null;
}
for (int i = 0; i < cookies.length; i++) {
if (ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY.equals(cookies[i].getName())) {
return cookies[i].getValue();
for (Cookie cookie : cookies) {
if (ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY.equals(cookie.getName())) {
return cookie.getValue();
}
}
......
......@@ -154,8 +154,8 @@ public class Fingerprinter extends Recorder implements Serializable, DependencyD
RunList builds = owner.getBuilds();
Set<String> seenUpstreamProjects = new HashSet<String>();
for ( ListIterator iter = builds.listIterator(); iter.hasNext(); ) {
Run build = (Run) iter.next();
for (Object build1 : builds) {
Run build = (Run) build1;
for (FingerprintAction action : build.getActions(FingerprintAction.class)) {
for (AbstractProject key : action.getDependencies().keySet()) {
if (key == owner) {
......
......@@ -96,8 +96,8 @@ public class MultipartFormDataParser implements AutoCloseable {
return false;
}
for (int i = 0; i < parts.length; i++) {
if ("multipart/form-data".equals(parts[i])) {
for (String part : parts) {
if ("multipart/form-data".equals(part)) {
return true;
}
}
......
......@@ -212,8 +212,7 @@ public class RobustReflectionConverter implements Converter {
if (mapping != null) {
if (mapping.getItemFieldName() != null) {
Collection list = (Collection) newObj;
for (Iterator iter = list.iterator(); iter.hasNext();) {
Object obj = iter.next();
for (Object obj : list) {
writeField(fieldName, mapping.getItemFieldName(), mapping.getItemType(), definedIn, obj);
}
} else {
......
......@@ -149,8 +149,8 @@ public class RegexValidator implements Serializable {
if (value == null) {
return false;
}
for (int i = 0; i < patterns.length; i++) {
if (patterns[i].matcher(value).matches()) {
for (Pattern pattern : patterns) {
if (pattern.matcher(value).matches()) {
return true;
}
}
......@@ -169,13 +169,13 @@ public class RegexValidator implements Serializable {
if (value == null) {
return null;
}
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(value);
for (Pattern pattern : patterns) {
Matcher matcher = pattern.matcher(value);
if (matcher.matches()) {
int count = matcher.groupCount();
String[] groups = new String[count];
for (int j = 0; j < count; j++) {
groups[j] = matcher.group(j+1);
groups[j] = matcher.group(j + 1);
}
return groups;
}
......@@ -196,8 +196,8 @@ public class RegexValidator implements Serializable {
if (value == null) {
return null;
}
for (int i = 0; i < patterns.length; i++) {
Matcher matcher = patterns[i].matcher(value);
for (Pattern pattern : patterns) {
Matcher matcher = pattern.matcher(value);
if (matcher.matches()) {
int count = matcher.groupCount();
if (count == 1) {
......@@ -205,7 +205,7 @@ public class RegexValidator implements Serializable {
}
StringBuilder buffer = new StringBuilder();
for (int j = 0; j < count; j++) {
String component = matcher.group(j+1);
String component = matcher.group(j + 1);
if (component != null) {
buffer.append(component);
}
......
......@@ -284,8 +284,8 @@ public class UrlValidator implements Serializable {
schemes = DEFAULT_SCHEMES;
}
allowedSchemes = new HashSet<String>(schemes.length);
for(int i=0; i < schemes.length; i++) {
allowedSchemes.add(schemes[i].toLowerCase(Locale.ENGLISH));
for (String scheme : schemes) {
allowedSchemes.add(scheme.toLowerCase(Locale.ENGLISH));
}
}
......
......@@ -56,10 +56,10 @@ public class LastGrantedAuthoritiesProperty extends UserProperty {
List<GrantedAuthority> grantedAuthorities = new ArrayList<>(roles.length + 1);
grantedAuthorities.add(new GrantedAuthorityImpl(authenticatedRole));
for (int i = 0; i < roles.length; i++){
for (String role : roles) {
// to avoid having twice that role
if(!authenticatedRole.equals(roles[i])){
grantedAuthorities.add(new GrantedAuthorityImpl(roles[i]));
if (!authenticatedRole.equals(role)) {
grantedAuthorities.add(new GrantedAuthorityImpl(role));
}
}
......
......@@ -124,8 +124,8 @@ public final class TreeString implements Serializable {
public int hashCode() {
int h = parent == null ? 0 : parent.hashCode();
for (int i = 0; i < label.length; i++) {
h = 31 * h + label[i];
for (char c : label) {
h = 31 * h + c;
}
assert toString().hashCode() == h;
......
......@@ -191,8 +191,7 @@ public abstract class VirtualFile implements Comparable<VirtualFile>, Serializab
public @Nonnull List<VirtualFile> listOnlyDescendants() throws IOException {
VirtualFile[] children = list();
List<VirtualFile> result = new ArrayList<>();
for (int i = 0; i < children.length; i++) {
VirtualFile child = children[i];
for (VirtualFile child : children) {
if (child.isDescendant("")) {
result.add(child);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册