From cd9042b49b903a3dac8ab92e5ec10382b30f4c20 Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Sat, 18 Jun 2016 14:43:56 -0700 Subject: [PATCH] core: Harden ServiceDescriptor API Over-specifying List prevents fewer things to be passed in and makes it less efficient to use a Map later. We definitely don't want people extending this class. --- core/src/main/java/io/grpc/ServiceDescriptor.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/io/grpc/ServiceDescriptor.java b/core/src/main/java/io/grpc/ServiceDescriptor.java index 3d0fc7167a..056c735bdd 100644 --- a/core/src/main/java/io/grpc/ServiceDescriptor.java +++ b/core/src/main/java/io/grpc/ServiceDescriptor.java @@ -35,22 +35,22 @@ import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; -import java.util.List; /** * Descriptor for a service. */ -public class ServiceDescriptor { +public final class ServiceDescriptor { private final String name; - private final List> methods; + private final Collection> methods; public ServiceDescriptor(String name, MethodDescriptor... methods) { this(name, Arrays.asList(methods)); } - public ServiceDescriptor(String name, List> methods) { + public ServiceDescriptor(String name, Collection> methods) { this.name = Preconditions.checkNotNull(name); this.methods = Collections.unmodifiableList(new ArrayList>(methods)); } @@ -61,9 +61,10 @@ public class ServiceDescriptor { } /** - * A list of {@link MethodDescriptor} instances describing the methods exposed by the service. + * A collection of {@link MethodDescriptor} instances describing the methods exposed by the + * service. */ - public List> getMethods() { + public Collection> getMethods() { return methods; } }