Skip to content

Commit

Permalink
KEYCLOAK-12220 Fix minor warnings for collections in module "server-s…
Browse files Browse the repository at this point in the history
…pi-private"
  • Loading branch information
Captain1653 authored and stianst committed Nov 26, 2019
1 parent 04cbea7 commit c8a00c2
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ public T create(KeycloakSession session) {

@Override
public Map<String, String> parseConfig(KeycloakSession session, InputStream inputStream) {
return new HashMap<String, String>();
return new HashMap<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static SimpleHttp doPut(String url, HttpClient client) {

public SimpleHttp header(String name, String value) {
if (headers == null) {
headers = new HashMap<String, String>();
headers = new HashMap<>();
}
headers.put(name, value);
return this;
Expand All @@ -123,7 +123,7 @@ public SimpleHttp json(Object entity) {

public SimpleHttp param(String name, String value) {
if (params == null) {
params = new HashMap<String, String>();
params = new HashMap<>();
}
params.put(name, value);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public EventBuilder detail(String key, String value) {
}

if (event.getDetails() == null) {
event.setDetails(new HashMap<String, String>());
event.setDetails(new HashMap<>());
}
event.getDetails().put(key, value);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public String getNote(String name) {
public void setNote(String name, String value) {
PersistentUserSessionData data = getData();
if (data.getNotes() == null) {
data.setNotes(new HashMap<String, String>());
data.setNotes(new HashMap<>());
}
data.getNotes().put(name, value);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,13 @@ public static UserRepresentation toRepresentation(KeycloakSession session, Realm

rep.setNotBefore(session.users().getNotBeforeOfUser(realm, user));

List<String> reqActions = new ArrayList<String>();
Set<String> requiredActions = user.getRequiredActions();
reqActions.addAll(requiredActions);
List<String> reqActions = new ArrayList<>(requiredActions);

rep.setRequiredActions(reqActions);

if (user.getAttributes() != null && !user.getAttributes().isEmpty()) {
Map<String, List<String>> attrs = new HashMap<>();
attrs.putAll(user.getAttributes());
Map<String, List<String>> attrs = new HashMap<>(user.getAttributes());
rep.setAttributes(attrs);
}

Expand Down Expand Up @@ -296,10 +294,10 @@ public static RealmRepresentation toRepresentation(RealmModel realm, boolean int
rep.setEventsExpiration(realm.getEventsExpiration());
}
if (realm.getEventsListeners() != null) {
rep.setEventsListeners(new LinkedList<String>(realm.getEventsListeners()));
rep.setEventsListeners(new LinkedList<>(realm.getEventsListeners()));
}
if (realm.getEnabledEventTypes() != null) {
rep.setEnabledEventTypes(new LinkedList<String>(realm.getEnabledEventTypes()));
rep.setEnabledEventTypes(new LinkedList<>(realm.getEnabledEventTypes()));
}

rep.setAdminEventsEnabled(realm.isAdminEventsEnabled());
Expand Down Expand Up @@ -365,8 +363,7 @@ public static RealmRepresentation toRepresentation(RealmModel realm, boolean int

List<String> defaultRoles = realm.getDefaultRoles();
if (!defaultRoles.isEmpty()) {
List<String> roleStrings = new ArrayList<String>();
roleStrings.addAll(defaultRoles);
List<String> roleStrings = new ArrayList<>(defaultRoles);
rep.setDefaultRoles(roleStrings);
}
List<GroupModel> defaultGroups = realm.getDefaultGroups();
Expand All @@ -379,8 +376,8 @@ public static RealmRepresentation toRepresentation(RealmModel realm, boolean int
}

List<RequiredCredentialModel> requiredCredentialModels = realm.getRequiredCredentials();
if (requiredCredentialModels.size() > 0) {
rep.setRequiredCredentials(new HashSet<String>());
if (!requiredCredentialModels.isEmpty()) {
rep.setRequiredCredentials(new HashSet<>());
for (RequiredCredentialModel cred : requiredCredentialModels) {
rep.getRequiredCredentials().add(cred.getType());
}
Expand All @@ -396,7 +393,7 @@ public static RealmRepresentation toRepresentation(RealmModel realm, boolean int

rep.setInternationalizationEnabled(realm.isInternationalizationEnabled());
if (realm.getSupportedLocales() != null) {
rep.setSupportedLocales(new HashSet<String>());
rep.setSupportedLocales(new HashSet<>());
rep.getSupportedLocales().addAll(realm.getSupportedLocales());
}
rep.setDefaultLocale(realm.getDefaultLocale());
Expand All @@ -422,8 +419,8 @@ public static void exportGroups(RealmModel realm, RealmRepresentation rep) {
}

public static void exportAuthenticationFlows(RealmModel realm, RealmRepresentation rep) {
rep.setAuthenticationFlows(new LinkedList<AuthenticationFlowRepresentation>());
rep.setAuthenticatorConfig(new LinkedList<AuthenticatorConfigRepresentation>());
rep.setAuthenticationFlows(new LinkedList<>());
rep.setAuthenticatorConfig(new LinkedList<>());

List<AuthenticationFlowModel> authenticationFlows = new ArrayList<>(realm.getAuthenticationFlows());
//ensure consistent ordering of authenticationFlows.
Expand Down Expand Up @@ -629,8 +626,7 @@ public static IdentityProviderRepresentation toRepresentation(RealmModel realm,
providerRep.setStoreToken(identityProviderModel.isStoreToken());
providerRep.setTrustEmail(identityProviderModel.isTrustEmail());
providerRep.setAuthenticateByDefault(identityProviderModel.isAuthenticateByDefault());
Map<String, String> config = new HashMap<>();
config.putAll(identityProviderModel.getConfig());
Map<String, String> config = new HashMap<>(identityProviderModel.getConfig());
providerRep.setConfig(config);
providerRep.setAddReadTokenRoleOnCreate(identityProviderModel.isAddReadTokenRoleOnCreate());

Expand Down Expand Up @@ -659,8 +655,7 @@ public static ProtocolMapperRepresentation toRepresentation(ProtocolMapperModel
ProtocolMapperRepresentation rep = new ProtocolMapperRepresentation();
rep.setId(model.getId());
rep.setProtocol(model.getProtocol());
Map<String, String> config = new HashMap<String, String>();
config.putAll(model.getConfig());
Map<String, String> config = new HashMap<>(model.getConfig());
rep.setConfig(config);
rep.setName(model.getName());
rep.setProtocolMapper(model.getProtocolMapper());
Expand All @@ -672,8 +667,7 @@ public static IdentityProviderMapperRepresentation toRepresentation(IdentityProv
rep.setId(model.getId());
rep.setIdentityProviderMapper(model.getIdentityProviderMapper());
rep.setIdentityProviderAlias(model.getIdentityProviderAlias());
Map<String, String> config = new HashMap<String, String>();
config.putAll(model.getConfig());
Map<String, String> config = new HashMap<>(model.getConfig());
rep.setConfig(config);
rep.setName(model.getName());
return rep;
Expand Down Expand Up @@ -707,7 +701,7 @@ public static AuthenticationFlowRepresentation toRepresentation(RealmModel realm
rep.setProviderId(model.getProviderId());
rep.setAlias(model.getAlias());
rep.setDescription(model.getDescription());
rep.setAuthenticationExecutions(new LinkedList<AuthenticationExecutionExportRepresentation>());
rep.setAuthenticationExecutions(new LinkedList<>());
for (AuthenticationExecutionModel execution : realm.getAuthenticationExecutions(model.getId())) {
rep.getAuthenticationExecutions().add(toRepresentation(realm, execution));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class PropertyQuery<V> {
}

this.targetClass = targetClass;
this.criteria = new ArrayList<PropertyCriteria>();
this.criteria = new ArrayList<>();
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public Map<String, Property<V>> getWritableResultList() {
* @return the results, or an empty list if there are no results
*/
private Map<String, Property<V>> getResultList(boolean writable) {
Map<String, Property<V>> properties = new HashMap<String, Property<V>>();
Map<String, Property<V>> properties = new HashMap<>();

// First check public accessor methods (we ignore private methods)
for (Method method : targetClass.getMethods()) {
Expand All @@ -165,7 +165,7 @@ private Map<String, Property<V>> getResultList(boolean writable) {
}

if (match) {
MethodProperty<V> property = Properties.<V>createProperty(method);
MethodProperty<V> property = Properties.createProperty(method);

if (!writable || !property.isReadOnly()) {
properties.put(property.getName(), property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public void setEmailVerified(boolean verified) {

@Override
public Set<GroupModel> getGroups() {
if (groupIds.size() == 0) return Collections.EMPTY_SET;
if (groupIds.isEmpty()) return Collections.emptySet();
Set<GroupModel> groups = new HashSet<>();
for (String id : groupIds) {
groups.add(realm.getGroupById(id));
Expand Down Expand Up @@ -311,7 +311,7 @@ public Set<RoleModel> getRealmRoleMappings() {
Set<RoleModel> allRoles = getRoleMappings();

// Filter to retrieve just realm roles
Set<RoleModel> realmRoles = new HashSet<RoleModel>();
Set<RoleModel> realmRoles = new HashSet<>();
for (RoleModel role : allRoles) {
if (role.getContainer() instanceof RealmModel) {
realmRoles.add(role);
Expand All @@ -322,7 +322,7 @@ public Set<RoleModel> getRealmRoleMappings() {

@Override
public Set<RoleModel> getClientRoleMappings(ClientModel app) {
Set<RoleModel> result = new HashSet<RoleModel>();
Set<RoleModel> result = new HashSet<>();
Set<RoleModel> roles = getRoleMappings();

for (RoleModel role : roles) {
Expand All @@ -348,7 +348,7 @@ public void grantRole(RoleModel role) {

@Override
public Set<RoleModel> getRoleMappings() {
if (roleIds.size() == 0) return Collections.EMPTY_SET;
if (roleIds.isEmpty()) return Collections.emptySet();
Set<RoleModel> roles = new HashSet<>();
for (String id : roleIds) {
roles.add(realm.getRoleById(id));
Expand Down

0 comments on commit c8a00c2

Please sign in to comment.