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