Example #1
0
 @Nonnull
 public static <T extends Enum<T> & Code.DescriptiveWrapper> String toString(@Nonnull T value) {
   return value.name()
       + "(0x"
       + UnsignedBytes.toString(value.getCode(), 16)
       + "): "
       + value.getDescription();
 }
  /**
   * 根据code查找得到Enum
   *
   * @param code
   * @param values
   * @return
   */
  public static <T extends EnumBase> T getByCode(Object code, T[] values) {
    if (code == null) return null;
    if (code instanceof String && StringUtils.isBlank((String) code)) return null;

    for (T item : values) {
      if (item.getCode().equals(code)) {
        return item;
      }
    }
    return null;
  }
 protected void issueCommand(String command, String content) {
   T response = null;
   String body = issueHttpRequest(command, content);
   try {
     response = context.getMapper().readValue(body, clazz);
   } catch (Exception e) {
     LOGGER.error("cannot parse response body", e);
     throw new TaskletException(); // mark termination
   }
   if (!response.isSucc()) {
     String msg = "driver report error: HTTP {} - {}";
     LOGGER.error(msg, response.getCode(), response.getError());
     throw new TaskletException(); // mark termination
   }
   handleResponse(response); // specific response handling
 }
  protected Window createEditEntityTypeDialog(final EntityKind entityKind, final T entityType) {
    final String code = entityType.getCode();
    String title =
        viewContext.getMessage(Dict.EDIT_TYPE_TITLE_TEMPLATE, entityKind.getDescription(), code);
    return new AbstractRegistrationDialog(viewContext, title, postRegistrationCallback) {
      private final DescriptionField descriptionField;

      {
        descriptionField = createDescriptionField(viewContext);
        descriptionField.setValueAndUnescape(entityType.getDescription());
        addField(descriptionField);
      }

      @Override
      protected void register(AsyncCallback<Void> registrationCallback) {
        entityType.setDescription(descriptionField.getValue());
        viewContext.getService().updateEntityType(entityKind, entityType, registrationCallback);
      }
    };
  }
Example #5
0
 @Nonnull
 public static <T extends Enum<T> & Code.Wrapper> T fromByte(@Nonnull Class<T> type, byte code) {
   for (T value : type.getEnumConstants()) if (value.getCode() == code) return value;
   throw new IllegalArgumentException(
       "Unknown " + type.getSimpleName() + " code 0x" + UnsignedBytes.toString(code, 16));
 }
 public static <T extends EnumBase<K>, K> K getCode(T enumValue) {
   if (enumValue == null) return null;
   return enumValue.getCode();
 }