Home | History | Annotate | Download | only in core
      1 /*
      2  *
      3  * Copyright 2001-2011 Texas Instruments, Inc. - http://www.ti.com/
      4  *
      5  * Licensed under the Apache License, Version 2.0 (the "License");
      6  * you may not use this file except in compliance with the License.
      7  * You may obtain a copy of the License at
      8  *
      9  *    http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package com.ti.jfm.core;
     19 
     20 import java.lang.Enum;
     21 import java.util.EnumSet; //import com.ti.jbtl.core.*;
     22 
     23 import com.ti.jfm.core.*;
     24 
     25 public final class JFmUtils {
     26 
     27     private static final String TAG = "JFmUtils";
     28 
     29     public static <V, E extends Enum<E> & IJFmEnum<V>> E getEnumConst(Class<E> enumType,
     30           V constValue) {
     31        EnumSet<E> es = EnumSet.allOf(enumType);
     32 
     33        E matchingConst = null;
     34 
     35        for (E enumConst : es) {
     36           if (enumConst.getValue().equals(constValue)) {
     37              matchingConst = enumConst;
     38              break;
     39           }
     40        }
     41 
     42        if (matchingConst == null) {
     43           JFmLog.e(TAG, "getEnumConst: Invalid const (" + constValue + ") for "
     44                 + enumType.toString());
     45        }
     46        return matchingConst;
     47     }
     48 }
     49