package io.scalecube.services.gateway.clientsdk.websocket;

import java.util.Arrays;

public enum Signal {
  COMPLETE(1),
  ERROR(2),
  CANCEL(3);

  private final int code;

  Signal(int code) {
    this.code = code;
  }

  public int code() {
    return code;
  }

  public String codeAsString() {
    return String.valueOf(code);
  }

  /**
   * Return appropriate instance of {@link Signal} for given signal code.
   *
   * @param code signal code
   * @return signal instance
   */
  public static Signal from(String code) {
    return from(Integer.parseInt(code));
  }

  /**
   * Return appropriate instance of {@link Signal} for given signal code.
   *
   * @param code signal code
   * @return signal instance
   */
  public static Signal from(int code) {
    return Arrays.stream(values())
        .filter(s -> s.code == code)
        .findFirst()
        .orElseThrow(() -> new IllegalArgumentException("Unknown signal: " + code));
  }
}

@@ -57,34 +57,8 @@
 t;%0A%0A
-import java.util.Arrays;%0A%0A
 publ
@@ -740,123 +740,164 @@
     
-return Arrays.stream(values())%0A        .filter(s -%3E s.code == code)%0A        .findFirst()%0A        .orElseThrow(() -%3E
+switch (code) %7B%0A      case 1:%0A        return COMPLETE;%0A      case 2:%0A        return ERROR;%0A      case 3:%0A        return CANCEL;%0A      default:%0A        throw
  new
@@ -944,21 +944,26 @@
 l: %22 + code)
-)
 ;
+%0A    %7D
 %0A  %7D%0A%7D%0A

refactor Signal#from