Prefer subtypes of Multimap
Guava team recommends using the subinterfaces of Multimap, for the same reasons they recommend using Set and List rather than Collection: it documents expectations about ordering, uniqueness, and behavior of equals. Do this across the board in Gerrit. Mostly this is straightforward and I tried to exactly match existing behavior where possible. However, there were a few wrinkles, where different callers passed different subtypes to the same method. The main one is arguments to ParameterParser#parse and splitQueryString, where some callers used SetMultimaps (perhaps semi-intentionally, or perhaps misunderstanding the nature of HashMultimap). For the purposes of parameter parsing, a ListMultimap makes more sense, because it preserves argument order and repetition. Another instance is a couple places in ReceiveCommits and downstream where there were SetMultimap<?, Ref>. Since Refs do not implement equals, this is effectively the same thing as a ListMultimap, and changing the interface no longer misleads readers into thinking there might be some deduplication happening. Finally, this change includes a breaking API change to the return type of ExternalIncludedIn#getIncludedIn. Change-Id: I5f1d15e27a32e534a6aaefe204e7a31815f4c8d7
This commit is contained in:
committed by
David Pursehouse
parent
e5c5953205
commit
484da493b3
@@ -17,22 +17,22 @@ package com.google.gerrit.audit;
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.google.common.base.MoreObjects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.MultimapBuilder;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.common.TimeUtil;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
|
||||
public class AuditEvent {
|
||||
|
||||
public static final String UNKNOWN_SESSION_ID = "000000000000000000000000000";
|
||||
protected static final Multimap<String, ?> EMPTY_PARAMS =
|
||||
MultimapBuilder.hashKeys().hashSetValues().build();
|
||||
protected static final ListMultimap<String, ?> EMPTY_PARAMS =
|
||||
ImmutableListMultimap.of();
|
||||
|
||||
public final String sessionId;
|
||||
public final CurrentUser who;
|
||||
public final long when;
|
||||
public final String what;
|
||||
public final Multimap<String, ?> params;
|
||||
public final ListMultimap<String, ?> params;
|
||||
public final Object result;
|
||||
public final long timeAtStart;
|
||||
public final long elapsed;
|
||||
@@ -59,7 +59,7 @@ public class AuditEvent {
|
||||
* @param result result of the event
|
||||
*/
|
||||
public AuditEvent(String sessionId, CurrentUser who, String what, long when,
|
||||
Multimap<String, ?> params, Object result) {
|
||||
ListMultimap<String, ?> params, Object result) {
|
||||
Preconditions.checkNotNull(what, "what is a mandatory not null param !");
|
||||
|
||||
this.sessionId = MoreObjects.firstNonNull(sessionId, UNKNOWN_SESSION_ID);
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
package com.google.gerrit.audit;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.extensions.restapi.RestResource;
|
||||
import com.google.gerrit.extensions.restapi.RestView;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
@@ -45,11 +45,11 @@ public class ExtendedHttpAuditEvent extends HttpAuditEvent {
|
||||
* @param view view rendering object
|
||||
*/
|
||||
public ExtendedHttpAuditEvent(String sessionId, CurrentUser who,
|
||||
HttpServletRequest httpRequest, long when, Multimap<String, ?> params,
|
||||
HttpServletRequest httpRequest, long when, ListMultimap<String, ?> params,
|
||||
Object input, int status, Object result, RestResource resource,
|
||||
RestView<RestResource> view) {
|
||||
super(sessionId, who, httpRequest.getRequestURI(), when, params, httpRequest.getMethod(),
|
||||
input, status, result);
|
||||
super(sessionId, who, httpRequest.getRequestURI(), when, params,
|
||||
httpRequest.getMethod(), input, status, result);
|
||||
this.httpRequest = Preconditions.checkNotNull(httpRequest);
|
||||
this.resource = resource;
|
||||
this.view = view;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// limitations under the License.
|
||||
package com.google.gerrit.audit;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
|
||||
public class HttpAuditEvent extends AuditEvent {
|
||||
@@ -34,8 +34,9 @@ public class HttpAuditEvent extends AuditEvent {
|
||||
* @param status HTTP status
|
||||
* @param result result of the event
|
||||
*/
|
||||
public HttpAuditEvent(String sessionId, CurrentUser who, String what, long when,
|
||||
Multimap<String, ?> params, String httpMethod, Object input, int status, Object result) {
|
||||
public HttpAuditEvent(String sessionId, CurrentUser who, String what,
|
||||
long when, ListMultimap<String, ?> params, String httpMethod,
|
||||
Object input, int status, Object result) {
|
||||
super(sessionId, who, what, when, params, result);
|
||||
this.httpMethod = httpMethod;
|
||||
this.input = input;
|
||||
|
||||
@@ -11,9 +11,10 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.audit;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
|
||||
public class RpcAuditEvent extends HttpAuditEvent {
|
||||
@@ -32,8 +33,8 @@ public class RpcAuditEvent extends HttpAuditEvent {
|
||||
* @param result result of the event
|
||||
*/
|
||||
public RpcAuditEvent(String sessionId, CurrentUser who, String what,
|
||||
long when, Multimap<String, ?> params, String httpMethod, Object input,
|
||||
int status, Object result) {
|
||||
long when, ListMultimap<String, ?> params, String httpMethod,
|
||||
Object input, int status, Object result) {
|
||||
super(sessionId, who, what, when, params, httpMethod, input, status, result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,16 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.audit;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
import com.google.gerrit.server.CurrentUser;
|
||||
|
||||
public class SshAuditEvent extends AuditEvent {
|
||||
|
||||
public SshAuditEvent(String sessionId, CurrentUser who, String what,
|
||||
long when, Multimap<String, ?> params, Object result) {
|
||||
long when, ListMultimap<String, ?> params, Object result) {
|
||||
super(sessionId, who, what, when, params, result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user