From ae8f44a50a29b3a955eefba13f900f94224d7c02 Mon Sep 17 00:00:00 2001 From: Dave Borowitz Date: Thu, 3 Sep 2015 16:10:09 -0400 Subject: [PATCH] DownloadConfig: Make set methods return ImmutableSet Constructing with ImmutableSet requires less typing and less wrapping than the previous idiom using java.util.Collections. Also, this singleton object is supposed to be an immutable view of the global Gerrit config, but some codepaths inadvertently left the archiveFormats set mutable. Convey the immutability of the accessors in the return type. Change-Id: Id775773de1031523d51baa124c649329eaf97072 --- .../gerrit/server/config/DownloadConfig.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java b/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java index 207508d4fd..a49e715dd7 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/config/DownloadConfig.java @@ -23,18 +23,15 @@ import com.google.inject.Singleton; import org.eclipse.jgit.lib.Config; -import java.util.Collections; import java.util.EnumSet; -import java.util.HashSet; import java.util.List; -import java.util.Set; /** Download protocol from {@code gerrit.config}. */ @Singleton public class DownloadConfig { - private final Set downloadSchemes; - private final Set downloadCommands; - private final Set archiveFormats; + private final ImmutableSet downloadSchemes; + private final ImmutableSet downloadCommands; + private final ImmutableSet archiveFormats; @Inject DownloadConfig(@GerritServerConfig final Config cfg) { @@ -62,11 +59,11 @@ public class DownloadConfig { String v = cfg.getString("download", null, "archive"); if (v == null) { - archiveFormats = EnumSet.allOf(ArchiveFormat.class); + archiveFormats = ImmutableSet.copyOf(EnumSet.allOf(ArchiveFormat.class)); } else if (v.isEmpty() || "off".equalsIgnoreCase(v)) { - archiveFormats = Collections.emptySet(); + archiveFormats = ImmutableSet.of(); } else { - archiveFormats = new HashSet<>(ConfigUtil.getEnumList(cfg, + archiveFormats = ImmutableSet.copyOf(ConfigUtil.getEnumList(cfg, "download", null, "archive", ArchiveFormat.TGZ)); } @@ -77,17 +74,17 @@ public class DownloadConfig { } /** Scheme used to download. */ - public Set getDownloadSchemes() { + public ImmutableSet getDownloadSchemes() { return downloadSchemes; } /** Command used to download. */ - public Set getDownloadCommands() { + public ImmutableSet getDownloadCommands() { return downloadCommands; } /** Archive formats for downloading. */ - public Set getArchiveFormats() { + public ImmutableSet getArchiveFormats() { return archiveFormats; } }