Example #1
0
  public static <T extends Enum<?>> EnumLookup<T> of(
      Class<T> className, Transform<String, String> t, Map<String, T> extras) {
    String name_ = className.getName();
    int lastDot = name_.lastIndexOf('.');
    EnumLookup<T> result = new EnumLookup<T>(name_.substring(lastDot + 1));

    try {
      result.transform = t = t == null ? CLEAN : t;
      Method m = className.getMethod("values", (Class<?>[]) null);
      @SuppressWarnings("unchecked")
      T[] values = (T[]) m.invoke(null);
      for (T value : values) {
        result.map.put(t.transform(value.name()), value);
        result.map.put(t.transform(value.toString()), value);
      }
    } catch (Exception e) {
      throw new IllegalArgumentException(e);
    }
    if (extras == null) {
      return result;
    }
    for (Entry<String, T> entry : extras.entrySet()) {
      final String key = t.transform(entry.getKey());
      final T newValue = entry.getValue();
      final T old = result.map.get(key);
      if (old == null) {
        result.map.put(key, newValue);
      } else if (old != newValue) {
        throw new IllegalArgumentException(
            "Incompatible mapping: " + key + "=" + old + "!=" + newValue);
      }
    }
    return result;
  }
 /**
  * Normalizes Burmese characters in specified input, detecting and converting Zawgyi encoding to
  * Unicode form.
  *
  * @param value the string to be normalized
  * @return the normalized Unicode string
  */
 public static String standardizeMyanmar(String value) {
   if (isZawgyiEncoded(value)) {
     // Call the converter to produce a Unicode result.
     return zawgyiUnicodeTransliterator.transform(value);
   }
   return value; // Unchanged since it was not Zawgyi.
 }
Example #3
0
 public T forString(String s, boolean allowNull) {
   T result = map.get(transform.transform(s));
   if (!allowNull && result == null) {
     throw new IllegalArgumentException(
         "Can't find match for «" + s + "» in " + map.keySet() + " in " + name);
   }
   return result;
 }
 /**
  * Converts Zawgyi-encoded string into Unicode equivalent.
  *
  * @param value the Zawgyi string to be converted
  * @return the Unicode string from converstion
  */
 public static String convertZawgyiToUnicode(String value) {
   return zawgyiUnicodeTransliterator.transform(value);
 }