Esempio n. 1
0
  public static boolean containsConstant(
      Enum<?>[] enumValues, String constant, boolean caseSensitive) {
    Enum[] arr$ = enumValues;
    int len$ = enumValues.length;
    int i$ = 0;

    while (true) {
      if (i$ >= len$) {
        return false;
      }

      Enum candidate = arr$[i$];
      if (caseSensitive) {
        if (candidate.toString().equals(constant)) {
          break;
        }
      } else if (candidate.toString().equalsIgnoreCase(constant)) {
        break;
      }

      ++i$;
    }

    return true;
  }
Esempio n. 2
0
/* 148:    */   
/* 149:    */   private static AnnotationValue enumValue(String name, DotName typeName, Enum value)
/* 150:    */   {
/* 151:182 */     if ((value != null) && (StringHelper.isNotEmpty(value.toString()))) {
/* 152:183 */       return AnnotationValue.createEnumValue(name, typeName, value.toString());
/* 153:    */     }
/* 154:185 */     return null;
/* 155:    */   }
Esempio n. 3
0
  public static Attributes attributes(Enum<?>... attrs) {
    Attributes res = new Attributes();
    for (Enum<?> attr : attrs) {
      res.generic(attr.toString(), attr.toString());
    }

    return res;
  }
Esempio n. 4
0
 public Description description() {
   Description description = new Description();
   for (Enum<?> e : _includeRanges)
     description.strong(e.toString()).description(", " + e._description).p();
   for (Enum<?> e : _excludeRanges)
     description.strong("not " + e.toString()).description(", " + e._description).p();
   for (Enum<?> e : _enumerations)
     description.strong(e.toString()).description(", " + e._description).p();
   return description;
 }
Esempio n. 5
0
 HashMap<String, CategoryKeyClassDTO> generateRules(EnumSet<RuleTypes> rules) {
   HashMap<String, CategoryKeyClassDTO> keyClasses = new HashMap<String, CategoryKeyClassDTO>();
   HashMap<String, CategoryKeyClassDTO> allClasses = generateAllRules();
   for (Enum<RuleTypes> ruleKey : rules) {
     CategoryKeyClassDTO ruleCategory = allClasses.get(ruleKey.toString());
     if (ruleCategory != null) {
       keyClasses.put(ruleKey.toString(), ruleCategory);
     } else {
       logger.warn(String.format("Rulekey: %s not found", ruleKey.toString()));
     }
   }
   return keyClasses;
 }
Esempio n. 6
0
 private Object enumsToString(Object value) {
   if (value instanceof Enum) {
     final Enum<?> e = (Enum<?>) value;
     value = e.toString();
   }
   return value;
 }
Esempio n. 7
0
  public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
    switch (typeName) {
      case BOOLEAN:
        writer.keyword(value == null ? "UNKNOWN" : (Boolean) value ? "TRUE" : "FALSE");
        break;
      case NULL:
        writer.keyword("NULL");
        break;
      case CHAR:
      case DECIMAL:
      case DOUBLE:
      case BINARY:

        // should be handled in subtype
        throw Util.unexpected(typeName);

      case SYMBOL:
        if (value instanceof Enum) {
          Enum enumVal = (Enum) value;
          writer.keyword(enumVal.toString());
        } else {
          writer.keyword(String.valueOf(value));
        }
        break;
      default:
        writer.literal(value.toString());
    }
  }
  private void addErrorUnsupported(Enum<?> val) {

    delim()
        .append(UNSUPPORTED)
        .append(val.toString())
        .append(Strings.TYPE)
        .append(val.getClass().getSimpleName());
  }
Esempio n. 9
0
 @Override
 public String getLabel(Enum enumValue) {
   if (enumValue != null) {
     return getLabel(enumValue.getClass().getName() + "." + enumValue.toString());
   } else {
     return "";
   }
 }
  public O createObjectInstance(Enum<E> modelObjectType) {

    try {
      return (O) getClassForType(modelObjectType).newInstance();

    } catch (Exception e) {
      throw new ConceptInstantiationException(modelObjectType.toString(), e);
    }
  }
Esempio n. 11
0
  /**
   * Builds the response to be shown.
   *
   * @param logMessageSetVO - Object of LogMessageSetVO containing errors/warnings to be shown.
   * @param isHTML - Whether response is in html format or not.
   * @return - The response string.
   */
  public static String buildResponse(LogMessageSetVO logMessageSetVO, boolean isHTML) {

    // Assume that eCodes contains a list of comma separated error/warning
    // codes
    // Get the Error message for each code and terminate it with <BR> in
    // case of HTML, else terminate with &

    StringBuffer err_buf = new StringBuffer();
    StringBuffer warn_buf = new StringBuffer();
    String errors = "";
    String notices = "";
    Set<LOGMESSAGE> errorSet = logMessageSetVO.getErrorsSet();
    Set<LOGMESSAGE> warningSet = logMessageSetVO.getWarningSet();

    for (Enum<LOGMESSAGE> error : errorSet) {
      // Error
      err_buf.append(error.toString());
    }
    for (Enum<LOGMESSAGE> warning : warningSet) {
      // Error
      err_buf.append(warning.toString());
    }

    if (err_buf.length() > 0)
      errors =
          (isHTML ? "<BR>" : "&")
              + "statusMessage="
              + err_buf.substring(0)
              + (isHTML ? "<BR>" : "&")
              + "statusCode="
              + Status.FAILURE.getCode();
    else errors = "statusMessage=" + Status.SUCCESS + "&statusCode=" + Status.SUCCESS.getCode();
    if (warn_buf.length() > 0)
      notices = (isHTML ? "<BR>" : "&") + "notice=" + warn_buf.substring(0);

    String otherMessages = logMessageSetVO.getOtherMessages();
    otherMessages = otherMessages == null ? "" : otherMessages;

    logger.info("Errors=" + errors);
    logger.info("Notices=" + notices);
    logger.info("Miscellaneous Messages=" + otherMessages);
    return errors + notices + otherMessages;
  }
Esempio n. 12
0
 /**
  * Check whether the given array of enum constants contains a constant with the given name.
  *
  * @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
  * @param constant the constant name to find (must not be null or empty string)
  * @param caseSensitive whether case is significant in determining a match
  * @return whether the constant has been found in the given array
  */
 public static boolean containsConstant(
     Enum<?>[] enumValues, String constant, boolean caseSensitive) {
   for (Enum<?> candidate : enumValues) {
     if (caseSensitive
         ? candidate.toString().equals(constant)
         : candidate.toString().equalsIgnoreCase(constant)) {
       return true;
     }
   }
   return false;
 }
Esempio n. 13
0
 public static String getEnumValue(Enum enumWithValue) {
   Class<?> type = enumWithValue.getClass();
   Field[] fields = type.getDeclaredFields();
   Field field;
   switch (fields.length) {
     case 0:
       return enumWithValue.toString();
     case 1:
       field = fields[0];
       break;
     default:
       try {
         field = type.getField("value");
       } catch (NoSuchFieldException ex) {
         return enumWithValue.toString();
       }
       break;
   }
   return TryCatchUtil.tryGetResult(() -> field.get(enumWithValue).toString());
 }
Esempio n. 14
0
 @Override
 public List<Object> getCompletionTokens() {
   List<Object> result = new ArrayList<Object>();
   Enum<?>[] constants = type.getEnumConstants();
   if (constants != null) {
     List<Enum<?>> list = Arrays.asList(constants);
     for (Enum<?> e : list) {
       result.add(e.toString());
     }
   }
   return result;
 }
Esempio n. 15
0
  /**
   * Get message string with parameters
   *
   * @param key the enum key
   * @param parameters params
   * @return i18n string
   */
  public static String getString(Enum<?> key, Object... parameters) {
    String text = getString(key);

    // Check the trivial cases ...
    if (text == null) {
      return OPEN_ANGLE_BRACKET + key.toString() + CLOSE_ANGLE_BRACKET;
    }
    if (parameters == null || parameters.length == 0) {
      return text;
    }

    return MessageFormat.format(text, parameters);
  }
Esempio n. 16
0
  public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, String constant) {
    Enum[] arr$ = enumValues;
    int len$ = enumValues.length;

    for (int i$ = 0; i$ < len$; ++i$) {
      Enum candidate = arr$[i$];
      if (candidate.toString().equalsIgnoreCase(constant)) {
        return (E) candidate;
      }
    }

    throw new IllegalArgumentException(
        String.format(
            "constant [%s] does not exist in enum type %s",
            new Object[] {constant, enumValues.getClass().getComponentType().getName()}));
  }
Esempio n. 17
0
  public void write(
      JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features)
      throws IOException {
    SerializeWriter out = serializer.getWriter();
    if (object == null) {
      serializer.getWriter().writeNull();
      return;
    }

    if (serializer.isEnabled(SerializerFeature.WriteEnumUsingToString)) {
      Enum<?> e = (Enum<?>) object;
      serializer.write(e.toString());
    } else {
      Enum<?> e = (Enum<?>) object;
      out.writeInt(e.ordinal());
    }
  }
Esempio n. 18
0
  public static Enum<?> setUpEnumAttribute(Scanner scan, Attributes.AttributeEnum attribute) {
    int num;
    Attributes.printEnumNValuesOfEnumAttribute(attribute);
    num =
        makeSureValInRange(
                scan,
                1,
                Attributes.getEnumAttrValues(attribute).length,
                attribute.toString(),
                ValType.INTEGER,
                true,
                true)
            .intValue();

    Enum<?> attr = Attributes.getEnumAttrByVal(num, attribute);
    System.out.println(
        inputString(attr.getClass().getSimpleName(), attr.toString(), StringOption.SELECTED, true));
    return attr;
  }
  @Override
  public void initializeField(
      SelectorFieldBase field, FieldSetting setting, DMOBasedTransformerContext context) {

    try {
      Enum[] enumValues = (Enum[]) Class.forName(setting.getType()).getEnumConstants();

      if (enumValues != null && (field.getOptions() == null || field.getOptions().isEmpty())) {
        List<DefaultSelectorOption<Enum>> options = new ArrayList<>();
        for (Enum enumConstant : enumValues) {
          DefaultSelectorOption<Enum> selectorOption =
              new DefaultSelectorOption<>(enumConstant, enumConstant.toString(), false);

          options.add(selectorOption);
        }
        field.setOptions(options);
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Esempio n. 20
0
  /**
   * Get message string
   *
   * @param key
   * @return i18n string
   */
  private static String getString(Enum<?> key) {
    try {
      return RESOURCE_BUNDLE.getString(key.toString());
    } catch (final Exception err) {
      String msg;

      if (err instanceof NullPointerException) {
        msg = "<No message available>"; // $NON-NLS-1$
      } else if (err instanceof MissingResourceException) {
        msg =
            OPEN_ANGLE_BRACKET
                + "Missing message for key \""
                + key
                + "\" in: "
                + BUNDLE_NAME
                + CLOSE_ANGLE_BRACKET; //$NON-NLS-1$ //$NON-NLS-2$
      } else {
        msg = err.getLocalizedMessage();
      }

      return msg;
    }
  }
Esempio n. 21
0
 void attr(String name, Enum<?> value) {
   attr(name, value.toString());
 }
Esempio n. 22
0
 public String getByEnumWithPrefix(Enum e, String prefix) {
   return map.get(prefix + "." + e.toString().toLowerCase());
 }
Esempio n. 23
0
 public String getBy(Enum e) {
   return map.get(e.toString().toLowerCase());
 }
Esempio n. 24
0
 public XmlStringBuilder optAttribute(String name, Enum<?> value) {
   if (value != null) {
     attribute(name, value.toString());
   }
   return this;
 }
 @Override
 public String getProperty(Enum<?> property, String defaultValue) {
   return getProperty(property.toString(), defaultValue);
 }
 @Override
 public String getProperty(Enum<?> property) {
   return getProperty(property.toString());
 }
 @Override
 public Boolean getPropertyAsBoolean(Enum<?> property, boolean defaultValue) {
   return getPropertyAsBoolean(property.toString(), defaultValue);
 }
 @Override
 public Registration addHandler(Enum<?> eventId, EventHandler handler) {
   checkNotNull(eventId);
   checkNotNull(handler);
   return addHandler(eventId.toString(), handler);
 }
Esempio n. 29
0
 /**
  * Returns a value by {@link Enum}.
  *
  * @param e an enum
  * @return the String at the given enum String
  */
 public String get(final Enum<?> e) {
   return get(e.toString());
 }
 @Override
 public Integer getPropertyAsInteger(Enum<?> property, Integer defaultValue) {
   return getPropertyAsInteger(property.toString(), defaultValue);
 }