Java 8 migration 83/69683/1
authorStephen Kitt <skitt@redhat.com>
Tue, 20 Mar 2018 15:02:27 +0000 (16:02 +0100)
committerStephen Kitt <skitt@redhat.com>
Tue, 20 Mar 2018 15:02:27 +0000 (16:02 +0100)
As suggested by IntelliJ:
* clean up lambdas;
* use new Map methods.

Change-Id: Icda29431e29a35849aa60be145b0029ae72ad055
Signed-off-by: Stephen Kitt <skitt@redhat.com>
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/IdMServiceImpl.java
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/DefaultMdsalSslData.java
aaa-cli-jar/src/main/java/org/opendaylight/aaa/cli/jar/StandaloneCommandLineInterface.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/IdmLightProxy.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/realm/util/http/SimpleHttpRequest.java

index 4f2066d3fb4a0cac6fe595c17ba3d83bf6d48186..9c71361e1044422bdeea0dff59a467189c63f70e 100644 (file)
@@ -88,7 +88,7 @@ public class IdMServiceImpl implements IdMService {
     @Override
     public List<String> listUserIDs() throws IDMStoreException {
         List<User> users = repository.getUsers().getUsers();
-        return users.stream().map(user -> user.getName()).collect(Collectors.toList());
+        return users.stream().map(User::getName).collect(Collectors.toList());
     }
 
 }
index 63535791a5695639fd5c90a797ef7a2e05df5656..1b104978e2848dbfc1c19750048c1de3a125e570 100644 (file)
@@ -134,9 +134,7 @@ public class DefaultMdsalSslData implements IAaaCertProvider {
     private String[] getCipherSuites(final List<CipherSuites> cipherSuites) {
         final List<String> suites = new ArrayList<>();
         if (cipherSuites != null && !cipherSuites.isEmpty()) {
-            cipherSuites.stream().forEach(cs -> {
-                suites.add(cs.getSuiteName());
-            });
+            cipherSuites.forEach(cs -> suites.add(cs.getSuiteName()));
         }
         return suites.toArray(new String[suites.size()]);
     }
index fdf859eaf962a7519e634dc6a979facf7e9ea3a8..b33e6356fa44443904461cec3fe1555f93f459dc 100644 (file)
@@ -49,7 +49,7 @@ public class StandaloneCommandLineInterface {
 
     public List<String> getAllUserNames() throws IDMStoreException {
         List<User> users = identityStore.getUsers().getUsers();
-        return users.stream().map(user -> user.getName()).collect(Collectors.toList());
+        return users.stream().map(User::getName).collect(Collectors.toList());
     }
 
     public boolean resetPassword(String userIdWithoutDomain, String newPassword) throws IDMStoreException {
index d76d36f117e24bd5b87f285a7dfa018dccd64fb8..872415602e77137e0a3676cdf34d14f3039e3e1e 100644 (file)
@@ -40,15 +40,15 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
     private static final Logger LOG = LoggerFactory.getLogger(IdmLightProxy.class);
 
     /**
-     * claimCache is responsible for storing the active claims per domain.  The
+     * CLAIM_CACHE is responsible for storing the active claims per domain.  The
      * outer map is keyed by domain, and the inner map is keyed by
      * <code>PasswordCredentials</code>.
      */
-    private static Map<String, Map<PasswordCredentials, Claim>> claimCache = new ConcurrentHashMap<>();
+    private static final Map<String, Map<PasswordCredentials, Claim>> CLAIM_CACHE = new ConcurrentHashMap<>();
 
     // adds a store for the default "sdn" domain
     static {
-        claimCache.put(IIDMStore.DEFAULT_DOMAIN,
+        CLAIM_CACHE.put(IIDMStore.DEFAULT_DOMAIN,
                 new ConcurrentHashMap<>());
     }
 
@@ -65,19 +65,11 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
         Preconditions.checkNotNull(creds.password());
         String domain = creds.domain() == null ? IIDMStore.DEFAULT_DOMAIN : creds.domain();
         // FIXME: Add cache invalidation
-        Map<PasswordCredentials, Claim> cache = claimCache.get(domain);
-        if (cache == null) {
-            cache = new ConcurrentHashMap<>();
-            claimCache.put(domain, cache);
-        }
+        Map<PasswordCredentials, Claim> cache = CLAIM_CACHE.computeIfAbsent(domain, k -> new ConcurrentHashMap<>());
         Claim claim = cache.get(creds);
         if (claim == null) {
-            synchronized (claimCache) {
-                claim = cache.get(creds);
-                if (claim == null) {
-                    claim = dbAuthenticate(creds);
-                    cache.put(creds, claim);
-                }
+            synchronized (CLAIM_CACHE) {
+                claim = cache.computeIfAbsent(creds, this::dbAuthenticate);
             }
         }
         return claim;
@@ -88,7 +80,7 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
      */
     public static synchronized void clearClaimCache() {
         LOG.info("Clearing the claim cache");
-        for (Map<PasswordCredentials, Claim> cache : claimCache.values()) {
+        for (Map<PasswordCredentials, Claim> cache : CLAIM_CACHE.values()) {
             cache.clear();
         }
     }
index 1393e760073a408de89221ad7586afe709c0c927..0df5bd74d6a021c28d0072295100b71011fa9f74 100644 (file)
@@ -52,8 +52,7 @@ public class SimpleHttpRequest<T> {
         WebResource webResource = client.resource(uri).path(path);
 
         // add the query params
-        queryParams.entrySet().forEach(queryParamEntry ->
-                webResource.queryParam(queryParamEntry.getKey(), queryParamEntry.getValue()));
+        queryParams.forEach(webResource::queryParam);
 
         try {
             if (outputType == Response.class) {