Skip to content

Commit

Permalink
Java 5: foreach
Browse files Browse the repository at this point in the history
  • Loading branch information
jsoref committed Feb 21, 2019
1 parent 893e5c0 commit 22b2720
Show file tree
Hide file tree
Showing 12 changed files with 29 additions and 33 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/ExtensionList.java
Expand Up @@ -245,8 +245,7 @@ private synchronized boolean removeSync(Object o) {
}

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);
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/Util.java
Expand Up @@ -1463,9 +1463,9 @@ public static void closeAndLogFailures(@CheckForNull Closeable toClose, @Nonnull
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;
}
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/hudson/model/DependencyGraph.java
Expand Up @@ -339,10 +339,9 @@ private void add(Map<AbstractProject, List<DependencyGroup>> map, AbstractProjec
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;
}
Expand Down
Expand Up @@ -189,9 +189,9 @@ private String findRememberMeCookieValue(HttpServletRequest request, HttpServlet
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();
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/tasks/Fingerprinter.java
Expand Up @@ -154,8 +154,8 @@ public void buildDependencyGraph(AbstractProject owner, DependencyGraph graph) {
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) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/util/MultipartFormDataParser.java
Expand Up @@ -96,8 +96,8 @@ public static boolean isMultiPartForm(@CheckForNull String contentType) {
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;
}
}
Expand Down
Expand Up @@ -212,8 +212,7 @@ public void visit(String fieldName, Class fieldType, Class definedIn, Object new
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 {
Expand Down
Expand Up @@ -149,8 +149,8 @@ public boolean isValid(String value) {
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;
}
}
Expand All @@ -169,13 +169,13 @@ public String[] match(String value) {
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;
}
Expand All @@ -196,16 +196,16 @@ public String validate(String value) {
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) {
return matcher.group(1);
}
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);
}
Expand Down
Expand Up @@ -284,8 +284,8 @@ public UrlValidator(String[] schemes, RegexValidator authorityValidator, long op
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));
}
}

Expand Down
Expand Up @@ -56,10 +56,10 @@ public GrantedAuthority[] getAuthorities() {
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));
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/jenkins/util/TreeString.java
Expand Up @@ -124,8 +124,8 @@ public boolean equals(final Object rhs) {
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;
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/jenkins/util/VirtualFile.java
Expand Up @@ -191,8 +191,7 @@ public boolean supportsQuickRecursiveListing() {
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);
}
Expand Down

0 comments on commit 22b2720

Please sign in to comment.