Don't use switch on string, for Java 6 compatibility

-------------
Created by MOE: http://code.google.com/p/moe-java
MOE_MIGRATED_REVID=75322297
This commit is contained in:
ejona 2014-09-11 13:53:10 -07:00 committed by Eric Anderson
parent 57bfc6a01d
commit 029f0d22f8
1 changed files with 35 additions and 32 deletions

View File

@ -263,39 +263,42 @@ public class Http2Negotiator {
@Override @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
String methodName = method.getName(); String methodName = method.getName();
switch (methodName) { if ("supports".equals(methodName)) {
case "supports": // both
// both return true;
return true; }
case "unsupported": if ("unsupported".equals(methodName)) {
// both // both
removeMethod.invoke(null, engine); removeMethod.invoke(null, engine);
protocolNegotiated.setException(new IllegalStateException( protocolNegotiated.setException(new IllegalStateException(
"ALPN/NPN protocol " + HTTP_VERSION_NAME + " not supported by server")); "ALPN/NPN protocol " + HTTP_VERSION_NAME + " not supported by server"));
return null; return null;
case "protocols": }
// ALPN only if ("protocols".equals(methodName)) {
return ImmutableList.of(HTTP_VERSION_NAME); // ALPN only
case "selected": return ImmutableList.of(HTTP_VERSION_NAME);
// ALPN only }
// Only 'supports' one protocol so we know what was selected. if ("selected".equals(methodName)) {
removeMethod.invoke(null, engine); // ALPN only
protocolNegotiated.set(null); // Only 'supports' one protocol so we know what was selected.
return null; removeMethod.invoke(null, engine);
case "selectProtocol": protocolNegotiated.set(null);
// NPN only return null;
@SuppressWarnings("unchecked") }
List<String> names = (List<String>) args[0]; if ("selectProtocol".equals(methodName)) {
for (String name : names) { // NPN only
if (name.startsWith(HTTP_VERSION_NAME)) { @SuppressWarnings("unchecked")
protocolNegotiated.set(null); List<String> names = (List<String>) args[0];
return name; 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)); protocolNegotiated.setException(
removeMethod.invoke(null, engine); new IllegalStateException("Protocol not available via ALPN/NPN: " + names));
return null; removeMethod.invoke(null, engine);
return null;
} }
throw new IllegalStateException("Unknown method " + methodName); throw new IllegalStateException("Unknown method " + methodName);
} }