2
0
Эх сурвалжийг харах

Use foreach where possible

Lars Grefer 6 жил өмнө
parent
commit
43737a56bd

+ 2 - 2
core/src/test/java/org/springframework/security/core/authority/mapping/SimpleRoles2GrantedAuthoritiesMapperTests.java

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

+ 2 - 2
core/src/test/java/org/springframework/security/core/session/SessionRegistryImplTests.java

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

+ 3 - 3
crypto/src/main/java/org/springframework/security/crypto/codec/Hex.java

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

+ 7 - 7
crypto/src/test/java/org/springframework/security/crypto/bcrypt/BCryptTests.java

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

+ 1 - 3
samples/xml/dms/src/main/java/sample/dms/AbstractElement.java

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

+ 7 - 7
samples/xml/dms/src/test/java/sample/DmsIntegrationTests.java

@@ -105,12 +105,12 @@ public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContex
 		assertThat(rootElements).hasSize(3);
 		Directory homeDir = null;
 		Directory nonHomeDir = null;
-		for (int i = 0; i < rootElements.length; i++) {
-			if (rootElements[i].getName().equals(username)) {
-				homeDir = (Directory) rootElements[i];
+		for (AbstractElement rootElement : rootElements) {
+			if (rootElement.getName().equals(username)) {
+				homeDir = (Directory) rootElement;
 			}
 			else {
-				nonHomeDir = (Directory) rootElements[i];
+				nonHomeDir = (Directory) rootElement;
 			}
 		}
 		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
 		// filtering
 		Directory nonHomeConfidentialDir = null;
-		for (int i = 0; i < nonHomeElements.length; i++) {
-			if (nonHomeElements[i].getName().equals("confidential")) {
-				nonHomeConfidentialDir = (Directory) nonHomeElements[i];
+		for (AbstractElement nonHomeElement : nonHomeElements) {
+			if (nonHomeElement.getName().equals("confidential")) {
+				nonHomeConfidentialDir = (Directory) nonHomeElement;
 			}
 		}
 

+ 2 - 2
web/src/test/java/org/springframework/security/web/authentication/preauth/j2ee/J2eeBasedPreAuthenticatedWebAuthenticationDetailsSourceTests.java

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