From 029f0d22f83ded28164f3dbca33b55f4c2597f1c Mon Sep 17 00:00:00 2001 From: ejona Date: Thu, 11 Sep 2014 13:53:10 -0700 Subject: [PATCH] Don't use switch on string, for Java 6 compatibility ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=75322297 --- .../newtransport/netty/Http2Negotiator.java | 67 ++++++++++--------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/com/google/net/stubby/newtransport/netty/Http2Negotiator.java b/core/src/main/java/com/google/net/stubby/newtransport/netty/Http2Negotiator.java index 2e39271623..c90610104f 100644 --- a/core/src/main/java/com/google/net/stubby/newtransport/netty/Http2Negotiator.java +++ b/core/src/main/java/com/google/net/stubby/newtransport/netty/Http2Negotiator.java @@ -263,39 +263,42 @@ public class Http2Negotiator { @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); - switch (methodName) { - case "supports": - // both - return true; - case "unsupported": - // both - removeMethod.invoke(null, engine); - protocolNegotiated.setException(new IllegalStateException( - "ALPN/NPN protocol " + HTTP_VERSION_NAME + " not supported by server")); - return null; - case "protocols": - // ALPN only - return ImmutableList.of(HTTP_VERSION_NAME); - case "selected": - // ALPN only - // Only 'supports' one protocol so we know what was selected. - removeMethod.invoke(null, engine); - protocolNegotiated.set(null); - return null; - case "selectProtocol": - // NPN only - @SuppressWarnings("unchecked") - List names = (List) args[0]; - for (String name : names) { - if (name.startsWith(HTTP_VERSION_NAME)) { - protocolNegotiated.set(null); - return name; - } + if ("supports".equals(methodName)) { + // both + return true; + } + if ("unsupported".equals(methodName)) { + // both + removeMethod.invoke(null, engine); + protocolNegotiated.setException(new IllegalStateException( + "ALPN/NPN protocol " + HTTP_VERSION_NAME + " not supported by server")); + return null; + } + if ("protocols".equals(methodName)) { + // ALPN only + return ImmutableList.of(HTTP_VERSION_NAME); + } + if ("selected".equals(methodName)) { + // ALPN only + // Only 'supports' one protocol so we know what was selected. + removeMethod.invoke(null, engine); + protocolNegotiated.set(null); + return null; + } + if ("selectProtocol".equals(methodName)) { + // NPN only + @SuppressWarnings("unchecked") + List names = (List) args[0]; + for (String name : names) { + if (name.startsWith(HTTP_VERSION_NAME)) { + protocolNegotiated.set(null); + return name; } - protocolNegotiated.setException( - new IllegalStateException("Protocol not available via ALPN/NPN: " + names)); - removeMethod.invoke(null, engine); - return null; + } + protocolNegotiated.setException( + new IllegalStateException("Protocol not available via ALPN/NPN: " + names)); + removeMethod.invoke(null, engine); + return null; } throw new IllegalStateException("Unknown method " + methodName); }