Merge "Bug 9092: revert to org.json temporarily"
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / restconf / restful / utils / ResolveEnumUtil.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.restconf.restful.utils;
9
10 /**
11  * Common util class for resolve enum from String.
12  *
13  */
14 public final class ResolveEnumUtil {
15
16     private ResolveEnumUtil() {
17         throw new UnsupportedOperationException("Util class");
18     }
19
20     /**
21      * Resolve specific type of enum by value.
22      *
23      * @param clazz
24      *             enum
25      * @param value
26      *             string of enum
27      * @return - enum
28      */
29     public static <T> T resolveEnum(final Class<T> clazz, final String value) {
30         for (final T t : clazz.getEnumConstants()) {
31             if (((Enum<?>) t).name().equals(value)) {
32                 return t;
33             }
34         }
35         return null;
36     }
37 }