Use foreach where possible

This commit is contained in:
Lars Grefer 2019-07-04 19:16:52 +02:00 committed by Josh Cummings
parent 7dc28ff376
commit 43737a56bd
7 changed files with 24 additions and 26 deletions

View File

@ -129,8 +129,8 @@ public class SimpleRoles2GrantedAuthoritiesMapperTests {
List<GrantedAuthority> result = mapper List<GrantedAuthority> result = mapper
.getGrantedAuthorities(Arrays.asList(roles)); .getGrantedAuthorities(Arrays.asList(roles));
Collection<String> resultColl = new ArrayList<>(result.size()); Collection<String> resultColl = new ArrayList<>(result.size());
for (int i = 0; i < result.size(); i++) { for (GrantedAuthority grantedAuthority : result) {
resultColl.add(result.get(i).getAuthority()); resultColl.add(grantedAuthority.getAuthority());
} }
Collection<String> expectedColl = Arrays.asList(expectedGas); Collection<String> expectedColl = Arrays.asList(expectedGas);
assertThat(expectedColl.containsAll(resultColl) assertThat(expectedColl.containsAll(resultColl)

View File

@ -180,8 +180,8 @@ public class SessionRegistryImplTests {
private boolean contains(String sessionId, Object principal) { private boolean contains(String sessionId, Object principal) {
List<SessionInformation> info = sessionRegistry.getAllSessions(principal, false); List<SessionInformation> info = sessionRegistry.getAllSessions(principal, false);
for (int i = 0; i < info.size(); i++) { for (SessionInformation sessionInformation : info) {
if (sessionId.equals(info.get(i).getSessionId())) { if (sessionId.equals(sessionInformation.getSessionId())) {
return true; return true;
} }
} }

View File

@ -34,11 +34,11 @@ public final class Hex {
char[] result = new char[2 * nBytes]; char[] result = new char[2 * nBytes];
int j = 0; int j = 0;
for (int i = 0; i < nBytes; i++) { for (byte aByte : bytes) {
// Char for top 4 bits // Char for top 4 bits
result[j++] = HEX[(0xF0 & bytes[i]) >>> 4]; result[j++] = HEX[(0xF0 & aByte) >>> 4];
// Bottom 4 // Bottom 4
result[j++] = HEX[(0x0F & bytes[i])]; result[j++] = HEX[(0x0F & aByte)];
} }
return result; return result;

View File

@ -122,10 +122,10 @@ public class BCryptTests {
@Test @Test
public void testHashpw() { public void testHashpw() {
print("BCrypt.hashpw(): "); print("BCrypt.hashpw(): ");
for (int i = 0; i < test_vectors.length; i++) { for (String[] test_vector : test_vectors) {
String plain = test_vectors[i][0]; String plain = test_vector[0];
String salt = test_vectors[i][1]; String salt = test_vector[1];
String expected = test_vectors[i][2]; String expected = test_vector[2];
String hashed = BCrypt.hashpw(plain, salt); String hashed = BCrypt.hashpw(plain, salt);
assertThat(expected).isEqualTo(hashed); assertThat(expected).isEqualTo(hashed);
print("."); print(".");
@ -176,9 +176,9 @@ public class BCryptTests {
@Test @Test
public void testCheckpw_success() { public void testCheckpw_success() {
print("BCrypt.checkpw w/ good passwords: "); print("BCrypt.checkpw w/ good passwords: ");
for (int i = 0; i < test_vectors.length; i++) { for (String[] test_vector : test_vectors) {
String plain = test_vectors[i][0]; String plain = test_vector[0];
String expected = test_vectors[i][2]; String expected = test_vector[2];
assertThat(BCrypt.checkpw(plain, expected)).isTrue(); assertThat(BCrypt.checkpw(plain, expected)).isTrue();
print("."); print(".");
} }

View File

@ -16,7 +16,6 @@
package sample.dms; package sample.dms;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List; import java.util.List;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -88,8 +87,7 @@ public abstract class AbstractElement {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
String lastCharacter = null; String lastCharacter = null;
for (Iterator<String> i = strings.iterator(); i.hasNext();) { for (String token : strings) {
String token = i.next();
if (!"/".equals(lastCharacter) && lastCharacter != null) { if (!"/".equals(lastCharacter) && lastCharacter != null) {
sb.append("/"); sb.append("/");
} }

View File

@ -105,12 +105,12 @@ public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContex
assertThat(rootElements).hasSize(3); assertThat(rootElements).hasSize(3);
Directory homeDir = null; Directory homeDir = null;
Directory nonHomeDir = null; Directory nonHomeDir = null;
for (int i = 0; i < rootElements.length; i++) { for (AbstractElement rootElement : rootElements) {
if (rootElements[i].getName().equals(username)) { if (rootElement.getName().equals(username)) {
homeDir = (Directory) rootElements[i]; homeDir = (Directory) rootElement;
} }
else { else {
nonHomeDir = (Directory) rootElements[i]; nonHomeDir = (Directory) rootElement;
} }
} }
System.out.println("Home directory......: " + homeDir.getFullName()); System.out.println("Home directory......: " + homeDir.getFullName());
@ -135,9 +135,9 @@ public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContex
// Of course, we shouldn't find a "confidential" directory in the results if we're // Of course, we shouldn't find a "confidential" directory in the results if we're
// filtering // filtering
Directory nonHomeConfidentialDir = null; Directory nonHomeConfidentialDir = null;
for (int i = 0; i < nonHomeElements.length; i++) { for (AbstractElement nonHomeElement : nonHomeElements) {
if (nonHomeElements[i].getName().equals("confidential")) { if (nonHomeElement.getName().equals("confidential")) {
nonHomeConfidentialDir = (Directory) nonHomeElements[i]; nonHomeConfidentialDir = (Directory) nonHomeElement;
} }
} }

View File

@ -128,8 +128,8 @@ public class J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests {
Collection<String> expectedRolesColl = Arrays.asList(expectedRoles); Collection<String> expectedRolesColl = Arrays.asList(expectedRoles);
Collection<String> gasRolesSet = new HashSet<>(); Collection<String> gasRolesSet = new HashSet<>();
for (int i = 0; i < gas.size(); i++) { for (GrantedAuthority grantedAuthority : gas) {
gasRolesSet.add(gas.get(i).getAuthority()); gasRolesSet.add(grantedAuthority.getAuthority());
} }
assertThat(expectedRolesColl.containsAll(gasRolesSet) assertThat(expectedRolesColl.containsAll(gasRolesSet)
&& gasRolesSet.containsAll(expectedRolesColl)).withFailMessage( && gasRolesSet.containsAll(expectedRolesColl)).withFailMessage(