/*
 * Copyright 2019 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, 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 io.vertx.ext.web.handler.graphql.impl;

import com.fasterxml.jackson.annotation.JsonValue;

/**
 * @author Rogelio Orts
 */
public enum ApolloWSMessageType {
  CONNECTION_INIT("connection_init"),
  CONNECTION_TERMINATE("connection_terminate"),
  START("start"),
  STOP("stop"),
  CONNECTION_ACK("connection_ack"),
  CONNECTION_ERROR("error"),
  CONNECTION_KEEP_ALIVE("ka"),
  DATA("data"),
  ERROR("error"),
  COMPLETE("complete");

  private String text;

  ApolloWSMessageType(String text) {
    this.text = text;
  }

  @JsonValue
  public String getText() {
    return text;
  }

  public static ApolloWSMessageType from(String type) {
    for (ApolloWSMessageType t : values()) {
      if (t.getText().equals(type)) {
        return t;
      }
    }
    return null;
  }
}

@@ -674,50 +674,47 @@
 ort 
-com.fasterxml.jackson.annotation.JsonValue
+java.util.HashMap;%0Aimport java.util.Map
 ;%0A%0A/
@@ -1145,21 +1145,8 @@
  %7D%0A%0A
-  @JsonValue%0A
   pu
@@ -1198,20 +1198,33 @@
 %0A  p
-ublic
+rivate
  static
+ Map%3CString,
  Apo
@@ -1243,26 +1243,60 @@
 Type
- from(String type)
+%3E lookup = new HashMap%3C%3E(values().length);%0A%0A  static
  %7B%0A 
@@ -1323,17 +1323,35 @@
 ageType 
-t
+apolloWSMessageType
  : value
@@ -1367,87 +1367,161 @@
     
-if (t.getText().equals(t
+lookup.put(apolloWSMessageType.text, apolloWSMessageT
 ype)
-) %7B
+;
 %0A    
-    return t;%0A      %7D%0A    %7D%0A    return null
+%7D%0A  %7D%0A%0A  public static ApolloWSMessageType from(String type) %7B%0A    return lookup.get(type)
 ;%0A  

use lookup table instead of iterating through values