Skip to content

Commit

Permalink
#28059 Refactor HostVariableAPIImpl to use ImmutableList
Browse files Browse the repository at this point in the history
The HostVariableAPIImpl was refactored to make use of Google's Immutable List implementation for returned site variables in the getUniqueSiteVariables() method. We previously used an ArrayList, but have made the shift for its immutable properties and thread-safety.
  • Loading branch information
jgambarios committed May 3, 2024
1 parent b2181ab commit ac804b5
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.hostvariable.model.HostVariable;
import com.google.common.collect.ImmutableList;
import com.liferay.portal.language.LanguageException;
import com.liferay.portal.model.User;
import java.util.ArrayList;
Expand Down Expand Up @@ -166,9 +167,9 @@ public List<HostVariable> save(final List<HostVariable> siteVariables, final Str
* @param siteVariables The list of site variables.
* @return A new ArrayList containing only the unique site variables based on their keys.
*/
private ArrayList<HostVariable> getUniqueSiteVariables(List<HostVariable> siteVariables) {
private List<HostVariable> getUniqueSiteVariables(List<HostVariable> siteVariables) {

return new ArrayList<>(siteVariables.stream().
return ImmutableList.copyOf(siteVariables.stream().
collect(Collectors.toMap(
HostVariable::getKey, // key is the HostVariable's `key`
hostVariable -> hostVariable, // value is the HostVariable itself
Expand Down

0 comments on commit ac804b5

Please sign in to comment.