Java 7 migration 82/69682/1
authorStephen Kitt <skitt@redhat.com>
Tue, 20 Mar 2018 10:47:54 +0000 (11:47 +0100)
committerStephen Kitt <skitt@redhat.com>
Tue, 20 Mar 2018 10:47:54 +0000 (11:47 +0100)
As suggested by IntelliJ:
* remove redundant type specifiers;
* use try-with-resources.

Change-Id: Ie6b777fd9cbf9d1e9e3f98fecccdb2f8b2ee2caa
Signed-off-by: Stephen Kitt <skitt@redhat.com>
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/model/Domains.java
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/model/Roles.java
aaa-authn-api/src/main/java/org/opendaylight/aaa/api/model/Users.java
aaa-cert/src/main/java/org/opendaylight/aaa/cert/impl/AaaCertRpcServiceImpl.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/provider/GsonProvider.java
aaa-shiro/impl/src/main/java/org/opendaylight/aaa/shiro/idm/IdmLightProxy.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/DomainHandlerTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/IDMTestStore.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/RoleHandlerTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/idm/rest/test/UserHandlerTest.java
aaa-shiro/impl/src/test/java/org/opendaylight/aaa/shiro/realm/ODLJndiLdapRealmTest.java

index a8f2064bd96142878d0e303a14dbb566205e0c7d..20cbed3cd9168743172919bf6244c5107409f2c3 100644 (file)
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement(name = "domains")
 public class Domains {
-    private List<Domain> domains = new ArrayList<Domain>();
+    private List<Domain> domains = new ArrayList<>();
 
     public void setDomains(List<Domain> domains) {
         this.domains = domains;
index 335210284c8ce67deab477e027c4330f1e5a400c..83213861241c5340ff3adbef94e926de18444bf7 100644 (file)
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement(name = "roles")
 public class Roles {
-    private List<Role> roles = new ArrayList<Role>();
+    private List<Role> roles = new ArrayList<>();
 
     public void setRoles(List<Role> roles) {
         this.roles = roles;
index a0a001bddfeb050659a9e8963174b858818183be..637f241b9c2e5552b07e7c5fcd3bdf98c41f4832 100644 (file)
@@ -21,7 +21,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 
 @XmlRootElement(name = "users")
 public class Users {
-    private List<User> users = new ArrayList<User>();
+    private List<User> users = new ArrayList<>();
 
     public void setUsers(List<User> users) {
         this.users = users;
index e38dba82937fb368d34926df1e141927d8b449ce..6f577fcf6b6aaeb6ab50cd24fbcc26b3789c15b1 100644 (file)
@@ -74,7 +74,7 @@ public class AaaCertRpcServiceImpl implements AaaCertRpcService {
         if (!Strings.isNullOrEmpty(cert)) {
             final GetNodeCertifcateOutput nodeCertOutput = new GetNodeCertifcateOutputBuilder().setNodeCert(cert)
                     .build();
-            futureResult.set(RpcResultBuilder.<GetNodeCertifcateOutput>success(nodeCertOutput).build());
+            futureResult.set(RpcResultBuilder.success(nodeCertOutput).build());
         } else {
             futureResult.set(RpcResultBuilder.<GetNodeCertifcateOutput>failed().build());
         }
@@ -99,7 +99,7 @@ public class AaaCertRpcServiceImpl implements AaaCertRpcService {
         final String cert = aaaCertProvider.getODLKeyStoreCertificate(false);
         if (!Strings.isNullOrEmpty(cert)) {
             final GetODLCertificateOutput odlCertOutput = new GetODLCertificateOutputBuilder().setOdlCert(cert).build();
-            futureResult.set(RpcResultBuilder.<GetODLCertificateOutput>success(odlCertOutput).build());
+            futureResult.set(RpcResultBuilder.success(odlCertOutput).build());
         } else {
             futureResult.set(RpcResultBuilder.<GetODLCertificateOutput>failed().build());
         }
@@ -113,7 +113,7 @@ public class AaaCertRpcServiceImpl implements AaaCertRpcService {
         if (!Strings.isNullOrEmpty(certReq)) {
             final GetODLCertificateReqOutput odlCertReqOutput = new GetODLCertificateReqOutputBuilder()
                     .setOdlCertReq(certReq).build();
-            futureResult.set(RpcResultBuilder.<GetODLCertificateReqOutput>success(odlCertReqOutput).build());
+            futureResult.set(RpcResultBuilder.success(odlCertReqOutput).build());
         } else {
             futureResult.set(RpcResultBuilder.<GetODLCertificateReqOutput>failed().build());
         }
index faa64be8208cb169de974550d7396068f3f64343..ae137e161f86c874411a5f1d7832c606abdb6ec0 100644 (file)
@@ -62,11 +62,8 @@ public class GsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<
                       MediaType mediaType, MultivaluedMap<String, String> httpHeaders,
                       InputStream entityStream) throws IOException, WebApplicationException {
 
-        InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8");
-        try {
+        try (InputStreamReader reader = new InputStreamReader(entityStream, "UTF-8")) {
             return gson.fromJson(reader, type);
-        } finally {
-            reader.close();
         }
     }
 
@@ -86,10 +83,9 @@ public class GsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<
     @SuppressFBWarnings("DM_DEFAULT_ENCODING")
     public void writeTo(T type, Class<?> theClass, Type genericType, Annotation[] annotations,
                         MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
-                        OutputStream entityStream) throws IOException, WebApplicationException {
+                        OutputStream entityStream) throws WebApplicationException {
 
-        PrintWriter printWriter = new PrintWriter(entityStream);
-        try {
+        try (PrintWriter printWriter = new PrintWriter(entityStream)) {
             String json;
             if (ui.getQueryParameters().containsKey(PRETTY_PRINT)) {
                 json = prettyGson.toJson(type);
@@ -98,8 +94,6 @@ public class GsonProvider<T> implements MessageBodyReader<T>, MessageBodyWriter<
             }
             printWriter.write(json);
             printWriter.flush();
-        } finally {
-            printWriter.close();
         }
     }
 }
index 7fc8b8e30d98144ab4d273ffbd19d886b3a8b6c8..d76d36f117e24bd5b87f285a7dfa018dccd64fb8 100644 (file)
@@ -49,7 +49,7 @@ public class IdmLightProxy implements CredentialAuth<PasswordCredentials>, IdMSe
     // adds a store for the default "sdn" domain
     static {
         claimCache.put(IIDMStore.DEFAULT_DOMAIN,
-                new ConcurrentHashMap<PasswordCredentials, Claim>());
+                new ConcurrentHashMap<>());
     }
 
     private final IIDMStore idmStore;
index 0ae801d34d764648313ea552c08be985c4803766..a03168d23fe10cbe88b5c9048d5e8ca35475a3a6 100644 (file)
@@ -52,7 +52,7 @@ public class DomainHandlerTest extends HandlerTest {
         }
 
         // check create domain
-        Map<String, String> domainData = new HashMap<String, String>();
+        Map<String, String> domainData = new HashMap<>();
         domainData.put("name", "dom1");
         domainData.put("description", "test dom");
         domainData.put("enabled", "true");
@@ -70,7 +70,7 @@ public class DomainHandlerTest extends HandlerTest {
         assertTrue(domain.getName().equals("dom1Update"));
 
         // check create grant
-        Map<String, String> grantData = new HashMap<String, String>();
+        Map<String, String> grantData = new HashMap<>();
         grantData.put("roleid", "1");
         clientResponse = resource().path("/v1/domains/1/users/0/roles").type(MediaType.APPLICATION_JSON)
                 .post(ClientResponse.class, grantData);
@@ -87,7 +87,7 @@ public class DomainHandlerTest extends HandlerTest {
         assertEquals(404, clientResponse.getStatus());
 
         // check validate user (admin)
-        Map<String, String> usrPwdData = new HashMap<String, String>();
+        Map<String, String> usrPwdData = new HashMap<>();
         usrPwdData.put("username", "admin");
         usrPwdData.put("userpwd", "admin");
         clientResponse = resource().path("/v1/domains/0/users/roles").type(MediaType.APPLICATION_JSON)
index b9c41e2619c39ab7f33b87e4a0abfa2320db14a0..70a61dcc78fe071bd9449ffff4747923782781fa 100644 (file)
@@ -23,10 +23,10 @@ import org.opendaylight.aaa.api.model.Users;
 
 public class IDMTestStore implements IIDMStore {
 
-    private List<Domain> domains = new ArrayList<Domain>();
-    private List<Grant> grants = new ArrayList<Grant>();
-    private List<Role> roles = new ArrayList<Role>();
-    private List<User> users = new ArrayList<User>();
+    private List<Domain> domains = new ArrayList<>();
+    private List<Grant> grants = new ArrayList<>();
+    private List<Role> roles = new ArrayList<>();
+    private List<User> users = new ArrayList<>();
 
     public IDMTestStore() {
         // TODO Auto-generated constructor stub
@@ -195,7 +195,7 @@ public class IDMTestStore implements IIDMStore {
         }
         for (Grant grant : grants) {
             if (grant.getUserid().equals(user.getUserid()) && grant.getDomainid().equals(domain.getDomainid())) {
-                List<User> usrList = new ArrayList<User>();
+                List<User> usrList = new ArrayList<>();
                 usrList.add(user);
                 usrs.setUsers(usrList);
                 break;
@@ -246,7 +246,7 @@ public class IDMTestStore implements IIDMStore {
     @Override
     public Grants getGrants(String domainid, String userid) throws IDMStoreException {
         Grants usrGrants = new Grants();
-        List<Grant> usrGrant = new ArrayList<Grant>();
+        List<Grant> usrGrant = new ArrayList<>();
         for (Grant grant : grants) {
             if (grant.getUserid().equals(userid) && grant.getDomainid().equals(domainid)) {
                 usrGrant.add(grant);
@@ -259,7 +259,7 @@ public class IDMTestStore implements IIDMStore {
     @Override
     public Grants getGrants(String userid) throws IDMStoreException {
         Grants usrGrants = new Grants();
-        List<Grant> usrGrant = new ArrayList<Grant>();
+        List<Grant> usrGrant = new ArrayList<>();
         for (Grant grant : grants) {
             if (grant.getUserid().equals(userid)) {
                 usrGrant.add(grant);
index 1e2bf444f3e7cb8f5f15fdab92e527bde603698a..c9d3884813449e565b9387f9eea3ecda750310b7 100644 (file)
@@ -55,7 +55,7 @@ public class RoleHandlerTest extends HandlerTest {
         }
 
         // check create Role
-        Map<String, String> roleData = new HashMap<String, String>();
+        Map<String, String> roleData = new HashMap<>();
         roleData.put("name", "role1");
         roleData.put("description", "test Role");
         roleData.put("domainid", "0");
@@ -98,7 +98,7 @@ public class RoleHandlerTest extends HandlerTest {
         }
 
         // Bug 8382: if a role id is specified, 400 is returned
-        roleData = new HashMap<String, String>();
+        roleData = new HashMap<>();
         roleData.put("name", "role1");
         roleData.put("description", "test Role");
         roleData.put("domainid", "0");
index 70f97f09e18384c3a2a99751a5a912d11d6a298b..742781a9823cf274c0a9a469e5cb063fcc2a07cc 100644 (file)
@@ -55,7 +55,7 @@ public class UserHandlerTest extends HandlerTest {
         }
 
         // check create user
-        Map<String, String> usrData = new HashMap<String, String>();
+        Map<String, String> usrData = new HashMap<>();
         usrData.put("name", "usr1");
         usrData.put("description", "test user");
         usrData.put("enabled", "true");
@@ -101,7 +101,7 @@ public class UserHandlerTest extends HandlerTest {
         }
 
         // Bug 8382: if a user id is specified, 400 is returned
-        usrData = new HashMap<String, String>();
+        usrData = new HashMap<>();
         usrData.put("name", "usr1");
         usrData.put("description", "test user");
         usrData.put("enabled", "true");
index 665d2cdb59db4c0d8ef2f4827d93b6620ca1692a..f5e5c620a9b657f4b2b6f3bfac2e979b81fc1fcd 100644 (file)
@@ -109,7 +109,7 @@ public class ODLJndiLdapRealmTest {
     class TestPrincipalCollection implements PrincipalCollection {
         private static final long serialVersionUID = -1236759619455574475L;
 
-        Vector<String> collection = new Vector<String>();
+        Vector<String> collection = new Vector<>();
 
         TestPrincipalCollection(String element) {
             collection.add(element);
@@ -127,7 +127,7 @@ public class ODLJndiLdapRealmTest {
 
         @Override
         public Set<String> asSet() {
-            HashSet<String> set = new HashSet<String>();
+            HashSet<String> set = new HashSet<>();
             set.addAll(collection);
             return set;
         }
@@ -189,7 +189,7 @@ public class ODLJndiLdapRealmTest {
         // emulates an ldap search and returns the mocked up test class
         when(
                 ldapContext.search((String) any(), (String) any(),
-                        (SearchControls) any())).thenReturn(new TestNamingEnumeration());
+                        any())).thenReturn(new TestNamingEnumeration());
         LdapContextFactory ldapContextFactory = mock(LdapContextFactory.class);
         when(ldapContextFactory.getSystemLdapContext()).thenReturn(ldapContext);
         AuthorizationInfo authorizationInfo = new ODLJndiLdapRealm().queryForAuthorizationInfo(
@@ -202,7 +202,7 @@ public class ODLJndiLdapRealmTest {
     @Test
     public void testBuildAuthorizationInfo() {
         assertNull(ODLJndiLdapRealm.buildAuthorizationInfo(null));
-        Set<String> roleNames = new HashSet<String>();
+        Set<String> roleNames = new HashSet<>();
         roleNames.add("engineering");
         AuthorizationInfo authorizationInfo = ODLJndiLdapRealm.buildAuthorizationInfo(roleNames);
         assertNotNull(authorizationInfo);
@@ -218,7 +218,7 @@ public class ODLJndiLdapRealmTest {
         // emulates an ldap search and returns the mocked up test class
         when(
                 ldapContext.search((String) any(), (String) any(),
-                        (SearchControls) any())).thenReturn(new TestNamingEnumeration());
+                        any())).thenReturn(new TestNamingEnumeration());
 
         // extracts the roles for "testuser" and ensures engineering is returned
         Set<String> roles = ldapRealm.getRoleNamesForUser("testuser", ldapContext);