1 /*
2  *******************************************************************************
3  * Copyright (C) 2007, International Business Machines Corporation and         *
4  * others. All Rights Reserved.                                                *
5  *******************************************************************************
6  */
7 package com.ibm.icu.dev.test.util;
8 
9 /**
10  * @author srl
11  *
12  */
13 
14 public class DebugUtilities {
15 
16     /**
17      * Count enum types
18      * @return the number of enum types available, starting at 0
19      */
typeCount()20     public static int typeCount() {
21         return DebugUtilitiesData.TYPES.length;
22     }
23 
24     /**
25      * Fetch the name of a particular type of enum
26      * @param type the enum type
27      * @return the name of the enum
28      */
typeString(int type)29     public static String typeString(int type) {
30         return enumString(DebugUtilitiesData.UDebugEnumType, type);
31     }
32 
33     /**
34      * Count the number of available enum values for an item, from 0
35      * @param type which enum to look up, such as DebugUtilitiesData.UCalendarDateFields
36      * @return the number of available enum values
37      */
enumCount(int type)38     public static int enumCount(int type) {
39         return DebugUtilitiesData.NAMES[type].length;
40     }
41 
42     /**
43      * Fetch the name of an enum
44      * @param type which enum to look up, such as DebugUtilitiesData.UCalendarDateFields
45      * @param field which enum value to look up
46      * @return the found name. Will throw an exception on out of bounds.
47      */
enumString(int type, int field)48     public static String enumString(int type, int field) {
49         return DebugUtilitiesData.NAMES[type][field];
50     }
51 
52     /**
53      * Lookup an enum by string
54      * @param type which enum to look up, such as DebugUtilitiesData.UCalendarDateFields
55      * @param string the string to search for
56      * @return the found enum value, or -1 if not found
57      */
enumByString(int type, String string)58     public static int enumByString(int type, String string) {
59         for(int j=0;j<DebugUtilitiesData.NAMES[type].length;j++) {
60             if(string.equals(DebugUtilitiesData.NAMES[type][j])) {
61                 return j;
62             }
63         }
64         return -1;
65     }
66 
67     /**
68      * for consistency checking
69      * @param type the type of enum
70      * @return the expected ordinal value (should be equal to "field")
71      * @internal
72      */
enumArrayValue(int type, int field)73     public static int enumArrayValue(int type, int field) {
74         return DebugUtilitiesData.VALUES[type][field];
75     }
76 
77 }
78