Util { public static <T extends Enum<T>> Map<String, T> enumConstants( Class<T> clazz) { final T[] ts = clazz.getEnumConstants(); if (ts == null) { return null; } ImmutableMap.Builder<String, T> builder = ImmutableMap.builder(); for (T t : ts) { builder.put(t.name(), t); } return builder.build(); } private  Util(); static boolean isSingleValue(SqlCall call); static void discard(Object o); static void discard(int i); static boolean discard(boolean b); static void discard(double d); static void swallow(
      Throwable e,
      Logger logger); static boolean equalShallow(
      List<? extends T> list0, List<? extends T> list1); static int hash(
      int i,
      int j); static int hash(
      int h,
      Object o); static int hashArray(
      int h,
      Object[] a); static int hashCode(double v); static Set<T> minus(Set<T> set1, Set<T> set2); static double nLogN(double d); static void print(
      PrintWriter pw,
      Object o); static void print(
      PrintWriter pw,
      Object o,
      int indent); static void printJavaString(
      PrintWriter pw,
      String s,
      boolean nullMeansNull); static void println(
      PrintWriter pw,
      Object o); static String toScientificNotation(BigDecimal bd); static String replace(
      String s,
      String find,
      String replace); static URL toURL(File file); static String getFileTimestamp(); static String stripDoubleQuotes(String value); static String toJavaId(
      String s,
      int ordinal); static String toLinux(String s); static List<T> toList(Iterator<T> iter); static boolean isNullOrEmpty(String s); static String commaList(List<T> list); static String sepList(List<T> list, String sep); static Charset getDefaultCharset(); static Error newInternal(); static Error newInternal(String s); static Error newInternal(Throwable e); static Error newInternal(Throwable e, String s); static String getMessages(Throwable t); static String getStackTrace(Throwable t); static void pre(boolean b, String description); static void post(boolean b, String description); static void permAssert(boolean b, String description); static RuntimeException needToImplement(Object o); static T deprecated(T argument, boolean fail); static boolean contains(
      String[] a,
      int length,
      String s); static String readAllAsString(Reader reader); static void squelchJar(JarFile jar); static void squelchStream(InputStream stream); static void squelchStream(OutputStream stream); static void squelchReader(Reader reader); static void squelchWriter(Writer writer); static void squelchStmt(Statement stmt); static void squelchConnection(Connection connection); static String rtrim(String s); static String rpad(String s, int len); static String toString(
      Iterable<T> iterable, String start, String sep, String end); static String lines(Iterable<String> strings); static String toPosix(TimeZone tz, boolean verbose); static Locale parseLocale(String localeString); static int runApplication(
      String[] cmdarray,
      Logger logger,
      Reader appInput,
      Writer appOutput); static ProcessBuilder newAppProcess(String[] cmdarray); static int runAppProcess(
      ProcessBuilder pb,
      Logger logger,
      Reader appInput,
      Writer appOutput); static List<E> cast(List<? super E> list, Class<E> clazz); static Iterator<E> cast(
      final Iterator<?> iter,
      final Class<E> clazz); static Iterable<E> cast(
      final Iterable<? super E> iterable,
      final Class<E> clazz); static Iterable<E> filter(
      final Iterable<? extends Object> iterable,
      final Class<E> includeFilter); static Collection<E> filter(
      final Collection<?> collection,
      final Class<E> includeFilter); static List<E> filter(
      final List<?> list,
      final Class<E> includeFilter); static Map<String, String> toMap(
      final Properties properties); static Map<K, V> mapOf(K key, V value, Object... keyValues); static Error unexpected(E value); static Map<String, T> enumConstants(
      Class<T> clazz); static synchronized T enumVal(
      Class<T> clazz,
      String name); static synchronized T enumVal(T default_,
      String name); static List<E> quotientList(
      final List<E> list, final int n, final int k); static T first(T v0, T v1); static double first(Double v0, double v1); static float first(Float v0, float v1); static int first(Integer v0, int v1); static long first(Long v0, long v1); static boolean first(Boolean v0, boolean v1); static short first(Short v0, short v1); static char first(Character v0, char v1); static byte first(Byte v0, byte v1); static Iterable<T> orEmpty(Iterable<T> v0); static E last(List<E> list); static List<E> skipLast(List<E> list); static List<E> skipLast(List<E> list, int n); static List<E> last(List<E> list, int n); static List<E> skip(List<E> list); static List<E> skip(List<E> list, int fromIndex); static List<Integer> range(final int end); static List<Integer> range(final int start, final int end); static boolean isDistinct(List<E> list); static int firstDuplicate(List<E> list); static int findMatch(List<String> strings, String seek,
      boolean caseSensitive); static boolean matches(boolean caseSensitive, String s0, String s1); static boolean startsWith(List<E> list0, List<E> list1); static String human(double d); static Map<K, V> asIndexMap(
      final Collection<V> values,
      final Function<V, K> function); static void debugCode(PrintStream out, String code); static boolean getBooleanProperty(String property); static final String LINE_SEPARATOR; static final String FILE_SEPARATOR; static final String FILE_TIMESTAMP_FORMAT; }
@Test public void testEnumConstants() { final Map<String, MemoryType> memoryTypeMap = Util.enumConstants(MemoryType.class); assertEquals(2, memoryTypeMap.size()); assertEquals(MemoryType.HEAP, memoryTypeMap.get("HEAP")); assertEquals(MemoryType.NON_HEAP, memoryTypeMap.get("NON_HEAP")); try { memoryTypeMap.put("FOO", null); fail("expected exception"); } catch (UnsupportedOperationException e) { } assertEquals("HEAP", Util.enumVal(MemoryType.class, "HEAP").name()); assertNull(Util.enumVal(MemoryType.class, "heap")); assertNull(Util.enumVal(MemoryType.class, "nonexistent")); }